def _get_keys(self, request): keys = request.keyGetParams.keys publication = kv_store_types.Publication({}) for key in keys: if key in self._kv_store: publication.keyVals[key] = self._kv_store[key] return publication
def _run(self, client: OpenrCtrl.Client) -> None: if not self.area_feature: super()._run(client) return all_kv = kv_store_types.Publication() all_kv.keyVals = {} node_area = {} nodes = set() for area in self.areas: prefix_keys = client.getKvStoreKeyValsFilteredArea( self.buildKvStoreKeyDumpParams(Consts.PREFIX_DB_MARKER), area ) all_kv.keyVals.update(prefix_keys.keyVals) adj_keys = client.getKvStoreKeyValsFilteredArea( self.buildKvStoreKeyDumpParams(Consts.ADJ_DB_MARKER), area ) host_id = client.getMyNodeName() node_set = self.get_connected_nodes(adj_keys, host_id) # save area associated with each node for node in node_set: node_area[node] = area nodes.update(node_set) self.print_kvstore_nodes(nodes, all_kv, host_id, node_area)
def _dump_all_with_filter(self, request): prefix = request.keyDumpParams.prefix publication = kv_store_types.Publication({}) for key in self._kv_store: if key.startswith(prefix): publication.keyVals[key] = self._kv_store[key] return publication
def _run(self, client: OpenrCtrl.Client, nodes: set, node: Any, interface: Any) -> None: if not self.area_feature: super()._run(client, nodes, interface) return keyDumpParams = self.buildKvStoreKeyDumpParams(Consts.ADJ_DB_MARKER) resp = kv_store_types.Publication() resp.keyVals = {} for area in self.areas: publication = client.getKvStoreKeyValsFilteredArea( keyDumpParams, area) resp.keyVals.update(publication.keyVals) self.printAdjNode(resp, nodes, node, interface)
def print_prefix( self, resp: Dict[str, kv_store_types.Publication], nodes: set, json: bool, prefix: str, client_type: str, ): all_kv = kv_store_types.Publication() all_kv.keyVals = {} for _, val in resp.items(): all_kv.keyVals.update(val.keyVals) if json: utils.print_prefixes_json(all_kv, nodes, prefix, client_type, self.iter_publication) else: utils.print_prefixes_table(all_kv, nodes, prefix, client_type, self.iter_publication)
def get_node_to_ips(self, client: OpenrCtrl.Client, area: str = None) -> Dict: """ get the dict of all nodes to their IP in the network """ node_dict = {} keyDumpParams = self.buildKvStoreKeyDumpParams(Consts.PREFIX_DB_MARKER) resp = kv_store_types.Publication() if not self.area_feature: resp = client.getKvStoreKeyValsFiltered(keyDumpParams) else: if area is None: print(f"Error: Must specify one of the areas: {self.areas}") sys.exit(1) resp = client.getKvStoreKeyValsFilteredArea(keyDumpParams, area) prefix_maps = utils.collate_prefix_keys(resp.keyVals) for node, prefix_db in prefix_maps.items(): node_dict[node] = self.get_node_ip(prefix_db) return node_dict
value3.originatorId = "san jose 3" value4 = kv_store_types.Value() value4.originatorId = "san jose 4" value5 = kv_store_types.Value() value5.originatorId = "san francisco 1" kv_store_cache = { "san jose 1": value1, "san jose 2": value2, "san jose 3": value3, "san jose 4": value4, "san francisco 1": value5, } publication = kv_store_types.Publication(kv_store_cache) class KvStorePub(object): def __init__(self, zmq_ctx, url): self._kv_store_publisher_socket = zmq_socket.ZmqSocket( zmq_ctx, zmq.PUB) self._kv_store_publisher_socket.bind(url) def publish(self): self._kv_store_publisher_zmq_socket.send_thrift_obj(publication) class TestKVStoreSubscriberClient(unittest.TestCase): def test(self): runtime_second = 1