示例#1
0
    def _create_vitrage_neighbors(self, event):
        event_type = event[EVALUATOR_EVENT_TYPE]

        timestamp = transformer_base.convert_timestamp_format(
            '%Y-%m-%d %H:%M:%S.%f', event[VProps.UPDATE_TIMESTAMP])

        if event_type in [ADD_EDGE, REMOVE_EDGE]:

            relation_edge = graph_utils.create_edge(
                source_id=event[TFields.SOURCE],
                target_id=event[TFields.TARGET],
                relationship_type=event[EProps.RELATIONSHIP_TYPE],
                update_timestamp=timestamp)

            return [Neighbor(None, relation_edge)]

        if event_type == ADD_VERTEX:
            result = []

            relation_edge = graph_utils.create_edge(
                source_id=TransformerBase.uuid_from_deprecated_vitrage_id(
                    self._create_entity_key(event)),
                target_id=event[TFields.TARGET],
                relationship_type=EdgeLabel.ON,
                update_timestamp=timestamp)

            neighbor_props = {
                VProps.VITRAGE_IS_PLACEHOLDER:
                True,
                VProps.UPDATE_TIMESTAMP:
                timestamp,
                VProps.VITRAGE_SAMPLE_TIMESTAMP:
                event[VProps.VITRAGE_SAMPLE_TIMESTAMP],
                VProps.IS_REAL_VITRAGE_ID:
                True,
                VProps.VITRAGE_TYPE:
                event.get(VProps.VITRAGE_RESOURCE_TYPE),
                VProps.VITRAGE_CATEGORY:
                EntityCategory.RESOURCE,
            }
            result.append(
                Neighbor(Vertex(event[TFields.TARGET], neighbor_props),
                         relation_edge))
            if event.get(TFields.CAUSING_ALARM):
                relation_edge = graph_utils.create_edge(
                    source_id=event[TFields.CAUSING_ALARM],
                    target_id=TransformerBase.uuid_from_deprecated_vitrage_id(
                        self._create_entity_key(event)),
                    relationship_type=EdgeLabel.CAUSES,
                    update_timestamp=timestamp)
                result.append(
                    Neighbor(
                        Vertex(
                            event[TFields.CAUSING_ALARM], {
                                VProps.UPDATE_TIMESTAMP: timestamp,
                                VProps.VITRAGE_IS_PLACEHOLDER: True,
                            }), relation_edge))
            return result

        return []
    def _create_neighbors(self, event):

        event_type = event[EVALUATOR_EVENT_TYPE]

        timestamp = transformer_base.convert_timestamp_format(
            '%Y-%m-%d %H:%M:%S.%f', event[VProps.UPDATE_TIMESTAMP])

        if event_type in [ADD_EDGE, REMOVE_EDGE]:

            relation_edge = graph_utils.create_edge(
                source_id=event[TFields.SOURCE],
                target_id=event[TFields.TARGET],
                relationship_type=event[EProps.RELATIONSHIP_TYPE],
                update_timestamp=timestamp)

            return [Neighbor(None, relation_edge)]

        if event_type == ADD_VERTEX:

            relation_edge = graph_utils.create_edge(
                source_id=self._create_entity_key(event),
                target_id=event[TFields.TARGET],
                relationship_type=EdgeLabels.ON,
                update_timestamp=timestamp)

            neighbor_props = {
                VProps.IS_PLACEHOLDER: True,
                VProps.UPDATE_TIMESTAMP: timestamp,
                VProps.SAMPLE_TIMESTAMP: event[VProps.SAMPLE_TIMESTAMP]
            }
            neighbor = Vertex(event[TFields.TARGET], neighbor_props)
            return [Neighbor(neighbor, relation_edge)]

        return []
示例#3
0
    def test_delete_relationship(self):
        # setup
        vertex1, neighbors1, processor = self._create_entity(
            spec_type=self.INSTANCE_SPEC,
            datasource_action=DSAction.INIT_SNAPSHOT)
        vertex2, neighbors2, processor = self._create_entity(
            spec_type=self.INSTANCE_SPEC,
            datasource_action=DSAction.INIT_SNAPSHOT,
            processor=processor)
        self.assertEqual(2, processor.entity_graph.num_edges())

        new_edge = graph_utils.create_edge(vertex1.vertex_id,
                                           vertex2.vertex_id,
                                           'backup')
        processor.entity_graph.add_edge(new_edge)
        self.assertEqual(3, processor.entity_graph.num_edges())
        new_neighbors = [Neighbor(vertex1, new_edge)]

        # action
        processor.delete_relationship(vertex2, new_neighbors)

        # test assertions
        edge_from_graph = processor.entity_graph.get_edge(vertex1.vertex_id,
                                                          vertex2.vertex_id,
                                                          'backup')
        self.assertEqual(3, processor.entity_graph.num_edges())
        self.assertTrue(edge_from_graph[EProps.VITRAGE_IS_DELETED])
