Merge "bugfix: update a placeholder vertex can add properties to a real vertex"
This commit is contained in:
commit
969b6cc349
@ -212,12 +212,11 @@ class Processor(processor.ProcessorBase):
|
||||
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_vitrage_aggregated_values(vertex, action)
|
||||
PUtils.update_entity_graph_vertex(self.entity_graph,
|
||||
graph_vertex,
|
||||
vertex)
|
||||
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)
|
||||
|
@ -94,11 +94,6 @@ def get_vertex_types(vertex):
|
||||
return vitrage_category, vitrage_type
|
||||
|
||||
|
||||
def can_update_vertex(graph_vertex, new_vertex):
|
||||
return (not graph_vertex) or \
|
||||
(not new_vertex[VProps.VITRAGE_IS_PLACEHOLDER])
|
||||
|
||||
|
||||
def update_entity_graph_vertex(g, graph_vertex, updated_vertex):
|
||||
if updated_vertex[VProps.VITRAGE_IS_PLACEHOLDER] and \
|
||||
graph_vertex and not graph_vertex[VProps.VITRAGE_IS_PLACEHOLDER]:
|
||||
@ -107,4 +102,5 @@ def update_entity_graph_vertex(g, graph_vertex, updated_vertex):
|
||||
updated_vertex[VProps.VITRAGE_IS_DELETED] = \
|
||||
graph_vertex[VProps.VITRAGE_IS_DELETED]
|
||||
|
||||
g.update_vertex(updated_vertex)
|
||||
g.update_vertex(updated_vertex,
|
||||
not updated_vertex[VProps.VITRAGE_IS_PLACEHOLDER])
|
||||
|
@ -259,13 +259,16 @@ class Graph(object):
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def update_vertex(self, v):
|
||||
def update_vertex(self, v, overwrite=True):
|
||||
"""Update the vertex properties
|
||||
|
||||
Update an existing vertex and create it if non existing.
|
||||
|
||||
:param v: the vertex with the new data
|
||||
:type v: Vertex
|
||||
|
||||
:param overwrite: whether to overwrite existing properties
|
||||
:type overwrite: Boolean
|
||||
"""
|
||||
pass
|
||||
|
||||
@ -293,12 +296,14 @@ class Graph(object):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _merge_properties(base_props, new_props):
|
||||
def _merged_properties(base_props, updated_props, overwrite):
|
||||
if base_props is None:
|
||||
base_props = copy.copy(new_props)
|
||||
return copy.copy(updated_props)
|
||||
else:
|
||||
base_props.update(copy.copy(new_props))
|
||||
return {k: v for k, v in base_props.items() if v is not None}
|
||||
# Return all updated properties if overwrite is true, or only the
|
||||
# new properties otherwise
|
||||
return {k: v for k, v in updated_props.items()
|
||||
if overwrite or k not in base_props}
|
||||
|
||||
@abc.abstractmethod
|
||||
def remove_vertex(self, v):
|
||||
|
@ -173,16 +173,24 @@ class NXGraph(Graph):
|
||||
return self._g.number_of_edges()
|
||||
|
||||
@Notifier.update_notify
|
||||
def update_vertex(self, v):
|
||||
def update_vertex(self, v, overwrite=True):
|
||||
"""Update the vertex properties
|
||||
|
||||
:param v: the vertex with the new data
|
||||
:type v: Vertex
|
||||
|
||||
:param overwrite: whether to overwrite existing properties
|
||||
:type overwrite: Boolean
|
||||
"""
|
||||
orig_prop = self._g.node.get(v.vertex_id, None)
|
||||
if not orig_prop:
|
||||
self._add_vertex(v)
|
||||
return
|
||||
self._g.node[v.vertex_id].update(v.properties)
|
||||
|
||||
merged_props = \
|
||||
self._merged_properties(orig_prop, v.properties, overwrite)
|
||||
self._g.node[v.vertex_id].update(merged_props)
|
||||
|
||||
for prop, value in v.properties.items():
|
||||
if value is None:
|
||||
del self._g.node[v.vertex_id][prop]
|
||||
|
Loading…
x
Reference in New Issue
Block a user