Exemplo n.º 1
0
    def test_mark_vertex_as_deleted(self):
        entity_graph = NXGraph("Entity Graph")

        # create vertex properties
        vertex = self._update_vertex_to_graph(entity_graph, 'RESOURCE',
                                              'INSTANCE', '12345', False, True,
                                              {})

        # check vitrage deleted
        self.assertFalse(PUtils.is_deleted(vertex))
        PUtils.mark_deleted(entity_graph, vertex)
        self.assertTrue(PUtils.is_deleted(vertex))
Exemplo n.º 2
0
    def delete_entity(self, deleted_vertex, neighbors):
        """Deletes the vertex from the entity graph

        Marks the corresponding vertex and its edges as deleted

        :param deleted_vertex: The vertex to be deleted from the graph
        :type deleted_vertex: Vertex

        :param neighbors: The neighbors of the deleted vertex
        :type neighbors: List
        """

        LOG.debug('Delete entity from entity graph:\n%s', deleted_vertex)

        graph_vertex = self.entity_graph.get_vertex(deleted_vertex.vertex_id)

        if graph_vertex and (not PUtils.is_deleted(graph_vertex)) and \
                PUtils.is_newer_vertex(graph_vertex, deleted_vertex):
            neighbor_vertices = self.entity_graph.neighbors(
                deleted_vertex.vertex_id)
            neighbor_edges = self.entity_graph.get_edges(
                deleted_vertex.vertex_id)

            for edge in neighbor_edges:
                self.entity_graph.mark_edge_as_deleted(edge)

            for vertex in neighbor_vertices:
                self.entity_graph.delete_placeholder_vertex(vertex)

            self.entity_graph.mark_vertex_as_deleted(deleted_vertex)
        else:
            LOG.warning("Delete event arrived on invalid resource: %s",
                        deleted_vertex)
Exemplo n.º 3
0
    def _connect_neighbors(self, neighbors, valid_edges, action):
        """Updates the neighbor vertex and adds the connection edges """
        if not neighbors:
            LOG.debug('connect_neighbors - nothing to do')
            return

        LOG.debug("Connect neighbors. Neighbors: %s, valid_edges: %s",
                  neighbors, valid_edges)
        for (vertex, edge) in neighbors:
            graph_vertex = self.entity_graph.get_vertex(vertex.vertex_id)
            if not graph_vertex or not PUtils.is_deleted(graph_vertex):
                if graph_vertex and not PUtils.is_newer_vertex(graph_vertex,
                                                               vertex):
                    LOG.warning("Neighbor update event arrived later than "
                                "expected - graph_vertex: %s --- "
                                "updated_vertex: %s", graph_vertex, vertex)
                else:
                    LOG.debug("Updates vertex: %s", vertex)
                    self._calculate_vitrage_aggregated_values(vertex, action)
                    PUtils.update_entity_graph_vertex(self.entity_graph,
                                                      graph_vertex,
                                                      vertex)
                if edge not in valid_edges:
                    LOG.debug("Updates edge: %s", edge)
                    self.entity_graph.update_edge(edge)
            else:
                LOG.debug("neighbor vertex wasn't updated: %s", vertex)
Exemplo n.º 4
0
    def delete_entity(self, deleted_vertex, neighbors):
        """Deletes the vertex from the entity graph

        Marks the corresponding vertex and its edges as deleted

        :param deleted_vertex: The vertex to be deleted from the graph
        :type deleted_vertex: Vertex

        :param neighbors: The neighbors of the deleted vertex
        :type neighbors: List
        """

        LOG.debug('Delete entity from entity graph:\n%s', deleted_vertex)

        graph_vertex = self.entity_graph.get_vertex(deleted_vertex.vertex_id)

        if graph_vertex and (not PUtils.is_deleted(graph_vertex)) and \
                PUtils.is_newer_vertex(graph_vertex, deleted_vertex):
            neighbor_vertices = self.entity_graph.neighbors(
                deleted_vertex.vertex_id)
            neighbor_edges = self.entity_graph.get_edges(
                deleted_vertex.vertex_id)

            for edge in neighbor_edges:
                self.entity_graph.mark_edge_as_deleted(edge)

            for vertex in neighbor_vertices:
                self.entity_graph.delete_placeholder_vertex(vertex)

            self.entity_graph.mark_vertex_as_deleted(deleted_vertex)
        else:
            LOG.warning("Delete event arrived on invalid resource: %s",
                        deleted_vertex)