示例#4
0
    def test_update_relationship(self):
        # setup
        vertex1, neighbors1, processor = self._create_entity(
            spec_type=self.INSTANCE_SPEC,
            datasource_action=DSAction.INIT_SNAPSHOT)
        vertex2, neighbors2, processor = self._create_entity(
            spec_type=self.INSTANCE_SPEC,
            datasource_action=DSAction.INIT_SNAPSHOT,
            processor=processor)
        self.assertEqual(2, processor.entity_graph.num_edges())

        new_edge = graph_utils.create_edge(vertex1.vertex_id,
                                           vertex2.vertex_id,
                                           'backup')
        mock_neighbor = graph_utils.create_vertex(
            "asdjashdkahsdashdalksjhd",
            vitrage_category="RESOURCE",
            vitrage_type="nova.instance",
            entity_id="wtw64768476",
            entity_state="AVAILABLE",
        )
        new_neighbors = [Neighbor(mock_neighbor, new_edge)]

        # action
        processor.update_relationship(vertex1, new_neighbors)

        # test assertions
        self.assertEqual(3, processor.entity_graph.num_edges())
示例#5
0
    def _create_neighbor(self,
                         entity_event,
                         neighbor):
        datasource_type = \
            self.RESOURCE_TYPE_CONVERSION[neighbor['resource_type']]
        transformer = self.transformers.get(datasource_type, None)

        stack_vitrage_id = self._create_entity_key(entity_event)

        neighbor_id = neighbor['physical_resource_id']

        sample_timestamp = entity_event[DSProps.SAMPLE_DATE]

        properties = {
            VProps.ID: neighbor_id,
            VProps.TYPE: datasource_type,
            VProps.SAMPLE_TIMESTAMP: sample_timestamp
        }
        instance_vertex = transformer.create_placeholder_vertex(**properties)

        relationship_edge = graph_utils.create_edge(
            source_id=stack_vitrage_id,
            target_id=instance_vertex.vertex_id,
            relationship_type=EdgeLabel.COMPRISED)

        return Neighbor(instance_vertex, relationship_edge)
示例#6
0
    def _create_neighbor(self, neighbor_details, entity_type, entity_key,
                         sample_timestamp):
        neighbor_type = neighbor_details[VProps.TYPE]
        entity_transformer = self.transformers[neighbor_type]

        if entity_transformer:
            neighbor_id = neighbor_details[VProps.ID]
            relation_type = neighbor_details[self.RELATION_TYPE]
            is_source = self._find_relation_direction_source(
                entity_type, neighbor_type)

            properties = {
                VProps.TYPE: neighbor_type,
                VProps.ID: neighbor_id,
                VProps.SAMPLE_TIMESTAMP: sample_timestamp
            }
            neighbor = entity_transformer.create_placeholder_vertex(
                **properties)

            relation_edge = graph_utils.create_edge(
                source_id=neighbor.vertex_id if is_source else entity_key,
                target_id=entity_key if is_source else neighbor.vertex_id,
                relationship_type=relation_type)

            return Neighbor(neighbor, relation_edge)
        else:
            LOG.warning('Cannot find zone transformer')
            return None
示例#7
0
    def _create_zone_neighbor(self,
                              entity_event,
                              sample_timestamp,
                              host_vertex_id,
                              zone_name_path):

        zone_transformer = self.transformers[NOVA_ZONE_DATASOURCE]

        if zone_transformer:

            zone_name = extract_field_value(entity_event, zone_name_path)

            properties = {
                VProps.ID: zone_name,
                VProps.TYPE: NOVA_ZONE_DATASOURCE,
                VProps.SAMPLE_TIMESTAMP: sample_timestamp
            }
            zone_neighbor = zone_transformer.create_placeholder_vertex(
                **properties)

            relation_edge = graph_utils.create_edge(
                source_id=zone_neighbor.vertex_id,
                target_id=host_vertex_id,
                relationship_type=EdgeLabel.CONTAINS)
            return Neighbor(zone_neighbor, relation_edge)
        else:
            LOG.warning('Cannot find zone transformer')

        return None
