本文整理汇总了Python中kazoo.client.KazooClient方法的典型用法代码示例。如果您正苦于以下问题:Python client.KazooClient方法的具体用法?Python client.KazooClient怎么用?Python client.KazooClient使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kazoo.client
的用法示例。
在下文中一共展示了client.KazooClient方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_zookeeper_fault_tolerance
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def test_zookeeper_fault_tolerance():
"""
Kill zookeeper1 and see if other zookeeper instances are in quorum
"""
zookeper_deployer = runtime.get_deployer("zookeeper")
kazoo_connection_url = str(runtime.get_active_config('zookeeper_host') + ':2181')
zkclient = KazooClient(hosts=kazoo_connection_url)
zkclient.start()
zkclient.ensure_path("/my/zookeeper_errorinjection")
# kill the Zookeeper1 instance
print "killing zoookeeper instance1"
zookeper_deployer.kill("zookeeper1")
time.sleep(20)
zkclient.stop()
示例2: test_zookeeper_process_tracking
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def test_zookeeper_process_tracking():
"""
Tests if process register node correctly with zookeeper and zookeeper deletes it when process terminates
"""
#Wait for zookeeper to start so that kazoo client can connect correctly
time.sleep(5)
#"connecting to esnure /my/zookeeper_test"
kazoo_connection_url = str(runtime.get_active_config('zookeeper_host') + ':2181')
zkclient = KazooClient(hosts=kazoo_connection_url)
zkclient.start()
zkclient.ensure_path("/my/zookeeper_test")
#spawn a python multiprocess which creates an ephermeral node
#once the process ends the node will be deleted.
p = Process(target=zookeeper_ephemeral_node, args=("process1",))
p.start()
zkclient.stop()
示例3: test
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def test(self):
"""
Tests if process register node correctly with zookeeper and zookeeper deletes it when process terminates
"""
#Wait for zookeeper to start so that kazoo client can connect correctly
time.sleep(5)
#"connecting to esnure /my/zookeeper_test"
kazoo_connection_url = str(runtime.get_active_config('zookeeper_host') + ':2181')
zkclient = KazooClient(hosts=kazoo_connection_url)
zkclient.start()
zkclient.ensure_path("/my/zookeeper_test")
#spawn a python multiprocess which creates an ephermeral node
#once the process ends the node will be deleted.
p = Process(target=zookeeper_ephemeral_node, args=("process1",))
p.start()
zkclient.stop()
示例4: _loop_acquire
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def _loop_acquire(self, n, ident):
zk = KazooClient(hosts='127.0.0.1:21811')
zk.start()
scheme, name, passw = zk_test_auth
zk.add_auth(scheme, name + ':' + passw)
for ii in range(n):
l = zkutil.ZKLock('foo_name', zkclient=zk)
with l:
self.total += 1
self.counter += 1
self.assertTrue(self.counter == 1)
time.sleep(0.01)
self.counter -= 1
dd("id={ident:0>2} n={ii:0>2} got and released lock: {holder}".format(
ident=ident,
ii=ii,
holder=l.lock_holder))
zk.stop()
示例5: setUp
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def setUp(self):
utdocker.create_network()
utdocker.start_container(
zk_name,
zk_tag,
env={
"ZOO_MY_ID": 1,
"ZOO_SERVERS": "server.1=0.0.0.0:2888:3888",
},
port_bindings={2181: 21811}
)
self.zk = KazooClient('127.0.0.1:21811')
self.zk.start()
dd('start zk-test in docker')
示例6: setUp
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def setUp(self):
utdocker.create_network()
utdocker.start_container(
zk_test_name,
zk_test_tag,
env={
"ZOO_MY_ID": 1,
"ZOO_SERVERS": "server.1=0.0.0.0:2888:3888",
},
port_bindings={
2181: 21811,
}
)
self.zk = KazooClient(hosts='127.0.0.1:21811')
self.zk.start()
self.val = {'a': 1, 'b': 2}
self.zk.create('foo', utfjson.dump(self.val))
示例7: setUp
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def setUp(self):
utdocker.create_network()
utdocker.start_container(
zk_name,
zk_tag,
env={
"ZOO_MY_ID": 1,
"ZOO_SERVERS": "server.1=0.0.0.0:2888:3888",
},
port_bindings={2181: 21811}
)
self.zk = KazooClient('127.0.0.1:21811')
self.zk.start()
dd('start zk-test in docker')
self.path = 'a'
self.zk.create(self.path, '1')
示例8: initial
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def initial(self, data):
if self.terminate:
#
# - we're done, commit suicide
# - the zk connection is guaranteed to be down at this point
#
self.exitcode()
cnx_string = ','.join(self.brokers)
data.zk = KazooClient(hosts=cnx_string, timeout=30.0, read_only=1, randomize_hosts=1)
data.zk.add_listener(self.feedback)
data.zk.start()
return 'wait_for_cnx', data, 0
示例9: __init__
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def __init__(self, solr, log):
'''
Helper class for working with Solr Zookeeper config and collections.
Still very experimental, I wouldn't even use it myself if I didn't like to live on the edge.
'''
if not kz_imported:
raise ImportError("To use the ZK Class you need to have Kazoo Client installed")
self.solr = solr
self.logger = log
try:
self.system_data = self.solr.transport.send_request(endpoint='admin/info/system', params={'wt':'json'})
self.zk_hosts = self.system_data[0]['zkHost']
except Exception as e:
self.logger.error("Couldn't get System info From Solr or bad format.")
self.logger.exception(e)
raise
try:
self.kz = KazooClient(hosts=self.zk_hosts)
self.kz.start()
if self.kz.state != 'CONNECTED':
self.logger.error("Couldn't establish connection to Zookeeper")
except Exception as e:
self.logger.error("Couldn't Establish Connection To Zookeeper")
raise(e)
示例10: __init__
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def __init__(self, name):
"""
初始化方法
:param str name: 分布式锁名字
:return: None
:rtype: None
:raises kazoo.interfaces.IHandler.timeout_exception: 连接超时异常
"""
self._lock_name = name
self._lock_node_path = config.GuardianConfig.get_persistent_path("lock")
self._lock_node = self._lock_node_path + '/' + self._lock_name
self._lock_handle = None
hosts = config.GuardianConfig.get(config.STATE_SERVICE_HOSTS_NAME)
self._zkc = KazooClient(hosts=hosts)
self._zkc.start()
示例11: list_deploy_queue
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def list_deploy_queue(request) -> Mapping[str, Any]:
zk_client = KazooClient(hosts=settings.system_paasta_config.get_zk_hosts())
zk_client.start()
queue = ZKDelayDeadlineQueue(client=zk_client)
available_service_instances = queue.get_available_service_instances(
fetch_service_instances=True
)
unavailable_service_instances = queue.get_unavailable_service_instances(
fetch_service_instances=True
)
available_service_instance_dicts = [
service_instance._asdict()
for _, service_instance in available_service_instances
]
unavailable_service_instance_dicts = [
service_instance._asdict()
for _, __, service_instance in unavailable_service_instances
]
return {
"available_service_instances": available_service_instance_dicts,
"unavailable_service_instances": unavailable_service_instance_dicts,
}
示例12: bounce_lock_zookeeper
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def bounce_lock_zookeeper(
name: str, system_paasta_config: Optional[SystemPaastaConfig] = None
) -> Iterator:
"""Acquire a bounce lock in zookeeper for the name given. The name should
generally be the service namespace being bounced.
This is a contextmanager. Please use it via 'with bounce_lock(name):'.
:param name: The lock name to acquire"""
if system_paasta_config is None:
system_paasta_config = load_system_paasta_config()
zk = KazooClient(
hosts=system_paasta_config.get_zk_hosts(), timeout=ZK_LOCK_CONNECT_TIMEOUT_S,
)
zk.start()
lock = zk.Lock(f"{ZK_LOCK_PATH}/{name}")
try:
lock.acquire(timeout=1) # timeout=0 throws some other strange exception
yield
except LockTimeout:
raise LockHeldException("Service %s is already being bounced!" % name)
else:
lock.release()
finally:
zk.stop()
zk.close()
示例13: create_autoscaling_lock
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def create_autoscaling_lock(service: str, instance: str) -> Iterator[None]:
"""Acquire a lock in zookeeper for autoscaling. This is
to avoid autoscaling a service multiple times, and to avoid
having multiple paasta services all attempting to autoscale and
fetching mesos data."""
zk = KazooClient(
hosts=load_system_paasta_config().get_zk_hosts(),
timeout=ZK_LOCK_CONNECT_TIMEOUT_S,
)
zk.start()
lock = zk.Lock(f"/autoscaling/{service}/{instance}/autoscaling.lock")
try:
lock.acquire(timeout=1) # timeout=0 throws some other strange exception
yield
except LockTimeout:
raise LockHeldException(
f"Failed to acquire lock for autoscaling! {service}.{instance}"
)
else:
lock.release()
finally:
zk.stop()
zk.close()
示例14: get_boost_values
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def get_boost_values(zk_boost_path: str, zk: KazooClient) -> BoostValues:
# Default values, non-boost.
end_time: float = 0
boost_factor: float = 1.0
expected_load: float = 0
try:
end_time = float(zk.get(zk_boost_path + "/end_time")[0].decode("utf-8"))
boost_factor = float(zk.get(zk_boost_path + "/factor")[0].decode("utf-8"))
expected_load = float(
zk.get(zk_boost_path + "/expected_load")[0].decode("utf-8")
)
except NoNodeError:
# If we can't read boost values from zookeeper
return BoostValues(end_time=0, boost_factor=1.0, expected_load=0)
return BoostValues(
end_time=end_time, boost_factor=boost_factor, expected_load=expected_load
)
示例15: get_number_of_mesos_masters
# 需要导入模块: from kazoo import client [as 别名]
# 或者: from kazoo.client import KazooClient [as 别名]
def get_number_of_mesos_masters(host, path):
"""Returns an array, containing mesos masters
:param zk_config: dict containing information about zookeeper config.
Masters register themselves in zookeeper by creating ``info_`` entries.
We count these entries to get the number of masters.
"""
zk = KazooClient(hosts=host, read_only=True)
zk.start()
try:
root_entries = zk.get_children(path)
result = [
info
for info in root_entries
if info.startswith("json.info_") or info.startswith("info_")
]
return len(result)
finally:
zk.stop()
zk.close()