Skip to content
Snippets Groups Projects

Change patcher signatur

Merged Benedikt Wetzel requested to merge wetzel/spesb:modify-patcher-signatur into master
All threads resolved!
Files
40
@@ -8,6 +8,7 @@ import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import io.quarkus.runtime.annotations.RegisterForReflection
import mu.KotlinLogging
import theodolite.k8s.K8sManager
import theodolite.patcher.PatchHandler
import theodolite.patcher.PatcherFactory
import theodolite.util.*
import kotlin.properties.Delegates
@@ -22,13 +23,13 @@ private var DEFAULT_THEODOLITE_APP_RESOURCES = "./benchmark-resources"
* Represents a benchmark in Kubernetes. An example for this is the BenchmarkType.yaml
* Contains a of:
* - [name] of the benchmark,
* - [appResource] list of the resources that have to be deployed for the benchmark,
* - [loadGenResource] resource that generates the load,
* - [infrastructure] resources that have to be deployed for the benchmark infrastructure
* - [sut] list of the resources that have to be deployed for the benchmark,
* - [loadGenerator] resource that generates the load,
* - [resourceTypes] types of scaling resources,
* - [loadTypes] types of loads that can be scaled for the benchmark,
* - [kafkaConfig] for the [theodolite.k8s.TopicManager],
* - [namespace] for the client,
* - [path] under which the resource yamls can be found.
*
* This class is used for the parsing(in the [theodolite.execution.TheodoliteStandalone]) and
* for the deserializing in the [theodolite.execution.operator.TheodoliteOperator].
@@ -72,6 +73,7 @@ class KubernetesBenchmark : KubernetesResource, Benchmark {
override fun teardownInfrastructure() {
val kubernetesManager = K8sManager(this.client)
loadResources(this.infrastructure.resources)
.map { it.second }
.forEach { kubernetesManager.remove(it) }
@@ -92,27 +94,33 @@ class KubernetesBenchmark : KubernetesResource, Benchmark {
res: Resource,
configurationOverrides: List<ConfigurationOverride?>,
loadGenerationDelay: Long,
afterTeardownDelay: Long
afterTeardownDelay: Long,
): BenchmarkDeployment {
logger.info { "Using $namespace as namespace." }
val appResources = loadResources(this.sut.resources)
val loadGenResources = loadResources(this.loadGenerator.resources)
val patcherFactory = PatcherFactory()
val appResources = loadResources(this.sut.resources).toResourceMap()
val loadGenResources = loadResources(this.loadGenerator.resources).toResourceMap()
// patch the load dimension the resources
load.getType().forEach { patcherDefinition ->
patcherFactory.createPatcher(patcherDefinition, loadGenResources).patch(load.get().toString())
loadGenResources[patcherDefinition.resource] =
PatchHandler.patchResource(loadGenResources, patcherDefinition, load.get().toString())
}
res.getType().forEach { patcherDefinition ->
patcherFactory.createPatcher(patcherDefinition, appResources).patch(res.get().toString())
appResources[patcherDefinition.resource] =
PatchHandler.patchResource(appResources, patcherDefinition, res.get().toString())
}
// Patch the given overrides
configurationOverrides.forEach { override ->
override?.let {
patcherFactory.createPatcher(it.patcher, appResources + loadGenResources).patch(override.value)
if (appResources.keys.contains(it.patcher.resource)) {
appResources[it.patcher.resource] =
PatchHandler.patchResource(appResources, override.patcher, override.value)
} else {
loadGenResources[it.patcher.resource] =
PatchHandler.patchResource(loadGenResources, override.patcher, override.value)
}
}
}
@@ -123,8 +131,8 @@ class KubernetesBenchmark : KubernetesResource, Benchmark {
sutAfterActions = sut.afterActions,
loadGenBeforeActions = loadGenerator.beforeActions,
loadGenAfterActions = loadGenerator.afterActions,
appResources = appResources.map { it.second },
loadGenResources = loadGenResources.map { it.second },
appResources = appResources.toList().flatMap { it.second },
loadGenResources = loadGenResources.toList().flatMap { it.second },
loadGenerationDelay = loadGenerationDelay,
afterTeardownDelay = afterTeardownDelay,
kafkaConfig = if (kafkaConfig != null) mapOf("bootstrap.servers" to kafkaConfig.bootstrapServer) else mapOf(),
@@ -144,3 +152,11 @@ class KubernetesBenchmark : KubernetesResource, Benchmark {
this.client = client
}
}
private fun Collection<Pair<String, HasMetadata>>.toResourceMap(): MutableMap<String, List<HasMetadata>> {
return this.toMap()
.toMutableMap()
.map { Pair(it.key, listOf(it.value)) }
.toMap()
.toMutableMap()
}
Loading