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


Python exceptions.NoNodeError方法代码示例

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


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

示例1: release

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def release(self):

        with self.mutex:

            if self.is_locked():

                # remove listener to avoid useless event triggering
                self.zkclient.remove_listener(self.on_connection_change)

                try:
                    self.zkclient.delete(self.lock_path)
                except NoNodeError as e:
                    logger.info(repr(e) + ' while delete lock: ' + str(self))

                self.lock_holder = None

                logger.info('RELEASED: {s}'.format(s=str(self)))
            else:
                logger.info('not acquired, do not need to release')

        self.close() 
开发者ID:bsc-s2,项目名称:pykit,代码行数:23,代码来源:zklock.py

示例2: test_get_next_deleted

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def test_get_next_deleted(self):

        cases = (
            0.4,
            1,
        )

        def _del_a():
            self.zk.delete('a')

        for timeout in cases:

            self.zk.create('a', 'a-val')
            th = threadutil.start_daemon(target=_del_a, after=0.3)

            with ututil.Timer() as t:
                self.assertRaises(NoNodeError,
                                  zkutil.get_next,
                                  self.zk, 'a', timeout=timeout, version=0)
                self.assertAlmostEqual(0.3, t.spent(), delta=0.2)

            th.join() 
开发者ID:bsc-s2,项目名称:pykit,代码行数:24,代码来源:test_zkutil.py

示例3: apply

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def apply(self):
        self.zk_journal_id_set, _ = self.journal_id_set.get()

        for journal_id in self._get_uncommitted_journal_ids():

            try:
                if self.zk_journal_id_set[PURGED].has(journal_id):
                    raise NoNodeError('journal {jid:0>10} has been deleted'.format(jid=journal_id))

                jour, _ = self.journal.get(journal_id)

            except NoNodeError:
                logger.warn('journal not found journal id: {jid:0>10}'.format(jid=journal_id))
                self._set_all_records()
                return

            self.storage.apply_jour(jour)
            self.storage.add_to_journal_id_set(COMMITTED, journal_id) 
开发者ID:bsc-s2,项目名称:pykit,代码行数:20,代码来源:slave.py

示例4: test_journal_purge

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def test_journal_purge(self):

        n_tx = 10
        k = 'foo'

        for ii in range(n_tx):

            with ZKTransaction(zkhost) as t1:
                t1.zkstorage.max_journal_history = 5
                foo = t1.lock_get(k)
                foo.v = foo.v or 0
                foo.v += 1
                t1.set(foo)
                t1.commit()

        t = ZKTransaction(zkhost)
        journal_id_set, ver = t.zkstorage.journal_id_set.get()
        self.assertEqual({PURGED: [[0, 5]], COMMITTED: [[0, 10]]}, journal_id_set)

        for i in range(5):
            self.assertRaises(NoNodeError, t.zkstorage.journal.get, i) 
开发者ID:bsc-s2,项目名称:pykit,代码行数:23,代码来源:test_tx.py

示例5: test_delete_node

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def test_delete_node(self):
        k = 'foo'
        with ZKTransaction(zkhost) as t1:
            foo = t1.lock_get(k)
            foo.v = 'foo'
            t1.set(foo)
            t1.commit()

        t = ZKTransaction(zkhost)
        self.assertEqual(([None, 'foo'], 0), t.zkstorage.record.get('foo'))

        with ZKTransaction(zkhost) as t1:
            foo = t1.lock_get(k)
            foo.v = None
            t1.set(foo)
            t1.commit()

        self.assertEqual(([None], -1), t.zkstorage.record.get('foo'))
        self.assertRaises(NoNodeError, t.zkstorage.zke.get, 'foo') 
开发者ID:bsc-s2,项目名称:pykit,代码行数:21,代码来源:test_tx.py

示例6: test_get_path

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def test_get_path(self):

        v = zktx.ZKValue(self.zk, get_path=lambda: 'foopath')

        v.create('1')

        rst, ver = self.zk.get('foopath')
        self.assertEqual('1', rst)

        rst, ver = v.get()
        self.assertEqual('1', rst)

        v.set('2')
        rst, ver = v.get()
        self.assertEqual('2', rst)

        v.delete()
        self.assertRaises(NoNodeError, v.get) 
开发者ID:bsc-s2,项目名称:pykit,代码行数:20,代码来源:test_zkaccessor.py

示例7: _get_task

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def _get_task(self, task_id: str) -> Tuple[MesosTaskParameters, ZnodeStat]:
        """Like get_task, but also returns the ZnodeStat that self.zk_client.get() returns """
        try:
            data, stat = self.zk_client.get("/%s" % task_id)
            return MesosTaskParameters.deserialize(data), stat
        except NoNodeError:
            return None, None
        except json.decoder.JSONDecodeError:
            _log(
                service=self.service_name,
                instance=self.instance_name,
                level="debug",
                component="deploy",
                line=f"Warning: found non-json-decodable value in zookeeper for task {task_id}: {data}",
            )
            return None, None 
开发者ID:Yelp,项目名称:paasta,代码行数:18,代码来源:task_store.py

示例8: get_boost_values

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [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
    ) 
开发者ID:Yelp,项目名称:paasta,代码行数:22,代码来源:load_boost.py

