diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt index 4f43e4c8cdd87d835a5d72987981253e742c5a75..b905677103a65b579a0f3b4b0374ba182ff1ace5 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 d7b8addb2e99772acad02e51a1f5ccaf5645ab81..3ddd0758430a141657dfcdc6b28f140c4bd2c7c9 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 c5c2baf07a0227070b72ec8eb86b9af0534b15a7..4eb3de4e1ab88703e9fe3e652a35d7f8a44fd5b8 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 7fdd3990ce313a5a77e37aa9215a7dbd1742ed24..e586e6b4c7db220cdb802537312af4ff862b3573 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 7fbf604c47b568881b068a798d4cc32e2afefa21..bf18ff7df07b4eb1e13d4a8c273fecd9283be267 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 9f6f3ab7a716111629a7cd1df78c5c715f09134e..3731b98fa2dd1096d357de53ee0defcd8adf037f 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 ed262d57ac952fb298a66ea98a5882ba37af79f7..a976849fac0e0df9d224e96f3d4d87bda1d97695 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 0b643ac101aa82c21559e123d221ba1ac750bdf5..bf504c7cf1e3f6616ccf64d0ae1edc02d9fbc1dc 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 645c2acdd142bdb2d949419ec4e3ea00e7e87e4f..506014e0a6569c1f0ef2fe9c77387eb5fb300b40 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 fdc953116f4032ba41e75af6ba1e8a1082ddb212..98c11167ae06cfc5552c4835e954aaa2e4a8b411 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 b7c5e811b2e7e53d09422192fae3a68ab30468c4..ffdc3e6d55f55721229c902f8aaba36df625355f 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 fb3574e57053436019a9c74cdc4d82e71268bcf5..dfe05009d05b63120d212f6208b05e929bf47e4f 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 5bef38aaf3e5ff446a839703e425f9dd3c5e22d8..2479e9429ba2f82522a28f24ce1aba76816063ec 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 3c6fc2eee9a9bde99682633d0922d9a06629875f..474389c9283b08c672186fe11504351db88995c6 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 20033a1d5084921f7d033dd3f5cb7cca6409c90c..b44d5ea5e842f205c0a5ead7f5eba3887f5da591 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 abbedf3c0acc1e1de4afc59b7a9c526a05928783..67a254989a9e56775787bf395934a3d5b299d694 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 2b0143c52ecbfc6fc140841d3e0166b13a87a44d..118d2f1625f704f4967a66e6c27a0a3fdaeb2895 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 8ba7877cfa7a0a279c1520e64a2a4db015a312b4..7b168037d7f4d4874b065ece6654ccb2d92e93ec 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 ba1facf34f4af8ca24f6fad72f5f8ed9d72297b7..17f1726902cfb61ee9162420ff781ae99abb55ea 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 d17a9daff0621a884543b63a92a3e1541131a544..bd3e1fb691084c07617b8ecc47d674443e38590b 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 a2e2cddb19d6485d5206489234f446bbf425d1d8..fdd38896d664e6f793a1fffe7cc39a0c25d09067 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 a9961d69bc22b8321577f1c7bb9bc37965f67360..fb98f11f212e40616e0907c2c61c71e7214c3d65 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)})