Ejemplo n.º 1
0
    def find_node_by_name_as_child(self, *, node_name: str, label: str,
                                   rel: str,
                                   parent_node_id: str) -> str or None:
        """
        Get node id of node based on its name, class label, as child of a parent node via a specified relationship
        or None
        :param node_name: 
        :param label: 
        :param rel: 
        :param parent_node_id: 
        :return: 
        """
        assert node_name is not None
        assert label is not None
        assert rel is not None
        assert parent_node_id is not None

        neighbs = self.get_first_neighbor(node_id=parent_node_id,
                                          rel=rel,
                                          node_label=label)
        for n in neighbs:
            _, props = self.get_node_properties(node_id=n)
            if props.get(ABCPropertyGraph.PROP_NAME, None) is not None and \
                props[ABCPropertyGraph.PROP_NAME] == node_name:
                return n
        raise PropertyGraphQueryException(
            graph_id=self.graph_id,
            node_id=None,
            msg=f"Unable to find node with name {node_name} "
            f"class {label} as child of {parent_node_id}")
Ejemplo n.º 2
0
    def find_node_by_name(self, *, node_name: str, label: str) -> str:

        assert node_name is not None
        assert label is not None
        query = f"MATCH(n:{label} {{GraphID: $graphId, Name: $name }}) RETURN collect(n.NodeID) as nodeids"
        with self.driver.session() as session:
            val = session.run(query, graphId=self.graph_id,
                              name=node_name).single()
            if val is None or len(val.data()) == 0:
                raise PropertyGraphQueryException(
                    graph_id=self.graph_id,
                    node_id=None,
                    msg=
                    f"Unable to find node with name {node_name} class {label}")
            if len(val.data()['nodeids']) > 1:
                raise PropertyGraphQueryException(
                    graph_id=self.graph_id,
                    node_id=None,
                    msg=f"Graph contains multiple nodes "
                    f"with name {node_name} class {label}")
            return val.data()['nodeids'][0]
Ejemplo n.º 3
0
    def find_node_by_name(self, node_name: str, label: str) -> str:
        """
        Return a node id of a node with this name
        :param node_name:
        :param label: label/class of the node
        :return:
        """
        assert node_name is not None
        my_graph = self.storage.get_graph(self.graph_id)
        graph_nodes = list(nxq.search_nodes(my_graph,
                                            {'and': [
                                                {'eq': [ABCPropertyGraphConstants.GRAPH_ID, self.graph_id]},
                                                {'eq': [ABCPropertyGraphConstants.PROP_NAME, node_name]},
                                                {'eq': [ABCPropertyGraphConstants.PROP_CLASS, label]}
                                            ]}))
        if len(graph_nodes) == 0:
            raise PropertyGraphQueryException(graph_id=self.graph_id, node_id=None,
                                              msg=f"Unable to find node with name {node_name} class {label}")
        if len(graph_nodes) > 1:
            raise PropertyGraphQueryException(graph_id=self.graph_id, node_id=None,
                                              msg=f"Graph contains multiple nodes with name {node_name} class {label}")

        return my_graph.nodes[graph_nodes[0]][ABCPropertyGraphConstants.NODE_ID]
Ejemplo n.º 4
0
    def find_ns_by_name(self, *, parent_node_id: str, nsname: str) -> str:

        assert nsname is not None

        ns_id_list = self.get_all_network_node_or_component_nss(
            parent_node_id=parent_node_id)
        for cid in ns_id_list:
            _, cprops = self.get_node_properties(node_id=cid)
            if cprops[ABCPropertyGraph.PROP_NAME] == nsname:
                return cid
        raise PropertyGraphQueryException(
            graph_id=self.graph_id,
            node_id=None,
            msg=f"Unable to find NetworkService with name {nsname}")
Ejemplo n.º 5
0
    def find_component_by_name(self, *, parent_node_id: str,
                               component_name: str) -> str:

        assert component_name is not None
        component_id_list = self.get_all_network_node_components(
            parent_node_id=parent_node_id)
        for cid in component_id_list:
            _, cprops = self.get_node_properties(node_id=cid)
            if cprops[ABCPropertyGraph.PROP_NAME] == component_name:
                return cid
        raise PropertyGraphQueryException(
            graph_id=self.graph_id,
            node_id=None,
            msg=f"Unable to find component with name {component_name}")
Ejemplo n.º 6
0
    def find_connection_point_by_name(self, *, parent_node_id: str,
                                      iname: str) -> str:

        assert iname is not None

        if_id_list = self.get_all_ns_or_link_connection_points(
            link_id=parent_node_id)
        for cid in if_id_list:
            _, cprops = self.get_node_properties(node_id=cid)
            if cprops[ABCPropertyGraph.PROP_NAME] == iname:
                return cid
        raise PropertyGraphQueryException(
            graph_id=self.graph_id,
            node_id=None,
            msg=f"Unable to find ConnectionPoint with name {iname}")
Ejemplo n.º 7
0
 def get_all_network_node_or_component_nss(
         self, parent_node_id: str) -> List[str]:
     assert parent_node_id is not None
     # check that parent is a NetworkNode or Component
     labels, parent_props = self.get_node_properties(node_id=parent_node_id)
     if ABCPropertyGraph.CLASS_NetworkNode not in labels and \
         ABCPropertyGraph.CLASS_Component not in labels:
         raise PropertyGraphQueryException(
             graph_id=self.graph_id,
             node_id=parent_node_id,
             msg="Parent node type is not NetworkNode or Component")
     return self.get_first_neighbor(
         node_id=parent_node_id,
         rel=ABCPropertyGraph.REL_HAS,
         node_label=ABCPropertyGraph.CLASS_NetworkService)
Ejemplo n.º 8
0
 def get_all_network_node_components(self,
                                     parent_node_id: str) -> List[str]:
     """
     Return a list of components, children of a prent (presumably network node)
     :param parent_node_id:
     :return:
     """
     assert parent_node_id is not None
     # check that parent is a NetworkNode
     labels, parent_props = self.get_node_properties(node_id=parent_node_id)
     if ABCPropertyGraph.CLASS_NetworkNode not in labels:
         raise PropertyGraphQueryException(
             graph_id=self.graph_id,
             node_id=parent_node_id,
             msg="Parent node type is not NetworkNode")
     return self.get_first_neighbor(
         node_id=parent_node_id,
         rel=ABCPropertyGraph.REL_HAS,
         node_label=ABCPropertyGraph.CLASS_Component)