From 563a65ec9b45b042ba6b554ad55ab344cd6d6e45 Mon Sep 17 00:00:00 2001 From: lorenz <stu203404@mail.uni-kiel.de> Date: Sat, 23 Jan 2021 03:21:34 +0100 Subject: [PATCH] Add limit and Image exchange funtions --- .../YAML/aggregation-deployment.yaml | 55 +++++++++++++++++++ .../kotlin/theodolite/DeploymentManager.kt | 48 +++++++++++----- 2 files changed, 89 insertions(+), 14 deletions(-) create mode 100644 theodolite-quarkus/YAML/aggregation-deployment.yaml diff --git a/theodolite-quarkus/YAML/aggregation-deployment.yaml b/theodolite-quarkus/YAML/aggregation-deployment.yaml new file mode 100644 index 000000000..07732ca1d --- /dev/null +++ b/theodolite-quarkus/YAML/aggregation-deployment.yaml @@ -0,0 +1,55 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: titan-ccp-aggregation +spec: + selector: + matchLabels: + app: titan-ccp-aggregation + replicas: 1 + template: + metadata: + labels: + app: titan-ccp-aggregation + spec: + terminationGracePeriodSeconds: 0 + containers: + - name: uc-application + image: uc-app:latest + ports: + - containerPort: 5555 + name: jmx + env: + - name: KAFKA_BOOTSTRAP_SERVERS + value: "my-confluent-cp-kafka:9092" + - name: SCHEMA_REGISTRY_URL + value: "http://my-confluent-cp-schema-registry:8081" + - name: JAVA_OPTS + value: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.port=5555" + - name: COMMIT_INTERVAL_MS # Set as default for the applications + value: "100" + resources: + limits: + memory: 4Gi + cpu: 1000m + - name: prometheus-jmx-exporter + image: "solsson/kafka-prometheus-jmx-exporter@sha256:6f82e2b0464f50da8104acd7363fb9b995001ddff77d248379f8788e78946143" + command: + - java + - -XX:+UnlockExperimentalVMOptions + - -XX:+UseCGroupMemoryLimitForHeap + - -XX:MaxRAMFraction=1 + - -XshowSettings:vm + - -jar + - jmx_prometheus_httpserver.jar + - "5556" + - /etc/jmx-aggregation/jmx-kafka-prometheus.yml + ports: + - containerPort: 5556 + volumeMounts: + - name: jmx-config + mountPath: /etc/jmx-aggregation + volumes: + - name: jmx-config + configMap: + name: aggregation-jmx-configmap diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/DeploymentManager.kt b/theodolite-quarkus/src/main/kotlin/theodolite/DeploymentManager.kt index a06f0354a..ea1d53ef6 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/DeploymentManager.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/DeploymentManager.kt @@ -1,6 +1,7 @@ package theodolite import com.fasterxml.jackson.annotation.JsonProperty +import io.fabric8.kubernetes.api.model.Quantity import io.fabric8.kubernetes.api.model.Service import io.fabric8.kubernetes.api.model.apps.Deployment import io.fabric8.kubernetes.client.DefaultKubernetesClient @@ -11,12 +12,15 @@ import java.nio.file.Paths class DeploymentManager { + val MEMORYLIMIT = "memory" + val CPULIMIT = "memory" val absolute = Paths.get("").toAbsolutePath().toString() val path = "/home/lorenz/git/spesb/theodolite-quarkus/YAML/" val theodoliteDeploment = "theodolite.yaml" val service = "aggregation-service.yaml" val workloadFile = "workloadGenerator.yaml" + val usecase = "aggregation-deployment.yaml" val inputStream: InputStream = path.byteInputStream() val client = DefaultKubernetesClient().inNamespace("default") @@ -25,25 +29,32 @@ class DeploymentManager { val dp: Service = client.services().load(path+service).get(); val workload : Deployment = client.apps().deployments().load(path+workloadFile).get(); + val use : Deployment = client.apps().deployments().load(path+usecase).get(); + // TODO MAKE YAML LOADING CATCH EXEPTION fun printFile(){ +// +// println(workload) +// changeWorkloadNumInstances(workload,"5000") +// println(workload) - //println(workload) - changeWorkloadNumInstances(workload,5000) - //println(workload) + println(use) + changeRessourceLimits(use, MEMORYLIMIT,"5Gi") + println(use) - println(path) - val f : File = File(path+theodoliteDeploment); - val fileAsString : String = String(f.readBytes()) - //println(fileAsString.replace("theodolite","spesb")) +// println(path) +// val f : File = File(path+theodoliteDeploment); +// val fileAsString : String = String(f.readBytes()) +// println(fileAsString.replace("theodolite","spesb")) } + // SERVICE fun changeServiceName (service: Service,newName : String){ service.metadata.apply { @@ -51,19 +62,28 @@ class DeploymentManager { } } - fun changeWorkloadNumInstances (dep: Deployment,num: String){ + // WORKLOAD GEN + fun changeWorkloadNumInstances (dep: Deployment,num: String) { - val vars = dep.spec.template.spec.containers.get(0).env.filter { + dep.spec.template.spec.containers.get(0).env.filter { it.name == "NUM_SENSORS" - }.forEach { - x -> - x.value = num + }.forEach { x -> + x.value = num } + } + // APPLICATION + fun changeRessourceLimits(dep: Deployment, ressource: String, limit: String) { - println(vars) - + val vars = dep.spec.template.spec.containers.filter { it.name == "uc-application" }.forEach { + it.resources.limits.replace(ressource, Quantity(limit)) + } } + fun changeImage(dep: Deployment, image: String) { + + dep.spec.template.spec.containers.filter { it.name == "uc-application" }.forEach { + it.image = image } + } } -- GitLab