diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt b/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt index a7846edadf07bcc5f1476dd5bd4242c4682642b0..2c72b044b206b78878fee63adbf8b581d4494350 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt @@ -6,9 +6,6 @@ import io.quarkus.runtime.annotations.QuarkusMain object Main { @JvmStatic fun main(args: Array<String>) { - println("Running main method") - //Quarkus.run() - } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/WorkloadGeneratorStateCleaner.kt b/theodolite-quarkus/src/main/kotlin/theodolite/WorkloadGeneratorStateCleaner.kt new file mode 100644 index 0000000000000000000000000000000000000000..c519b0c843ae3f75c21a7596446c700972b44753 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/WorkloadGeneratorStateCleaner.kt @@ -0,0 +1,58 @@ +package theodolite + +import org.apache.zookeeper.KeeperException +import org.apache.zookeeper.WatchedEvent +import org.apache.zookeeper.Watcher +import org.apache.zookeeper.ZooKeeper + +class WorkloadGeneratorStateCleaner(ip: String) { + val path = "/workload-generation" + val sessionTimeout = 60 + val retryTime = 3000L + lateinit var zookeeperClient: ZooKeeper + + init { + try { + val watcher: Watcher = ZookeperWatcher() // defined below + zookeeperClient = ZooKeeper(ip, sessionTimeout, watcher) + } catch (e:Exception) { + System.out.println(e.toString()) + } + } + + fun deleteAll() { + var deleted = false + while (!deleted) { + + // + try { + zookeeperClient.delete(path, -1) + } catch (ex: Exception) { + System.out.println(ex.toString()) + } + + try { + val clients = zookeeperClient.getChildren(path, true) + if (clients.isEmpty()){ + break; + } + } catch (ex: Exception) { + when (ex) { + is KeeperException -> { deleted = true } + is InterruptedException -> { + System.out.println(ex.toString()) + } + } + } + Thread.sleep(retryTime) + System.out.println("ZooKeeper reset was not successful. Retrying in 5s") + } + + System.out.println("ZooKeeper reset was successful") + } +} + +private class ZookeperWatcher : Watcher { + + override fun process(event: WatchedEvent) {} +}