diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/Benchmark.kt index 1c8b98f81b920797a5831f733ec06bcd738fca42..6373262d8c6b6fce99347abb5eeaebb08d19130c 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 1680e2173998f4f5a4ed30f0ad5fd4d72d6f3085..596f768f7b864750d23d9971690752f962823c5f 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 ecfe516770f59c0a8b0001a124b71f30b8c37097..61a8dcfc27dc6e3cb97b5a7756a6ec5fcff64fda 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 4905766d39ffee5bd44e743af3532cc45d3f6a07..714a27885759fa37e0dfc15e500f28b4b9e65047 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 d782ed9a5cf86e16320fbc8a84046b664987b295..c034dd6e9599949240fa0b8137c240254e21eab8 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 db2084a850e91db8ead8029b8e4b14a76a83374d..66506055e67a63ae7aa7156c28c83e2186b8b960 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 774d6d389cb63a5b6daef9e98b3be3976034f520..b7e35b578d0f18c7a608050531813f90d012a5de 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 0000000000000000000000000000000000000000..c996fbe90246d0ab0013dfacbf33d12f64e68d94 --- /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 e1bbc64bd21dc4d194212237fd54bec6d0f82f05..1b4b274370a6b713e623fd503896fd8f2949179f 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 a5bc49c6caaa1ffa97303a8a97f376a6df549bfd..9f386ba8634b3104ba54be60cef220f2f3f84e66 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 57c3e2b66498e2b66d07930485d37cac47423d65..f8c9d3fffd61b29f0e56ddbb7e7963f3ccdd62c4 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 fc5cc40571ddf52ddd7132325220c1c6883b06a7..6073f8de61df312aa2a33544ca2afd45f84ddd53 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"