Python kazoo.exceptions.NoNodeError() Examples
The following are 30
code examples of kazoo.exceptions.NoNodeError().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
kazoo.exceptions
, or try the search function
.
Example #1
Source File: load_boost.py From paasta with Apache License 2.0 | 6 votes |
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 )
Example #2
Source File: zklock.py From pykit with MIT License | 6 votes |
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()
Example #3
Source File: test_zkaccessor.py From pykit with MIT License | 6 votes |
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)
Example #4
Source File: task_store.py From paasta with Apache License 2.0 | 6 votes |
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
Example #5
Source File: test_zkutil.py From pykit with MIT License | 6 votes |
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()
Example #6
Source File: znode.py From huskar with MIT License | 6 votes |
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)
Example #7
Source File: slave.py From pykit with MIT License | 6 votes |
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)
Example #8
Source File: zookeeper.py From kafka-utils with Apache License 2.0 | 6 votes |
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}
Example #9
Source File: __init__.py From bubuku with MIT License | 6 votes |
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)
Example #10
Source File: check_orphans.py From paasta with Apache License 2.0 | 6 votes |
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
Example #11
Source File: management.py From huskar with MIT License | 6 votes |
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]
Example #12
Source File: test_zookeeper.py From bubuku with MIT License | 6 votes |
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')
Example #13
Source File: test_tx.py From pykit with MIT License | 6 votes |
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')
Example #14
Source File: test_tx.py From pykit with MIT License | 6 votes |
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)
Example #15
Source File: client.py From huskar with MIT License | 5 votes |
def set(self, application, cluster, key, value, version=None): value = str(value) if value else '' path = self.get_path(application, cluster, key) try: if version is None: self.raw_client.set(path, value) else: self.raw_client.set(path, value, version) zk_payload(payload_data=value, payload_type='set') except NoNodeError: self.raw_client.create(path, value, makepath=True) zk_payload(payload_data=value, payload_type='create') except BadVersionError as e: raise OutOfSyncError(e)
Example #16
Source File: zookeeper.py From kafka-utils with Apache License 2.0 | 5 votes |
def get_broker_metadata(self, broker_id): try: broker_json = load_json(self.get( "/brokers/ids/{b_id}".format(b_id=broker_id) )[0]) if (broker_json['host'] is None): pattern = '(?:[SSL|INTERNAL|PLAINTEXTSASL].*://)?(?P<host>[^:/ ]+).?(?P<port>[0-9]*).*' result = re.search(pattern, broker_json['endpoints'][0]) broker_json['host'] = result.group('host') except NoNodeError: _log.error( "broker '{b_id}' not found.".format(b_id=broker_id), ) raise return broker_json
Example #17
Source File: management.py From huskar with MIT License | 5 votes |
def list_cluster_names(self): """Gets all cluster names of current application. :returns: The list of names. """ info = self._make_service_info() try: return sorted(self.huskar_client.client.get_children(info.path)) except NoNodeError: return []
Example #18
Source File: management.py From huskar with MIT License | 5 votes |
def lookup(self): """Lists all applications and clusters on this container. :returns: A list of ``(application_name, cluster_name)`` tuples. """ path = self._make_container_path() try: location_list = self.huskar_client.client.get_children(path) return sorted(_unpack_list(location_list, self.container_id)) except NoNodeError: return []
Example #19
Source File: offset_manager.py From kafka-utils with Apache License 2.0 | 5 votes |
def get_topics_for_group_from_zookeeper( cls, cluster_config, groupid, fail_on_error ): topics = [] with ZK(cluster_config) as zk: # Query zookeeper to get the list of topics that this consumer is # subscribed to. try: topics = zk.get_my_subscribed_topics(groupid) except NoNodeError: if groupid in zk.get_children("/consumers"): print( "Error: Offsets for Consumer Group ID {groupid} not found.".format( groupid=groupid ), file=sys.stderr, ) else: if fail_on_error: print( "Error: Consumer Group ID {groupid} does not exist.".format( groupid=groupid ), file=sys.stderr, ) sys.exit(1) return topics
Example #20
Source File: zookeeper.py From kafka-utils with Apache License 2.0 | 5 votes |
def _get_entity_config(self, entity_type, entity_name, entity_exists): """Get configuration information for specified broker. :entity_type : "brokers" or "topics" :entity_name : broker id or topic name :entity_exists : fn(entity_name) -> bool to determine whether an entity exists. used to determine whether to throw an exception when a configuration cannot be found for the given entity_name :rtype : dict of configuration """ assert entity_type in ("brokers", "topics"), "Supported entities are brokers and topics" try: config_data = load_json( self.get( "/config/{entity_type}/{entity_name}".format(entity_type=entity_type, entity_name=entity_name) )[0] ) except NoNodeError as e: if entity_exists(entity_name): _log.info("Configuration not available for {entity_type} {entity_name}.".format( entity_type=entity_type, entity_name=entity_name, )) config_data = {"config": {}} else: _log.error("{entity_type} {entity_name} not found".format(entity_type=entity_type, entity_name=entity_name)) raise e return config_data
Example #21
Source File: test_support_route_program.py From huskar with MIT License | 5 votes |
def test_update_list_with_invalid_cluster( client, test_application, admin_token, hijack_url, hijack_list, last_audit_log): r = client.post(hijack_url, data={ 'application': test_application.application_name, 'stage': 'E', 'cluster': 'foo' }, headers={'Authorization': admin_token}) assert r.status_code == 400, r.data assert r.json['status'] == 'BadRequest' assert r.json['message'] == 'cluster is invalid' with raises(NoNodeError): hijack_list.get('foo') assert last_audit_log() is None
Example #22
Source File: client.py From huskar with MIT License | 5 votes |
def get(self, application=None, cluster=None, key=None): # TODO [refactor] those should be different functions if application and cluster and key: # application+cluster+key path = self.get_path(application, cluster, key) try: value, _ = self.raw_client.get(path) return value except NoNodeError: return None else: # pragma: no cover raise NotImplementedError()
Example #23
Source File: test_rebalance.py From bubuku with MIT License | 5 votes |
def test_rebalance_invoked_on_broker_list_change(self): zk = MagicMock() zk.get = MagicMock(side_effect=NoNodeError) check = RebalanceOnBrokerListCheck(zk, MagicMock()) zk.get_broker_ids.return_value = ['1', '2', '3'] assert check.check() is not None assert check.check() is None zk.get_broker_ids.return_value = ['1', '2', '3'] assert check.check() is None zk.get_broker_ids.return_value = ['1', '2', '4'] assert check.check() is not None assert check.check() is None
Example #24
Source File: __init__.py From bubuku with MIT License | 5 votes |
def is_rebalancing(self): try: rebalance_data = self.exhibitor.get('/admin/reassign_partitions')[0].decode('utf-8') _LOG.info('Old rebalance is still in progress: {}, waiting'.format(rebalance_data)) return True except NoNodeError: return False
Example #25
Source File: __init__.py From bubuku with MIT License | 5 votes |
def get_disk_stats(self) -> Dict[str, dict]: stats = {} for broker_id in self.get_broker_ids(): try: broker_stats_data, zk_stat = self.exhibitor.get('/bubuku/size_stats/{}'.format(broker_id)) broker_stats = json.loads(broker_stats_data.decode("utf-8")) stats[broker_id] = broker_stats except NoNodeError: pass return stats
Example #26
Source File: __init__.py From bubuku with MIT License | 5 votes |
def is_broker_registered(self, broker_id): try: _, stat = self.exhibitor.get('/brokers/ids/{}'.format(broker_id)) return stat is not None except NoNodeError: return False
Example #27
Source File: __init__.py From bubuku with MIT License | 5 votes |
def get_children(self, *args, **kwargs): self.hosts_cache.touch() try: return self.client.retry(self.client.get_children, *args, **kwargs) except NoNodeError: return []
Example #28
Source File: __init__.py From bubuku with MIT License | 5 votes |
def delete(self, *args, **kwargs): self.hosts_cache.touch() try: return self.client.retry(self.client.delete, *args, **kwargs) except NoNodeError: pass
Example #29
Source File: __init__.py From bubuku with MIT License | 5 votes |
def is_node_present(self, node): try: _, stat = self.get(node) return stat is not None except NoNodeError: return False
Example #30
Source File: cluster.py From incubator-retired-cotton with Apache License 2.0 | 5 votes |
def _data_callback(self, master_id, master_completion): try: master_content, _ = master_completion.get() except NoNodeError: # ZNode could be gone after we detected it but before we read it. master_id, master_content = None, None self._swap(master_id, master_content)