示例#8
0
    def _create_neighbor(self,
                         vitrage_id,
                         sample_timestamp,
                         resource_type,
                         resource_name):
        transformer = self.transformers[resource_type]

        if transformer:
            properties = {
                VProps.TYPE: resource_type,
                VProps.ID: resource_name,
                VProps.SAMPLE_TIMESTAMP: sample_timestamp
            }
            resource_vertex = transformer.create_placeholder_vertex(
                **properties)

            relationship_edge = graph_utils.create_edge(
                source_id=vitrage_id,
                target_id=resource_vertex.vertex_id,
                relationship_type=EdgeLabel.ON)

            return Neighbor(resource_vertex, relationship_edge)

        LOG.warning('Cannot transform host, host transformer does not exist')
        return None
示例#9
0
 def _create_aodh_neighbors(self, entity_event):
     graph_neighbors = entity_event.get(self.QUERY_RESULT, [])
     result = []
     for vertex in graph_neighbors:
         edge = graph_utils.create_edge(
             source_id=self._create_entity_key(entity_event),
             target_id=vertex.vertex_id,
             relationship_type=EdgeLabel.ON)
         result.append(Neighbor(vertex, edge))
     return result
示例#10
0
    def _create_host_neighbor(vertex_id, host_name, sample_timestamp,
                              host_transformer):
        properties = {
            VProps.ID: host_name,
            VProps.TYPE: NOVA_HOST_DATASOURCE,
            VProps.SAMPLE_TIMESTAMP: sample_timestamp
        }
        host_vertex = host_transformer.create_placeholder_vertex(**properties)

        relationship_edge = graph_utils.create_edge(
            source_id=host_vertex.vertex_id,
            target_id=vertex_id,
            relationship_type=EdgeLabel.CONTAINS)

        return Neighbor(host_vertex, relationship_edge)
示例#11
0
    def test_update_relationship(self):
        # setup
        vertex1, neighbors1, processor = self._create_entity(
            spec_type=self.INSTANCE_SPEC, sync_mode=SyncMode.INIT_SNAPSHOT)
        vertex2, neighbors2, processor = self._create_entity(
            spec_type=self.INSTANCE_SPEC,
            sync_mode=SyncMode.INIT_SNAPSHOT,
            processor=processor)
        self.assertEqual(2, processor.entity_graph.num_edges())

        new_edge = graph_utils.create_edge(vertex1.vertex_id,
                                           vertex2.vertex_id, 'backup')
        new_neighbors = [Neighbor(None, new_edge)]

        # action
        processor.update_relationship(None, new_neighbors)

        # test assertions
        self.assertEqual(3, processor.entity_graph.num_edges())
示例#12
0
    def _create_instance_neighbor(self, entity_event, instance_id_property):
        port_vitrage_id = self._create_entity_key(entity_event)

        instance_id = entity_event[instance_id_property]

        sample_timestamp = entity_event[DSProps.SAMPLE_DATE]

        properties = {
            VProps.ID: instance_id,
            VProps.TYPE: NOVA_INSTANCE_DATASOURCE,
            VProps.SAMPLE_TIMESTAMP: sample_timestamp
        }
        instance_vertex = self.create_placeholder_vertex(**properties)

        relationship_edge = graph_utils.create_edge(
            source_id=port_vitrage_id,
            target_id=instance_vertex.vertex_id,
            relationship_type=EdgeLabel.ATTACHED)

        return Neighbor(instance_vertex, relationship_edge)
示例#13
0
    def _create_net_neighbor(self, entity_event, net_id_property):
        port_vitrage_id = self._create_entity_key(entity_event)

        net_id = entity_event[net_id_property]

        sample_timestamp = entity_event[DSProps.SAMPLE_DATE]

        properties = {
            VProps.ID: net_id,
            VProps.TYPE: NEUTRON_NETWORK_DATASOURCE,
            VProps.SAMPLE_TIMESTAMP: sample_timestamp
        }

        net_vertex = self.create_placeholder_vertex(**properties)

        relationship_edge = graph_utils.create_edge(
            source_id=net_vertex.vertex_id,
            target_id=port_vitrage_id,
            relationship_type=EdgeLabel.CONTAINS)

        return Neighbor(net_vertex, relationship_edge)