Example #1
0
 def __init__(self, conf, e_graph=None):
     super(Processor, self).__init__()
     self.conf = conf
     self.transformer_manager = TransformerManager(self.conf)
     self.info_mapper = DatasourceInfoMapper(self.conf)
     self._initialize_events_actions()
     self.entity_graph = e_graph
    def test_aggregated_state(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)
        metadata1 = {VProps.VITRAGE_STATE: 'SUSPENDED'}
        new_vertex1 = create_vertex('12345',
                                    entity_state='ACTIVE',
                                    entity_category=EntityCategory.RESOURCE,
                                    entity_type=NOVA_INSTANCE_DATASOURCE,
                                    metadata=metadata1)
        metadata2 = {VProps.VITRAGE_STATE: 'ACTIVE'}
        new_vertex2 = create_vertex('23456',
                                    entity_state='SUSPENDED',
                                    entity_category=EntityCategory.RESOURCE,
                                    entity_type=NOVA_INSTANCE_DATASOURCE,
                                    metadata=metadata2)

        # action
        state_manager.aggregated_state(new_vertex1, None)
        state_manager.aggregated_state(new_vertex2, None)

        # test assertions
        self.assertEqual('SUSPENDED', new_vertex1[VProps.AGGREGATED_STATE])
        self.assertEqual(OperationalResourceState.SUBOPTIMAL,
                         new_vertex1[VProps.OPERATIONAL_STATE])
        self.assertEqual('SUSPENDED', new_vertex2[VProps.AGGREGATED_STATE])
        self.assertEqual(OperationalResourceState.SUBOPTIMAL,
                         new_vertex2[VProps.OPERATIONAL_STATE])
Example #3
0
    def test_vitrage_aggregated_value(self):
        # setup
        info_mapper = DatasourceInfoMapper(self.conf)
        metadata1 = {VProps.VITRAGE_STATE: 'SUSPENDED'}
        new_vertex1 = create_vertex('12345',
                                    vitrage_category=EntityCategory.RESOURCE,
                                    vitrage_type=NOVA_INSTANCE_DATASOURCE,
                                    entity_state='ACTIVE',
                                    metadata=metadata1)
        metadata2 = {VProps.VITRAGE_STATE: 'ACTIVE'}
        new_vertex2 = create_vertex('23456',
                                    vitrage_category=EntityCategory.RESOURCE,
                                    vitrage_type=NOVA_INSTANCE_DATASOURCE,
                                    entity_state='SUSPENDED',
                                    metadata=metadata2)

        # action
        info_mapper.vitrage_aggregate_values(new_vertex1, None)
        info_mapper.vitrage_aggregate_values(new_vertex2, None)

        # test assertions
        self.assertEqual('SUSPENDED',
                         new_vertex1[VProps.VITRAGE_AGGREGATED_STATE])
        self.assertEqual(OperationalResourceState.SUBOPTIMAL,
                         new_vertex1[VProps.VITRAGE_OPERATIONAL_STATE])
        self.assertEqual('SUSPENDED',
                         new_vertex2[VProps.VITRAGE_AGGREGATED_STATE])
        self.assertEqual(OperationalResourceState.SUBOPTIMAL,
                         new_vertex2[VProps.VITRAGE_OPERATIONAL_STATE])
Example #4
0
 def __init__(self, conf, initialization_status, e_graph):
     super(Processor, self).__init__()
     self.conf = conf
     self.transformer_manager = TransformerManager(self.conf)
     self.state_manager = DatasourceInfoMapper(self.conf)
     self._initialize_events_actions()
     self.initialization_status = initialization_status
     self.entity_graph = e_graph
     self._notifier = GraphNotifier(conf)
Example #5
0
 def __init__(self, conf, initialization_status, e_graph=None):
     super(Processor, self).__init__()
     self.conf = conf
     self.transformer_manager = TransformerManager(self.conf)
     self.state_manager = DatasourceInfoMapper(self.conf)
     self._initialize_events_actions()
     self.initialization_status = initialization_status
     self.entity_graph = entity_graph.EntityGraph("Entity Graph") if \
         e_graph is None else e_graph
     self._notifier = DeducedAlarmNotifier(conf)
Example #6
0
    def test_value_priority(self):
        # setup
        info_mapper = DatasourceInfoMapper(self.conf)

        # action
        value_priority = \
            info_mapper.value_priority(NOVA_INSTANCE_DATASOURCE, 'ACTIVE')

        # test assertions
        self.assertEqual(10, value_priority)
