From 8ceb7cfa1b3f5c6bf0cb474d6e43ac973ff0fd84 Mon Sep 17 00:00:00 2001
From: Simon Ehrenstein <simon.ehrenstein@gmail.com>
Date: Wed, 3 Jun 2020 20:14:56 +0200
Subject: [PATCH] Make zookeeper reset block until succeeded

---
 execution/run_uc1-new.sh | 21 ++++++++++++++++++++-
 execution/run_uc2-new.sh | 21 ++++++++++++++++++++-
 execution/run_uc3-new.sh | 21 ++++++++++++++++++++-
 execution/run_uc4-new.sh | 21 ++++++++++++++++++++-
 4 files changed, 80 insertions(+), 4 deletions(-)

diff --git a/execution/run_uc1-new.sh b/execution/run_uc1-new.sh
index 6e09144af..f3beccdf6 100755
--- a/execution/run_uc1-new.sh
+++ b/execution/run_uc1-new.sh
@@ -83,7 +83,26 @@ echo "Finish topic deletion, print topics:"
 echo "Delete ZooKeeper configurations used for workload generation"
 kubectl exec zookeeper-client -- bash -c "zookeeper-shell my-confluent-cp-zookeeper:2181 deleteall /workload-generation"
 echo "Waiting for deletion"
-sleep 5s
+
+while [ true ]
+do
+    IFS=', ' read -r -a array <<< $(kubectl exec zookeeper-client -- bash -c "zookeeper-shell my-confluent-cp-zookeeper:2181 ls /" | tail -n 1 | awk -F[\]\[] '{print $2}')
+    found=0
+    for element in "${array[@]}"
+    do
+        if [ "$element" == "workload-generation" ]; then
+                found=1
+                break
+        fi
+    done
+    if [ $found -ne 1 ]; then
+        echo "ZooKeeper reset was successful."
+        break
+    else 
+        echo "ZooKeeper reset was not successful. Retrying in 5s."
+        sleep 5s
+    fi
+done
 echo "Deletion finished"
 
 echo "Exiting script"
diff --git a/execution/run_uc2-new.sh b/execution/run_uc2-new.sh
index bd33b305c..d913b135e 100755
--- a/execution/run_uc2-new.sh
+++ b/execution/run_uc2-new.sh
@@ -76,7 +76,26 @@ echo "Finish topic deletion, print topics:"
 echo "Delete ZooKeeper configurations used for workload generation"
 kubectl exec zookeeper-client -- bash -c "zookeeper-shell my-confluent-cp-zookeeper:2181 deleteall /workload-generation"
 echo "Waiting for deletion"
-sleep 5s
+
+while [ true ]
+do
+    IFS=', ' read -r -a array <<< $(kubectl exec zookeeper-client -- bash -c "zookeeper-shell my-confluent-cp-zookeeper:2181 ls /" | tail -n 1 | awk -F[\]\[] '{print $2}')
+    found=0
+    for element in "${array[@]}"
+    do
+        if [ "$element" == "workload-generation" ]; then
+                found=1
+                break
+        fi
+    done
+    if [ $found -ne 1 ]; then
+        echo "ZooKeeper reset was successful."
+        break
+    else 
+        echo "ZooKeeper reset was not successful. Retrying in 5s."
+        sleep 5s
+    fi
+done
 echo "Deletion finished"
 
 echo "Exiting script"
diff --git a/execution/run_uc3-new.sh b/execution/run_uc3-new.sh
index 4d48eedb9..725b1ab95 100755
--- a/execution/run_uc3-new.sh
+++ b/execution/run_uc3-new.sh
@@ -84,7 +84,26 @@ echo "Finish topic deletion, print topics:"
 echo "Delete ZooKeeper configurations used for workload generation"
 kubectl exec zookeeper-client -- bash -c "zookeeper-shell my-confluent-cp-zookeeper:2181 deleteall /workload-generation"
 echo "Waiting for deletion"
-sleep 5s
+
+while [ true ]
+do
+    IFS=', ' read -r -a array <<< $(kubectl exec zookeeper-client -- bash -c "zookeeper-shell my-confluent-cp-zookeeper:2181 ls /" | tail -n 1 | awk -F[\]\[] '{print $2}')
+    found=0
+    for element in "${array[@]}"
+    do
+        if [ "$element" == "workload-generation" ]; then
+                found=1
+                break
+        fi
+    done
+    if [ $found -ne 1 ]; then
+        echo "ZooKeeper reset was successful."
+        break
+    else 
+        echo "ZooKeeper reset was not successful. Retrying in 5s."
+        sleep 5s
+    fi
+done
 echo "Deletion finished"
 
 echo "Exiting script"
diff --git a/execution/run_uc4-new.sh b/execution/run_uc4-new.sh
index b5156796d..c9fbfdae5 100755
--- a/execution/run_uc4-new.sh
+++ b/execution/run_uc4-new.sh
@@ -79,7 +79,26 @@ echo "Finish topic deletion, print topics:"
 echo "Delete ZooKeeper configurations used for workload generation"
 kubectl exec zookeeper-client -- bash -c "zookeeper-shell my-confluent-cp-zookeeper:2181 deleteall /workload-generation"
 echo "Waiting for deletion"
-sleep 5s
+
+while [ true ]
+do
+    IFS=', ' read -r -a array <<< $(kubectl exec zookeeper-client -- bash -c "zookeeper-shell my-confluent-cp-zookeeper:2181 ls /" | tail -n 1 | awk -F[\]\[] '{print $2}')
+    found=0
+    for element in "${array[@]}"
+    do
+        if [ "$element" == "workload-generation" ]; then
+                found=1
+                break
+        fi
+    done
+    if [ $found -ne 1 ]; then
+        echo "ZooKeeper reset was successful."
+        break
+    else 
+        echo "ZooKeeper reset was not successful. Retrying in 5s."
+        sleep 5s
+    fi
+done
 echo "Deletion finished"
 
 echo "Exiting script"
-- 
GitLab