From 9bac7e0dd8ab2bc6ff82f8da028e4da7ca53652b Mon Sep 17 00:00:00 2001 From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de> Date: Fri, 19 Feb 2021 13:02:31 +0100 Subject: [PATCH] Allow to set config overrides via EnvVarPatcher --- .../kotlin/theodolite/benchmark/Benchmark.kt | 3 ++- .../theodolite/benchmark/BenchmarkContext.kt | 4 +++- .../benchmark/KubernetesBenchmark.kt | 8 ++++--- .../theodolite/execution/BenchmarkExecutor.kt | 7 ++---- .../execution/BenchmarkExecutorImpl.kt | 8 ++----- .../execution/TestBenchmarkExecutorImpl.kt | 2 +- .../theodolite/patcher/PatcherManager.kt | 22 ++++++++++++++----- .../util/OverridePatcherDefinition.kt | 8 +++++++ .../theodolite/util/PatcherDefinition.kt | 1 + .../kotlin/theodolite/util/TestBenchmark.kt | 2 +- .../resources/yaml/testBenchmarkType.yaml | 6 +---- .../src/main/resources/yaml/testContext.yaml | 7 +++++- 12 files changed, 49 insertions(+), 29 deletions(-) create mode 100644 theodolite-quarkus/src/main/kotlin/theodolite/util/OverridePatcherDefinition.kt diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt index 1c8b98f81..6373262d8 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt @@ -1,8 +1,9 @@ package theodolite.benchmark import theodolite.util.LoadDimension +import theodolite.util.OverridePatcherDefinition import theodolite.util.Resource interface Benchmark { - fun buildDeployment(load: LoadDimension, res: Resource, override: Map<String, String>): BenchmarkDeployment + fun buildDeployment(load: LoadDimension, res: Resource, overrides: List<OverridePatcherDefinition>): BenchmarkDeployment } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkContext.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkContext.kt index 1680e2173..596f768f7 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkContext.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkContext.kt @@ -1,5 +1,7 @@ package theodolite.benchmark +import theodolite.util.OverridePatcherDefinition +import theodolite.util.PatcherDefinition import kotlin.properties.Delegates @@ -10,7 +12,7 @@ class BenchmarkContext() { lateinit var resources: List<Int> lateinit var slos: List<Slo> lateinit var execution: Execution - lateinit var configOverrides: Map<String, String> + lateinit var configOverrides: List<OverridePatcherDefinition> class Execution() { lateinit var strategy: String diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index ecfe51677..61a8dcfc2 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -5,6 +5,7 @@ import io.fabric8.kubernetes.client.DefaultKubernetesClient import theodolite.k8s.YamlLoader import theodolite.patcher.PatcherManager import theodolite.util.LoadDimension +import theodolite.util.OverridePatcherDefinition import theodolite.util.Resource import theodolite.util.TypeName @@ -33,7 +34,7 @@ class KubernetesBenchmark(): Benchmark { - override fun buildDeployment(load: LoadDimension, res: Resource, override: Map<String, String>): BenchmarkDeployment { + override fun buildDeployment(load: LoadDimension, res: Resource, overrides: List<OverridePatcherDefinition>): BenchmarkDeployment { // TODO("set node selector") val resources = loadKubernetesResources(this.appResource + this.loadGenResource) val patcherManager = PatcherManager() @@ -42,9 +43,10 @@ class KubernetesBenchmark(): Benchmark { patcherManager.applyPatcher(res.getType(), this.resourceTypes, resources, res.get()) patcherManager.applyPatcher(load.getType(), this.loadTypes, resources, load.get().toString()) - resources.forEach {x -> println(x)} + // patch overrides + overrides.forEach {override -> patcherManager.applyPatcher(override, resources)} - // handle overrides (resource, container, variableName, variableValue) + resources.forEach {x -> println(x)} return KubernetesBenchmarkDeployment(emptyList(), hashMapOf<String, Any>(), "", emptyList()) } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt index 4905766d3..714a27885 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt @@ -3,10 +3,7 @@ package theodolite.execution import mu.KotlinLogging import theodolite.benchmark.Benchmark import theodolite.benchmark.KubernetesBenchmark -import theodolite.util.AbstractBenchmark -import theodolite.util.LoadDimension -import theodolite.util.Resource -import theodolite.util.Results +import theodolite.util.* import java.time.Duration private val logger = KotlinLogging.logger {} @@ -19,7 +16,7 @@ private val logger = KotlinLogging.logger {} * @property executionDuration * @constructor Create empty Benchmark executor */ -abstract class BenchmarkExecutor(val benchmark: Benchmark, val results: Results, val executionDuration: Duration, override: Map<String, String>) { +abstract class BenchmarkExecutor(val benchmark: Benchmark, val results: Results, val executionDuration: Duration, overrides: List<OverridePatcherDefinition>) { /** * 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 d782ed9a5..c034dd6e9 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt @@ -1,14 +1,10 @@ package theodolite.execution import theodolite.benchmark.Benchmark -import theodolite.benchmark.KubernetesBenchmark -import theodolite.util.AbstractBenchmark -import theodolite.util.LoadDimension -import theodolite.util.Resource -import theodolite.util.Results +import theodolite.util.* import java.time.Duration -class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDuration: Duration, private val overrides: Map<String, String>) : BenchmarkExecutor(benchmark, results, executionDuration, overrides) { +class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDuration: Duration, private val overrides: List<OverridePatcherDefinition>) : BenchmarkExecutor(benchmark, results, executionDuration, overrides) { override fun runExperiment(load: LoadDimension, res: Resource): Boolean { val benchmarkDeployment = benchmark.buildDeployment(load, res, this.overrides) benchmarkDeployment.setup() diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutorImpl.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutorImpl.kt index db2084a85..66506055e 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutorImpl.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutorImpl.kt @@ -10,7 +10,7 @@ import java.time.Duration class TestBenchmarkExecutorImpl(private val mockResults: Array<Array<Boolean>>, benchmark: Benchmark, results: Results): BenchmarkExecutor(benchmark, results, executionDuration = Duration.ofSeconds(1), - override = emptyMap<String,String>() + overrides = emptyList() ) { override fun runExperiment(load: LoadDimension, res: Resource): Boolean { diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt index 774d6d389..b7e35b578 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/patcher/PatcherManager.kt @@ -1,6 +1,7 @@ package theodolite.patcher import io.fabric8.kubernetes.api.model.KubernetesResource +import theodolite.util.OverridePatcherDefinition import theodolite.util.PatcherDefinition import theodolite.util.TypeName import java.lang.IllegalArgumentException @@ -16,17 +17,28 @@ class PatcherManager { } } - private fun getPatcherDef(requiredType: String, resourceTypes: List<TypeName>): List<PatcherDefinition> { - return resourceTypes + private fun getPatcherDef(requiredType: String, patcherTypes: List<TypeName>): List<PatcherDefinition> { + return patcherTypes .filter { type -> type.typeName == requiredType} .flatMap { type -> type.patchers} } - fun applyPatcher(type: String, resourceTypes: List<TypeName>, resources: List<Pair<String, KubernetesResource>>, value: Any) { - this.getPatcherDef(type, resourceTypes) + fun applyPatcher(type: String, patcherTypes: List<TypeName>, resources: List<Pair<String, KubernetesResource>>, value: Any) { + this.getPatcherDef(type, patcherTypes) .forEach {patcherDef -> createK8sPatcher(patcherDef, resources).patch(value) } - } + + fun applyPatcher(overrides: OverridePatcherDefinition, resources: List<Pair<String, KubernetesResource>>){ + var pdef = PatcherDefinition() + pdef.type = overrides.type + pdef.container = overrides.container + pdef.resource = overrides.resource + overrides.overrides.forEach{ override -> + pdef.variableName = override.key + this.createK8sPatcher(pdef, resources).patch(override.value) + } + } + } \ No newline at end of file diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/OverridePatcherDefinition.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/OverridePatcherDefinition.kt new file mode 100644 index 000000000..c996fbe90 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/OverridePatcherDefinition.kt @@ -0,0 +1,8 @@ +package theodolite.util + +class OverridePatcherDefinition() { + lateinit var type: String + lateinit var resource: String + lateinit var container: String + lateinit var overrides: Map<String, String> +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/PatcherDefinition.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/PatcherDefinition.kt index e1bbc64bd..1b4b27437 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/PatcherDefinition.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/PatcherDefinition.kt @@ -5,4 +5,5 @@ class PatcherDefinition() { lateinit var resource: String lateinit var container: String lateinit var variableName: String + lateinit var value: String } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/TestBenchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/TestBenchmark.kt index a5bc49c6c..9f386ba86 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/util/TestBenchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/TestBenchmark.kt @@ -41,7 +41,7 @@ class TestBenchmark : AbstractBenchmark( override fun buildDeployment( load: LoadDimension, res: Resource, - override: Map<String, String> + override: List<OverridePatcherDefinition> ): BenchmarkDeployment { TODO("Not yet implemented") } diff --git a/theodolite-quarkus/src/main/resources/yaml/testBenchmarkType.yaml b/theodolite-quarkus/src/main/resources/yaml/testBenchmarkType.yaml index 57c3e2b66..f8c9d3fff 100644 --- a/theodolite-quarkus/src/main/resources/yaml/testBenchmarkType.yaml +++ b/theodolite-quarkus/src/main/resources/yaml/testBenchmarkType.yaml @@ -15,8 +15,4 @@ loadTypes: - type: "EnvVarPatcher" resource: "workloadGenerator.yaml" container: "workload-generator" - variableName: "NUM_SENSORS" -EnvVars: - - typeName: "override" - patchers: - - type: "EnvVarPatcher" \ No newline at end of file + variableName: "NUM_SENSORS" \ No newline at end of file diff --git a/theodolite-quarkus/src/main/resources/yaml/testContext.yaml b/theodolite-quarkus/src/main/resources/yaml/testContext.yaml index fc5cc4057..6073f8de6 100644 --- a/theodolite-quarkus/src/main/resources/yaml/testContext.yaml +++ b/theodolite-quarkus/src/main/resources/yaml/testContext.yaml @@ -16,4 +16,9 @@ execution: restrictions: - "LowerBound" configOverrides: - key: "value" \ No newline at end of file + - type: "EnvVarPatcher" + resource: "workloadGenerator.yaml" + container: "workload-generator" + overrides: + overrideTestA: "8888" + overrideTestB: "6666" -- GitLab