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) if not updated_vertex.get(VProps.IS_REAL_VITRAGE_ID, False): self._find_and_fix_graph_vertex(updated_vertex, neighbors) graph_vertex = self.entity_graph.get_vertex(updated_vertex.vertex_id) if (not graph_vertex) or \ PUtils.is_newer_vertex(graph_vertex, updated_vertex): PUtils.update_entity_graph_vertex(self.entity_graph, graph_vertex, updated_vertex) self._update_neighbors(updated_vertex, neighbors) else: LOG.warning("Update event arrived on invalid resource: %s", updated_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 _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 PUtils.can_update_vertex(graph_vertex, vertex): LOG.debug("Updates vertex: %s", vertex) self._calculate_aggregated_state(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)