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
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)
}
......
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
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)
......
......@@ -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.*
......
......@@ -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",
......
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
}
}
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