def update_entity(self, updated_vertex, neighbors): """Updates the vertex in the entity graph Updates the in entity in the entity graph. In addition it removes old neighbor connections, and connects the new neighbors. :param updated_vertex: The vertex to be updated in the graph :type updated_vertex: Vertex :param neighbors: The neighbors of the updated vertex :type neighbors: List """ LOG.debug('Update entity in entity graph:\n%s', updated_vertex) graph_vertex = self.entity_graph.get_vertex(updated_vertex.vertex_id) if graph_vertex and not PUtils.is_newer_vertex(graph_vertex, updated_vertex): LOG.warning("Update event arrived later than expected - " "graph_vertex: %s --- updated_vertex: %s", graph_vertex, updated_vertex) return self._add_resource_details_to_alarm(updated_vertex, neighbors) PUtils.update_entity_graph_vertex(self.entity_graph, graph_vertex, updated_vertex) self._update_neighbors(updated_vertex, neighbors)
def update_entity(self, updated_vertex, neighbors): """Updates the vertex in the entity graph Updates the in entity in the entity graph. In addition it removes old neighbor connections, and connects the new neighbors. :param updated_vertex: The vertex to be updated in the graph :type updated_vertex: Vertex :param neighbors: The neighbors of the updated vertex :type neighbors: List """ LOG.debug('Update entity in entity graph:\n%s', updated_vertex) graph_vertex = self.entity_graph.get_vertex(updated_vertex.vertex_id) if (not graph_vertex) or \ PUtils.is_newer_vertex(graph_vertex, updated_vertex): self.entity_graph.update_entity_graph_vertex(graph_vertex, updated_vertex) self._update_neighbors(updated_vertex, neighbors) else: LOG.warning("Update event arrived on invalid resource: %s", updated_vertex)
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)
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)
def update_entity(self, updated_vertex, neighbors): """Updates the vertex in the entity graph Updates the in entity in the entity graph. In addition it removes old neighbor connections, and connects the new neighbors. :param updated_vertex: The vertex to be updated in the graph :type updated_vertex: Vertex :param neighbors: The neighbors of the updated vertex :type neighbors: List """ LOG.debug('Update entity in entity graph:\n%s', updated_vertex) graph_vertex = self.entity_graph.get_vertex(updated_vertex.vertex_id) if (not graph_vertex) or \ PUtils.is_newer_vertex(graph_vertex, updated_vertex): self.entity_graph.update_entity_graph_vertex( graph_vertex, updated_vertex) self._update_neighbors(updated_vertex, neighbors) else: LOG.warning("Update event arrived on invalid resource: %s", updated_vertex)
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)
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)