diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt b/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt index e83c7bdff3406e73c6cb20d9d7d3fd570aff98a9..2c72b044b206b78878fee63adbf8b581d4494350 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/Main.kt @@ -6,15 +6,6 @@ import io.quarkus.runtime.annotations.QuarkusMain object Main { @JvmStatic fun main(args: Array<String>) { - println("Running main method") - - val run = RunUc() - - val testtopic = mapOf<String,Int>("test" to 1) - - run.createTopics(testtopic, 1.toShort()) - run.deleteTopics(listOf("test")) //Quarkus.run() - run.resetZookeeper() } } 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..1fe1ae27d8f573f1f3cd4c947ad6715314677ef6 --- /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) {} +}