Exemplo n.º 5
0
    def test_mark_edge_as_deleted(self):
        entity_graph = NXGraph("Entity Graph")

        # create vertex properties
        vertex1 = self._update_vertex_to_graph(entity_graph, 'RESOURCE',
                                               'INSTANCE', '12345', False,
                                               True, {})
        vertex2 = self._update_vertex_to_graph(entity_graph, 'RESOURCE',
                                               'HOST', '54321', False, True,
                                               {})
        edge = self._update_edge_to_graph(entity_graph, vertex1.vertex_id,
                                          vertex2.vertex_id, 'contains')

        # check vitrage deleted
        self.assertFalse(PUtils.is_deleted(edge))
        PUtils.mark_deleted(entity_graph, edge)
        self.assertTrue(PUtils.is_deleted(edge))
Exemplo n.º 6
0
    def test_delete_entity(self):
        # create instance event with host neighbor and check validity
        (vertex, neighbors, processor) = self._create_and_check_entity()

        # delete entity
        processor.delete_entity(vertex, neighbors)

        # check deleted entity
        self._check_graph(processor, self.NUM_VERTICES_AFTER_DELETION,
                          self.NUM_EDGES_AFTER_DELETION)
        self.assertTrue(PUtils.is_deleted(vertex))
Exemplo n.º 7
0
    def _find_and_fix_graph_vertex(self,
                                   vertex,
                                   neighbors=None,
                                   include_deleted=False):
        """Search for vertex in graph, and update vertex id and vitrage ID

        Search for vertex in graph, and update vertex id and vitrage ID
        Both in the Vertex itself, and in it's neighbors and edges

        :param new_vertex: The vertex to update
        :type new_vertex: Vertex

        :param neighbors: The neighbors of the vertex
        :type neighbors: list

        :param include_deleted: If True, Include deleted entities in the search
        :type include_deleted: bool
        """

        previous_vitrage_id = vertex[VProps.VITRAGE_ID]

        graph_vertex = self._get_single_graph_vertex_by_props(
            vertex, include_deleted)

        if not graph_vertex or (PUtils.is_deleted(graph_vertex)
                                and not include_deleted):

            vitrage_id = uuidutils.generate_uuid()
            if vertex[VProps.TYPE] == OPENSTACK_CLUSTER:
                self.entity_graph.root_id = vitrage_id
        else:
            vitrage_id = graph_vertex[VProps.VITRAGE_ID]

        vertex[VProps.VITRAGE_ID] = vitrage_id
        vertex.vertex_id = vitrage_id

        if not neighbors:
            return

        for neighbor_vertex, edge in neighbors:
            if not neighbor_vertex.get(VProps.IS_REAL_VITRAGE_ID, False):
                self._find_and_fix_graph_vertex(neighbor_vertex)
            if edge.target_id == previous_vitrage_id:
                edge.target_id = vitrage_id
                edge.source_id = neighbor_vertex.vertex_id
            else:
                edge.source_id = vitrage_id
                edge.target_id = neighbor_vertex.vertex_id
Exemplo n.º 8
0
    def delete_entity(self, deleted_vertex, neighbors):
        """Deletes the vertex from the entity graph

        Marks the corresponding vertex and its edges as deleted

        :param deleted_vertex: The vertex to be deleted from the graph
        :type deleted_vertex: Vertex

        :param neighbors: The neighbors of the deleted vertex
        :type neighbors: List
        """

        LOG.debug('Delete entity from entity graph:\n%s', deleted_vertex)

        graph_vertex = self.entity_graph.get_vertex(deleted_vertex.vertex_id)

        if not graph_vertex:
            LOG.warning('Delete - vertex not found %s', deleted_vertex)
            return
        elif PUtils.is_deleted(graph_vertex):
            LOG.warning(
                'Delete - vertex already deleted - '
                "graph_vertex: %s --- deleted_vertex: %s", graph_vertex,
                deleted_vertex)
            return
        elif not PUtils.is_newer_vertex(graph_vertex, deleted_vertex):
            LOG.warning(
                "Delete event arrived later than expected - "
                "graph_vertex: %s --- deleted_vertex: %s", graph_vertex,
                deleted_vertex)
            return

        neighbor_vertices = self.entity_graph.neighbors(
            deleted_vertex.vertex_id)
        neighbor_edges = self.entity_graph.get_edges(deleted_vertex.vertex_id)

        for edge in neighbor_edges:
            PUtils.mark_deleted(self.entity_graph, edge)

        for vertex in neighbor_vertices:
            PUtils.delete_placeholder_vertex(self.entity_graph, vertex)

        PUtils.mark_deleted(self.entity_graph, deleted_vertex)