Example #7
0
 def __init__(self, conf, initialization_status, e_graph=None, uuid=False):
     super(Processor, self).__init__()
     self.conf = conf
     self.transformer_manager = TransformerManager(self.conf)
     self.state_manager = DatasourceInfoMapper(self.conf)
     self._initialize_events_actions()
     self.initialization_status = initialization_status
     self.entity_graph = e_graph if e_graph is not None\
         else NXGraph("Entity Graph", uuid=uuid)
     self._notifier = GraphNotifier(conf)
    def test_operational_state_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        operational_state = \
            state_manager.operational_state(NOVA_INSTANCE_DATASOURCE,
                                            'BUILDING')

        # test assertions
        self.assertEqual(OperationalResourceState.TRANSIENT, operational_state)
    def test_operational_state_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        operational_state = \
            state_manager.operational_state(NOVA_INSTANCE_DATASOURCE,
                                            'NON EXISTING STATE')

        # test assertions
        self.assertEqual(OperationalResourceState.NA, operational_state)
    def test_state_priority_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        state_priority = \
            state_manager.state_priority(NOVA_INSTANCE_DATASOURCE,
                                         'NON EXISTING STATE')

        # test assertions
        self.assertEqual(0, state_priority)
Example #11
0
    def test_value_priority_not_exists(self):
        # setup
        info_mapper = DatasourceInfoMapper(self.conf)

        # action
        value_priority = \
            info_mapper.value_priority(NOVA_INSTANCE_DATASOURCE,
                                       'NON EXISTING STATE')

        # test assertions
        self.assertEqual(0, value_priority)
    def test_state_priority(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        state_priority = \
            state_manager.state_priority(NOVA_INSTANCE_DATASOURCE,
                                         'ACTIVE')

        # test assertions
        self.assertEqual(10, state_priority)
    def test_operational_state_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        operational_state = \
            state_manager.operational_state(NOVA_INSTANCE_DATASOURCE,
                                            'NON EXISTING STATE')

        # test assertions
        self.assertEqual(OperationalResourceState.NA, operational_state)
    def test_operational_state_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        operational_state = \
            state_manager.operational_state(NOVA_INSTANCE_DATASOURCE,
                                            'BUILDING')

        # test assertions
        self.assertEqual(OperationalResourceState.TRANSIENT, operational_state)
    def test_state_priority(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        state_priority = \
            state_manager.state_priority(NOVA_INSTANCE_DATASOURCE,
                                         'ACTIVE')

        # test assertions
        self.assertEqual(10, state_priority)
    def test_state_priority_datasource_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        state_priority = \
            state_manager.state_priority('NON EXISTING DATASOURCE',
                                         'ACTIVE')

        # test assertions
        self.assertEqual(10, state_priority)
    def test_state_priority_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        state_priority = \
            state_manager.state_priority(NOVA_INSTANCE_DATASOURCE,
                                         'NON EXISTING STATE')

        # test assertions
        self.assertEqual(0, state_priority)
Example #18
0
    def test_value_priority_datasource_not_exists(self):
        # setup
        info_mapper = DatasourceInfoMapper(self.conf)

        # action
        value_priority = \
            info_mapper.value_priority('NON EXISTING DATASOURCE',
                                       'ACTIVE')

        # test assertions
        self.assertEqual(10, value_priority)
Example #19
0
    def test_operational_state_datasource_not_exists_and_state_exist(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        operational_state = \
            state_manager.operational_state('NON EXISTING DATASOURCE',
                                            'AVAILABLE')

        # test assertions
        self.assertEqual(OperationalResourceState.OK,
                         operational_state)
    def test_operational_state_datasource_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        operational_state = \
            state_manager.operational_state('NON EXISTING DATASOURCE',
                                            'BUILDING')

        # test assertions
        self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
                         operational_state)
Example #21
0
 def __init__(self, conf, db_connection):
     info_mapper = DatasourceInfoMapper(conf)
     self._db = db_connection
     alarms_score = info_mapper.get_datasource_priorities('vitrage')
     all_scores = info_mapper.get_datasource_priorities()
     self._action_tools = {
         ActionType.SET_STATE: pt.SetStateTools(all_scores),
         ActionType.RAISE_ALARM: pt.RaiseAlarmTools(alarms_score),
         ActionType.ADD_CAUSAL_RELATIONSHIP: pt.BaselineTools,
         ActionType.MARK_DOWN: pt.BaselineTools,
         ActionType.EXECUTE_MISTRAL: pt.BaselineTools
     }
    def test_state_priority_datasource_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        state_priority = \
            state_manager.state_priority('NON EXISTING DATASOURCE',
                                         'ACTIVE')

        # test assertions
        self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
                         state_priority)
Example #23
0
    def test_vitrage_operational_value_DS_not_exists_and_value_exist(self):
        # setup
        info_mapper = DatasourceInfoMapper(self.conf)

        # action
        vitrage_operational_value = \
            info_mapper.vitrage_operational_value('NON EXISTING DATASOURCE',
                                                  'AVAILABLE')

        # test assertions
        self.assertEqual(OperationalResourceState.OK,
                         vitrage_operational_value)
Example #24
0
    def test_vitrage_operational_value_not_exists(self):
        # setup
        info_mapper = DatasourceInfoMapper(self.conf)

        # action
        vitrage_operational_value = \
            info_mapper.vitrage_operational_value(NOVA_INSTANCE_DATASOURCE,
                                                  'NON EXISTING STATE')

        # test assertions
        self.assertEqual(OperationalResourceState.NA,
                         vitrage_operational_value)
    def test_vitrage_operational_state_DS_not_exists_and_state_not_exist(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        vitrage_operational_state = \
            state_manager.vitrage_operational_state('NON EXISTING DATASOURCE',
                                                    'BUILDING')

        # test assertions
        self.assertEqual(OperationalResourceState.NA,
                         vitrage_operational_state)
    def test_operational_state_datasource_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)

        # action
        operational_state = \
            state_manager.operational_state('NON EXISTING DATASOURCE',
                                            'BUILDING')

        # test assertions
        self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
                         operational_state)
