From 131eb0c3b30bbd0cbf6aa6bb185c6d2e8a5c9a16 Mon Sep 17 00:00:00 2001 From: Joshua Harlow Date: Sun, 28 Jun 2015 21:09:21 -0700 Subject: [PATCH] Replace clear zookeeper python with clear zookeeper bash The zk-shell binary/library can save us from having to do alot here so just use it and remove some code. Change-Id: I07bde4dea61a125f7368349517e9878c2ee25608 --- tools/clear_zk.py | 50 ----------------------------------------------- tools/clear_zk.sh | 15 ++++++++++++++ 2 files changed, 15 insertions(+), 50 deletions(-) delete mode 100644 tools/clear_zk.py create mode 100755 tools/clear_zk.sh diff --git a/tools/clear_zk.py b/tools/clear_zk.py deleted file mode 100644 index d0a9e3da..00000000 --- a/tools/clear_zk.py +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env python - -import contextlib -import os -import re -import sys - -top_dir = os.path.abspath(os.path.join(os.path.dirname(__file__), - os.pardir)) -sys.path.insert(0, top_dir) - -from taskflow.utils import kazoo_utils - - -@contextlib.contextmanager -def finalize_client(client): - try: - yield client - finally: - kazoo_utils.finalize_client(client) - - -def iter_children(client, path): - if client.exists(path): - for child_path in client.get_children(path): - if path == "/": - child_path = "/%s" % (child_path) - else: - child_path = "%s/%s" % (path, child_path) - yield child_path - for child_child_path in iter_children(client, child_path): - yield child_child_path - - -def main(): - conf = {} - if len(sys.argv) > 1: - conf['hosts'] = sys.argv[1:] - with finalize_client(kazoo_utils.make_client(conf)) as client: - client.start(timeout=1.0) - children = list(iter_children(client, "/taskflow")) - for child_path in reversed(children): - if not re.match(r"^/taskflow/(.*?)-test/(.*)$", child_path): - continue - print("Deleting %s" % child_path) - client.delete(child_path) - - -if __name__ == "__main__": - main() diff --git a/tools/clear_zk.sh b/tools/clear_zk.sh new file mode 100755 index 00000000..e6dde4b7 --- /dev/null +++ b/tools/clear_zk.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +# This requires https://pypi.python.org/pypi/zk_shell/ to be installed... + +set -e + +ZK_HOSTS=${ZK_HOSTS:-localhost:2181} +TF_PATH=${TF_PATH:-taskflow} + +for path in `zk-shell --run-once "ls" $ZK_HOSTS`; do + if [[ $path == ${TF_PATH}* ]]; then + echo "Removing (recursively) path \"$path\"" + zk-shell --run-once "rmr $path" $ZK_HOSTS + fi +done