コード例 #1
0
ファイル: processor.py プロジェクト: wookiist/vitrage
    def _find_edges_status(self, vertex, neighbors):
        """Finds "vertex" valid and old connections

        Checks all the edges that are connected to the vertex in the entity
        graph, and finds which of them are old connections (edges that are no
        longer connected to those entities), and which are valid connections.
        """

        valid_edges = set()
        obsolete_edges = set()

        graph_neighbor_types = \
            PUtils.find_neighbor_types(neighbors)

        neighbor_edges = set(e for v, e in neighbors)
        for curr_edge in self.entity_graph.get_edges(vertex.vertex_id,
                                                     direction=Direction.BOTH):
            # check if the edge in the graph has a connection to the
            # same type of resources in the new neighbors list
            neighbor_vertex = self.entity_graph.get_vertex(
                curr_edge.other_vertex(vertex.vertex_id))

            is_connection_type_exist = PUtils.get_vertex_types(
                neighbor_vertex) in graph_neighbor_types

            if not is_connection_type_exist:
                valid_edges.add(curr_edge)
                continue

            if curr_edge in neighbor_edges:
                valid_edges.add(curr_edge)
            else:
                obsolete_edges.add(curr_edge)

        return valid_edges, obsolete_edges
コード例 #2
0
    def test_find_neighbor_types(self):
        neighbors = []
        entity_graph = NXGraph("Entity Graph")
        entities_details = [('RESOURCE', 'HOST', '1', False, True),
                            ('RESOURCE', 'STORAGE', '2', False, True),
                            ('RESOURCE', 'APPLICATION', '3', False, True),
                            ('RESOURCE', 'STORAGE', '4', False, True),
                            ('ALARM', 'INSTANCE_AT_RISK', '5', False, True)]

        # add neighbors
        for details in entities_details:
            # neighbor
            vertex = self._update_vertex_to_graph(entity_graph, details[0],
                                                  details[1], details[2],
                                                  details[3], details[4], {})
            neighbors.append((vertex, None))

        # get neighbors types
        types = PUtils.find_neighbor_types(neighbors)
        self.assertEqual(4, len(types))
コード例 #3
0
ファイル: test_entity_graph.py プロジェクト: wookiist/vitrage
    def test_find_neighbor_types(self):
        neighbors = []
        entity_graph = NXGraph("Entity Graph")
        entities_details = \
            [(EntityCategory.RESOURCE, 'HOST', '1', False, True),
             (EntityCategory.RESOURCE, 'STORAGE', '2', False, True),
             (EntityCategory.RESOURCE, 'APPLICATION', '3', False, True),
             (EntityCategory.RESOURCE, 'STORAGE', '4', False, True),
             (EntityCategory.ALARM, 'INSTANCE_AT_RISK', '5', False, True)]

        # add neighbors
        for details in entities_details:
            # neighbor
            vertex = self._update_vertex_to_graph(entity_graph, details[0],
                                                  details[1], details[2],
                                                  details[3], details[4], {})
            neighbors.append((vertex, None))

        # get neighbors types
        types = PUtils.find_neighbor_types(neighbors)
        self.assertThat(types, matchers.HasLength(4))