Example #27
0
    def test_vitrage_operational_value_exists(self):
        # setup
        info_mapper = DatasourceInfoMapper(self.conf)

        # action
        vitrage_operational_value = \
            info_mapper.vitrage_operational_value(NOVA_INSTANCE_DATASOURCE,
                                                  'BUILDING')

        # test assertions
        self.assertEqual(OperationalResourceState.TRANSIENT,
                         vitrage_operational_value)
Example #28
0
 def _init_action_tools(cls, conf):
     if cls.action_tools:
         return
     info_mapper = DatasourceInfoMapper(conf)
     alarms_score = info_mapper.get_datasource_priorities('vitrage')
     all_scores = info_mapper.get_datasource_priorities()
     cls.action_tools = {
         ActionType.SET_STATE: pt.SetStateTools(all_scores),
         ActionType.RAISE_ALARM: pt.RaiseAlarmTools(alarms_score),
         ActionType.ADD_CAUSAL_RELATIONSHIP: pt.BaselineTools,
         ActionType.MARK_DOWN: pt.BaselineTools,
         ActionType.EXECUTE_MISTRAL: pt.BaselineTools
     }
Example #29
0
    def test_vitrage_aggregated_value_datasource_not_exists(self):
        # setup
        info_mapper = DatasourceInfoMapper(self.conf)
        metadata = {VProps.VITRAGE_STATE: 'SUSPENDED'}
        new_vertex = create_vertex('12345',
                                   vitrage_category=EntityCategory.RESOURCE,
                                   vitrage_type='NON EXISTING DATASOURCE',
                                   entity_state='ACTIVE',
                                   metadata=metadata)

        # action
        info_mapper.vitrage_aggregate_values(new_vertex, None)

        # test assertions
        self.assertEqual('ACTIVE', new_vertex[VProps.VITRAGE_AGGREGATED_STATE])
        self.assertEqual(OperationalResourceState.OK,
                         new_vertex[VProps.VITRAGE_OPERATIONAL_STATE])
    def test_aggregated_state_datasource_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)
        metadata = {VProps.VITRAGE_STATE: 'SUSPENDED'}
        new_vertex = create_vertex('12345',
                                   entity_state='ACTIVE',
                                   entity_category=EntityCategory.RESOURCE,
                                   entity_type='NON EXISTING DATASOURCE',
                                   metadata=metadata)

        # action
        state_manager.aggregated_state(new_vertex, None)

        # test assertions
        self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
                         new_vertex[VProps.AGGREGATED_STATE])
        self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
                         new_vertex[VProps.OPERATIONAL_STATE])
    def test_aggregated_state_datasource_not_exists(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)
        metadata = {VProps.VITRAGE_STATE: 'SUSPENDED'}
        new_vertex = create_vertex('12345',
                                   entity_state='ACTIVE',
                                   entity_category=EntityCategory.RESOURCE,
                                   entity_type='NON EXISTING DATASOURCE',
                                   metadata=metadata)

        # action
        state_manager.aggregated_state(new_vertex, None)

        # test assertions
        self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
                         new_vertex[VProps.AGGREGATED_STATE])
        self.assertEqual(DatasourceInfoMapper.UNDEFINED_DATASOURCE,
                         new_vertex[VProps.OPERATIONAL_STATE])
    def test_load_datasource_state_without_errors(self):
        # action
        state_manager = DatasourceInfoMapper(self.conf)

        # test assertions

        # Total datasources plus the evaluator which is not definable
        total_datasources = len(self.conf.datasources.types) + 1
        self.assertEqual(total_datasources,
                         len(state_manager.datasources_state_confs))
