当前位置: 首页>>代码示例>>Python>>正文


Python retry.KazooRetry方法代码示例

本文整理汇总了Python中kazoo.retry.KazooRetry方法的典型用法代码示例。如果您正苦于以下问题:Python retry.KazooRetry方法的具体用法?Python retry.KazooRetry怎么用?Python retry.KazooRetry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在kazoo.retry的用法示例。


在下文中一共展示了retry.KazooRetry方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getMockServerSet

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def getMockServerSet(smox):
  listeners = []
  def add_listener(listener):
    listeners.append(listener)

  zk = smox.CreateMock(KazooClient)
  zk.connected = True
  zk.handler = SequentialGeventHandler()
  zk.retry = KazooRetry()

  mock_stat = smox.CreateMock(ZnodeStat)
  mock_stat.mzxid = 1

  zk.exists(TEST_PATH).AndReturn(True)
  zk.add_listener(mox.IgnoreArg()).WithSideEffects(add_listener)
  zk.get(TEST_PATH, mox.IgnoreArg()).AndReturn((1, mock_stat))
  zk.add_listener(mox.IgnoreArg()).WithSideEffects(add_listener)

  return zk 
开发者ID:tellapart,项目名称:aurproxy,代码行数:21,代码来源:aurora.py

示例2: __init__

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def __init__(self, handler=SequentialGeventHandler(), hosts=None):
        self.handler = handler
        self.hosts = hosts
        self._state = KazooState.LOST
        self._listeners = []
        self.Party = partial(Party, self)
        self.ShallowParty = partial(ShallowParty, self)
        self.retry = KazooRetry(
            max_tries=3,
            delay=0.0,
            backoff=1,
            max_jitter=0.0,
            sleep_func=gevent.sleep
        )
        self.ChildrenWatch = partial(ChildrenWatch, self)
        self.DataWatch = partial(DataWatch, self)
        self._children_watches = {}
        self._data_watches = {} 
开发者ID:pinterest,项目名称:kingpin,代码行数:20,代码来源:mock_kazoo_client.py

示例3: start

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def start(self):
        """Create a new group and wait until the partitions have been
        acquired. This function should never be called twice.

        :raises: PartitionerError upon partitioner failures

        .. note: This is a blocking operation.
        """
        self.kazoo_retry = KazooRetry(**KAZOO_RETRY_DEFAULTS)
        self.kazoo_client = KazooClient(
            self.config.zookeeper,
            connection_retry=self.kazoo_retry,
        )
        self.kafka_client = KafkaClient(self.config.broker_list)

        self.log.debug("Starting a new group for topics %s", self.topics)
        self.released_flag = True
        self._refresh() 
开发者ID:Yelp,项目名称:yelp_kafka,代码行数:20,代码来源:partitioner.py

示例4: _lazy_initialize

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def _lazy_initialize(self):
        if not self.client:
            hosts = _parse_hosts(self.config.remote_db_hosts)
            _handler = eventlet.SequentialEventletHandler()
            _retry = retry.KazooRetry(max_tries=CLIENT_CONNECTION_RETRIES,
                                      delay=0.5,
                                      backoff=2,
                                      sleep_func=_handler.sleep_func)
            self.client = client.KazooClient(hosts=hosts,
                                             handler=_handler,
                                             connection_retry=_retry)
            self.client.start()
            self.client.ensure_path(ROOT_NS) 
开发者ID:openstack,项目名称:dragonflow,代码行数:15,代码来源:zookeeper_db_driver.py

示例5: __enter__

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def __enter__(self):
        kazooRetry = KazooRetry(
            max_tries=5,
        )
        self.zk = KazooClient(
            hosts=self.cluster_config.zookeeper,
            read_only=True,
            connection_retry=kazooRetry,
        )
        _log.debug(
            "ZK: Creating new zookeeper connection: {zookeeper}"
            .format(zookeeper=self.cluster_config.zookeeper),
        )
        self.zk.start()
        return self 
开发者ID:Yelp,项目名称:kafka-utils,代码行数:17,代码来源:zookeeper.py

示例6: __init__

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def __init__(self):
        retry_policy = KazooRetry(max_tries=self.max_tries)
        self.zk_client = self.get_kazoo_client(command_retry=retry_policy)
        self.zk_client.start()
        self.register_signal_handlers() 
开发者ID:Yelp,项目名称:data_pipeline,代码行数:7,代码来源:zookeeper.py

示例7: zk

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk() -> KazooClient:
    conn_retry_policy = KazooRetry(max_tries=-1, delay=0.1, max_delay=0.1)
    cmd_retry_policy = KazooRetry(
        max_tries=3, delay=0.3, backoff=1, max_delay=1, ignore_expire=False)
    zk = KazooClient(
        hosts='zk-1.zk:2181,zk-2.zk:2181,zk-3.zk:2181',
        connection_retry=conn_retry_policy,
        command_retry=cmd_retry_policy,
    )
    zk.start()
    yield zk
    zk.stop() 
