Skip to content
Snippets Groups Projects
Commit 2a4546a2 authored by Simon Ehrenstein's avatar Simon Ehrenstein
Browse files

Add initialized check

parent df0812d6
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!106Introduce a Theodolite operator,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
......@@ -17,7 +17,8 @@ class TheodoliteController(
val informerBenchmarkExecution: SharedInformer<BenchmarkExecution>,
val informerBenchmarkType: SharedInformer<KubernetesBenchmark>
) {
var executor: TheodoliteExecutor = TheodoliteExecutor()
lateinit var executor: TheodoliteExecutor
val self = this
val executionsQueue: Queue<BenchmarkExecution> = LinkedList<BenchmarkExecution>()
val benchmarks: MutableMap<String, KubernetesBenchmark> = HashMap()
......@@ -34,7 +35,7 @@ class TheodoliteController(
override fun onUpdate(oldExecution: BenchmarkExecution, newExecution: BenchmarkExecution) {
if (executor.getExecution().name == newExecution.name) {
executor.stop()
executor.setExecution(newExecution)
executor = TheodoliteExecutor(config = newExecution, kubernetesBenchmark = executor.getBenchmark())
executor.run()
} else {
executionsQueue.remove(oldExecution)
......@@ -60,7 +61,7 @@ class TheodoliteController(
onAdd(newBenchmark)
if (executor.getBenchmark().name == oldBenchmark.name) {
executor.stop()
executor.setBenchmark(newBenchmark)
executor = TheodoliteExecutor(config = executor.getExecution(), kubernetesBenchmark = newBenchmark)
executor.run()
}
}
......@@ -86,16 +87,17 @@ class TheodoliteController(
@Synchronized
private fun reconcile() {
while(executionsQueue.isNotEmpty() && !executor.isRunning) {
while(executionsQueue.isNotEmpty()) {
val execution = executionsQueue.poll()
val benchmark = benchmarks[execution.name]
if (benchmark == null) {
logger.error { "No benchmark found for execution ${execution.name}" }
executionsQueue.add(execution)
} else {
executor.setExecution(execution)
executor.setBenchmark(benchmark)
executor.run()
if ((this::executor.isInitialized && !executor.isRunning) || !this::executor.isInitialized) {
executor = TheodoliteExecutor(config = execution, kubernetesBenchmark = benchmark)
executor.run()
}
}
}
}
......
......@@ -24,13 +24,14 @@ class TheodoliteExecutor(
private val executionThread = Thread {
if(config == null || kubernetesBenchmark == null) {
logger.error { "Execution or Benchmark not found" }
}else {
} else {
val config = buildConfig()
// execute benchmarks for each load
for (load in config.loads) {
config.compositeStrategy.findSuitableResource(load, config.resources)
}
}
isRunning = false
}
var isRunning = false
......@@ -91,21 +92,13 @@ class TheodoliteExecutor(
fun run() {
isRunning = true
logger.info { "Start thread" }
executionThread.run()
logger.info { "Stop Thread" }
}
fun stop() {
isRunning = false
executionThread.interrupt()
}
fun setExecution(config: BenchmarkExecution) {
this.config = config
}
fun setBenchmark(benchmark: KubernetesBenchmark) {
this.kubernetesBenchmark = benchmark
}
constructor() {}
}
}
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