Exemplo n.º 9
0
    def remove_deleted_entity(self, vertex, neighbors):
        """Removes the deleted vertex from the entity graph

        Removes vertex that it's is_deleted value is True

        :param vertex: The vertex to be removed from the graph
        :type vertex: Vertex

        :param neighbors: The neighbors of the deleted vertex
        :type neighbors: List
        """

        LOG.debug('Remove deleted entity from entity graph:\n%s', vertex)

        graph_vertex = self.entity_graph.get_vertex(vertex.vertex_id)

        if graph_vertex and PUtils.is_deleted(graph_vertex) and \
                PUtils.is_newer_vertex(graph_vertex, vertex):
            self.entity_graph.remove_vertex(vertex)
        else:
            LOG.warning("Delete event arrived on invalid resource: %s", vertex)
Exemplo n.º 10
0
    def remove_deleted_entity(self, vertex, neighbors):
        """Removes the deleted vertex from the entity graph

        Removes vertex that it's is_deleted value is True

        :param vertex: The vertex to be removed from the graph
        :type vertex: Vertex

        :param neighbors: The neighbors of the deleted vertex
        :type neighbors: List
        """

        LOG.debug('Remove deleted entity from entity graph:\n%s', vertex)

        graph_vertex = self.entity_graph.get_vertex(vertex.vertex_id)

        if graph_vertex and PUtils.is_deleted(graph_vertex) and \
                PUtils.is_newer_vertex(graph_vertex, vertex):
            self.entity_graph.remove_vertex(vertex)
        else:
            LOG.warning("Delete event arrived on invalid resource: %s", vertex)
Exemplo n.º 11
0
    def _connect_neighbors(self, neighbors, valid_edges, action):
        """Updates the neighbor vertex and adds the connection edges """
        if not neighbors:
            LOG.debug('connect_neighbors - nothing to do')
            return

        LOG.debug("Connect neighbors. Neighbors: %s, valid_edges: %s",
                  neighbors, valid_edges)
        for (vertex, edge) in neighbors:
            graph_vertex = self.entity_graph.get_vertex(vertex.vertex_id)
            if not graph_vertex or not PUtils.is_deleted(graph_vertex):
                if self.entity_graph.can_update_vertex(graph_vertex, vertex):
                    LOG.debug("Updates vertex: %s", vertex)
                    self._calculate_aggregated_state(vertex, action)
                    self.entity_graph.update_entity_graph_vertex(graph_vertex,
                                                                 vertex)

                if edge not in valid_edges:
                    LOG.debug("Updates edge: %s", edge)
                    self.entity_graph.update_edge(edge)
            else:
                LOG.debug("neighbor vertex wasn't updated: %s", vertex)
Exemplo n.º 12
0
    def _connect_neighbors(self, neighbors, valid_edges, action):
        """Updates the neighbor vertex and adds the connection edges """
        if not neighbors:
            LOG.debug('connect_neighbors - nothing to do')
            return

        LOG.debug("Connect neighbors. Neighbors: %s, valid_edges: %s",
                  neighbors, valid_edges)
        for (vertex, edge) in neighbors:
            graph_vertex = self.entity_graph.get_vertex(vertex.vertex_id)
            if not graph_vertex or not PUtils.is_deleted(graph_vertex):
                if self.entity_graph.can_update_vertex(graph_vertex, vertex):
                    LOG.debug("Updates vertex: %s", vertex)
                    self._calculate_aggregated_state(vertex, action)
                    self.entity_graph.update_entity_graph_vertex(
                        graph_vertex, vertex)

                if edge not in valid_edges:
                    LOG.debug("Updates edge: %s", edge)
                    self.entity_graph.update_edge(edge)
            else:
                LOG.debug("neighbor vertex wasn't updated: %s", vertex)