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

Fix WorkloadGEneratorStateCleaner

parent ea12bae6
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"
...@@ -10,7 +10,7 @@ import java.time.Duration ...@@ -10,7 +10,7 @@ import java.time.Duration
private val logger = KotlinLogging.logger {} private val logger = KotlinLogging.logger {}
/** /**
* Resets the workloadgenerator states in zookeper (and potetially watches for Zookeper events) * Resets the workloadgenerator states in zookeper (and potentially watches for Zookeper events)
* *
* @param ip of zookeeper * @param ip of zookeeper
* @param path path of the zookeeper node * @param path path of the zookeeper node
...@@ -30,33 +30,36 @@ class WorkloadGeneratorStateCleaner(ip: String, val path: String) { ...@@ -30,33 +30,36 @@ class WorkloadGeneratorStateCleaner(ip: String, val path: String) {
} }
/** /**
* Deletes all Zookeeper nodes with the corresponding path. * Deletes a Zookeeper node and its children with the corresponding path.
*/ */
fun deleteAll() { fun deleteAll() {
var deleted = false
while (!deleted) { while (true) {
var children = emptyList<String>();
try { try {
zookeeperClient.delete(this.path, -1) children = zookeeperClient.getChildren(this.path, true)
} catch (ex: Exception) { } catch (e: KeeperException.NoNodeException) {
logger.error { ex.toString() } break;
}
// delete all children nodes
for (s: String in children) {
try {
zookeeperClient.delete(s, -1)
} catch (ex: Exception) {
logger.info { "$ex" }
}
} }
// delete main node
try { try {
// get list of all nodes of the given path zookeeperClient.delete(this.path, -1)
val clients = zookeeperClient.getChildren(this.path, true) break;
if (clients.isEmpty()) {
deleted = true
break
}
} catch (ex: Exception) { } catch (ex: Exception) {
when (ex) { // no instance of node found
// indicates that there are no nodes to delete left if (ex is KeeperException.NoNodeException) {
is KeeperException -> { break;
deleted = true } else {
} logger.error { ex.toString() }
is InterruptedException -> {
logger.error { ex.toString() }
}
} }
} }
Thread.sleep(retryAfter.toMillis()) Thread.sleep(retryAfter.toMillis())
......
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