From 94dc4d342ab489bcebd32520462bb48a61464846 Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Fri, 19 Feb 2021 14:45:11 +0100
Subject: [PATCH] Read basic configuration for Kafka and Zookeeper

---
 .../benchmark/KubernetesBenchmark.kt          | 19 ++++++++++++-------
 .../KubernetesBenchmarkDeployment.kt          |  1 +
 .../kotlin/theodolite/util/KafkaConfig.kt     | 16 ++++++++++++++++
 .../resources/yaml/testBenchmarkType.yaml     | 10 +++++++++-
 .../src/main/resources/yaml/testContext.yaml  |  2 +-
 5 files changed, 39 insertions(+), 9 deletions(-)
 create mode 100644 theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt
index 61a8dcfc2..8f08bf282 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt
@@ -2,12 +2,11 @@ package theodolite.benchmark
 
 import io.fabric8.kubernetes.api.model.KubernetesResource
 import io.fabric8.kubernetes.client.DefaultKubernetesClient
+import org.apache.kafka.clients.admin.NewTopic
 import theodolite.k8s.YamlLoader
 import theodolite.patcher.PatcherManager
-import theodolite.util.LoadDimension
-import theodolite.util.OverridePatcherDefinition
-import theodolite.util.Resource
-import theodolite.util.TypeName
+import theodolite.util.*
+import java.util.*
 
 class KubernetesBenchmark(): Benchmark {
     lateinit var name: String
@@ -15,6 +14,8 @@ class KubernetesBenchmark(): Benchmark {
     lateinit var loadGenResource: List<String>
     lateinit var resourceTypes: List<TypeName>
     lateinit var loadTypes: List<TypeName>
+    lateinit var kafkaConfig: KafkaConfig
+    lateinit var zookeeperConfig: HashMap<String,String>
 
 
 
@@ -45,9 +46,13 @@ class KubernetesBenchmark(): Benchmark {
 
         // patch overrides
         overrides.forEach {override ->  patcherManager.applyPatcher(override, resources)}
+        println(zookeeperConfig["server"] !! )
 
-        resources.forEach {x -> println(x)}
-
-        return KubernetesBenchmarkDeployment(emptyList(), hashMapOf<String, Any>(), "", emptyList())
+        return KubernetesBenchmarkDeployment(
+            resources.map { r -> r.second },
+            kafkaConfig = hashMapOf("bootstrap.servers" to kafkaConfig.bootstrapSever),
+            zookeeperConfig = zookeeperConfig["server"].toString() !!,
+            topics = kafkaConfig.topics.map { topic -> NewTopic(topic.name, topic.partition, topic.replication ) })
     }
 }
+
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt
index ac7ab1b01..3c1473691 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmarkDeployment.kt
@@ -6,6 +6,7 @@ import org.apache.kafka.clients.admin.NewTopic
 import theodolite.k8s.K8sManager
 import theodolite.k8s.TopicManager
 import theodolite.k8s.WorkloadGeneratorStateCleaner
+import java.util.*
 
 class KubernetesBenchmarkDeployment(
     val resources: List<KubernetesResource>, // List of already patched resources
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt b/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt
new file mode 100644
index 000000000..dd6471d59
--- /dev/null
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/util/KafkaConfig.kt
@@ -0,0 +1,16 @@
+package theodolite.util
+
+import kotlin.properties.Delegates
+
+
+class KafkaConfig() {
+    lateinit var bootstrapSever: String
+    lateinit var topics: List<Topic>
+
+    class Topic() {
+        lateinit var name: String
+        var partition by Delegates.notNull<Int>()
+        var replication by Delegates.notNull<Short>()
+
+    }
+}
\ No newline at end of file
diff --git a/theodolite-quarkus/src/main/resources/yaml/testBenchmarkType.yaml b/theodolite-quarkus/src/main/resources/yaml/testBenchmarkType.yaml
index f8c9d3fff..dfc19f967 100644
--- a/theodolite-quarkus/src/main/resources/yaml/testBenchmarkType.yaml
+++ b/theodolite-quarkus/src/main/resources/yaml/testBenchmarkType.yaml
@@ -15,4 +15,12 @@ loadTypes:
       - type: "EnvVarPatcher"
         resource: "workloadGenerator.yaml"
         container: "workload-generator"
-        variableName: "NUM_SENSORS"
\ No newline at end of file
+        variableName: "NUM_SENSORS"
+kafkaConfig:
+  bootstrapSever: "my-confluent-cp-kafka:9092"
+  topics:
+    - name: "test"
+      partition: "1"
+      replication: "1"
+zookeeperConfig:
+  server: "my-confluent-cp-zookeeper:2181"
\ No newline at end of file
diff --git a/theodolite-quarkus/src/main/resources/yaml/testContext.yaml b/theodolite-quarkus/src/main/resources/yaml/testContext.yaml
index 6073f8de6..46ba710c8 100644
--- a/theodolite-quarkus/src/main/resources/yaml/testContext.yaml
+++ b/theodolite-quarkus/src/main/resources/yaml/testContext.yaml
@@ -21,4 +21,4 @@ configOverrides:
     container: "workload-generator"
     overrides:
       overrideTestA: "8888"
-      overrideTestB: "6666"
+      overrideTestB: "6666"
\ No newline at end of file
-- 
GitLab