def get_node_by_name(self, node_name: str): """ Search a node instance by it's name. :param node_name: the node's name to search. :return: Node instance whose name is node_name. :raise TypeError: Node name given as parameter is None. :raise DataNotFoundError: Node instance has not been found. """ if node_name is None: raise TypeError("No node name has been given. node_name is None.") content_as_string = self.db.get(Node.KEY_PREFIX + node_name) if content_as_string is not None: content_as_dict = ast.literal_eval( content_as_string.decode('utf-8')) if type(content_as_dict) == dict: # node_type = self.get_type_by_name(content_as_dict.get('type', '')) n = Node() n.from_dict(node_dict=content_as_dict) # n.from_dict(node_dict=content_as_dict, node_type=node_type) return n else: raise TypeError( "Type obtained from redis {} after conversion isn't a dictionary." .format(Node.KEY_PREFIX + node_name)) raise DataNotFoundError( "Node whose name is {} hasn't been found in the db.".format( node_name))
def get_ping_node(self, **kwargs): """ Get a ping node. Pass a node object. :param key: Ping key to look for. """ key = kwargs.get('key', None) node = None if key: self.pingNodesListMutex.acquire() # if exists ... self.db.sismember(PING_NODES, key) content_as_string = self.db.get(key) if content_as_string != None: res = ast.literal_eval(content_as_string.decode('utf-8')) node = Node() node.from_dict(res['n']) # node.from_dict(res['n'], res['t']) self.pingNodesListMutex.release() return node
def update_ping_hosts(self, **kwargs): """ Updates a given node's counter. :param node_dict: Node dictionary representation. """ node_dict = kwargs.get('node_dict', None) # type_dict = kwargs.get('type_dict', None) # if not node_dict: # return # t = Type() # t.from_dict(type_dict) node = Node() node.from_dict(node_dict) # node.from_dict(node_dict, t) # print(node, ' ACQUIRE') self.db.update_ping_node_list(node=node)