diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt index a21d2c747b3870567f7306de4fdf853470dc8c09..8c15fa1dc60d2d72a5b30508ea4570b8449f817b 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt @@ -1,9 +1,13 @@ package theodolite.benchmark -import theodolite.util.LoadDimension import theodolite.util.ConfigurationOverride +import theodolite.util.LoadDimension import theodolite.util.Resource interface Benchmark { - fun buildDeployment(load: LoadDimension, res: Resource, configurationOverrides: List<ConfigurationOverride>): BenchmarkDeployment -} \ No newline at end of file + fun buildDeployment( + load: LoadDimension, + res: Resource, + configurationOverrides: List<ConfigurationOverride> + ): BenchmarkDeployment +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkDeployment.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkDeployment.kt index 5cba87f9b52d2b16a9fcf46d650758ff00d86a49..df01fae2ece683a9bec6ad0d8489987f94249375 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkDeployment.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkDeployment.kt @@ -3,4 +3,4 @@ package theodolite.benchmark interface BenchmarkDeployment { fun setup() fun teardown() -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt index bb816fb1d268d67a19e82f61dfb61154f77017e1..32b06d10f609b8898ac94d514baf4f293b1a2c97 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt @@ -3,7 +3,6 @@ package theodolite.benchmark import theodolite.util.ConfigurationOverride import kotlin.properties.Delegates - class BenchmarkExecution { lateinit var name: String lateinit var benchmark: String @@ -14,13 +13,13 @@ class BenchmarkExecution { lateinit var configOverrides: List<ConfigurationOverride> class Execution { - lateinit var strategy: String + lateinit var strategy: String var duration by Delegates.notNull<Long>() var repetitions by Delegates.notNull<Int>() lateinit var restrictions: List<String> } - class Slo{ + class Slo { lateinit var sloType: String var threshold by Delegates.notNull<Int>() } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index 69e45e46ab37b1b32ae4a1178ee35abe12b4582d..1aab9716438375923342c28193733eae2ea909a9 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -7,16 +7,14 @@ import theodolite.patcher.PatcherManager import theodolite.util.* import java.util.* -class KubernetesBenchmark: Benchmark { +class KubernetesBenchmark : Benchmark { lateinit var name: String - private lateinit var appResource: List<String> - private lateinit var loadGenResource: List<String> - private lateinit var resourceTypes: List<TypeName> - private lateinit var loadTypes: List<TypeName> - private lateinit var kafkaConfig: KafkaConfig - private lateinit var zookeeperConfig: HashMap<String,String> - - + lateinit var appResource: List<String> + lateinit var loadGenResource: List<String> + lateinit var resourceTypes: List<TypeName> + lateinit var loadTypes: List<TypeName> + lateinit var kafkaConfig: KafkaConfig + lateinit var zookeeperConfig: HashMap<String, String> private fun loadKubernetesResources(resources: List<String>): List<Pair<String, KubernetesResource>> { val basePath = "./../../../resources/main/yaml/" @@ -25,13 +23,17 @@ class KubernetesBenchmark: Benchmark { return resources .map { resource -> val resourcePath = "$basePath/$resource" - val kind = parser.parse(resourcePath, HashMap<String, String>()::class.java)?.get("kind") !! - val k8sResource = loader.loadK8sResource(kind , resourcePath) + val kind = parser.parse(resourcePath, HashMap<String, String>()::class.java)?.get("kind")!! + val k8sResource = loader.loadK8sResource(kind, resourcePath) Pair(resource, k8sResource) } - } + } - override fun buildDeployment(load: LoadDimension, res: Resource, configurationOverrides: List<ConfigurationOverride>): BenchmarkDeployment { + override fun buildDeployment( + load: LoadDimension, + res: Resource, + configurationOverrides: List<ConfigurationOverride> + ): BenchmarkDeployment { val resources = loadKubernetesResources(this.appResource + this.loadGenResource) val patcherManager = PatcherManager() @@ -40,13 +42,19 @@ class KubernetesBenchmark: Benchmark { patcherManager.createAndApplyPatcher(load.getType(), this.loadTypes, resources, load.get().toString()) // patch overrides - configurationOverrides.forEach{ override -> patcherManager.applyPatcher(listOf(override.patcher), resources, override.value)} + configurationOverrides.forEach { override -> + patcherManager.applyPatcher( + listOf(override.patcher), + resources, + override.value + ) + } return KubernetesBenchmarkDeployment( resources = resources.map { r -> r.second }, kafkaConfig = hashMapOf("bootstrap.servers" to kafkaConfig.bootstrapServer), zookeeperConfig = zookeeperConfig["server"].toString(), - topics = kafkaConfig.getKafkaTopics()) + topics = kafkaConfig.getKafkaTopics() + ) } } - diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt index 2c30bea402bfe97bece2967500b57025c5ab8a3f..8dc916351ede44da6c8081311fc152ec1d87b5d6 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt @@ -13,7 +13,7 @@ class KubernetesBenchmarkDeployment( private val kafkaConfig: HashMap<String, Any>, private val zookeeperConfig: String, private val topics: Collection<NewTopic> -): BenchmarkDeployment { +) : BenchmarkDeployment { private val workloadGeneratorStateCleaner = WorkloadGeneratorStateCleaner(this.zookeeperConfig) private val kafkaController = TopicManager(this.kafkaConfig) private val kubernetesManager = K8sManager(DefaultKubernetesClient().inNamespace("theodolite-she")) @@ -32,6 +32,5 @@ class KubernetesBenchmarkDeployment( resources.forEach { kubernetesManager.remove(it) } - } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/SLOChecker.kt b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/SLOChecker.kt index 10e113fdf1110e0c8bb30cad8a4b5f04f9e82c0d..396e1864b491e15d44881439c10847a39ea18286 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/SLOChecker.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/SLOChecker.kt @@ -1,4 +1,3 @@ package theodolite.evaluation -interface SLOChecker { -} \ No newline at end of file +interface SLOChecker {} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt index 6540004e019bc62cb743c578939a9b80edc0cd80..1e939812298da33c47513b3322ff33c00ea001be 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt @@ -2,7 +2,10 @@ package theodolite.execution import mu.KotlinLogging import theodolite.benchmark.Benchmark -import theodolite.util.* +import theodolite.util.ConfigurationOverride +import theodolite.util.LoadDimension +import theodolite.util.Resource +import theodolite.util.Results import java.time.Duration private val logger = KotlinLogging.logger {} @@ -15,7 +18,12 @@ private val logger = KotlinLogging.logger {} * @property executionDuration * @constructor Create empty Benchmark executor */ -abstract class BenchmarkExecutor(val benchmark: Benchmark, val results: Results, val executionDuration: Duration, configurationOverrides: List<ConfigurationOverride>) { +abstract class BenchmarkExecutor( + val benchmark: Benchmark, + val results: Results, + val executionDuration: Duration, + configurationOverrides: List<ConfigurationOverride> +) { /** * Run a experiment for the given parametrization, evaluate the experiment and save the result. diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt index 1c286b7f2ce956165eb5285a48f86ace15e8bbbe..45616a100a8ed067237413ac5afa9fd32f4865e1 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt @@ -1,10 +1,18 @@ package theodolite.execution import theodolite.benchmark.Benchmark -import theodolite.util.* +import theodolite.util.ConfigurationOverride +import theodolite.util.LoadDimension +import theodolite.util.Resource +import theodolite.util.Results import java.time.Duration -class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDuration: Duration, private val configurationOverrides: List<ConfigurationOverride>) : BenchmarkExecutor(benchmark, results, executionDuration, configurationOverrides) { +class BenchmarkExecutorImpl( + benchmark: Benchmark, + results: Results, + executionDuration: Duration, + private val configurationOverrides: List<ConfigurationOverride> +) : BenchmarkExecutor(benchmark, results, executionDuration, configurationOverrides) { override fun runExperiment(load: LoadDimension, res: Resource): Boolean { val benchmarkDeployment = benchmark.buildDeployment(load, res, this.configurationOverrides) benchmarkDeployment.setup() @@ -15,4 +23,4 @@ class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDur this.results.setResult(Pair(load, res), result) return result } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt index c6694943d347e64aa6d5a66c70d9a9ba3837c1a1..87388cb61cf8fcb93a1028d20d2e3b68d322ab3d 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt @@ -12,9 +12,10 @@ import java.time.Duration class TheodoliteExecutor( private val config: BenchmarkExecution, - private val kubernetesBenchmark: KubernetesBenchmark) { + private val kubernetesBenchmark: KubernetesBenchmark +) { - private fun buildConfig(): Config{ + private fun buildConfig(): Config { val results = Results() val strategyFactory = StrategyFactory() @@ -22,12 +23,18 @@ class TheodoliteExecutor( val executor = BenchmarkExecutorImpl(kubernetesBenchmark, results, executionDuration, config.configOverrides) return Config( - loads = config.load.loadValues.map { load -> LoadDimension(load, config.load.loadType ) }, - resources = config.resources.resourceValues.map { resource -> Resource(resource, config.resources.resourceType) }, - compositeStrategy = CompositeStrategy( - benchmarkExecutor = executor, - searchStrategy = strategyFactory.createSearchStrategy(executor, config.execution.strategy), - restrictionStrategies = strategyFactory.createRestrictionStrategy(results, config.execution.restrictions))) + loads = config.load.loadValues.map { load -> LoadDimension(load, config.load.loadType) }, + resources = config.resources.resourceValues.map + { resource -> Resource(resource, config.resources.resourceType) }, + compositeStrategy = CompositeStrategy( + benchmarkExecutor = executor, + searchStrategy = strategyFactory.createSearchStrategy(executor, config.execution.strategy), + restrictionStrategies = strategyFactory.createRestrictionStrategy( + results, + config.execution.restrictions + ) + ) + ) } fun run() { diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt index 8ae567f97e34667240adbc69c7048c5eed1c2779..95d7c57fbdf36f006a9f30fca115db92bcccd4e8 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteYamlExecutor.kt @@ -1,17 +1,19 @@ package theodolite.execution import theodolite.benchmark.BenchmarkExecution -import theodolite.util.YamlParser import theodolite.benchmark.KubernetesBenchmark +import theodolite.util.YamlParser class TheodoliteYamlExecutor { fun run() { // load the BenchmarkExecution and the BenchmarkType val parser = YamlParser() - val benchmarkExecution = parser.parse("./../../../resources/main/yaml/testBenchmarkExecution.yaml", BenchmarkExecution::class.java) !! - val benchmark = parser.parse("./../../../resources/main/yaml/testBenchmarkType.yaml", KubernetesBenchmark::class.java) !! + val benchmarkExecution = + parser.parse("./../../../resources/main/yaml/testBenchmarkExecution.yaml", BenchmarkExecution::class.java)!! + val benchmark = + parser.parse("./../../../resources/main/yaml/testBenchmarkType.yaml", KubernetesBenchmark::class.java)!! val executor = TheodoliteExecutor(benchmarkExecution, benchmark) executor.run() } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt index 8a7a9304b82f74c17de004856e5e7a5324257a06..6a4c5827afdb5e0b40120ca72cc165b2310a71e2 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sManager.kt @@ -6,7 +6,6 @@ import io.fabric8.kubernetes.api.model.Service import io.fabric8.kubernetes.api.model.apps.Deployment import io.fabric8.kubernetes.api.model.apps.StatefulSet import io.fabric8.kubernetes.client.NamespacedKubernetesClient -import java.lang.IllegalArgumentException class K8sManager(private val client: NamespacedKubernetesClient) { fun deploy(resource: KubernetesResource) { @@ -36,4 +35,4 @@ class K8sManager(private val client: NamespacedKubernetesClient) { else -> throw IllegalArgumentException("Unknown Kubernetes resource.") } } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt index a34efc90fd55f352712bc853422d4aacb31756d1..dbc31de96df4d1a4a48347c5f33853c0c98e1f95 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/K8sResourceLoader.kt @@ -59,7 +59,7 @@ class K8sResourceLoader(private val client: NamespacedKubernetesClient) { try { resource = f(path) } catch (e: Exception) { - logger.warn {"You potentially misspelled the path: $path"} + logger.warn { "You potentially misspelled the path: $path" } logger.warn { e } } @@ -70,7 +70,7 @@ class K8sResourceLoader(private val client: NamespacedKubernetesClient) { } fun loadK8sResource(kind: String, path: String): KubernetesResource { - return when (kind){ + return when (kind) { "Deployment" -> loadDeployment(path) "Service" -> loadService(path) "ServiceMonitor" -> loadServiceMonitor(path) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt index 1336f57517ef74d8c781cc3b51bf130dbf8d99c5..9cdf1c43fae9a72bd78126d420522b2d41a399ee 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt @@ -4,7 +4,6 @@ import mu.KotlinLogging import org.apache.kafka.clients.admin.AdminClient import org.apache.kafka.clients.admin.ListTopicsResult import org.apache.kafka.clients.admin.NewTopic -import java.util.* private val logger = KotlinLogging.logger {} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/AbstractPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/AbstractPatcher.kt index 7ee31881e0f23127f0323219094590c17044eb1d..2757d106868637978443d1562306ae4603a5b7e3 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/AbstractPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/AbstractPatcher.kt @@ -2,4 +2,8 @@ package theodolite.patcher import io.fabric8.kubernetes.api.model.KubernetesResource -abstract class AbstractPatcher(k8sResource: KubernetesResource, container: String? = null, variableName: String? = null): Patcher +abstract class AbstractPatcher( + k8sResource: KubernetesResource, + container: String? = null, + variableName: String? = null +) : Patcher diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt index a9eafb93e5b58115d652e0ebac2a38cb166a7f5e..5bdf66f183e3ad553e29f8754a4d3ef7ac0ccecd 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/EnvVarPatcher.kt @@ -6,12 +6,18 @@ import io.fabric8.kubernetes.api.model.EnvVarSource import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.api.model.apps.Deployment -class EnvVarPatcher(private val k8sResource: KubernetesResource, private val container: String, private val variableName: String): AbstractPatcher(k8sResource, container, variableName) { +class EnvVarPatcher( + private val k8sResource: KubernetesResource, + private val container: String, + private val variableName: String +) : AbstractPatcher(k8sResource, container, variableName) { override fun <String> patch(value: String) { if (k8sResource is Deployment) { - this.setEnv(k8sResource, this.container, - mapOf(this.variableName to value) as Map<kotlin.String, kotlin.String>) + this.setEnv( + k8sResource, this.container, + mapOf(this.variableName to value) as Map<kotlin.String, kotlin.String> + ) } } @@ -43,6 +49,4 @@ class EnvVarPatcher(private val k8sResource: KubernetesResource, private val con workloadDeployment.spec.template.spec.containers.filter { it.name == containerName } .forEach { setContainerEnv(it, map) } } - - -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ImagePatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ImagePatcher.kt index f1ac252fa7d555454e60875c74c569f2393ca695..960ed6d6f1eb67705da77d14d280c246a5fa6fa2 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ImagePatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ImagePatcher.kt @@ -4,7 +4,8 @@ import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.api.model.apps.Deployment import io.fabric8.kubernetes.api.model.apps.StatefulSet -class ImagePatcher(private val k8sResource: KubernetesResource, private val container: String): AbstractPatcher(k8sResource, container) { +class ImagePatcher(private val k8sResource: KubernetesResource, private val container: String) : + AbstractPatcher(k8sResource, container) { override fun <String> patch(imagePath: String) { if (k8sResource is Deployment) { @@ -17,4 +18,4 @@ class ImagePatcher(private val k8sResource: KubernetesResource, private val cont } } } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt index d588e7daed70a2c7b66d15c931f3c8a2867b91f8..ad0b8d411dd7c3b743177bd1f3e5862d55c7fe65 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/NodeSelectorPatcher.kt @@ -3,10 +3,11 @@ package theodolite.patcher import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.api.model.apps.Deployment -class NodeSelectorPatcher(private val k8sResource: KubernetesResource, private val variableName: String): AbstractPatcher(k8sResource, variableName){ +class NodeSelectorPatcher(private val k8sResource: KubernetesResource, private val variableName: String) : + AbstractPatcher(k8sResource, variableName) { override fun <String> patch(value: String) { if (k8sResource is Deployment) { - k8sResource.spec.template.spec.nodeSelector = mapOf(variableName to value as kotlin.String) + k8sResource.spec.template.spec.nodeSelector = mapOf(variableName to value as kotlin.String) } } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/Patcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/Patcher.kt index 61c2dd5fdfa97fe66889149df991314ad53911ea..82c562572de4acd932997d71e53138ecf2865462 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/Patcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/Patcher.kt @@ -2,4 +2,4 @@ package theodolite.patcher interface Patcher { fun <T> patch(value: T) -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt index 9fbbf98fe3801675671eae0fcd13d48f3e990a15..5557eb4b98d5da3bbc8b8d82227de29335c5da67 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt @@ -3,39 +3,57 @@ package theodolite.patcher import io.fabric8.kubernetes.api.model.KubernetesResource import theodolite.util.PatcherDefinition import theodolite.util.TypeName -import java.lang.IllegalArgumentException class PatcherManager { - private fun createK8sPatcher(patcherDefinition: PatcherDefinition, k8sResources: List<Pair<String, KubernetesResource>>): Patcher { - val resource = k8sResources.filter { it.first == patcherDefinition.resource}.map { resource -> resource.second }[0] - return when(patcherDefinition.type) { + private fun createK8sPatcher( + patcherDefinition: PatcherDefinition, + k8sResources: List<Pair<String, KubernetesResource>> + ): Patcher { + val resource = + k8sResources.filter { it.first == patcherDefinition.resource }.map { resource -> resource.second }[0] + return when (patcherDefinition.type) { "ReplicaPatcher" -> ReplicaPatcher(resource) "EnvVarPatcher" -> EnvVarPatcher(resource, patcherDefinition.container, patcherDefinition.variableName) "NodeSelectorPatcher" -> NodeSelectorPatcher(resource, patcherDefinition.variableName) - "ResourceLimitPatcher" -> ResourceLimitPatcher(resource, patcherDefinition.container, patcherDefinition.variableName) - "ResourceRequestPatcher" -> ResourceRequestPatcher(resource, patcherDefinition.container, patcherDefinition.variableName) + "ResourceLimitPatcher" -> ResourceLimitPatcher( + resource, + patcherDefinition.container, + patcherDefinition.variableName + ) + "ResourceRequestPatcher" -> ResourceRequestPatcher( + resource, + patcherDefinition.container, + patcherDefinition.variableName + ) else -> throw IllegalArgumentException("Patcher type ${patcherDefinition.type} not found") } } private fun getPatcherDef(requiredType: String, patcherTypes: List<TypeName>): List<PatcherDefinition> { return patcherTypes - .filter { type -> type.typeName == requiredType} - .flatMap { type -> type.patchers} + .filter { type -> type.typeName == requiredType } + .flatMap { type -> type.patchers } } /** - * This function first creates a patcher definition and then patches the list of resources based on this patcher definition + * This function first creates a patcher definition and + * then patches the list of resources based on this patcher definition * * @param type Patcher type, for example "EnvVarPatcher" * @param patcherTypes List of patcher types definitions, for example for resources and threads * @param resources List of K8s resources, a patcher takes the resources that are needed * @param value The value to patch */ - fun createAndApplyPatcher(type: String, patcherTypes: List<TypeName>, resources: List<Pair<String, KubernetesResource>>, value: Any) { + fun createAndApplyPatcher( + type: String, + patcherTypes: List<TypeName>, + resources: List<Pair<String, KubernetesResource>>, + value: Any + ) { this.getPatcherDef(type, patcherTypes) - .forEach {patcherDef -> - createK8sPatcher(patcherDef, resources).patch(value) } + .forEach { patcherDef -> + createK8sPatcher(patcherDef, resources).patch(value) + } } /** @@ -45,8 +63,11 @@ class PatcherManager { * @param resources List of patcher types definitions, for example for resources and threads * @param value The value to patch */ - fun applyPatcher(patcherDefinition: List<PatcherDefinition>, resources: List<Pair<String, KubernetesResource>>, value: Any) { - patcherDefinition.forEach { def -> this.createK8sPatcher(def, resources).patch(value) } - + fun applyPatcher( + patcherDefinition: List<PatcherDefinition>, + resources: List<Pair<String, KubernetesResource>>, + value: Any + ) { + patcherDefinition.forEach { def -> this.createK8sPatcher(def, resources).patch(value) } } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ReplicaPatcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ReplicaPatcher.kt index 9e0e048567080b6d0982c7069c5aa84e1d3fdcd4..ca34e9e3511f0ee35eff8f2ccf0cbd0582fc8646 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ReplicaPatcher.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/ReplicaPatcher.kt @@ -3,7 +3,7 @@ package theodolite.patcher import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.api.model.apps.Deployment -class ReplicaPatcher(private val k8sResource: KubernetesResource): AbstractPatcher(k8sResource){ +class ReplicaPatcher(private val k8sResource: KubernetesResource) : AbstractPatcher(k8sResource) { override fun <Int> patch(value: Int) { if (k8sResource is Deployment) { if (value is kotlin.Int) { @@ -11,4 +11,4 @@ class ReplicaPatcher(private val k8sResource: KubernetesResource): AbstractPatch } } } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/StrategyFactory.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/StrategyFactory.kt index ccbe6fac4106dd47dbc61684af4184ff26733df1..3d0135a8884e581bd8caa61fb5c0632057812150 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/StrategyFactory.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/StrategyFactory.kt @@ -7,7 +7,6 @@ import theodolite.strategies.searchstrategy.BinarySearch import theodolite.strategies.searchstrategy.LinearSearch import theodolite.strategies.searchstrategy.SearchStrategy import theodolite.util.Results -import java.lang.IllegalArgumentException class StrategyFactory { @@ -28,4 +27,4 @@ class StrategyFactory { } }.toSet() } -} \ No newline at end of file +} 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 aa5878ef2a7e789c48c76d8f166da26905f58f87..dfd6bc8052b8ca44ac8a9220fbf1e3c8df43b93d 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt @@ -1,8 +1,8 @@ package theodolite.strategies.restriction -import theodolite.util.Results import theodolite.util.LoadDimension import theodolite.util.Resource +import theodolite.util.Results /** * The Lower Bound Restriction sets the lower bound of the resources to be examined to the value @@ -12,11 +12,11 @@ import theodolite.util.Resource */ class LowerBoundRestriction(results: Results) : RestrictionStrategy(results) { override fun next(load: LoadDimension, resources: List<Resource>): List<Resource> { - val maxLoad: LoadDimension? = this.results.getMaxBenchmarkedLoad(load) - var lowerBound: Resource? = this.results.getMinRequiredInstances(maxLoad, resources[0].getType()) - if(lowerBound == null) { - lowerBound = resources[0] - } - return resources.filter{x -> x.get() >= lowerBound.get()} + val maxLoad: LoadDimension? = this.results.getMaxBenchmarkedLoad(load) + var lowerBound: Resource? = this.results.getMinRequiredInstances(maxLoad, resources[0].getType()) + if (lowerBound == null) { + lowerBound = resources[0] + } + return resources.filter { x -> x.get() >= lowerBound.get() } } -} \ No newline at end of file +} 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 6cca627e6a2359fccf4781510960e82869e8d017..b2e09a0cc2ce03bb735a00994c7f7f109527a56b 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/RestrictionStrategy.kt @@ -1,12 +1,12 @@ package theodolite.strategies.restriction -import theodolite.util.Results import theodolite.util.LoadDimension import theodolite.util.Resource - +import theodolite.util.Results /** - * A "Restriction Strategy" restricts a list of resources based on the current results of all previously performed benchmarks. + * A "Restriction Strategy" restricts a list of resources based on the current + * results of all previously performed benchmarks. */ abstract class RestrictionStrategy(val results: Results) { /** @@ -14,7 +14,8 @@ abstract class RestrictionStrategy(val results: Results) { * * @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). + * @return Returns a list containing only elements that have not been filtered out by the + * restriction (possibly empty). */ 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 88972ffdba8021d3bca7bd69140f9749b6747b4a..04f25fd9925d83b2a034536f9116c660dae6377d 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/BinarySearch.kt @@ -3,7 +3,6 @@ package theodolite.strategies.searchstrategy import theodolite.execution.BenchmarkExecutor import theodolite.util.LoadDimension import theodolite.util.Resource -import java.lang.IllegalArgumentException /** * Search for the smallest suitable resource with binary search. @@ -13,13 +12,13 @@ import java.lang.IllegalArgumentException class BinarySearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchmarkExecutor) { override fun findSuitableResource(load: LoadDimension, resources: List<Resource>): Resource? { val result = binarySearch(load, resources, 0, resources.size - 1) - if( result == -1 ) { + if (result == -1) { return null } return resources[result] } - private fun binarySearch (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() } @@ -27,21 +26,21 @@ class BinarySearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm if (lower == upper) { if (this.benchmarkExecutor.runExperiment(load, resources[lower])) return lower else { - if (lower + 1 == resources.size) return - 1 + if (lower + 1 == resources.size) return -1 return lower + 1 } } else { - // apply binary search for a list with length > 2 and adjust upper and lower depending on the result for `resources[mid]` + // apply binary search for a list with + // length > 2 and adjust upper and lower depending on the result for `resources[mid]` val mid = (upper + lower) / 2 if (this.benchmarkExecutor.runExperiment(load, resources[mid])) { if (mid == lower) { return lower } - return binarySearch(load, resources, lower, mid - 1 ) + return binarySearch(load, resources, lower, mid - 1) } else { - return binarySearch(load, resources, mid + 1 , upper) + return binarySearch(load, resources, mid + 1, upper) } } } - -} \ No newline at end of file +} 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 b44d5ea5e842f205c0a5ead7f5eba3887f5da591..8ffca54fa8b6e1359f60dbfe9394b348ef5e71c4 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/CompositeStrategy.kt @@ -4,9 +4,12 @@ import theodolite.execution.BenchmarkExecutor import theodolite.strategies.restriction.RestrictionStrategy import theodolite.util.LoadDimension import theodolite.util.Resource -import theodolite.util.Results -class CompositeStrategy(benchmarkExecutor: BenchmarkExecutor, private val searchStrategy: SearchStrategy, val restrictionStrategies: Set<RestrictionStrategy>) : SearchStrategy(benchmarkExecutor) { +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() @@ -15,4 +18,4 @@ class CompositeStrategy(benchmarkExecutor: BenchmarkExecutor, private val search } return this.searchStrategy.findSuitableResource(load, restrictedResources) } -} \ No newline at end of file +} 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 c2d6c0933e7c4c6136fce6e83087b760cb957f61..f1e8591a0a619d7c3ce59a40505989714f40972c 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/LinearSearch.kt @@ -12,4 +12,4 @@ class LinearSearch(benchmarkExecutor: BenchmarkExecutor) : SearchStrategy(benchm } return null } -} \ No newline at end of file +} 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 2c03d1eeb27874028a7492f126f4c6103747eace..d57246ca4337290ab3502192e3b3b0dc275c6596 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt @@ -13,4 +13,4 @@ abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor) { * @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/Config.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Config.kt index 36f4d9bf96a7a122edf21a0fc8cc8deafaf65fa7..a6120564c8a69f50461acdc857b02ac2198cafc8 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/Config.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Config.kt @@ -1,11 +1,9 @@ package theodolite.util -import theodolite.strategies.restriction.RestrictionStrategy import theodolite.strategies.searchstrategy.CompositeStrategy -import theodolite.strategies.searchstrategy.SearchStrategy -import java.time.Duration data class Config( val loads: List<LoadDimension>, val resources: List<Resource>, - val compositeStrategy: CompositeStrategy) {} \ No newline at end of file + val compositeStrategy: CompositeStrategy +) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/ConfigurationOverride.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/ConfigurationOverride.kt index f9099929c06b43a931ac210bd60629553777ffb1..fcf8244e87b87d0e6470c021474ca0ed5bb2eeec 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/ConfigurationOverride.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/ConfigurationOverride.kt @@ -1,6 +1,6 @@ package theodolite.util -class ConfigurationOverride() { +class ConfigurationOverride { lateinit var patcher: PatcherDefinition lateinit var value: String } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt index 1ad2f1b21c85bdac48de6f21f478d4a509885f90..8c529e3d8e793d96819afe78008c663e76504911 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt @@ -3,7 +3,7 @@ package theodolite.util import org.apache.kafka.clients.admin.NewTopic import kotlin.properties.Delegates -class KafkaConfig() { +class KafkaConfig { lateinit var bootstrapServer: String lateinit var topics: List<TopicWrapper> @@ -16,4 +16,4 @@ class KafkaConfig() { var numPartitions by Delegates.notNull<Int>() var replicationFactor by Delegates.notNull<Short>() } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt index 2f6fcb22e5faf3bddfb5b9bbefbf3901caef2f48..29d47460bc49ec44e9a46a129e3dab3246f305b6 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/LoadDimension.kt @@ -2,7 +2,7 @@ package theodolite.util data class LoadDimension(private val number: Int, private val type: String) { fun get(): Int { - return this.number; + return this.number } fun getType(): String { diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/Parser.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Parser.kt index 11e637c89fa4559433aefc43f59659fd51d1ce8e..886fd0b1f7a8a9a2219c74197ebb878f6d87775e 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/Parser.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Parser.kt @@ -1,5 +1,5 @@ package theodolite.util interface Parser { - fun <T> parse(path: String, E:Class<T>): T? -} \ No newline at end of file + fun <T> parse(path: String, E: Class<T>): T? +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/PatcherDefinition.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/PatcherDefinition.kt index e1bbc64bd21dc4d194212237fd54bec6d0f82f05..13b1e721cdf1f54a43414127ffcc8b227e7693ee 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/PatcherDefinition.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/PatcherDefinition.kt @@ -1,8 +1,8 @@ package theodolite.util -class PatcherDefinition() { - lateinit var type: String - lateinit var resource: String - lateinit var container: String - lateinit var variableName: String +class PatcherDefinition { + lateinit var type: String + lateinit var resource: String + lateinit var container: String + lateinit var variableName: String } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt index f315bb54d0c69f52dc794851fa3572b24385e370..cb172e0b8de4cff5fc08828a177f3dd9d58bbb53 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Resource.kt @@ -2,10 +2,10 @@ package theodolite.util data class Resource(private val number: Int, private val type: String) { fun get(): Int { - return this.number; + return this.number } fun getType(): String { return this.type } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt index b46286f5a968f38b327721c78172455d8a2704a2..91bde71792fdca383fc9511658bab39aa58d12ce 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Results.kt @@ -7,7 +7,7 @@ class Results { this.results[experiment] = successful } - fun getResult (experiment: Pair<LoadDimension, Resource>): Boolean? { + fun getResult(experiment: Pair<LoadDimension, Resource>): Boolean? { return this.results[experiment] } @@ -15,11 +15,11 @@ class Results { if (this.results.isEmpty()) return Resource(Int.MIN_VALUE, resourceTyp) var requiredInstances: Resource? = Resource(Int.MAX_VALUE, resourceTyp) - for(experiment in results) { - if(experiment.key.first == load && experiment.value){ - if(requiredInstances == null) { + for (experiment in results) { + if (experiment.key.first == load && experiment.value) { + if (requiredInstances == null) { requiredInstances = experiment.key.second - }else if (experiment.key.second.get() < requiredInstances.get()) { + } else if (experiment.key.second.get() < requiredInstances.get()) { requiredInstances = experiment.key.second } } @@ -28,10 +28,10 @@ class Results { } fun getMaxBenchmarkedLoad(load: LoadDimension): LoadDimension? { - var maxBenchmarkedLoad: LoadDimension? = null; - for(experiment in results) { + var maxBenchmarkedLoad: LoadDimension? = null + for (experiment in results) { if (experiment.value) { - if(experiment.key.first.get() <= load.get()) { + if (experiment.key.first.get() <= load.get()) { if (maxBenchmarkedLoad == null) { maxBenchmarkedLoad = experiment.key.first } else if (maxBenchmarkedLoad.get() < experiment.key.first.get()) { @@ -42,4 +42,4 @@ class Results { } return maxBenchmarkedLoad } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/TypeName.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/TypeName.kt index f4a65bb5850c88a0ce9c4904a49a613c6696bdf2..3568a355edbddd3b29e6d934deecb923518af3df 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/TypeName.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/TypeName.kt @@ -1,6 +1,6 @@ package theodolite.util -class TypeName() { +class TypeName { lateinit var typeName: String lateinit var patchers: List<PatcherDefinition> -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/YamlParser.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/YamlParser.kt index fb953a7443146423d3e4ef28e195f882db10015d..ec91150df6c9999c418660424aa8b74163030e34 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/YamlParser.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/YamlParser.kt @@ -6,11 +6,10 @@ import java.io.File import java.io.FileInputStream import java.io.InputStream - -class YamlParser: Parser { +class YamlParser : Parser { override fun <T> parse(path: String, E: Class<T>): T? { val input: InputStream = FileInputStream(File(path)) val parser = Yaml(Constructor(E)) return parser.loadAs(input, E) } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/main/resources/yaml/testBenchmarkExecution.yaml b/theodolite-quarkus/src/main/resources/yaml/testBenchmarkExecution.yaml index cbb4bf3b55abca623e1f809bb6845c63cfd26e81..b1c9af6e48bb9115989b74dd5739649be6269e4e 100644 --- a/theodolite-quarkus/src/main/resources/yaml/testBenchmarkExecution.yaml +++ b/theodolite-quarkus/src/main/resources/yaml/testBenchmarkExecution.yaml @@ -14,7 +14,7 @@ slos: execution: strategy: "LinearSearch" duration: 300 - repititions: 1 + repetitions: 1 restrictions: - "LowerBound" configOverrides: diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt index 7975da57a5aec207010e364e46b668b883447f94..31eaa40fbe5424cf4df00860623e91fa5f1a9408 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt @@ -1,14 +1,15 @@ package theodolite import io.quarkus.test.junit.QuarkusTest -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -import theodolite.strategies.searchstrategy.LinearSearch -import theodolite.strategies.searchstrategy.BinarySearch import theodolite.strategies.restriction.LowerBoundRestriction +import theodolite.strategies.searchstrategy.BinarySearch import theodolite.strategies.searchstrategy.CompositeStrategy -import theodolite.util.* -import java.util.* +import theodolite.strategies.searchstrategy.LinearSearch +import theodolite.util.LoadDimension +import theodolite.util.Resource +import theodolite.util.Results @QuarkusTest class CompositeStrategyTest { @@ -16,28 +17,29 @@ class CompositeStrategyTest { @Test fun testEnd2EndLinearSearch() { val mockResults = arrayOf( - arrayOf( true , true , true , true , true , true , true), - arrayOf( false, false, true , true , true , true , true), - arrayOf( false, false, true , true , true , true , true), - arrayOf( false, false, false, true , true , true , true), - arrayOf( false, false, false, false, true , true , true), - arrayOf( false, false, false, false, false, false, true), - arrayOf( false, false, false, false, false, false, false) + arrayOf(true, true, true, true, true, true, true), + arrayOf(false, false, true, true, true, true, true), + arrayOf(false, false, true, true, true, true, true), + arrayOf(false, false, false, true, true, true, true), + arrayOf(false, false, false, false, true, true, true), + arrayOf(false, false, false, false, false, false, true), + arrayOf(false, false, false, false, false, false, false) ) - val mockLoads: List<LoadDimension> = (0..6).map{number -> LoadDimension(number, "NumSensors")} - val mockResources: List<Resource> = (0..6).map{number -> Resource(number, "Instances")} - val results: Results = Results(); + val mockLoads: List<LoadDimension> = (0..6).map { number -> LoadDimension(number, "NumSensors") } + val mockResources: List<Resource> = (0..6).map { number -> Resource(number, "Instances") } + val results = Results() val benchmark = TestBenchmark() - 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)) + val benchmarkExecutor = TestBenchmarkExecutorImpl(mockResults, benchmark, results) + val linearSearch = LinearSearch(benchmarkExecutor) + val lowerBoundRestriction = LowerBoundRestriction(results) + val strategy = + 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, "Instances")}) + val actual: ArrayList<Resource?> = ArrayList() + val expected: ArrayList<Resource?> = ArrayList(listOf(0, 2, 2, 3, 4, 6).map { x -> Resource(x, "Instances") }) expected.add(null) - for(load in mockLoads) { + for (load in mockLoads) { actual.add(strategy.findSuitableResource(load, mockResources)) } @@ -47,28 +49,30 @@ class CompositeStrategyTest { @Test fun testEnd2EndBinarySearch() { val mockResults = arrayOf( - arrayOf( true , true , true , true , true , true , true), - arrayOf( false, false, true , true , true , true , true), - arrayOf( false, false, true , true , true , true , true), - arrayOf( false, false, false, true , true , true , true), - arrayOf( false, false, false, false, true , true , true), - arrayOf( false, false, false, false, false, false, true), - arrayOf( false, false, false, false, false, false, false) + arrayOf(true, true, true, true, true, true, true), + arrayOf(false, false, true, true, true, true, true), + arrayOf(false, false, true, true, true, true, true), + arrayOf(false, false, false, true, true, true, true), + arrayOf(false, false, false, false, true, true, true), + arrayOf(false, false, false, false, false, false, true), + arrayOf(false, false, false, false, false, false, false) ) - val mockLoads: List<LoadDimension> = (0..6).map{number -> LoadDimension(number, "NumSensors")} - val mockResources: List<Resource> = (0..6).map{number -> Resource(number, "Instances")} - val results: Results = Results(); + val mockLoads: List<LoadDimension> = (0..6).map { number -> LoadDimension(number, "NumSensors") } + val mockResources: List<Resource> = (0..6).map { number -> Resource(number, "Instances") } + val results = Results() val benchmark = TestBenchmark() - val benchmarkExecutorImpl: TestBenchmarkExecutorImpl = TestBenchmarkExecutorImpl(mockResults, benchmark, results) - val binarySearch: BinarySearch = BinarySearch(benchmarkExecutorImpl); - val lowerBoundRestriction: LowerBoundRestriction = LowerBoundRestriction(results); - val strategy: CompositeStrategy = CompositeStrategy(benchmarkExecutorImpl, binarySearch, setOf(lowerBoundRestriction)) + val benchmarkExecutorImpl = + TestBenchmarkExecutorImpl(mockResults, benchmark, results) + val binarySearch = BinarySearch(benchmarkExecutorImpl) + val lowerBoundRestriction = LowerBoundRestriction(results) + val strategy = + 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, "Instances")}) + val actual: ArrayList<Resource?> = ArrayList() + val expected: ArrayList<Resource?> = ArrayList(listOf(0, 2, 2, 3, 4, 6).map { x -> Resource(x, "Instances") }) expected.add(null) - for(load in mockLoads) { + for (load in mockLoads) { actual.add(strategy.findSuitableResource(load, mockResources)) } @@ -78,31 +82,32 @@ class CompositeStrategyTest { @Test fun testEnd2EndBinarySearch2() { val mockResults = arrayOf( - arrayOf( true , true , true , true , true , true , true, true), - arrayOf( false, false, true , true , true , true , true, true), - arrayOf( false, false, true , true , true , true , true, true), - arrayOf( false, false, false, true , true , true , true, true), - arrayOf( false, false, false, false, true , true , true, true), - arrayOf( false, false, false, false, false, false, true, true), - arrayOf( false, false, false, false, false, false, false, true) + arrayOf(true, true, true, true, true, true, true, true), + arrayOf(false, false, true, true, true, true, true, true), + arrayOf(false, false, true, true, true, true, true, true), + arrayOf(false, false, false, true, true, true, true, true), + arrayOf(false, false, false, false, true, true, true, true), + arrayOf(false, false, false, false, false, false, true, true), + arrayOf(false, false, false, false, false, false, false, true) ) - val mockLoads: List<LoadDimension> = (0..6).map{number -> LoadDimension(number, "NumSensors")} - val mockResources: List<Resource> = (0..7).map{number -> Resource(number, "Instances")} - val results: Results = Results(); + val mockLoads: List<LoadDimension> = (0..6).map { number -> LoadDimension(number, "NumSensors") } + val mockResources: List<Resource> = (0..7).map { number -> Resource(number, "Instances") } + val results = Results() val benchmark = TestBenchmark() - 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)) + val benchmarkExecutor = TestBenchmarkExecutorImpl(mockResults, benchmark, results) + val binarySearch = BinarySearch(benchmarkExecutor) + val lowerBoundRestriction = LowerBoundRestriction(results) + val strategy = + 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, "Instances")}) + val actual: ArrayList<Resource?> = ArrayList() + val expected: ArrayList<Resource?> = + ArrayList(listOf(0, 2, 2, 3, 4, 6, 7).map { x -> Resource(x, "Instances") }) - for(load in mockLoads) { + for (load in mockLoads) { actual.add(strategy.findSuitableResource(load, mockResources)) } assertEquals(actual, expected) } - -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt index 3e7be5bd9313ffa786f70cc331ce3c8c68b2974a..9b0da36dd9913b929350772297a47fa9289a0559 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/ResourceLimitPatcherTest.kt @@ -12,7 +12,8 @@ import theodolite.util.PatcherDefinition /** * Resource patcher test * - * This class tested 4 scenarios for the ResourceLimitPatcher and the ResourceRequestPatcher. The different test cases specifies four possible situations: + * This class tested 4 scenarios for the ResourceLimitPatcher and the ResourceRequestPatcher. + * The different test cases specifies four possible situations: * Case 1: In the given YAML declaration memory and cpu are defined * Case 2: In the given YAML declaration only cpu is defined * Case 3: In the given YAML declaration only memory is defined @@ -24,10 +25,9 @@ class ResourceLimitPatcherTest { val loader = K8sResourceLoader(DefaultKubernetesClient().inNamespace("")) val manager = PatcherManager() - fun applyTest(fileName: String) { - val CPUValue = "50m" - val MEMValue = "3Gi" + val cpuValue = "50m" + val memValue = "3Gi" val k8sResource = loader.loadK8sResource("Deployment", testPath + fileName) as Deployment val defCPU = PatcherDefinition() @@ -45,19 +45,19 @@ class ResourceLimitPatcherTest { manager.applyPatcher( patcherDefinition = listOf(defCPU), resources = listOf(Pair("cpu-memory-deployment.yaml", k8sResource)), - value = CPUValue + value = cpuValue ) manager.applyPatcher( patcherDefinition = listOf(defMEM), resources = listOf(Pair("cpu-memory-deployment.yaml", k8sResource)), - value = MEMValue + value = memValue ) k8sResource.spec.template.spec.containers.filter { it.name == defCPU.container } .forEach { println(it) - assertTrue(it.resources.limits["cpu"].toString() == "$CPUValue") - assertTrue(it.resources.limits["memory"].toString() == "$MEMValue") + assertTrue(it.resources.limits["cpu"].toString() == cpuValue) + assertTrue(it.resources.limits["memory"].toString() == memValue) } } @@ -66,19 +66,22 @@ class ResourceLimitPatcherTest { // Case 1: In the given YAML declaration memory and cpu are defined applyTest("cpu-memory-deployment.yaml") } + @Test fun case2() { // Case 2: In the given YAML declaration only cpu is defined applyTest("cpu-deployment.yaml") } + @Test fun case3() { // Case 3: In the given YAML declaration only memory is defined applyTest("memory-deployment.yaml") } + @Test fun case4() { // Case 4: In the given YAML declaration neither `Resource Request` nor `Request Limit` is defined applyTest("no-resources-deployment.yaml") } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt index 10ff5320e114564bb43d153b29d77f4e102034a5..22d19d221f6b5af3153e767cd14f7c81c3995b01 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/ResourceRequestPatcherTest.kt @@ -12,7 +12,8 @@ import theodolite.util.PatcherDefinition /** * Resource patcher test * - * This class tested 4 scenarios for the ResourceLimitPatcher and the ResourceRequestPatcher. The different test cases specifies four possible situations: + * This class tested 4 scenarios for the ResourceLimitPatcher and the ResourceRequestPatcher. + * The different test cases specifies four possible situations: * Case 1: In the given YAML declaration memory and cpu are defined * Case 2: In the given YAML declaration only cpu is defined * Case 3: In the given YAML declaration only memory is defined @@ -24,10 +25,9 @@ class ResourceRequestPatcherTest { val loader = K8sResourceLoader(DefaultKubernetesClient().inNamespace("")) val manager = PatcherManager() - fun applyTest(fileName: String) { - val CPUValue = "50m" - val MEMValue = "3Gi" + val cpuValue = "50m" + val memValue = "3Gi" val k8sResource = loader.loadK8sResource("Deployment", testPath + fileName) as Deployment val defCPU = PatcherDefinition() @@ -45,19 +45,19 @@ class ResourceRequestPatcherTest { manager.applyPatcher( patcherDefinition = listOf(defCPU), resources = listOf(Pair("cpu-memory-deployment.yaml", k8sResource)), - value = CPUValue + value = cpuValue ) manager.applyPatcher( patcherDefinition = listOf(defMEM), resources = listOf(Pair("cpu-memory-deployment.yaml", k8sResource)), - value = MEMValue + value = memValue ) k8sResource.spec.template.spec.containers.filter { it.name == defCPU.container } .forEach { println(it) - assertTrue(it.resources.requests["cpu"].toString() == "$CPUValue") - assertTrue(it.resources.requests["memory"].toString() == "$MEMValue") + assertTrue(it.resources.requests["cpu"].toString() == cpuValue) + assertTrue(it.resources.requests["memory"].toString() == memValue) } } @@ -66,19 +66,22 @@ class ResourceRequestPatcherTest { // Case 1: In the given YAML declaration memory and cpu are defined applyTest("cpu-memory-deployment.yaml") } + @Test fun case2() { // Case 2: In the given YAML declaration only cpu is defined applyTest("cpu-deployment.yaml") } + @Test fun case3() { // Case 3: In the given YAML declaration only memory is defined applyTest("memory-deployment.yaml") } + @Test fun case4() { // Case 4: In the given YAML declaration neither `Resource Request` nor `Request Limit` is defined applyTest("no-resources-deployment.yaml") } -} \ No newline at end of file +} diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkDeployment.kt b/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkDeployment.kt index c59e8b4e1d01cc28bfc8a1fb508930ee408571ee..68b08c294128368ee1b65549aa85c877bd4bf313 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkDeployment.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkDeployment.kt @@ -2,10 +2,8 @@ package theodolite import theodolite.benchmark.BenchmarkDeployment -class TestBenchmarkDeployment: BenchmarkDeployment { - override fun setup() { - } +class TestBenchmarkDeployment : BenchmarkDeployment { + override fun setup() {} - override fun teardown() { - } -} \ No newline at end of file + override fun teardown() {} +} diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkExecutorImpl.kt b/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkExecutorImpl.kt index e6a6f672ab5440bf5e4cc9a1dbfa01ab36fcc410..bab20b7b56a6b95efd7e616338419b632a8f42d7 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkExecutorImpl.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkExecutorImpl.kt @@ -7,8 +7,13 @@ import theodolite.util.Resource import theodolite.util.Results import java.time.Duration -class TestBenchmarkExecutorImpl(private val mockResults: Array<Array<Boolean>>, benchmark: Benchmark, results: Results): - BenchmarkExecutor(benchmark, results, executionDuration = Duration.ofSeconds(1), +class TestBenchmarkExecutorImpl( + private val mockResults: Array<Array<Boolean>>, + benchmark: Benchmark, + results: Results +) : + BenchmarkExecutor( + benchmark, results, executionDuration = Duration.ofSeconds(1), configurationOverrides = emptyList() ) { @@ -16,6 +21,6 @@ class TestBenchmarkExecutorImpl(private val mockResults: Array<Array<Boolean>>, val result = this.mockResults[load.get()][res.get()] this.results.setResult(Pair(load, res), result) - return result; + return result } -} \ No newline at end of file +}