def setUp(self): if not settings.configured: settings.configure() settings.DJKEEPER = dict() pykeeper.install_log_stream()
def connect(path=None): if path is None: path=zk.source.com:2181 pykeeper.install_log_stream() client = pykeeper.ZooKeeper(path) client.connect() print path+"θΏζ₯ζε!" return client
def check_zookeeper_lock(key, value, logger): zk_key = "%s/%s" % (FLAGS.zk_lockpath, key) zk = None try: pykeeper.install_log_stream() zk = pykeeper.ZooKeeper(FLAGS.zk_lockserver) zk.connect() if FLAGS.unlock: try: zk.delete(zk_key) logger.info('%s has been deleted', zk_key) except NoNodeException: logger.info('%s has been deleted.', zk_key) except: logger.error("Clean lock failed %s, %s", zk_key, traceback.format_exc()) sys.exit(0) if zk.exists(zk_key): logger.warning('%s is running, val %s', key, zk.get(zk_key)) sys.exit(1) except: logger.error("Zookeeper failed %s, %s", zk_key, traceback.format_exc()) sys.exit(0) try: try: zk.create_recursive(FLAGS.zk_lockpath, '') zk.create(zk_key, value) except: logger.error("Zookeeper lock failed %s, %s", zk_key, traceback.format_exc()) sys.exit(0) yield finally: if FLAGS.autounlock: zk.delete(zk_key)
def __init__(self, zkhost): pykeeper.install_log_stream() self.zk = pykeeper.ZooKeeper(self.zk_list[zkhost]) self.zk.connect()
def __init__(self): pykeeper.install_log_stream()
#!/usr/bin/python # -*- coding:utf-8 -*- # [email protected] # 2014-03-10 import re import os import sys import pykeeper import redis import socket pykeeper.install_log_stream() class zookeeper_client(object): def __init__(self,host): self.zkh = pykeeper.ZooKeeper(host, reconnect = True) self.zkh.connect() self.zkh.wait_until_connected(timeout=1) self.connected = True if self.zkh.state_name == 'connected' else False def execute(self, action, path, value=None): try: func = getattr(zookeeper_client, action) except Exception: pass else: return func(self,path) def list(self, path): try: return self.zkh.get_children(path)
import_json = "" zk_host = '127.0.0.1' zk_port = '2181' for op, value in opts: if op in ("-h", "--help"): help() exit(1) if op in ("-i", "--import"): import_json = value elif op in ("-z", "--zkhost"): zk_host = value elif op in ("-p", "--zkport"): zk_port = value else: help() exit(1) if not import_json: help() exit(1) pykeeper.install_log_stream() client = pykeeper.ZooKeeper(":".join([zk_host, zk_port])) client.connect() data = json.load(open(import_json), "utf-8") zk_import(client, data) zk_dump(client) pass