Example #33
0
 def __init__(self, conf, initialization_status, e_graph=None):
     super(Processor, self).__init__()
     self.conf = conf
     self.transformer_manager = TransformerManager(self.conf)
     self.state_manager = DatasourceInfoMapper(self.conf)
     self._initialize_events_actions()
     self.initialization_status = initialization_status
     self.entity_graph = entity_graph.EntityGraph("Entity Graph") if \
         e_graph is None else e_graph
     self._notifier = GraphNotifier(conf)
Example #34
0
    def test_load_datasource_value_without_errors(self):
        # action
        info_mapper = DatasourceInfoMapper(self.conf)

        # test assertions

        # Total datasources plus the evaluator which is not definable
        total_datasources = len(self.conf.datasources.types) + 1
        self.assertThat(info_mapper.datasources_value_confs,
                        matchers.HasLength(total_datasources))
Example #35
0
 def __init__(self,
              conf,
              entity_graph,
              scenario_repo,
              event_queue,
              enabled=False):
     self.conf = conf
     self._scenario_repo = scenario_repo
     self._entity_graph = entity_graph
     self._action_executor = ActionExecutor(event_queue)
     self._entity_graph.subscribe(self.process_event)
     self._action_tracker = ActionTracker(DatasourceInfoMapper(self.conf))
     self.enabled = enabled
     self.connected_component_cache = defaultdict(dict)
Example #36
0
 def __init__(self,
              conf,
              entity_graph,
              scenario_repo,
              event_queue,
              enabled=False):
     self.conf = conf
     self._scenario_repo = scenario_repo
     self._entity_graph = entity_graph
     self._graph_algs = create_algorithm(entity_graph)
     self._action_executor = ActionExecutor(event_queue)
     self._entity_graph.subscribe(self.process_event)
     self._action_tracker = ActionTracker(DatasourceInfoMapper(self.conf))
     self.enabled = enabled
Example #37
0
    def test_load_datasources_value_with_errors(self):
        # setup
        self.cfg_fixture.config(
            group='entity_graph',
            datasources_values_dir=utils.get_resources_dir() +
            '/datasources_values/erroneous_values')
        self._load_datasources()

        # action
        info_mapper = DatasourceInfoMapper()

        # test assertions
        missing_values = 1
        erroneous_values = 1
        num_valid_datasources = len(info_mapper.datasources_value_confs) + \
            missing_values + erroneous_values
        self.assertThat(self.conf.datasources.types,
                        matchers.HasLength(num_valid_datasources))
