Skip to content
Snippets Groups Projects
Commit 4da0a590 authored by Lorenz Boguhn's avatar Lorenz Boguhn
Browse files

Logger + ServiceManager + ConfigMaps + Refactoring

parent 884d7a12
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus,!78Resolve "Implement Quarkus/Kotlin protype"
apiVersion: v1
kind: ConfigMap
metadata:
name: aggregation-jmx-configmap
data:
jmx-kafka-prometheus.yml: |+
jmxUrl: service:jmx:rmi:///jndi/rmi://localhost:5555/jmxrmi
lowercaseOutputName: true
lowercaseOutputLabelNames: true
ssl: false
package theodolite package theodolite
import com.fasterxml.jackson.annotation.JsonProperty
import io.fabric8.kubernetes.api.model.* import io.fabric8.kubernetes.api.model.*
import io.fabric8.kubernetes.api.model.apps.Deployment import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.fabric8.kubernetes.client.DefaultKubernetesClient
import io.fabric8.kubernetes.client.dsl.RollableScalableResource import mu.KotlinLogging
import java.io.File
import java.io.InputStream import java.io.InputStream
import java.nio.file.Paths import java.nio.file.Paths
private val logger = KotlinLogging.logger {}
class DeploymentManager { class DeploymentManager {
val MEMORYLIMIT = "memory" val MEMORYLIMIT = "memory"
...@@ -20,95 +19,94 @@ class DeploymentManager { ...@@ -20,95 +19,94 @@ class DeploymentManager {
val service = "aggregation-service.yaml" val service = "aggregation-service.yaml"
val workloadFile = "workloadGenerator.yaml" val workloadFile = "workloadGenerator.yaml"
val usecase = "aggregation-deployment.yaml" val usecase = "aggregation-deployment.yaml"
val configMap = "jmx-configmap.yaml"
val inputStream: InputStream = path.byteInputStream() val inputStream: InputStream = path.byteInputStream()
val client = DefaultKubernetesClient().inNamespace("default") val client = DefaultKubernetesClient().inNamespace("default")
val core = client.configMaps()
//val deployment = client.apps().deployments().load(absolute + path) val dp: Service = client.services().load(path + service).get()
val dp: Service = client.services().load(path + service).get();
val workload: Deployment = client.apps().deployments().load(path + workloadFile).get() val workload: Deployment = client.apps().deployments().load(path + workloadFile).get()
val use: Deployment = client.apps().deployments().load(path + usecase).get() val use: Deployment = client.apps().deployments().load(path + usecase).get()
// TODO CHANGE CONFIGURATION ENVIROMENT VARIABLES (DONE)
// TODO ASSEMBLE GOOD SEPERATION
// TODO ADD SERVICES
// TODO ADD CONFIG MAP
// TODO DELETE STUFF
// TODO MAKE YAML LOADING CATCH EXEPTION
fun printFile(){ val loader = YamlLoader(client)
val config: ConfigMap? = loader.loadConfigmap(path + configMap) // TODO ASSEMBLE GOOD SEPERATION
// // TODO REFACTOR EVErythiNG
fun printFile() {
// println(workload) // println(workload)
// changeEnviromentsInstances(workload,"5000") // changeEnviromentsInstances(workload,"5000")
// println(workload) // println(workload)
println(use) // logger.debug(use.toString())
changeRessourceLimits(use, MEMORYLIMIT,"5Gi") // changeRessourceLimits(use, MEMORYLIMIT, "5Gi")
println(use) // logger.debug(use.toString())
// println(path)
logger.info(workload.toString())
val testMap = mapOf<String, String>("NUM_SENSORS" to "5000")
val vars =
workload.spec.template.spec.containers.filter { it.name == "workload-generator" }.forEach { it: Container ->
setContainerEnv(it, testMap)
}
logger.info(workload.toString())
// logger.debug(config.toString())
// println(path)
// val f : File = File(path+theodoliteDeploment); // val f : File = File(path+theodoliteDeploment);
// val fileAsString : String = String(f.readBytes()) // val fileAsString : String = String(f.readBytes())
// println(fileAsString.replace("theodolite","spesb")) // println(fileAsString.replace("theodolite","spesb"))
} }
/** /**
* TODO REFACTOR * Sets the ContainerEvironmentVariables, creates new if variable don t exist.
* @param container - The Container
* @param map - Map of k=Name,v =Value of EnviromentVariables
*/ */
fun setContainerEnv (container: Container, map: Map<String,String>){ fun setContainerEnv(container: Container, map: Map<String, String>) {
map.forEach{ k,v -> map.forEach { k, v ->
// filter for mathing name and set value
container.env val x = container.env.filter { envvar -> envvar.name == k }
container.env.filter { x -> x.name == k }.forEach { if (x.isEmpty()) {
it.value = v val newVar = EnvVar(k, v, EnvVarSource())
container.env.add(newVar)
} else {
x.forEach {
it.value = v
}
} }
var c = container.env.filter { x -> x.name == k }
if(c.isEmpty()){
val y = EnvVar(k,v, EnvVarSource())
c = listOf(y)
}
} }
} }
/**
// SERVICE * Set the enviroment Variable for a Container
fun changeServiceName (service: Service,newName : String){ */
fun setWorkloadEnv(workloadDeployment: Deployment, containerName: String, map: Map<String, String>) {
service.metadata.apply { workloadDeployment.spec.template.spec.containers.filter { it.name == containerName }
name = newName .forEach { it: Container ->
} setContainerEnv(it, map)
} }
// WORKLOAD GEN
// TODO REFACTOR
fun changeEnviromentsInstances (dep: Deployment,num: String) {
dep.spec.template.spec.containers.get(0).env.filter {
it.name == "NUM_SENSORS"
}.forEach { x ->
x.value = num
}
} }
// APPLICATION /**
* Change the RessourceLimit of the SUT
*/
fun changeRessourceLimits(dep: Deployment, ressource: String, limit: String) { fun changeRessourceLimits(dep: Deployment, ressource: String, limit: String) {
val vars = dep.spec.template.spec.containers.filter { it.name == "uc-application" }.forEach { val vars = dep.spec.template.spec.containers.filter { it.name == "uc-application" }.forEach {
it.resources.limits.replace(ressource, Quantity(limit)) it.resources.limits.replace(ressource, Quantity(limit))
} }
} }
/**
* Change the image of the SUT and the Worklaodgenerators
*/
fun changeImage(dep: Deployment, image: String) { fun changeImage(dep: Deployment, image: String) {
dep.spec.template.spec.containers.filter { it.name == "uc-application" }.forEach { dep.spec.template.spec.containers.filter { it.name == "uc-application" }.forEach {
it.image = image } it.image = image
}
} }
} }
package theodolite package theodolite
import io.quarkus.runtime.annotations.QuarkusMain import io.quarkus.runtime.annotations.QuarkusMain
import mu.KotlinLogging import mu.KotlinLogging
private val logger = KotlinLogging.logger {} private val logger = KotlinLogging.logger {}
@QuarkusMain @QuarkusMain
...@@ -9,6 +11,8 @@ object Main { ...@@ -9,6 +11,8 @@ object Main {
fun main(args: Array<String>) { fun main(args: Array<String>) {
logger.info("Application started") logger.info("Application started")
val x = DeploymentManager()
x.printFile()
//Quarkus.run() //Quarkus.run()
} }
} }
package theodolite
import io.fabric8.kubernetes.api.model.Service
class ServiceManager {
fun changeServiceName(service: Service, newName: String) {
service.metadata.apply {
name = newName
}
}
}
package theodolite package theodolite
import io.fabric8.kubernetes.api.model.ConfigMap
import io.fabric8.kubernetes.api.model.Service import io.fabric8.kubernetes.api.model.Service
import io.fabric8.kubernetes.api.model.apps.Deployment import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import mu.KotlinLogging import mu.KotlinLogging
private val logger = KotlinLogging.logger {} private val logger = KotlinLogging.logger {}
class YamlLoader(client: NamespacedKubernetesClient) { class YamlLoader(client: NamespacedKubernetesClient) {
lateinit var client: NamespacedKubernetesClient lateinit var client: NamespacedKubernetesClient
init{ init {
this.client = client this.client = client
} }
fun loadService(path: String): Service? { fun loadService(path: String): Service? {
var service: Service? = null val service = loadGenericRessource(path, { x: String -> client.services().load(x).get() })
try {
service = client.services().load(path).get()
} catch (e: Exception) {
logger.info("You potentially misspeled the path: $path")
logger.info("$e")
}
return service return service
} }
fun loadDeployment(path: String): Deployment? { fun loadDeployment(path: String): Deployment? {
val deployment = loadGenericRessource(path,{x: String-> client.apps().deployments().load(x).get()}) val deployment = loadGenericRessource(path, { x: String -> client.apps().deployments().load(x).get() })
return deployment return deployment
} }
fun <T> loadGenericRessource(path: String, f: (String) -> T): T?{ fun loadConfigmap(path: String): ConfigMap? {
var service: T? = null val configMap = loadGenericRessource(path, { x: String -> client.configMaps().load(x).get() })
return configMap
}
fun <T> loadGenericRessource(path: String, f: (String) -> T): T? {
var resource: T? = null
try { try {
service = f(path) resource = f(path)
} catch (e: Exception) { } catch (e: Exception) {
logger.info("You potentially misspelled the path: $path") logger.info("You potentially misspelled the path: $path")
logger.info("$e") logger.info("$e")
} }
return resource
return service
}
} }
} }
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