From 4ffaa587c5cbbb9f98caecf3a29fc35f3155e70a Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Fri, 5 Feb 2021 10:02:13 +0100
Subject: [PATCH] apply review, minor code changes

---
 .../theodolite/execution/BenchmarkExecutor.kt      | 14 ++++++++++++++
 .../theodolite/execution/BenchmarkExecutorImpl.kt  |  9 ---------
 .../kotlin/theodolite/k8s/DeploymentManager.kt     |  2 +-
 .../src/main/kotlin/theodolite/k8s/TopicManager.kt | 12 ++++++------
 .../src/main/kotlin/theodolite/k8s/UC1Benchmark.kt |  4 ----
 .../src/main/kotlin/theodolite/k8s/YamlLoader.kt   |  2 +-
 .../restriction/LowerBoundRestriction.kt           |  3 ++-
 7 files changed, 24 insertions(+), 22 deletions(-)

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt
index b90567710..751e2d322 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt
@@ -1,11 +1,14 @@
 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 {}
+
 /**
  * The Benchmark Executor runs a single experiment.
  *
@@ -23,4 +26,15 @@ abstract class BenchmarkExecutor(val benchmark: Benchmark, val results: Results,
      * @return True, if the number of resources are suitable for the given load, false otherwise.
      */
     abstract fun runExperiment(load: LoadDimension, res: Resource): Boolean;
+
+    /**
+     * Wait while the benchmark is running and log the number of minutes executed every 1 minute.
+     *
+     */
+    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/BenchmarkExecutorImpl.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt
index 3ddd07584..189b32043 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt
@@ -7,8 +7,6 @@ import theodolite.util.Resource
 import theodolite.util.Results
 import java.time.Duration
 
-private val logger = KotlinLogging.logger {}
-
 class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDuration: Duration) : BenchmarkExecutor(benchmark, results, executionDuration) {
     override fun runExperiment(load: LoadDimension, res: Resource): Boolean {
         benchmark.start(load, res)
@@ -19,11 +17,4 @@ class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDur
         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/k8s/DeploymentManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt
index 3731b98fa..af59c5236 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/DeploymentManager.kt
@@ -34,7 +34,7 @@ class DeploymentManager(private val client: NamespacedKubernetesClient) {
     }
 
     /**
-     * Set the enviroment Variable for a container
+     * Set the environment Variable for a container
      */
     fun setWorkloadEnv(workloadDeployment: Deployment, containerName: String, map: Map<String, String>) {
         workloadDeployment.spec.template.spec.containers.filter { it.name == containerName }
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt
index bf504c7cf..4f75298f3 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/TopicManager.kt
@@ -8,8 +8,8 @@ import org.apache.kafka.clients.admin.NewTopic
 
 private val logger = KotlinLogging.logger {}
 
-class TopicManager(boostrapIp: String) {
-    private val props = hashMapOf<String, Any>(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG to boostrapIp)
+class TopicManager(bootstrapServers: String) {
+    private val props = hashMapOf<String, Any>(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG to bootstrapServers)
     lateinit var kafkaAdmin: AdminClient
 
     init {
@@ -20,22 +20,22 @@ class TopicManager(boostrapIp: String) {
         }
     }
 
-    fun createTopics(topics: Map<String, Int>, replicationfactor: Short) {
+    fun createTopics(topics: Map<String, Int>, replicationFactor: Short) {
 
         val newTopics = mutableSetOf<NewTopic>()
         for (i in topics) {
-            val tops = NewTopic(i.key, i.value, replicationfactor)
+            val tops = NewTopic(i.key, i.value, replicationFactor)
             newTopics.add(tops)
         }
         kafkaAdmin.createTopics(newTopics)
         logger.info {"Topics created"}
     }
 
-    fun createTopics(topics: List<String>, numPartitions: Int, replicationfactor: Short) {
+    fun createTopics(topics: List<String>, numPartitions: Int, replicationFactor: Short) {
 
         val newTopics = mutableSetOf<NewTopic>()
         for (i in topics) {
-            val tops = NewTopic(i, numPartitions, replicationfactor)
+            val tops = NewTopic(i, numPartitions, replicationFactor)
             newTopics.add(tops)
         }
         kafkaAdmin.createTopics(newTopics)
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/UC1Benchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/UC1Benchmark.kt
index 506014e0a..7e1347973 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/UC1Benchmark.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/UC1Benchmark.kt
@@ -51,10 +51,6 @@ class UC1Benchmark(config: UC1BenchmarkConfig) : Benchmark(config) {
     }
 
     override fun initializeClusterEnvironment() {
-        // this.workloadGeneratorStateCleaner.deleteAll()
-        // since the workloadGenerators are not started they cant be deleted
-
-        this.topicManager.deleteTopics(this.config.kafkaTopics)
         this.topicManager.createTopics(
             this.config.kafkaTopics,
             this.config.kafkaPartition,
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/YamlLoader.kt b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/YamlLoader.kt
index ffdc3e6d5..5e37e97df 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/k8s/YamlLoader.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/k8s/YamlLoader.kt
@@ -63,7 +63,7 @@ class YamlLoader(private val client: NamespacedKubernetesClient) {
         }
 
         if (resource == null) {
-            throw NullPointerException("The Ressource at path: $path could not be loaded")
+            throw IllegalArgumentException("The Resource at path: $path could not be loaded")
         }
 
         return resource
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt
index dfe05009d..093ef3b10 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/strategies/restriction/LowerBoundRestriction.kt
@@ -5,7 +5,8 @@ import theodolite.util.LoadDimension
 import theodolite.util.Resource
 
 /**
- * The Lower Bound Restriction
+ * The Lower Bound Restriction sets the lower bound of the resources to be examined to the value
+ * needed to successfully execute the next smaller load.
  *
  * @param results Result object used as a basis to restrict the resources.
  */
-- 
GitLab