Fix processor bug - cannot create an alarm after it was deleted

Change-Id: Ie9339d5b28ab76beffb31ee7aed7c6e6492eb07d
This commit is contained in:
Idan Hefetz 2016-04-17 14:42:06 +00:00
parent c1266cb25d
commit 22e3f1f636
3 changed files with 47 additions and 32 deletions

View File

@ -12,7 +12,6 @@
# License for the specific language governing permissions and limitations
# under the License.
from dateutil import parser
from oslo_log import log
from vitrage.common.constants import EdgeProperties as EProps
@ -86,27 +85,6 @@ class EntityGraph(NXGraph):
type_ = vertex[VProps.TYPE]
return category, type_
def check_update_validation(self, graph_vertex, updated_vertex):
"""Checks current and updated validation
Check 2 conditions:
1. is the vertex not deleted
2. is updated timestamp bigger then current timestamp
"""
return (not self.is_vertex_deleted(graph_vertex)) and \
self.check_timestamp(graph_vertex, updated_vertex)
@staticmethod
def check_timestamp(graph_vertex, new_vertex):
curr_timestamp = graph_vertex.get(VProps.SAMPLE_TIMESTAMP)
if not curr_timestamp:
return True
current_time = parser.parse(curr_timestamp)
new_time = parser.parse(new_vertex[VProps.SAMPLE_TIMESTAMP])
return current_time <= new_time
@staticmethod
def can_update_vertex(graph_vertex, new_vertex):
return (not graph_vertex) or (not new_vertex[VProps.IS_PLACEHOLDER])

View File

@ -21,6 +21,7 @@ from vitrage.datasources.transformer_base import TransformerBase
from vitrage.entity_graph.processor import base as processor
from vitrage.entity_graph.processor import entity_graph
from vitrage.entity_graph.processor.notifier import DeducedAlarmNotifier
from vitrage.entity_graph.processor import processor_utils as PUtils
from vitrage.entity_graph.states.state_manager import StateManager
from vitrage.entity_graph.transformer_manager import TransformerManager
from vitrage.graph import Direction
@ -90,11 +91,10 @@ class Processor(processor.ProcessorBase):
LOG.debug('Update entity in entity graph:\n%s', updated_vertex)
graph_vertex = \
self.entity_graph.get_vertex(updated_vertex.vertex_id)
graph_vertex = self.entity_graph.get_vertex(updated_vertex.vertex_id)
if (not graph_vertex) or self.entity_graph.check_update_validation(
graph_vertex, updated_vertex):
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)
@ -116,11 +116,10 @@ class Processor(processor.ProcessorBase):
LOG.debug('Delete entity from entity graph:\n%s', deleted_vertex)
graph_vertex = \
self.entity_graph.get_vertex(deleted_vertex.vertex_id)
graph_vertex = self.entity_graph.get_vertex(deleted_vertex.vertex_id)
if (not graph_vertex) or self.entity_graph.check_update_validation(
graph_vertex, deleted_vertex):
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(
@ -192,8 +191,7 @@ class Processor(processor.ProcessorBase):
neighbors, valid_edges)
for (vertex, edge) in neighbors:
graph_vertex = self.entity_graph.get_vertex(vertex.vertex_id)
if not graph_vertex or \
not self.entity_graph.is_vertex_deleted(graph_vertex):
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)

View File

@ -0,0 +1,39 @@
# Copyright 2016 - Nokia
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from dateutil import parser
from vitrage.common.constants import EdgeProperties as EProps
from vitrage.common.constants import VertexProperties as VProps
from vitrage.graph import Edge
from vitrage.graph import Vertex
def is_newer_vertex(prev_vertex, new_vertex):
prev_timestamp = prev_vertex.get(VProps.SAMPLE_TIMESTAMP)
if not prev_timestamp:
return True
prev_time = parser.parse(prev_timestamp)
new_timestamp = new_vertex[VProps.SAMPLE_TIMESTAMP]
if not new_timestamp:
return False
new_time = parser.parse(new_timestamp)
return prev_time <= new_time
def is_deleted(item):
return item and \
(isinstance(item, Vertex) and item.get(VProps.IS_DELETED, False)) or\
(isinstance(item, Edge) and item.get(EProps.IS_DELETED, False))