From 2f1990d7e1e1aa6b9f53c74c70a5e897a4d66e45 Mon Sep 17 00:00:00 2001 From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de> Date: Thu, 4 Feb 2021 21:35:18 +0100 Subject: [PATCH] Improve code style Add KDoc comments, Renaming modify visibility of variables (make them private) apply code style suggestion of intellji ... --- .../theodolite/execution/BenchmarkExecutor.kt | 15 +++++++++++ ...rkExecutor.kt => BenchmarkExecutorImpl.kt} | 2 +- ...ecutor.kt => TestBenchmarkExecutorImpl.kt} | 2 +- .../execution/TheodoliteExecutor.kt | 17 ++++++------ .../kotlin/theodolite/k8s/ConfigMapManager.kt | 11 +++----- .../theodolite/k8s/DeploymentManager.kt | 11 +++----- .../kotlin/theodolite/k8s/ServiceManager.kt | 7 +---- .../kotlin/theodolite/k8s/TopicManager.kt | 2 +- .../kotlin/theodolite/k8s/UC1Benchmark.kt | 26 +++++++++---------- .../k8s/WorkloadGeneratorStateCleaner.kt | 10 +++---- .../main/kotlin/theodolite/k8s/YamlLoader.kt | 24 +++++------------ .../restriction/LowerBoundRestriction.kt | 5 ++++ .../restriction/RestrictionStrategy.kt | 11 ++++++++ .../strategies/searchstrategy/BinarySearch.kt | 16 +++++++----- .../searchstrategy/CompositeStrategy.kt | 2 +- .../strategies/searchstrategy/LinearSearch.kt | 2 +- .../searchstrategy/SearchStrategy.kt | 9 ++++++- .../main/kotlin/theodolite/util/Benchmark.kt | 1 - .../kotlin/theodolite/util/LoadDimension.kt | 2 +- .../main/kotlin/theodolite/util/Resource.kt | 2 +- .../main/kotlin/theodolite/util/Results.kt | 4 +-- .../theodolite/CompositeStrategyTest.kt | 22 +++++++--------- 22 files changed, 107 insertions(+), 96 deletions(-) rename theodolite-quarkus/src/main/kotlin/theodolite/execution/{KafkaBenchmarkExecutor.kt => BenchmarkExecutorImpl.kt} (83%) rename theodolite-quarkus/src/main/kotlin/theodolite/execution/{TestBenchmarkExecutor.kt => TestBenchmarkExecutorImpl.kt} (82%) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt index 4f43e4c8c..b90567710 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt @@ -6,6 +6,21 @@ import theodolite.util.Resource import theodolite.util.Results import java.time.Duration +/** + * The Benchmark Executor runs a single experiment. + * + * @property benchmark + * @property results + * @property executionDuration + * @constructor Create empty Benchmark executor + */ abstract class BenchmarkExecutor(val benchmark: Benchmark, val results: Results, val executionDuration: Duration) { + /** + * Run a experiment for the given parametrization, evaluate the experiment and save the result. + * + * @param load load to be tested. + * @param res resources to be tested. + * @return True, if the number of resources are suitable for the given load, false otherwise. + */ abstract fun runExperiment(load: LoadDimension, res: Resource): Boolean; } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/KafkaBenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt similarity index 83% rename from theodolite-quarkus/src/main/kotlin/theodolite/execution/KafkaBenchmarkExecutor.kt rename to theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt index d7b8addb2..3ddd07584 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/KafkaBenchmarkExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt @@ -9,7 +9,7 @@ import java.time.Duration private val logger = KotlinLogging.logger {} -class KafkaBenchmarkExecutor(benchmark: Benchmark, results: Results, executionDuration: Duration) : BenchmarkExecutor(benchmark, results, executionDuration) { +class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDuration: Duration) : BenchmarkExecutor(benchmark, results, executionDuration) { override fun runExperiment(load: LoadDimension, res: Resource): Boolean { benchmark.start(load, res) this.waitAndLog() diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutorImpl.kt similarity index 82% rename from theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt rename to theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutorImpl.kt index c5c2baf07..4eb3de4e1 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutorImpl.kt @@ -8,7 +8,7 @@ import theodolite.util.Resource import theodolite.util.Results import java.time.Duration -class TestBenchmarkExecutor(private val mockResults: Array<Array<Boolean>>, benchmark: Benchmark, results: Results): +class TestBenchmarkExecutorImpl(private val mockResults: Array<Array<Boolean>>, benchmark: Benchmark, results: Results): BenchmarkExecutor(benchmark, results, executionDuration = Duration.ofSeconds(1)) { override fun runExperiment(load: LoadDimension, res: Resource): Boolean { diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt index 7fdd3990c..e586e6b4c 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt @@ -14,7 +14,7 @@ import java.time.Duration private val logger = KotlinLogging.logger {} class TheodoliteExecutor() { - val path = "/home/lorenz/git/spesb/theodolite-quarkus/src/main/resources/yaml" + private val path = "/home/lorenz/git/spesb/theodolite-quarkus/src/main/resources/yaml" private fun loadConfig(): Config { val benchmark: UC1Benchmark = UC1Benchmark( UC1Benchmark.UC1BenchmarkConfig( // use port forward 2181 -> 2181 @@ -25,10 +25,10 @@ class TheodoliteExecutor() { kafkaReplication = 1, kafkaTopics = listOf("input", "output"), // TODO("handle path in a more nice way (not absolut)") - ucDeploymentPath = path + "/aggregation-deployment.yaml", - ucServicePath = path + "/aggregation-service.yaml", - wgDeploymentPath = path + "/workloadGenerator.yaml", - configMapPath = path + "/jmx-configmap.yaml", + ucDeploymentPath = "$path/aggregation-deployment.yaml", + ucServicePath = "$path/aggregation-service.yaml", + wgDeploymentPath = "$path/workloadGenerator.yaml", + configMapPath = "$path/jmx-configmap.yaml", ucImageURL = "ghcr.io/cau-se/theodolite-uc1-kstreams-app:latest", wgImageURL = "ghcr.io/cau-se/theodolite-uc1-workload-generator:theodolite-kotlin-latest" ) @@ -37,10 +37,10 @@ class TheodoliteExecutor() { val executionDuration = Duration.ofSeconds(60 * 5) - val executor: BenchmarkExecutor = KafkaBenchmarkExecutor(benchmark, results, executionDuration) + val executor: BenchmarkExecutor = BenchmarkExecutorImpl(benchmark, results, executionDuration) val restrictionStrategy = LowerBoundRestriction(results) - val searchStrategy = LinearSearch(executor, results) + val searchStrategy = LinearSearch(executor) return Config( loads = (1..6).map { number -> LoadDimension(number) }, @@ -48,8 +48,7 @@ class TheodoliteExecutor() { compositeStrategy = CompositeStrategy( executor, searchStrategy, - restrictionStrategies = setOf(restrictionStrategy), - results = results + restrictionStrategies = setOf(restrictionStrategy) ), executionDuration = executionDuration ) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ConfigMapManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ConfigMapManager.kt index 7fbf604c4..bf18ff7df 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ConfigMapManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ConfigMapManager.kt @@ -3,18 +3,13 @@ package theodolite.k8s import io.fabric8.kubernetes.api.model.ConfigMap import io.fabric8.kubernetes.client.NamespacedKubernetesClient -class ConfigMapManager(client: NamespacedKubernetesClient) { - var client: NamespacedKubernetesClient - - init { - this.client = client - } +class ConfigMapManager(private val client: NamespacedKubernetesClient) { fun deploy(configMap: ConfigMap) { - client.configMaps().createOrReplace(configMap) + this.client.configMaps().createOrReplace(configMap) } fun delete(configMap: ConfigMap) { - client.configMaps().delete(configMap) + this.client.configMaps().delete(configMap) } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt index 9f6f3ab7a..3731b98fa 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt @@ -10,12 +10,7 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} -class DeploymentManager(client: NamespacedKubernetesClient) { - var client: NamespacedKubernetesClient - - init { - this.client = client - } +class DeploymentManager(private val client: NamespacedKubernetesClient) { /** * Sets the ContainerEvironmentVariables, creates new if variable don t exist. @@ -75,11 +70,11 @@ class DeploymentManager(client: NamespacedKubernetesClient) { // TODO potential add exception handling fun deploy(deployment: Deployment) { - client.apps().deployments().createOrReplace(deployment) + this.client.apps().deployments().createOrReplace(deployment) } // TODO potential add exception handling fun delete(deployment: Deployment) { - client.apps().deployments().delete(deployment) + this.client.apps().deployments().delete(deployment) } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ServiceManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ServiceManager.kt index ed262d57a..a976849fa 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ServiceManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/ServiceManager.kt @@ -3,12 +3,7 @@ package theodolite.k8s import io.fabric8.kubernetes.api.model.Service import io.fabric8.kubernetes.client.NamespacedKubernetesClient -class ServiceManager(client: NamespacedKubernetesClient) { - var client: NamespacedKubernetesClient - - init { - this.client = client - } +class ServiceManager(private val client: NamespacedKubernetesClient) { fun changeServiceName(service: Service, newName: String) { diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt index 0b643ac10..bf504c7cf 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt @@ -9,7 +9,7 @@ import org.apache.kafka.clients.admin.NewTopic private val logger = KotlinLogging.logger {} class TopicManager(boostrapIp: String) { - val props = hashMapOf<String, Any>(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG to boostrapIp) + private val props = hashMapOf<String, Any>(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG to boostrapIp) lateinit var kafkaAdmin: AdminClient init { diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/UC1Benchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/UC1Benchmark.kt index 645c2acdd..506014e0a 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/UC1Benchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/UC1Benchmark.kt @@ -13,19 +13,19 @@ import theodolite.util.Resource private val logger = KotlinLogging.logger {} class UC1Benchmark(config: UC1BenchmarkConfig) : Benchmark(config) { - val workloadGeneratorStateCleaner: WorkloadGeneratorStateCleaner - val topicManager: TopicManager + private val workloadGeneratorStateCleaner: WorkloadGeneratorStateCleaner + private val topicManager: TopicManager // TODO("service monitor") - val kubernetesClient: NamespacedKubernetesClient - val yamlLoader: YamlLoader - val deploymentManager: DeploymentManager - val serviceManager: ServiceManager - val configMapManager: ConfigMapManager - var ucDeployment: Deployment - var ucService: Service - var wgDeployment: Deployment - var configMap: ConfigMap + private val kubernetesClient: NamespacedKubernetesClient + private val yamlLoader: YamlLoader + private val deploymentManager: DeploymentManager + private val serviceManager: ServiceManager + private val configMapManager: ConfigMapManager + private var ucDeployment: Deployment + private var ucService: Service + private var wgDeployment: Deployment + private var configMap: ConfigMap init { @@ -92,8 +92,8 @@ class UC1Benchmark(config: UC1BenchmarkConfig) : Benchmark(config) { //environmentVariables.put("KAFKA_BOOTSTRAP_SERVERS", this.config.kafkaIPConnectionString) //environmentVariables.put("ZK_HOST", this.config.zookeeperConnectionString.split(":")[0]) //environmentVariables.put("ZK_PORT", this.config.zookeeperConnectionString.split(":")[1]) - environmentVariables.put("NUM_SENSORS", load.get().toString()) - environmentVariables.put("INSTANCES", requiredInstances.toString()) + environmentVariables["NUM_SENSORS"] = load.get().toString() + environmentVariables["INSTANCES"] = requiredInstances.toString() this.deploymentManager.setWorkloadEnv(this.wgDeployment, "workload-generator", environmentVariables) this.deploymentManager.deploy(this.wgDeployment) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt index fdc953116..98c11167a 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt @@ -10,14 +10,14 @@ private val logger = KotlinLogging.logger {} class WorkloadGeneratorStateCleaner(ip: String) { - val path = "/workload-generation" - val sessionTimeout = 60 - val retryTime = 3000L + private val path = "/workload-generation" + private val sessionTimeout = 60 + private val retryTime = 3000L lateinit var zookeeperClient: ZooKeeper init { try { - val watcher: Watcher = ZookeperWatcher() // defined below + val watcher: Watcher = ZookeeperWatcher() // defined below zookeeperClient = ZooKeeper(ip, sessionTimeout, watcher) } catch (e: Exception) { logger.error {e.toString()} @@ -57,7 +57,7 @@ class WorkloadGeneratorStateCleaner(ip: String) { logger.info {"ZooKeeper reset was successful"} } - private class ZookeperWatcher : Watcher { + private class ZookeeperWatcher : Watcher { override fun process(event: WatchedEvent) {} } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/YamlLoader.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/YamlLoader.kt index b7c5e811b..ffdc3e6d5 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/YamlLoader.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/YamlLoader.kt @@ -9,12 +9,7 @@ import mu.KotlinLogging private val logger = KotlinLogging.logger {} -class YamlLoader(client: NamespacedKubernetesClient) { - var client: NamespacedKubernetesClient - - init { - this.client = client - } +class YamlLoader(private val client: NamespacedKubernetesClient) { /** * Parses a Service from a servive yaml @@ -22,9 +17,7 @@ class YamlLoader(client: NamespacedKubernetesClient) { * @return service from fabric8 */ fun loadService(path: String): Service { - - val service = loadGenericRessource(path, { x: String -> client.services().load(x).get() }) - return service + return loadGenericRessource(path) { x: String -> client.services().load(x).get() } } /** @@ -33,10 +26,7 @@ class YamlLoader(client: NamespacedKubernetesClient) { * @return service from fabric8 */ fun loadServiceMonitor(path: String): CustomResourceDefinition { - - val serviceMonitor = - loadGenericRessource(path, { x: String -> client.customResourceDefinitions().load(x).get() }) - return serviceMonitor + return loadGenericRessource(path) { x: String -> client.customResourceDefinitions().load(x).get() } } /** @@ -45,8 +35,7 @@ class YamlLoader(client: NamespacedKubernetesClient) { * @return Deployment from fabric8 */ fun loadDeployment(path: String): Deployment { - val deployment = loadGenericRessource(path, { x: String -> client.apps().deployments().load(x).get() }) - return deployment + return loadGenericRessource(path) { x: String -> client.apps().deployments().load(x).get() } } /** @@ -55,8 +44,7 @@ class YamlLoader(client: NamespacedKubernetesClient) { * @return ConfigMap from fabric8 */ fun loadConfigmap(path: String): ConfigMap { - val configMap = loadGenericRessource(path, { x: String -> client.configMaps().load(x).get() }) - return configMap + return loadGenericRessource(path) { x: String -> client.configMaps().load(x).get() } } /** @@ -75,7 +63,7 @@ class YamlLoader(client: NamespacedKubernetesClient) { } if (resource == null) { - throw NullPointerException("The Ressource at path: " + path + " could not be loaded") + throw NullPointerException("The Ressource at path: $path could not be loaded") } return resource diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt index fb3574e57..dfe05009d 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt @@ -4,6 +4,11 @@ import theodolite.util.Results import theodolite.util.LoadDimension import theodolite.util.Resource +/** + * The Lower Bound Restriction + * + * @param results Result object used as a basis to restrict the resources. + */ class LowerBoundRestriction(results: Results) : RestrictionStrategy(results) { override fun next(load: LoadDimension, resources: List<Resource>): List<Resource> { val maxLoad: LoadDimension? = this.results.getMaxBenchmarkedLoad(load) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt index 5bef38aaf..2479e9429 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt @@ -4,6 +4,17 @@ import theodolite.util.Results import theodolite.util.LoadDimension import theodolite.util.Resource + +/** + * A "Restriction Strategy" restricts a list of resources based on the current results of all previously performed benchmarks. + */ abstract class RestrictionStrategy(val results: Results) { + /** + * Next Restrict the given resource list for the given load based on the result object. + * + * @param load Load dimension for which a subset of resources are required. + * @param resources List of resources to be restricted. + * @return Returns a list containing only elements that have not been filtered out by the restriction (possibly empty). + */ public abstract fun next(load: LoadDimension, resources: List<Resource>): List<Resource> } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt index 3c6fc2eee..474389c92 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt @@ -3,19 +3,23 @@ package theodolite.strategies.searchstrategy import theodolite.execution.BenchmarkExecutor import theodolite.util.LoadDimension import theodolite.util.Resource -import theodolite.util.Results import java.lang.IllegalArgumentException -class BinarySearch(benchmarkExecutor: BenchmarkExecutor, results: Results) : SearchStrategy(benchmarkExecutor, results) { +/** + * Search for the smallest suitable resource with binary search. + * + * @param benchmarkExecutor Benchmark executor which runs the individual benchmarks. + */ +class BinarySearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchmarkExecutor) { override fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource? { - val result = search(load, resources, 0, resources.size - 1) + val result = binarySearch(load, resources, 0, resources.size - 1) if( result == -1 ) { return null; } return resources[result] } - private fun search (load: LoadDimension, resources: List<Resource>, lower: Int, upper: Int): Int { + private fun binarySearch (load: LoadDimension, resources: List<Resource>, lower: Int, upper: Int): Int { if (lower > upper) { throw IllegalArgumentException() } @@ -33,9 +37,9 @@ class BinarySearch(benchmarkExecutor: BenchmarkExecutor, results: Results) : Sea if (mid == lower) { return lower } - return search(load, resources, lower, mid - 1 ) + return binarySearch(load, resources, lower, mid - 1 ) } else { - return search(load, resources, mid + 1 , upper) + return binarySearch(load, resources, mid + 1 , upper) } } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt index 20033a1d5..b44d5ea5e 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt @@ -6,7 +6,7 @@ import theodolite.util.LoadDimension import theodolite.util.Resource import theodolite.util.Results -class CompositeStrategy(benchmarkExecutor: BenchmarkExecutor, val searchStrategy: SearchStrategy, val restrictionStrategies: Set<RestrictionStrategy>, results: Results) : SearchStrategy(benchmarkExecutor, results) { +class CompositeStrategy(benchmarkExecutor: BenchmarkExecutor, private val searchStrategy: SearchStrategy, val restrictionStrategies: Set<RestrictionStrategy>) : SearchStrategy(benchmarkExecutor) { override fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource? { var restrictedResources = resources.toList() diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt index abbedf3c0..67a254989 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt @@ -5,7 +5,7 @@ import theodolite.util.LoadDimension import theodolite.util.Resource import theodolite.util.Results -class LinearSearch(benchmarkExecutor: BenchmarkExecutor, results: Results) : SearchStrategy(benchmarkExecutor, results) { +class LinearSearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchmarkExecutor) { override fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource? { for (res in resources) { diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt index 2b0143c52..118d2f162 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt @@ -5,6 +5,13 @@ import theodolite.util.LoadDimension import theodolite.util.Resource import theodolite.util.Results -abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor, val results: Results) { +abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor) { + /** + * Find smallest suitable resource from the specified resource list for the given load. + * + * @param load Load to be tested. + * @param resources List of all possible resources. + * @return suitable resource for the specified load, or null if no suitable resource exists. + */ abstract fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource?; } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/Benchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Benchmark.kt index 8ba7877cf..7b168037d 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/Benchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Benchmark.kt @@ -2,7 +2,6 @@ package theodolite.util import theodolite.k8s.UC1Benchmark -// todo: needs cluster and resource config abstract class Benchmark(val config: UC1Benchmark.UC1BenchmarkConfig) { fun start(load: LoadDimension, resources: Resource) { this.initializeClusterEnvironment() diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt index ba1facf34..17f172690 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt @@ -1,6 +1,6 @@ package theodolite.util -data class LoadDimension(val number: Int) { +data class LoadDimension(private val number: Int) { public fun get(): Int { return this.number; } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt index d17a9daff..bd3e1fb69 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt @@ -1,6 +1,6 @@ package theodolite.util -data class Resource(val number: Int) { +data class Resource(private val number: Int) { public fun get(): Int { return this.number; } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt index a2e2cddb1..fdd38896d 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt @@ -9,11 +9,11 @@ class Results { private val results: MutableMap<Pair<LoadDimension, Resource>, Boolean> = mutableMapOf() // multi map guava public fun setResult(experiment: Pair<LoadDimension, Resource>, successful: Boolean) { - this.results.put(experiment, successful) + this.results[experiment] = successful } public fun getResult (experiment: Pair<LoadDimension, Resource>): Boolean? { - return this.results.get(experiment) + return this.results[experiment] } public fun getMinRequiredInstances(load: LoadDimension?): Resource? { diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt index a9961d69b..fb98f11f2 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt @@ -7,9 +7,7 @@ import theodolite.strategies.searchstrategy.LinearSearch import theodolite.strategies.searchstrategy.BinarySearch import theodolite.strategies.restriction.LowerBoundRestriction import theodolite.strategies.searchstrategy.CompositeStrategy -import theodolite.execution.TestBenchmarkExecutor -import theodolite.strategies.restriction.RestrictionStrategy -import theodolite.strategies.searchstrategy.SearchStrategy +import theodolite.execution.TestBenchmarkExecutorImpl import theodolite.util.* @QuarkusTest @@ -30,10 +28,10 @@ class CompositeStrategyTest { val mockResources: List<Resource> = (0..6).map{number -> Resource(number)} val results: Results = Results(); val benchmark = TestBenchmark() - val benchmarkExecutor: TestBenchmarkExecutor = TestBenchmarkExecutor(mockResults, benchmark, results) - val linearSearch: LinearSearch = LinearSearch(benchmarkExecutor, results); + val benchmarkExecutor: TestBenchmarkExecutorImpl = TestBenchmarkExecutorImpl(mockResults, benchmark, results) + val linearSearch: LinearSearch = LinearSearch(benchmarkExecutor); val lowerBoundRestriction: LowerBoundRestriction = LowerBoundRestriction(results); - val strategy: CompositeStrategy = CompositeStrategy(benchmarkExecutor, linearSearch, setOf(lowerBoundRestriction), results) + val strategy: CompositeStrategy = CompositeStrategy(benchmarkExecutor, linearSearch, setOf(lowerBoundRestriction)) val actual: ArrayList<Resource?> = ArrayList<Resource?>() val expected: ArrayList<Resource?> = ArrayList(listOf(0,2,2,3,4,6).map{ x -> Resource(x)}) @@ -61,10 +59,10 @@ class CompositeStrategyTest { val mockResources: List<Resource> = (0..6).map{number -> Resource(number)} val results: Results = Results(); val benchmark = TestBenchmark() - val benchmarkExecutor: TestBenchmarkExecutor = TestBenchmarkExecutor(mockResults, benchmark, results) - val binarySearch: BinarySearch = BinarySearch(benchmarkExecutor, results); + val benchmarkExecutorImpl: TestBenchmarkExecutorImpl = TestBenchmarkExecutorImpl(mockResults, benchmark, results) + val binarySearch: BinarySearch = BinarySearch(benchmarkExecutorImpl); val lowerBoundRestriction: LowerBoundRestriction = LowerBoundRestriction(results); - val strategy: CompositeStrategy = CompositeStrategy(benchmarkExecutor, binarySearch, setOf(lowerBoundRestriction), results) // sets instead of lists + val strategy: CompositeStrategy = CompositeStrategy(benchmarkExecutorImpl, binarySearch, setOf(lowerBoundRestriction)) val actual: ArrayList<Resource?> = ArrayList<Resource?>() val expected: ArrayList<Resource?> = ArrayList(listOf(0,2,2,3,4,6).map{ x -> Resource(x)}) @@ -92,10 +90,10 @@ class CompositeStrategyTest { val mockResources: List<Resource> = (0..7).map{number -> Resource(number)} val results: Results = Results(); val benchmark = TestBenchmark() - val benchmarkExecutor: TestBenchmarkExecutor = TestBenchmarkExecutor(mockResults, benchmark, results) - val binarySearch: BinarySearch = BinarySearch(benchmarkExecutor, results); + val benchmarkExecutor: TestBenchmarkExecutorImpl = TestBenchmarkExecutorImpl(mockResults, benchmark, results) + val binarySearch: BinarySearch = BinarySearch(benchmarkExecutor); val lowerBoundRestriction: LowerBoundRestriction = LowerBoundRestriction(results); - val strategy: CompositeStrategy = CompositeStrategy(benchmarkExecutor, binarySearch, setOf(lowerBoundRestriction), results) // sets instead of lists + val strategy: CompositeStrategy = CompositeStrategy(benchmarkExecutor, binarySearch, setOf(lowerBoundRestriction)) val actual: ArrayList<Resource?> = ArrayList<Resource?>() val expected: ArrayList<Resource?> = ArrayList(listOf(0,2,2,3,4,6,7).map{ x -> Resource(x)}) -- GitLab