开发者ID:dcos,项目名称:dcos,代码行数:14,代码来源:test_iam_migration.py

示例8: zk_connect

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_connect():
    print("Connecting to ZooKeeper")
    zk_user = os.environ.get('CALICO_ZK_USER')
    zk_secret = os.environ.get('CALICO_ZK_SECRET')
    conn_retry_policy = KazooRetry(
        max_tries=-1,
        delay=0.3,
        backoff=1.3,
        max_jitter=1,
        max_delay=3,
        ignore_expire=True,
    )
    # Retry commands every 0.3 seconds, for a total of <1s (usually 0.9)
    cmd_retry_policy = KazooRetry(
        max_tries=3,
        delay=0.3,
        backoff=1,
        max_jitter=0.1,
        max_delay=1,
        ignore_expire=False,
    )
    default_acl = None
    auth_data = None
    if zk_user and zk_secret:
        default_acl = [make_digest_acl(zk_user, zk_secret, all=True)]
        scheme = 'digest'
        credential = "{}:{}".format(zk_user, zk_secret)
        auth_data = [(scheme, credential)]
    zk = KazooClient(
        hosts=ZK_SERVER,
        timeout=30,
        connection_retry=conn_retry_policy,
        command_retry=cmd_retry_policy,
        default_acl=default_acl,
        auth_data=auth_data,
    )
    zk.start()
    return zk 
开发者ID:dcos,项目名称:dcos,代码行数:40,代码来源:create-calico-docker-network.py

示例9: zk_conn

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_conn():
    conn_retry_policy = KazooRetry(max_tries=-1,
                                   delay=0.1,
                                   backoff=2,
                                   max_delay=3600)
    handler = SequentialThreadingHandler()
    conn = KazooClient(hosts="127.0.0.1:2181",
                       timeout=60,
                       handler=handler,
                       connection_retry=conn_retry_policy,
                       command_retry=conn_retry_policy)

    conn.start()
    yield conn
    conn.stop() 
开发者ID:dcos,项目名称:dcos,代码行数:17,代码来源:conftest.py

示例10: __init__

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def __init__(self, zk_hosts):
        conn_retry_policy = KazooRetry(max_tries=-1, delay=0.1, max_delay=0.1)
        cmd_retry_policy = KazooRetry(max_tries=3, delay=0.3, backoff=1, max_delay=1, ignore_expire=False)
        self._zk = KazooClient(hosts=zk_hosts, connection_retry=conn_retry_policy, command_retry=cmd_retry_policy) 
开发者ID:dcos,项目名称:dcos,代码行数:6,代码来源:bootstrap.py

示例11: zk_client

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_client(three_master_cluster: Cluster) -> KazooClient:
    """
    ZooKeeper client connected to a given DC/OS cluster.
    """
    zk_hostports = ','.join(['{}:2181'.format(m.public_ip_address)
                             for m in three_master_cluster.masters])
    retry_policy = KazooRetry(
        max_tries=-1,
        delay=1,
        backoff=1,
        max_delay=600,
        ignore_expire=True,
    )
    zk_client = KazooClient(
        hosts=zk_hostports,
        # Avoid failure due to client session timeout.
        timeout=40,
        # Work around https://github.com/python-zk/kazoo/issues/374
        connection_retry=retry_policy,
        command_retry=retry_policy,
    )
    zk_client.start()
    try:
        yield zk_client
    finally:
        zk_client.stop()
        zk_client.close() 
开发者ID:dcos,项目名称:dcos,代码行数:29,代码来源:test_zookeeper_backup.py

示例12: _zookeeper_resolver

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def _zookeeper_resolver(self, cfg):
        hosts, path = cfg[5:].split("/", 1)
        path = "/" + path

        retry = KazooRetry(max_tries=10)
        with zookeeper.client(
            hosts=hosts, read_only=True, connection_retry=retry, command_retry=retry
        ) as zk:

            def master_id(key):
                return int(key.split("_")[-1])

            def get_masters():
                return [x for x in zk.get_children(path) if re.search(r"\d+", x)]

            leader = sorted(get_masters(), key=lambda x: master_id(x))

            if len(leader) == 0:
                raise exceptions.MasterNotAvailableException(
                    f"cannot find any masters at {cfg}"
                )
            data, stat = zk.get(os.path.join(path, leader[0]))

            if not data:
                exceptions.MasterNotAvailableException(
                    "Cannot retrieve valid MasterInfo data from ZooKeeper"
                )
            else:
                data = data.decode("utf8")

            try:
                parsed = json.loads(data)
                if parsed and "address" in parsed:
                    ip = parsed["address"].get("ip")
                    port = parsed["address"].get("port")
                    if ip and port:
                        return f"{ip}:{port}"
            except ValueError as parse_error:
                log.debug(
                    "[WARN] No JSON content, probably connecting to older "
                    "Mesos version. Reason: {}".format(parse_error)
                )
                raise exceptions.MasterNotAvailableException(
                    "Failed to parse mesos master ip from ZK"
                ) 
