diff --git a/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt b/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt index 430921275ae5591aaf682afe56e937a9df6bbc53..5c07c703474978b82b2211fbb3a6494a7be5a161 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt @@ -6,10 +6,7 @@ import theodolite.benchmark.Benchmark import theodolite.benchmark.BenchmarkExecution import theodolite.evaluation.AnalysisExecutor import theodolite.execution.operator.EventCreator -import theodolite.util.ConfigurationOverride -import theodolite.util.LoadDimension -import theodolite.util.Resource -import theodolite.util.Results +import theodolite.util.* import java.time.Duration import java.time.Instant @@ -40,6 +37,7 @@ class BenchmarkExecutorImpl( executionName ) { private val eventCreator = EventCreator() + private val mode = Configuration.EXECUTION_MODE override fun runExperiment(load: LoadDimension, res: Resource): Boolean { var result = false @@ -82,39 +80,46 @@ class BenchmarkExecutorImpl( try { benchmarkDeployment.setup() this.waitAndLog() - eventCreator.createEvent( - executionName = executionName, - type = "NORMAL", - reason = "Start experiment", - message = "load: ${load.get()}, resources: ${res.get()}") + if (mode == ExecutionModes.OPERATOR.value) { + eventCreator.createEvent( + executionName = executionName, + type = "NORMAL", + reason = "Start experiment", + message = "load: ${load.get()}, resources: ${res.get()}") + } } catch (e: Exception) { logger.error { "Error while setup experiment." } logger.error { "Error is: $e" } this.run.set(false) - eventCreator.createEvent( - executionName = executionName, - type = "WARNING", - reason = "Start experiment failed", - message = "load: ${load.get()}, resources: ${res.get()}") + if (mode == ExecutionModes.OPERATOR.value) { + eventCreator.createEvent( + executionName = executionName, + type = "WARNING", + reason = "Start experiment failed", + message = "load: ${load.get()}, resources: ${res.get()}") + } } val to = Instant.now() try { benchmarkDeployment.teardown() - eventCreator.createEvent( - executionName = executionName, - type = "NORMAL", - reason = "Stop experiment", - message = "Teardown complete") + if (mode == ExecutionModes.OPERATOR.value) { + eventCreator.createEvent( + executionName = executionName, + type = "NORMAL", + reason = "Stop experiment", + message = "Teardown complete") + } } catch (e: Exception) { logger.warn { "Error while tearing down the benchmark deployment." } logger.debug { "Teardown failed, caused by: $e" } - - eventCreator.createEvent( - executionName = executionName, - type = "WARNING", - reason = "Stop experiment failed", - message = "Teardown failed: ${e.message}") + if (mode == ExecutionModes.OPERATOR.value) { + eventCreator.createEvent( + executionName = executionName, + type = "WARNING", + reason = "Stop experiment failed", + message = "Teardown failed: ${e.message}") + } } return Pair(from, to) } diff --git a/theodolite/src/main/kotlin/theodolite/execution/ExecutionModes.kt b/theodolite/src/main/kotlin/theodolite/execution/ExecutionModes.kt new file mode 100644 index 0000000000000000000000000000000000000000..bf947be01b534fd000d3967f0b72ef25978d4110 --- /dev/null +++ b/theodolite/src/main/kotlin/theodolite/execution/ExecutionModes.kt @@ -0,0 +1,7 @@ +package theodolite.execution + +enum class ExecutionModes(val value: String) { + OPERATOR("operator"), + YAML_EXECUTOR("yaml-executor"), + STANDALONE("standalone") +} \ No newline at end of file diff --git a/theodolite/src/main/kotlin/theodolite/execution/Main.kt b/theodolite/src/main/kotlin/theodolite/execution/Main.kt index 7d5fca859422a194e81468d9766a9e7ba29fb998..11f696ddd739e987e92ecec724390948714d898b 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/Main.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/Main.kt @@ -3,6 +3,7 @@ package theodolite.execution import io.quarkus.runtime.annotations.QuarkusMain import mu.KotlinLogging import theodolite.execution.operator.TheodoliteOperator +import theodolite.util.Configuration import kotlin.system.exitProcess private val logger = KotlinLogging.logger {} @@ -13,13 +14,12 @@ object Main { @JvmStatic fun main(args: Array<String>) { - val mode = System.getenv("MODE") ?: "standalone" + val mode = Configuration.EXECUTION_MODE logger.info { "Start Theodolite with mode $mode" } - when (mode) { - "standalone" -> TheodoliteStandalone().start() - "yaml-executor" -> TheodoliteStandalone().start() // TODO remove (#209) - "operator" -> TheodoliteOperator().start() + when (mode.toLowerCase()) { + ExecutionModes.STANDALONE.value, ExecutionModes.YAML_EXECUTOR.value -> TheodoliteStandalone().start() // TODO remove standalone (#209) + ExecutionModes.OPERATOR.value -> TheodoliteOperator().start() else -> { logger.error { "MODE $mode not found" } exitProcess(1) diff --git a/theodolite/src/main/kotlin/theodolite/execution/operator/EventCreator.kt b/theodolite/src/main/kotlin/theodolite/execution/operator/EventCreator.kt index 69b21155d939c4e17b4da21f12f9d4e4d7e993f5..fab098ebd5fe765a455d787ddb7fcbfbb6c9ffc7 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/operator/EventCreator.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/operator/EventCreator.kt @@ -6,7 +6,6 @@ import io.fabric8.kubernetes.api.model.ObjectReference import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.fabric8.kubernetes.client.NamespacedKubernetesClient import mu.KotlinLogging -import theodolite.util.Config import theodolite.util.Configuration import java.time.Instant import java.util.* diff --git a/theodolite/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt b/theodolite/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt index 98bb4ed2a3fa8ab6fdef9af10b4601787c2306cf..131093a432dfd6ec409c75d084ad8bbfef78ac56 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt @@ -5,6 +5,7 @@ import io.fabric8.kubernetes.client.dsl.Resource import mu.KotlinLogging import theodolite.benchmark.BenchmarkExecution import theodolite.benchmark.KubernetesBenchmark +import theodolite.execution.ExecutionModes import theodolite.execution.TheodoliteExecutor import theodolite.model.crd.* import theodolite.patcher.ConfigOverrideModifier @@ -96,7 +97,7 @@ class TheodoliteController( } } } catch (e: Exception) { - EventCreator().createEvent( + EventCreator().createEvent( executionName = execution.name, type = "WARNING", reason = "Execution failed", diff --git a/theodolite/src/main/kotlin/theodolite/util/Configuration.kt b/theodolite/src/main/kotlin/theodolite/util/Configuration.kt index 5bc1edd1954726146ac32dd2139459d60e013d2b..dac3b943e69bd7e208d318f2a788275f19db11e4 100644 --- a/theodolite/src/main/kotlin/theodolite/util/Configuration.kt +++ b/theodolite/src/main/kotlin/theodolite/util/Configuration.kt @@ -1,5 +1,7 @@ package theodolite.util +import theodolite.execution.ExecutionModes + // Defaults private const val DEFAULT_NAMESPACE = "default" private const val DEFAULT_COMPONENT_NAME = "theodolite-operator" @@ -10,6 +12,7 @@ class Configuration( companion object { val NAMESPACE = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE val COMPONENT_NAME = System.getenv("COMPONENT_NAME") ?: DEFAULT_COMPONENT_NAME + val EXECUTION_MODE = System.getenv("MODE") ?: ExecutionModes.STANDALONE.value } }