From 88bc461adf6f0d8efe5051361b3c3411cc4abe3a Mon Sep 17 00:00:00 2001
From: Simon Ehrenstein <simon.ehrenstein@gmail.com>
Date: Sat, 23 Jan 2021 15:59:56 +0100
Subject: [PATCH] Integrate kubernetes resources an logging

---
 .../src/main/kotlin/theodolite/Benchmark.kt     |  9 ---------
 .../main/kotlin/theodolite/BenchmarkExecutor.kt | 17 -----------------
 .../execution/KafkaBenchmarkExecutor.kt         | 16 +++++++++++++---
 .../execution/TestBenchmarkExecutor.kt          |  3 ++-
 .../kotlin/theodolite/{ => k8s}/TopicManager.kt |  2 +-
 .../{ => k8s}/WorkloadGeneratorStateCleaner.kt  |  0
 .../main/kotlin/theodolite/util/Benchmark.kt    |  3 +++
 .../kotlin/theodolite/util/TestBenchmark.kt     |  6 +++++-
 8 files changed, 24 insertions(+), 32 deletions(-)
 delete mode 100644 theodolite-quarkus/src/main/kotlin/theodolite/Benchmark.kt
 delete mode 100644 theodolite-quarkus/src/main/kotlin/theodolite/BenchmarkExecutor.kt
 rename theodolite-quarkus/src/main/kotlin/theodolite/{ => k8s}/TopicManager.kt (98%)
 rename theodolite-quarkus/src/main/kotlin/theodolite/{ => k8s}/WorkloadGeneratorStateCleaner.kt (100%)

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/Benchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/Benchmark.kt
deleted file mode 100644
index b68007278..000000000
--- a/theodolite-quarkus/src/main/kotlin/theodolite/Benchmark.kt
+++ /dev/null
@@ -1,9 +0,0 @@
-package theodolite
-
-class Benchmark {
-    fun start() {}
-
-    fun stop() {}
-
-    fun startWorkloadGenerator(wg: String, dimValue: Int, ucId: String) { }
-}
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/BenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/BenchmarkExecutor.kt
deleted file mode 100644
index 1790cfe81..000000000
--- a/theodolite-quarkus/src/main/kotlin/theodolite/BenchmarkExecutor.kt
+++ /dev/null
@@ -1,17 +0,0 @@
-package theodolite
-
-class BenchmarkExecutor(benchmark: Benchmark) {
-    val benchmark: Benchmark = benchmark
-
-    fun waitExecution(executionMinutes: Int) {
-    val milliToMinutes = 60000
-    System.out.println("Wait while executing")
-    for (i in 1.rangeTo(executionMinutes)) {
-       Thread.sleep((milliToMinutes * i).toLong())
-       System.out.println("Executed: $i minutes")
-    }
-
-    System.out.println("Execution finished")
- }
-    fun runExperiment() {}
-}
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/KafkaBenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/KafkaBenchmarkExecutor.kt
index 730be8765..e019e80d0 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/KafkaBenchmarkExecutor.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/KafkaBenchmarkExecutor.kt
@@ -1,19 +1,29 @@
 package theodolite.execution
 
+import mu.KotlinLogging
 import theodolite.util.Benchmark
 import theodolite.util.LoadDimension
 import theodolite.util.Resource
 import theodolite.util.Results
 import java.time.Duration
 
+private val logger = KotlinLogging.logger {}
+
 class KafkaBenchmarkExecutor(benchmark: Benchmark, results: Results, executionDuration: Duration) : BenchmarkExecutor(benchmark, results, executionDuration) {
     override fun runExperiment(load: LoadDimension, res: Resource): Boolean {
         benchmark.start()
-        // wait
+        this.waitAndLog()
         benchmark.stop()
-        // evaluate
-        val result = false // if success else false
+        // todo evaluate
+        val result = false // if success else falsew
         this.results.setResult(Pair(load, res), result)
         return result;
     }
+
+    private fun waitAndLog() {
+        for (i in 1.rangeTo(executionDuration.toMinutes())) {
+            Thread.sleep(Duration.ofMinutes(1).toMillis())
+            logger.info { "Executed: $i minutes" }
+        }
+    }
 }
\ No newline at end of file
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt
index d98ba3fb1..5bcfa5e77 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TestBenchmarkExecutor.kt
@@ -5,9 +5,10 @@ import theodolite.util.Benchmark
 import theodolite.util.LoadDimension
 import theodolite.util.Resource
 import theodolite.util.Results
+import java.time.Duration
 
 class TestBenchmarkExecutor(private val mockResults: Array<Array<Boolean>>, benchmark: Benchmark, results: Results):
-    BenchmarkExecutor(benchmark, results) {
+    BenchmarkExecutor(benchmark, results, executionDuration = Duration.ofSeconds(1)) {
 
     override fun runExperiment(load: LoadDimension, res: Resource): Boolean {
         val result = this.mockResults[load.get()][res.get()]
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/TopicManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt
similarity index 98%
rename from theodolite-quarkus/src/main/kotlin/theodolite/TopicManager.kt
rename to theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt
index a62a8d825..73daeda6f 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/TopicManager.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt
@@ -1,4 +1,4 @@
-package theodolite
+package theodolite.k8s
 
 import org.apache.kafka.clients.admin.AdminClient
 import org.apache.kafka.clients.admin.AdminClientConfig
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/WorkloadGeneratorStateCleaner.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt
similarity index 100%
rename from theodolite-quarkus/src/main/kotlin/theodolite/WorkloadGeneratorStateCleaner.kt
rename to theodolite-quarkus/src/main/kotlin/theodolite/k8s/WorkloadGeneratorStateCleaner.kt
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/Benchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/Benchmark.kt
index c4cb2be17..c3ddab0fa 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/util/Benchmark.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/Benchmark.kt
@@ -5,4 +5,7 @@ abstract class Benchmark(val config: Map<String, Any>) {
     abstract fun start();
 
     abstract fun stop();
+
+    abstract fun startWorkloadGenerator(wg: String, dimValue: Int, ucId: String);
+
 }
\ No newline at end of file
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/TestBenchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/TestBenchmark.kt
index e95c2070f..6d2dbb116 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/util/TestBenchmark.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/TestBenchmark.kt
@@ -1,6 +1,6 @@
 package theodolite.util
 
-class TestBenchmark: Benchmark {
+class TestBenchmark: Benchmark(config = emptyMap()) {
     override fun start() {
         TODO("Not yet implemented")
     }
@@ -8,4 +8,8 @@ class TestBenchmark: Benchmark {
     override fun stop() {
         TODO("Not yet implemented")
     }
+
+    override fun startWorkloadGenerator(wg: String, dimValue: Int, ucId: String) {
+        TODO("Not yet implemented")
+    }
 }
\ No newline at end of file
-- 
GitLab