开发者ID:Yelp,项目名称:paasta,代码行数:47,代码来源:master.py

示例13: zk_connect

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_connect(zk_addr: str,
               zk_user: Optional[str] = None,
               zk_secret: Optional[str] = None) -> KazooClient:
    """Connect to ZooKeeper.

    On connection failure, the function attempts to reconnect indefinitely with
    exponential backoff up to 3 seconds. If a command fails, that command is
    retried every 300ms for 3 attempts before failing.

    These values are chosen to suit a human-interactive time.

    Args:
        zk_addr: The address to connect to
        zk_user: The username to use when connecting to ZooKeeper or `None`
            if no authentication is necessary.
        zk_secret: The secret to use when connecting to ZooKeeper or `None`
            if no authentication is necessary.

    Returns:
        A ZooKeeper client connection in the form of a `kazoo.client.KazooClient`.
    """
    # Try to reconnect indefinitely, with time between updates going
    # exponentially to ~3s. Then every retry occurs every ~3 seconds.
    conn_retry_policy = KazooRetry(
        max_tries=-1,
        delay=0.3,
        backoff=1.3,
        max_delay=3,
        ignore_expire=True,
    )

    # Retry commands every 0.3 seconds, for a total of <1s (usually 0.9)
    cmd_retry_policy = KazooRetry(
        max_tries=3,
        delay=0.3,
        backoff=1,
        max_delay=1,
        ignore_expire=False,
    )

    default_acl = None
    auth_data = None
    if zk_user and zk_secret:
        default_acl = [make_digest_acl(zk_user, zk_secret, all=True)]
        scheme = 'digest'
        credential = "{}:{}".format(zk_user, zk_secret)
        auth_data = [(scheme, credential)]

    zk = KazooClient(
        hosts=zk_addr,
        timeout=30,
        connection_retry=conn_retry_policy,
        command_retry=cmd_retry_policy,
        default_acl=default_acl,
        auth_data=auth_data,
    )

    zk.start()
    return zk 
开发者ID:dcos,项目名称:dcos,代码行数:61,代码来源:etcd_discovery.py

示例14: zk_connect

# 需要导入模块: from kazoo import retry [as 别名]
# 或者: from kazoo.retry import KazooRetry [as 别名]
def zk_connect(zk_user: Optional[str] = None, zk_secret: Optional[str] = None) -> KazooClient:
    """Connect to ZooKeeper.

    On connection failure, the function attempts to reconnect indefinitely with exponential backoff
    up to 3 seconds. If a command fails, that command is retried every 300ms for 3 attempts before failing.

    These values are chosen to suit a human-interactive time.

    Args:
        zk_user:
            The username to use when connecting to ZooKeeper or `None` if no authentication is necessary.
        zk_secret:
            The secret to use when connecting to ZooKeeper or `None` if no authentication is necessary.

    Returns:
        A ZooKeeper client connection in the form of a `kazoo.client.KazooClient`.
    """
    # Try to reconnect indefinitely, with time between updates going
    # exponentially to ~3s. Then every retry occurs every ~3 seconds.
    conn_retry_policy = KazooRetry(
        max_tries=-1,
        delay=0.3,
        backoff=1.3,
        max_jitter=1,
        max_delay=3,
        ignore_expire=True,
    )
    # Retry commands every 0.3 seconds, for a total of <1s (usually 0.9)
    cmd_retry_policy = KazooRetry(
        max_tries=3,
        delay=0.3,
        backoff=1,
        max_jitter=0.1,
        max_delay=1,
        ignore_expire=False,
        )
    default_acl = None
    auth_data = None
    if zk_user and zk_secret:
        default_acl = [make_digest_acl(zk_user, zk_secret, all=True)]
        scheme = 'digest'
        credential = "{}:{}".format(zk_user, zk_secret)
        auth_data = [(scheme, credential)]
    zk = KazooClient(
        hosts="127.0.0.1:2181",
        timeout=30,
        connection_retry=conn_retry_policy,
        command_retry=cmd_retry_policy,
        default_acl=default_acl,
        auth_data=auth_data,
        )
    zk.start()
    return zk


# The prefix used for cockroachdb in ZK. 
开发者ID:dcos,项目名称:dcos,代码行数:58,代码来源:register.py


注:本文中的kazoo.retry.KazooRetry方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。