def recursive_flush(handle, path): """ Recursively deletes the path and the value of the children of the given node. Args: handle: A Zookeeper client handler. path: The Zookeeper path to delete. """ try: children = handle.get_children(path) if not any(path.startswith(item) for item in ZK_IGNORE_PATHS): logging.debug("Processing path: {0}".format(path)) for child in children: logging.debug("Processing child: {0}".format(child)) new_path = '{0}{1}'.format(path, child) if path != ZK_TOP_LEVEL: new_path = PATH_SEPARATOR.join([path, child]) recursive_flush(handle, new_path) try: handle.delete(path) except kazoo.exceptions.BadArgumentsError: logging.warning('BadArgumentsError while deleting path: {0}.'.format( path)) except kazoo.exceptions.NotEmptyError: logging.warning('NotEmptyError while deleting path: {0}. Skipping..'. format(path)) except kazoo.exceptions.NoNodeError: logging.debug('Reached the end of the zookeeper path.')
def recursive_flush(handle, path): """ Recursively deletes the path and the value of the children of the given node. Args: handle: A Zookeeper client handler. path: The Zookeeper path to delete. """ try: children = handle.get_children(path) if not any(path.startswith(item) for item in ZK_IGNORE_PATHS): logging.debug("Processing path: {0}".format(path)) for child in children: logging.debug("Processing child: {0}".format(child)) new_path = '{0}{1}'.format(path, child) if path != ZK_TOP_LEVEL: new_path = PATH_SEPARATOR.join([path, child]) recursive_flush(handle, new_path) try: handle.delete(path) except kazoo.exceptions.BadArgumentsError: logging.warning('BadArgumentsError while deleting path: {0}.'.format( path)) except kazoo.exceptions.NoNodeError: logging.debug('Reached the end of the zookeeper path.')
def recursive_dump(handle, path, file_handler): """ Recursively dumps the path and the value of the children of the given node. Args: handle: A Zookeeper client handler. path: The Zookeeper path to dump to a file. file_handler: A file handler to dump the data to. """ try: children = handle.get_children(path) logging.debug("Processing path: {0}".format(path)) for child in children: logging.debug("Processing child: {0}".format(child)) new_path = '{0}{1}'.format(path, child) if path != ZK_TOP_LEVEL: new_path = PATH_SEPARATOR.join([path, child]) recursive_dump(handle, new_path, file_handler) if path != ZK_TOP_LEVEL: value = handle.get(path)[0].encode('base64') file_handler.write("{}\n".format(json.dumps({path: value}))) except kazoo.exceptions.NoNodeError: logging.debug('Reached the end of the zookeeper path.')