Example #38
0
    def test_aggregated_state_functionalities(self):
        # setup
        state_manager = DatasourceInfoMapper(self.conf)
        new_vertex1 = create_vertex('12345',
                                    entity_state='ACTIVE',
                                    entity_category=EntityCategory.RESOURCE,
                                    entity_type=NOVA_INSTANCE_DATASOURCE)
        metadata2 = {VProps.VITRAGE_STATE: 'SUBOPTIMAL'}
        new_vertex2 = create_vertex('23456',
                                    entity_category=EntityCategory.RESOURCE,
                                    entity_type=NOVA_INSTANCE_DATASOURCE,
                                    metadata=metadata2)
        metadata3 = {VProps.VITRAGE_STATE: 'SUBOPTIMAL'}
        new_vertex3 = create_vertex('34567',
                                    entity_state='ACTIVE',
                                    entity_category=EntityCategory.RESOURCE,
                                    entity_type=NOVA_INSTANCE_DATASOURCE)
        graph_vertex3 = create_vertex('34567',
                                      entity_state='SUSPENDED',
                                      entity_category=EntityCategory.RESOURCE,
                                      entity_type=NOVA_INSTANCE_DATASOURCE,
                                      metadata=metadata3)

        # action
        state_manager.aggregated_state(new_vertex1,
                                       None)
        state_manager.aggregated_state(new_vertex2,
                                       None)
        state_manager.aggregated_state(new_vertex3,
                                       graph_vertex3)

        # test assertions
        self.assertEqual('ACTIVE', new_vertex1[VProps.AGGREGATED_STATE])
        self.assertEqual(OperationalResourceState.OK,
                         new_vertex1[VProps.OPERATIONAL_STATE])
        self.assertEqual('SUBOPTIMAL', new_vertex2[VProps.AGGREGATED_STATE])
        self.assertEqual(OperationalResourceState.SUBOPTIMAL,
                         new_vertex2[VProps.OPERATIONAL_STATE])
        self.assertEqual('SUBOPTIMAL', new_vertex3[VProps.AGGREGATED_STATE])
        self.assertEqual(OperationalResourceState.SUBOPTIMAL,
                         new_vertex3[VProps.OPERATIONAL_STATE])
    def test_load_datasources_state_with_errors(self):
        # setup
        entity_graph_opts = [
            cfg.StrOpt('datasources_values_dir',
                       default=utils.get_resources_dir() +
                       '/datasources_values/erroneous_values'),
        ]
        conf = cfg.ConfigOpts()
        conf.register_opts(entity_graph_opts, group='entity_graph')
        conf.register_opts(self.DATASOURCES_OPTS, group='datasources')
        self._load_datasources(conf)

        # action
        state_manager = DatasourceInfoMapper(conf)

        # test assertions
        missing_states = 1
        erroneous_values = 1
        num_valid_datasources = len(state_manager.datasources_state_confs) + \
            missing_states + erroneous_values
        self.assertEqual(num_valid_datasources, len(conf.datasources.types))
