Skip to content
Snippets Groups Projects
Commit 14a594a1 authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

create first prototypical patcher

parent 61654c2b
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!85Introduce new Benchmark class and Patcher,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
Showing with 75 additions and 17 deletions
package theodolite.benchmark package theodolite.benchmark
import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.constructor.BaseConstructor
import org.yaml.snakeyaml.constructor.Constructor import org.yaml.snakeyaml.constructor.Constructor
import theodolite.util.Parser
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.InputStream import java.io.InputStream
......
package theodolite.benchmark package theodolite.benchmark
import io.fabric8.kubernetes.api.model.KubernetesResource import io.fabric8.kubernetes.api.model.KubernetesResource
import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.client.DefaultKubernetesClient import io.fabric8.kubernetes.client.DefaultKubernetesClient
import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.Yaml
import theodolite.k8s.YamlLoader import theodolite.k8s.YamlLoader
import theodolite.patcher.AbstractPatcher
import theodolite.patcher.Patcher
import theodolite.patcher.ReplicaPatcher
import theodolite.util.LoadDimension import theodolite.util.LoadDimension
import theodolite.util.PatcherDefinition
import theodolite.util.Resource import theodolite.util.Resource
import theodolite.util.TypeName
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.InputStream import java.io.InputStream
import java.lang.IllegalArgumentException
class KubernetesBenchmark(): Benchmark { class KubernetesBenchmark(): Benchmark {
lateinit var name: String lateinit var name: String
lateinit var appResource: List<String> lateinit var appResource: List<String>
lateinit var loadGenResource: List<String> lateinit var loadGenResource: List<String>
lateinit var resourceTypes: List<TypeName>
private fun loadKubernetesResources(): List<KubernetesResource?> { private fun loadKubernetesResources(resources: List<String>): List<Pair<String, KubernetesResource?>> {
val basePath = "./../../../resources/main/yaml/" val basePath = "./../../../resources/main/yaml/"
var parser = theodolite.benchmark.BenchmarkYamlParser() var parser = theodolite.benchmark.BenchmarkYamlParser()
val loader = YamlLoader(DefaultKubernetesClient().inNamespace("default")) val loader = YamlLoader(DefaultKubernetesClient().inNamespace("default"))
return this.appResource return resources
.map { resource -> "$basePath/$resource" } .map { resource ->
.map { resourcePath -> val resourcePath = "$basePath/$resource"
val kind = parser.parse(resourcePath, HashMap<String, String>()::class.java) !! val kind = parser.parse(resourcePath, HashMap<String, String>()::class.java) !!
kind["kind"]?.let { loader.loadK8sResource(it, resourcePath) } val k8sResource = kind["kind"]?.let { loader.loadK8sResource(it, resourcePath) }
} Pair<String, KubernetesResource?>(resource, k8sResource)
}
} }
private fun patchKubernetesResources() { private fun createK8sPatcher(patcherDefinition: PatcherDefinition, k8sResources: List<Pair<String, KubernetesResource>>): Patcher<Int> {
return when(patcherDefinition.type) {
"ReplicaPatcher" -> ReplicaPatcher(k8sResources.filter { it.first == patcherDefinition.resource}.map { resource -> resource.second }[0])
"EnvVarPatcher" -> TODO("create env var patcher")
else -> throw IllegalArgumentException("Patcher type ${patcherDefinition.type} not fount")
}
TODO("Use reflection to load patchers")
} }
override fun buildDeployment(load: LoadDimension, res: Resource, override: Map<String, String>): BenchmarkDeployment { override fun buildDeployment(load: LoadDimension, res: Resource, override: Map<String, String>): BenchmarkDeployment {
// TODO("") // TODO("set node selector")
val resources = loadKubernetesResources() val resources = loadKubernetesResources(this.appResource + this.loadGenResource)
resources.forEach {x -> println(x.toString())} val patchers = this.resourceTypes.map { patcherDef -> createK8sPatcher(patcherDef.patchers[0],
// Return KubernetesBenchmarkDeployment with individual parametrisation resources as List<Pair<String, KubernetesResource>>
return KubernetesBenchmarkDeployment(emptyList(), hashMapOf<String, Any>(), "", emptyList() ) ) }
// exemplary only for replica patcher
patchers.forEach{ patcher -> patcher.patch(res.get()) }
return KubernetesBenchmarkDeployment(emptyList(), hashMapOf<String, Any>(), "", emptyList())
} }
} }
\ No newline at end of file
package theodolite.patcher
import io.fabric8.kubernetes.api.model.KubernetesResource
abstract class AbstractPatcher<T>(k8sResource: KubernetesResource): Patcher<T> {
}
package theodolite.patcher
interface Patcher<T> {
fun patch(value: T)
}
\ No newline at end of file
package theodolite.patcher
import io.fabric8.kubernetes.api.model.KubernetesResource
import io.fabric8.kubernetes.api.model.apps.Deployment
class ReplicaPatcher(private val k8sResource: KubernetesResource): AbstractPatcher<Int>(k8sResource){
override fun patch(replicas: Int) {
if (k8sResource is Deployment)
this.k8sResource.spec.replicas = replicas
}
}
\ No newline at end of file
package theodolite.benchmark package theodolite.util
interface Parser { interface Parser {
fun <T> parse(path: String, E:Class<T>): T? //Yaml fun <T> parse(path: String, E:Class<T>): T? //Yaml
......
package theodolite.util
class PatcherDefinition() {
lateinit var type: String
lateinit var resource: String
lateinit var container: String
lateinit var variableName: String
}
package theodolite.util
class TypeName() {
lateinit var typeName: String
lateinit var patchers: List<PatcherDefinition>
}
\ No newline at end of file
...@@ -3,4 +3,9 @@ appResource: ...@@ -3,4 +3,9 @@ appResource:
- "aggregation-deployment.yaml" - "aggregation-deployment.yaml"
- "aggregation-service.yaml" - "aggregation-service.yaml"
loadGenResource: loadGenResource:
- "workloadGenerator.yaml" - "workloadGenerator.yaml"
\ No newline at end of file resourceTypes:
- typeName: "Instances"
patchers:
- type: "ReplicaPatcher"
resource: "aggregation-deployment.yaml"
\ No newline at end of file
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