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

wait for inf resources before starting sut resources and wait for sut...

wait for inf resources before starting sut resources and wait for sut resources before starting load gen resources
parent de0ad9f9
No related branches found
No related tags found
1 merge request!261Wait until the resources of the predecessor resourceSet are ready
Pipeline #7296 failed
...@@ -26,6 +26,12 @@ spec: ...@@ -26,6 +26,12 @@ spec:
description: This field exists only for technical reasons and should not be set by the user. The value of the field will be overwritten. description: This field exists only for technical reasons and should not be set by the user. The value of the field will be overwritten.
type: string type: string
default: "" default: ""
rolloutMode:
type: string
default: "default"
enum:
- "no-waiting"
- "default"
infrastructure: infrastructure:
description: (Optional) A list of file names that reference Kubernetes resources that are deployed on the cluster to create the required infrastructure. description: (Optional) A list of file names that reference Kubernetes resources that are deployed on the cluster to create the required infrastructure.
type: object type: object
......
...@@ -37,6 +37,7 @@ private var DEFAULT_THEODOLITE_APP_RESOURCES = "./benchmark-resources" ...@@ -37,6 +37,7 @@ private var DEFAULT_THEODOLITE_APP_RESOURCES = "./benchmark-resources"
@RegisterForReflection @RegisterForReflection
class KubernetesBenchmark : KubernetesResource, Benchmark { class KubernetesBenchmark : KubernetesResource, Benchmark {
lateinit var name: String lateinit var name: String
lateinit var rolloutMode: RolloutMode
lateinit var resourceTypes: List<TypeName> lateinit var resourceTypes: List<TypeName>
lateinit var loadTypes: List<TypeName> lateinit var loadTypes: List<TypeName>
var kafkaConfig: KafkaConfig? = null var kafkaConfig: KafkaConfig? = null
...@@ -59,10 +60,8 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { ...@@ -59,10 +60,8 @@ class KubernetesBenchmark : KubernetesResource, Benchmark {
override fun setupInfrastructure() { override fun setupInfrastructure() {
this.infrastructure.beforeActions.forEach { it.exec(client = client) } this.infrastructure.beforeActions.forEach { it.exec(client = client) }
val kubernetesManager = K8sManager(this.client) RolloutManager(rolloutMode, this.client)
loadKubernetesResources(this.infrastructure.resources) .rollout(loadKubernetesResources(this.infrastructure.resources).map { it.second })
.map{it.second}
.forEach { kubernetesManager.deploy(it) }
} }
override fun teardownInfrastructure() { override fun teardownInfrastructure() {
...@@ -124,7 +123,9 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { ...@@ -124,7 +123,9 @@ class KubernetesBenchmark : KubernetesResource, Benchmark {
afterTeardownDelay = afterTeardownDelay, afterTeardownDelay = afterTeardownDelay,
kafkaConfig = if (kafkaConfig != null) hashMapOf("bootstrap.servers" to kafkaConfig.bootstrapServer) else mapOf(), kafkaConfig = if (kafkaConfig != null) hashMapOf("bootstrap.servers" to kafkaConfig.bootstrapServer) else mapOf(),
topics = kafkaConfig?.topics ?: listOf(), topics = kafkaConfig?.topics ?: listOf(),
client = this.client client = this.client,
rolloutMode = rolloutMode
) )
} }
......
...@@ -27,6 +27,7 @@ class KubernetesBenchmarkDeployment( ...@@ -27,6 +27,7 @@ class KubernetesBenchmarkDeployment(
private val sutAfterActions: List<Action>, private val sutAfterActions: List<Action>,
private val loadGenBeforeActions: List<Action>, private val loadGenBeforeActions: List<Action>,
private val loadGenAfterActions: List<Action>, private val loadGenAfterActions: List<Action>,
private val rolloutMode: RolloutMode,
val appResources: List<KubernetesResource>, val appResources: List<KubernetesResource>,
val loadGenResources: List<KubernetesResource>, val loadGenResources: List<KubernetesResource>,
private val loadGenerationDelay: Long, private val loadGenerationDelay: Long,
...@@ -46,19 +47,20 @@ class KubernetesBenchmarkDeployment( ...@@ -46,19 +47,20 @@ class KubernetesBenchmarkDeployment(
* - Deploy the needed resources. * - Deploy the needed resources.
*/ */
override fun setup() { override fun setup() {
val rolloutManager = RolloutManager(rolloutMode, client)
if (this.topics.isNotEmpty()) { if (this.topics.isNotEmpty()) {
val kafkaTopics = this.topics val kafkaTopics = this.topics
.filter { !it.removeOnly } .filter { !it.removeOnly }
.map { NewTopic(it.name, it.numPartitions, it.replicationFactor) } .map { NewTopic(it.name, it.numPartitions, it.replicationFactor) }
kafkaController.createTopics(kafkaTopics) kafkaController.createTopics(kafkaTopics)
} }
sutBeforeActions.forEach { it.exec(client = client) } sutBeforeActions.forEach { it.exec(client = client) }
appResources.forEach { kubernetesManager.deploy(it) } rolloutManager.rollout(appResources)
logger.info { "Wait ${this.loadGenerationDelay} seconds before starting the load generator." } logger.info { "Wait ${this.loadGenerationDelay} seconds before starting the load generator." }
Thread.sleep(Duration.ofSeconds(this.loadGenerationDelay).toMillis()) Thread.sleep(Duration.ofSeconds(this.loadGenerationDelay).toMillis())
loadGenBeforeActions.forEach { it.exec(client = client) } loadGenBeforeActions.forEach { it.exec(client = client) }
loadGenResources.forEach { kubernetesManager.deploy(it) } rolloutManager.rollout(loadGenResources)
} }
/** /**
......
package theodolite.benchmark
import io.fabric8.kubernetes.api.model.KubernetesResource
import io.fabric8.kubernetes.api.model.apps.DaemonSet
import io.fabric8.kubernetes.api.model.apps.Deployment
import io.fabric8.kubernetes.api.model.apps.ReplicaSet
import io.fabric8.kubernetes.api.model.apps.StatefulSet
import io.fabric8.kubernetes.client.NamespacedKubernetesClient
import theodolite.k8s.K8sManager
private var SLEEP_TIME_MS = 500L
class RolloutManager(private val rolloutMode: RolloutMode, private val client: NamespacedKubernetesClient) {
fun rollout(resources: List<KubernetesResource>) {
println("MODE IS: ${rolloutMode.value}")
resources
.forEach { K8sManager(client).deploy(it) }
if (rolloutMode == RolloutMode.DEFAULT) {
resources
.forEach {
when (it) {
is Deployment -> waitFor { client.apps().deployments().withName(it.metadata.name).isReady }
is StatefulSet -> waitFor { client.apps().statefulSets().withName(it.metadata.name).isReady }
is DaemonSet -> waitFor { client.apps().daemonSets().withName(it.metadata.name).isReady }
is ReplicaSet -> waitFor { client.apps().replicaSets().withName(it.metadata.name).isReady }
}
}
}
}
private fun waitFor(f: () -> Boolean) {
while (!f()) {
Thread.sleep(SLEEP_TIME_MS)
println("wait for resource")
}
}
}
\ No newline at end of file
package theodolite.benchmark
import com.fasterxml.jackson.annotation.JsonValue
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
@JsonDeserialize
enum class RolloutMode(@JsonValue val value: String) {
NONE("no-waiting"),
DEFAULT("default")
}
\ 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