Example #40
0
class Processor(processor.ProcessorBase):

    def __init__(self, conf, initialization_status, e_graph=None):
        super(Processor, self).__init__()
        self.conf = conf
        self.transformer_manager = TransformerManager(self.conf)
        self.state_manager = DatasourceInfoMapper(self.conf)
        self._initialize_events_actions()
        self.initialization_status = initialization_status
        self.entity_graph = entity_graph.EntityGraph("Entity Graph") if \
            e_graph is None else e_graph
        self._notifier = GraphNotifier(conf)

    def process_event(self, event):
        """Decides which action to run on given event

        Transforms the event into a tuple (vertex, neighbors,action).
        After transforming, it runs the correct action according to the
        action received from the transformer.

        :param event: The event to be processed
        :type event: Dictionary
        """

        LOG.debug('processor event:\n%s', event)

        self._enrich_event(event)
        entity = self.transformer_manager.transform(event)
        self._calculate_aggregated_state(entity.vertex, entity.action)
        self.actions[entity.action](entity.vertex, entity.neighbors)

    def create_entity(self, new_vertex, neighbors):
        """Adds new vertex to the entity graph

        Adds the entity to the entity graph, and connects it's neighbors

        :param new_vertex: The new vertex to add to graph
        :type new_vertex: Vertex

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

        LOG.debug('Add entity to entity graph:\n%s', new_vertex)
        self.entity_graph.add_vertex(new_vertex)
        self._connect_neighbors(neighbors, [], GraphAction.CREATE_ENTITY)

    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 update_relationship(self, entity_vertex, neighbors):
        LOG.debug('Update relationship in entity graph:\n%s', neighbors)

        for neighbor in neighbors:
            # TODO(Alexey): maybe to check if the vertices exists
            if entity_vertex is not None:
                self.entity_graph.update_vertex(entity_vertex)
            self.entity_graph.update_edge(neighbor.edge)

    def delete_relationship(self, updated_vertex, neighbors):
        LOG.debug('Delete relationship from entity graph:\n%s', neighbors)

        for neighbor in neighbors:
            graph_edge = self.entity_graph.get_edge(neighbor.edge.source_id,
                                                    neighbor.edge.target_id,
                                                    neighbor.edge.label)
            if updated_vertex is not None:
                self.entity_graph.update_vertex(updated_vertex)
            if graph_edge:
                self.entity_graph.remove_edge(graph_edge)

    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)

    def handle_end_message(self, vertex, neighbors):
        self.initialization_status.end_messages[vertex[VProps.TYPE]] = True

        if len(self.initialization_status.end_messages) == \
                len(self.conf.datasources.types):
            self.initialization_status.status = \
                self.initialization_status.RECEIVED_ALL_END_MESSAGES
            self.do_on_initialization_end()

    def do_on_initialization_end(self):
        if self._notifier.enabled:
            self.entity_graph.subscribe(self._notifier.notify_when_applicable)
            LOG.info('Graph notifications subscription added')

    def _update_neighbors(self, vertex, neighbors):
        """Updates vertices neighbor connections

        1. Removes old neighbor connections
        2. connects the new neighbors.
        """

        (valid_edges, obsolete_edges) = self._find_edges_status(
            vertex, neighbors)
        self._delete_old_connections(vertex, obsolete_edges)
        self._connect_neighbors(neighbors,
                                valid_edges,
                                GraphAction.UPDATE_ENTITY)

    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)

    def _delete_old_connections(self, vertex, obsolete_edges):
        """Deletes the "vertex" old connections

        Finds the old connections that are connected to updated_vertex,
        and marks them as deleted
        """
        if not obsolete_edges:
            LOG.debug('obsolete_edges - nothing to do')
            return

        LOG.debug('Delete old connections. Vertex:\n%s', vertex)
        # remove old edges and placeholder vertices if exist
        for edge in obsolete_edges:
            LOG.debug("Delete obsolete edge:\n%s", edge)
            self.entity_graph.mark_edge_as_deleted(edge)
            graph_ver = self.entity_graph.get_vertex(
                edge.other_vertex(vertex.vertex_id))
            self.entity_graph.delete_placeholder_vertex(graph_ver)

    def _find_edges_status(self, vertex, neighbors):
        """Finds "vertex" valid and old connections

        Checks all the edges that are connected to the vertex in the entity
        graph, and finds which of them are old connections (edges that are no
        longer connected to those entities), and which are valid connections.
        """

        valid_edges = []
        obsolete_edges = []

        graph_neighbor_types = \
            self.entity_graph.find_neighbor_types(neighbors)

        for curr_edge in self.entity_graph.get_edges(
                vertex.vertex_id,
                direction=Direction.BOTH):
            # check if the edge in the graph has a a connection to the
            # same type of resources in the new neighbors list
            neighbor_vertex = self.entity_graph.get_vertex(
                curr_edge.other_vertex(vertex.vertex_id))

            is_connection_type_exist = self.entity_graph.get_vertex_category(
                neighbor_vertex) in graph_neighbor_types

            if not is_connection_type_exist:
                valid_edges.append(curr_edge)
                continue

            neighbor_edges = [e for v, e in neighbors]
            if curr_edge in neighbor_edges:
                valid_edges.append(curr_edge)
            else:
                obsolete_edges.append(curr_edge)

        return valid_edges, obsolete_edges

    def _initialize_events_actions(self):
        self.actions = {
            GraphAction.CREATE_ENTITY: self.create_entity,
            GraphAction.UPDATE_ENTITY: self.update_entity,
            GraphAction.DELETE_ENTITY: self.delete_entity,
            GraphAction.UPDATE_RELATIONSHIP: self.update_relationship,
            GraphAction.DELETE_RELATIONSHIP: self.delete_relationship,
            GraphAction.REMOVE_DELETED_ENTITY: self.remove_deleted_entity,
            # should not be called explicitly
            GraphAction.END_MESSAGE: self.handle_end_message
        }

    def _calculate_aggregated_state(self, vertex, action):
        LOG.debug("calculate event state")

        try:
            if action in [GraphAction.UPDATE_ENTITY,
                          GraphAction.DELETE_ENTITY,
                          GraphAction.CREATE_ENTITY]:
                graph_vertex = self.entity_graph.get_vertex(vertex.vertex_id)
            elif action in [GraphAction.END_MESSAGE,
                            GraphAction.REMOVE_DELETED_ENTITY,
                            GraphAction.UPDATE_RELATIONSHIP,
                            GraphAction.DELETE_RELATIONSHIP]:
                return None
            else:
                LOG.error('unrecognized action: %s for vertex: %s',
                          action, vertex)
                return None

            self.state_manager.aggregated_state(vertex, graph_vertex)
        except Exception as e:
            LOG.exception("Calculate aggregated state failed - %s", e)

    def _enrich_event(self, event):
        attr = self.transformer_manager.get_enrich_query(event)
        if attr is None:
            return
        result = self.entity_graph.get_vertices(attr)
        event[TransformerBase.QUERY_RESULT] = result