示例9: get_zk_data

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def get_zk_data(blacklisted_services: Set[str]) -> SmartstackData:
    logger.info(f"using {DEFAULT_ZK_DISCOVERY_PATH} for zookeeper")
    zk_hosts = get_zk_hosts(DEFAULT_ZK_DISCOVERY_PATH)

    logger.debug(f"connecting to zk hosts {zk_hosts}")
    zk = KazooClient(hosts=zk_hosts)
    zk.start()

    logger.debug(f"pulling smartstack data from zookeeper")
    zk_data = {}
    services = zk.get_children(PREFIX)
    for service in services:
        if service in blacklisted_services:
            continue
        service_instances = zk.get_children(os.path.join(PREFIX, service))
        instances_data = {}
        for instance in service_instances:
            try:
                instance_node = zk.get(os.path.join(PREFIX, service, instance))
            except NoNodeError:
                continue
            instances_data[instance] = json.loads(instance_node[0])
            zk_data[service] = instances_data

    return zk_data 
开发者ID:Yelp,项目名称:paasta,代码行数:27,代码来源:check_orphans.py

示例10: apply_configuration_properties

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def apply_configuration_properties(self, entity: str, changes: dict, entity_type: str):
        """
        Applies dynamic config changes using zookeeper
        :param entity: id of the entity (broker id or topic name)
        :param changes: dictionary containing property and key values
        :param entity_type: type of the entity to apply config changes (ConfigEntityType.BROKER/ConfigEntityType.TOPIC)
        """

        zk_config_path = "/config/{}/{}".format(entity_type, entity)
        try:
            config = json.loads(self.exhibitor.get(zk_config_path)[0].decode('utf-8'))
            updated_config = config
            for config_property, value in changes.items():
                updated_config.get('config', {})[config_property] = value
            self.exhibitor.set(zk_config_path, json.dumps(updated_config).encode('utf-8'))
        except NoNodeError:
            updated_config = {
                "version": 1,
                "config": changes
            }
            self.exhibitor.create(zk_config_path, json.dumps(updated_config).encode('utf-8'))
        self._apply_change_notification(entity, entity_type) 
开发者ID:zalando-nakadi,项目名称:bubuku,代码行数:24,代码来源:__init__.py

示例11: test_is_broker_registered

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def test_is_broker_registered():
    def _get(path):
        if path == '/brokers/ids/123':
            return '123', object()
        elif path == '/brokers/ids/321':
            return None, None
        else:
            raise NoNodeError()

    exhibitor_mock = MagicMock()
    exhibitor_mock.get = _get
    buku = BukuExhibitor(exhibitor_mock)

    assert buku.is_broker_registered('123')
    assert buku.is_broker_registered(123)
    assert not buku.is_broker_registered('321')
    assert not buku.is_broker_registered(321)
    assert not buku.is_broker_registered(333)
    assert not buku.is_broker_registered('333') 
开发者ID:zalando-nakadi,项目名称:bubuku,代码行数:21,代码来源:test_zookeeper.py

示例12: list_instance_keys

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def list_instance_keys(self, cluster_name, resolve=True):
        """Gets all keys of specified cluster.

        The cluster will be resolved here, including the symlink and route.

        :param cluster_name: The name of callee cluster.
        :param resolve: ``False`` if you don't wanna resolving the cluster.
        :returns: The list of keys.
        """
        if resolve:
            physical_name = self.resolve_cluster_name(cluster_name)
            cluster_name = physical_name or cluster_name
        info = self._make_cluster_info(cluster_name)
        try:
            keys = sorted(self.huskar_client.client.get_children(info.path))
        except NoNodeError:
            keys = []
        return [decode_key(k) for k in keys] 
开发者ID:huskar-org,项目名称:huskar,代码行数:20,代码来源:management.py

示例13: load

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def load(self):
        """Loads data from ZooKeeper and parses it.

        The :attr:`ZnodeModel.stat` will be ``None`` if the target node does
        not exist.

        :raises MalformedDataError: The data source is malformed.
        """
        try:
            data, stat = self.client.get(self.path)
        except NoNodeError:
            return
        self.stat = stat
        if data:
            try:
                self.data, _ = self.MARSHMALLOW_SCHEMA.loads(data)
            except self._MALFORMED_DATA_EXCEPTIONS as e:
                raise MalformedDataError(self, e) 
开发者ID:huskar-org,项目名称:huskar,代码行数:20,代码来源:znode.py

示例14: get_brokers

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def get_brokers(self, names_only=False):
        """Get information on all the available brokers.

        :rtype : dict of brokers
        """
        try:
            broker_ids = self.get_children("/brokers/ids")
        except NoNodeError:
            _log.info(
                "cluster is empty."
            )
            return {}
        # Return broker-ids only
        if names_only:
            return {int(b_id): None for b_id in broker_ids}
        return {int(b_id): self.get_broker_metadata(b_id) for b_id in broker_ids} 
开发者ID:Yelp,项目名称:kafka-utils,代码行数:18,代码来源:zookeeper.py

示例15: get

# 需要导入模块: from kazoo import exceptions [as 别名]
# 或者: from kazoo.exceptions import NoNodeError [as 别名]
def get(self, key: bytes) -> bytes:
        from kazoo.exceptions import NoNodeError
        _validate_key(key)

        formatted_key = key.decode('ascii')

        full_path = os.path.join(self.namespace, formatted_key)

        try:
            data = self._client.get(full_path)
            return bytes(data[0])
        except NoNodeError:
            return None 
开发者ID:intel,项目名称:workload-collocation-agent,代码行数:15,代码来源:databases.py


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