Skip to content
Snippets Groups Projects
Commit dcab3da4 authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

Check if Theodolite is running in operator mode before creating K8s events

parent 3cd94b43
No related branches found
No related tags found
1 merge request!173Introduce events in order to make it possible to see simple log message with...
...@@ -6,10 +6,7 @@ import theodolite.benchmark.Benchmark ...@@ -6,10 +6,7 @@ import theodolite.benchmark.Benchmark
import theodolite.benchmark.BenchmarkExecution import theodolite.benchmark.BenchmarkExecution
import theodolite.evaluation.AnalysisExecutor import theodolite.evaluation.AnalysisExecutor
import theodolite.execution.operator.EventCreator import theodolite.execution.operator.EventCreator
import theodolite.util.ConfigurationOverride import theodolite.util.*
import theodolite.util.LoadDimension
import theodolite.util.Resource
import theodolite.util.Results
import java.time.Duration import java.time.Duration
import java.time.Instant import java.time.Instant
...@@ -40,6 +37,7 @@ class BenchmarkExecutorImpl( ...@@ -40,6 +37,7 @@ class BenchmarkExecutorImpl(
executionName executionName
) { ) {
private val eventCreator = EventCreator() private val eventCreator = EventCreator()
private val mode = Configuration.EXECUTION_MODE
override fun runExperiment(load: LoadDimension, res: Resource): Boolean { override fun runExperiment(load: LoadDimension, res: Resource): Boolean {
var result = false var result = false
...@@ -82,39 +80,46 @@ class BenchmarkExecutorImpl( ...@@ -82,39 +80,46 @@ class BenchmarkExecutorImpl(
try { try {
benchmarkDeployment.setup() benchmarkDeployment.setup()
this.waitAndLog() this.waitAndLog()
eventCreator.createEvent( if (mode == ExecutionModes.OPERATOR.value) {
executionName = executionName, eventCreator.createEvent(
type = "NORMAL", executionName = executionName,
reason = "Start experiment", type = "NORMAL",
message = "load: ${load.get()}, resources: ${res.get()}") reason = "Start experiment",
message = "load: ${load.get()}, resources: ${res.get()}")
}
} catch (e: Exception) { } catch (e: Exception) {
logger.error { "Error while setup experiment." } logger.error { "Error while setup experiment." }
logger.error { "Error is: $e" } logger.error { "Error is: $e" }
this.run.set(false) this.run.set(false)
eventCreator.createEvent( if (mode == ExecutionModes.OPERATOR.value) {
executionName = executionName, eventCreator.createEvent(
type = "WARNING", executionName = executionName,
reason = "Start experiment failed", type = "WARNING",
message = "load: ${load.get()}, resources: ${res.get()}") reason = "Start experiment failed",
message = "load: ${load.get()}, resources: ${res.get()}")
}
} }
val to = Instant.now() val to = Instant.now()
try { try {
benchmarkDeployment.teardown() benchmarkDeployment.teardown()
eventCreator.createEvent( if (mode == ExecutionModes.OPERATOR.value) {
executionName = executionName, eventCreator.createEvent(
type = "NORMAL", executionName = executionName,
reason = "Stop experiment", type = "NORMAL",
message = "Teardown complete") reason = "Stop experiment",
message = "Teardown complete")
}
} catch (e: Exception) { } catch (e: Exception) {
logger.warn { "Error while tearing down the benchmark deployment." } logger.warn { "Error while tearing down the benchmark deployment." }
logger.debug { "Teardown failed, caused by: $e" } logger.debug { "Teardown failed, caused by: $e" }
if (mode == ExecutionModes.OPERATOR.value) {
eventCreator.createEvent( eventCreator.createEvent(
executionName = executionName, executionName = executionName,
type = "WARNING", type = "WARNING",
reason = "Stop experiment failed", reason = "Stop experiment failed",
message = "Teardown failed: ${e.message}") message = "Teardown failed: ${e.message}")
}
} }
return Pair(from, to) return Pair(from, to)
} }
......
package theodolite.execution
enum class ExecutionModes(val value: String) {
OPERATOR("operator"),
YAML_EXECUTOR("yaml-executor"),
STANDALONE("standalone")
}
\ No newline at end of file
...@@ -3,6 +3,7 @@ package theodolite.execution ...@@ -3,6 +3,7 @@ package theodolite.execution
import io.quarkus.runtime.annotations.QuarkusMain import io.quarkus.runtime.annotations.QuarkusMain
import mu.KotlinLogging import mu.KotlinLogging
import theodolite.execution.operator.TheodoliteOperator import theodolite.execution.operator.TheodoliteOperator
import theodolite.util.Configuration
import kotlin.system.exitProcess import kotlin.system.exitProcess
private val logger = KotlinLogging.logger {} private val logger = KotlinLogging.logger {}
...@@ -13,13 +14,12 @@ object Main { ...@@ -13,13 +14,12 @@ object Main {
@JvmStatic @JvmStatic
fun main(args: Array<String>) { fun main(args: Array<String>) {
val mode = System.getenv("MODE") ?: "standalone" val mode = Configuration.EXECUTION_MODE
logger.info { "Start Theodolite with mode $mode" } logger.info { "Start Theodolite with mode $mode" }
when (mode) { when (mode.toLowerCase()) {
"standalone" -> TheodoliteStandalone().start() ExecutionModes.STANDALONE.value, ExecutionModes.YAML_EXECUTOR.value -> TheodoliteStandalone().start() // TODO remove standalone (#209)
"yaml-executor" -> TheodoliteStandalone().start() // TODO remove (#209) ExecutionModes.OPERATOR.value -> TheodoliteOperator().start()
"operator" -> TheodoliteOperator().start()
else -> { else -> {
logger.error { "MODE $mode not found" } logger.error { "MODE $mode not found" }
exitProcess(1) exitProcess(1)
......
...@@ -6,7 +6,6 @@ import io.fabric8.kubernetes.api.model.ObjectReference ...@@ -6,7 +6,6 @@ import io.fabric8.kubernetes.api.model.ObjectReference
import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.fabric8.kubernetes.client.DefaultKubernetesClient
import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import mu.KotlinLogging import mu.KotlinLogging
import theodolite.util.Config
import theodolite.util.Configuration import theodolite.util.Configuration
import java.time.Instant import java.time.Instant
import java.util.* import java.util.*
......
...@@ -5,6 +5,7 @@ import io.fabric8.kubernetes.client.dsl.Resource ...@@ -5,6 +5,7 @@ import io.fabric8.kubernetes.client.dsl.Resource
import mu.KotlinLogging import mu.KotlinLogging
import theodolite.benchmark.BenchmarkExecution import theodolite.benchmark.BenchmarkExecution
import theodolite.benchmark.KubernetesBenchmark import theodolite.benchmark.KubernetesBenchmark
import theodolite.execution.ExecutionModes
import theodolite.execution.TheodoliteExecutor import theodolite.execution.TheodoliteExecutor
import theodolite.model.crd.* import theodolite.model.crd.*
import theodolite.patcher.ConfigOverrideModifier import theodolite.patcher.ConfigOverrideModifier
...@@ -96,7 +97,7 @@ class TheodoliteController( ...@@ -96,7 +97,7 @@ class TheodoliteController(
} }
} }
} catch (e: Exception) { } catch (e: Exception) {
EventCreator().createEvent( EventCreator().createEvent(
executionName = execution.name, executionName = execution.name,
type = "WARNING", type = "WARNING",
reason = "Execution failed", reason = "Execution failed",
......
package theodolite.util package theodolite.util
import theodolite.execution.ExecutionModes
// Defaults // Defaults
private const val DEFAULT_NAMESPACE = "default" private const val DEFAULT_NAMESPACE = "default"
private const val DEFAULT_COMPONENT_NAME = "theodolite-operator" private const val DEFAULT_COMPONENT_NAME = "theodolite-operator"
...@@ -10,6 +12,7 @@ class Configuration( ...@@ -10,6 +12,7 @@ class Configuration(
companion object { companion object {
val NAMESPACE = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE val NAMESPACE = System.getenv("NAMESPACE") ?: DEFAULT_NAMESPACE
val COMPONENT_NAME = System.getenv("COMPONENT_NAME") ?: DEFAULT_COMPONENT_NAME val COMPONENT_NAME = System.getenv("COMPONENT_NAME") ?: DEFAULT_COMPONENT_NAME
val EXECUTION_MODE = System.getenv("MODE") ?: ExecutionModes.STANDALONE.value
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment