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:

            relation_edge = graph_utils.create_edge(
                source_id=self._create_entity_key(event),
                target_id=event[TFields.TARGET],
                relationship_type=EdgeLabel.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 []
예제 #2
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 []
예제 #4
0
    def _add_alarms(self):
        # find hosts and instances
        host_vertices = self.processor.entity_graph.get_vertices({
            VProps.VITRAGE_CATEGORY: EntityCategory.RESOURCE,
            VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE
        })

        # add host alarms + deduced alarms
        self.evaluator.enabled = True
        alarms_on_hosts_list = []
        for index, host_vertex in enumerate(host_vertices):
            alarm_name = '%s:%s' % ('nagios_alarm_on_host_',
                                    host_vertex[VProps.NAME])
            alarms_on_hosts_list.append(
                self._create_alarm(alarm_name, NAGIOS_DATASOURCE))
            self.processor.entity_graph.add_vertex(alarms_on_hosts_list[index])
            edge = graph_utils.create_edge(
                alarms_on_hosts_list[index].vertex_id,
                host_vertex.vertex_id,
                EdgeLabel.ON)
            self.processor.entity_graph.add_edge(edge)

            # reliable action to check that the events in the queue
            while self.event_queue.empty():
                time.sleep(0.1)

            while not self.event_queue.empty():
                self.processor.process_event(self.event_queue.get())

        # remove external alarms
        self.evaluator.enabled = False
        self.processor.entity_graph.remove_vertex(alarms_on_hosts_list[2])
        self.processor.entity_graph.remove_vertex(alarms_on_hosts_list[3])
        self.evaluator.enabled = True
예제 #5
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
예제 #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_neighbor(self,
                         entity_event,
                         neighbor_id,
                         neighbor_datasource_type,
                         relationship_type,
                         neighbor_category=EntityCategory.RESOURCE,
                         is_entity_source=True,
                         metadata=None):
        metadata = {} if metadata is None else metadata
        # create placeholder vertex
        entity_vitrage_id = \
            self.uuid_from_deprecated_vitrage_id(
                self._create_entity_key(entity_event))
        vitrage_sample_timestamp = entity_event[DSProps.SAMPLE_DATE]
        properties = {
            VProps.ID: neighbor_id,
            VProps.VITRAGE_TYPE: neighbor_datasource_type,
            VProps.VITRAGE_CATEGORY: neighbor_category,
            VProps.VITRAGE_SAMPLE_TIMESTAMP: vitrage_sample_timestamp,
            self.METADATA: metadata
        }
        neighbor_vertex = \
            self.create_neighbor_placeholder_vertex(**properties)
        # connect placeholder vertex to entity vertex
        edge_direction = self._get_edge_direction(entity_vitrage_id,
                                                  neighbor_vertex.vertex_id,
                                                  is_entity_source)
        relationship_edge = graph_utils.create_edge(
            source_id=edge_direction[0],
            target_id=edge_direction[1],
            relationship_type=relationship_type)

        return Neighbor(neighbor_vertex, relationship_edge)
예제 #8
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
예제 #9
0
    def _add_alarms(self):
        # find hosts and instances
        host_vertices = self.processor.entity_graph.get_vertices({
            VProps.CATEGORY: EntityCategory.RESOURCE,
            VProps.TYPE: NOVA_HOST_DATASOURCE
        })

        # add host alarms + deduced alarms
        self.evaluator.enabled = True
        alarms_on_hosts_list = []
        for index, host_vertex in enumerate(host_vertices):
            alarm_name = '%s:%s' % ('nagios_alarm_on_host_',
                                    host_vertex[VProps.NAME])
            alarms_on_hosts_list.append(
                self._create_alarm(alarm_name, NAGIOS_DATASOURCE))
            self.processor.entity_graph.add_vertex(alarms_on_hosts_list[index])
            edge = graph_utils.create_edge(
                alarms_on_hosts_list[index].vertex_id,
                host_vertex.vertex_id,
                EdgeLabel.ON)
            self.processor.entity_graph.add_edge(edge)

            # reliable action to check that the events in the queue
            while self.event_queue.empty():
                time.sleep(0.1)

            while not self.event_queue.empty():
                self.processor.process_event(self.event_queue.get())

        # remove external alarms
        self.evaluator.enabled = False
        self.processor.entity_graph.remove_vertex(alarms_on_hosts_list[2])
        self.processor.entity_graph.remove_vertex(alarms_on_hosts_list[3])
        self.evaluator.enabled = True
예제 #10
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())
예제 #11
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)
예제 #12
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])
예제 #13
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=EdgeLabels.ON)

            return Neighbor(resource_vertex, relationship_edge)

        LOG.warning('Cannot transform host, host transformer does not exist')
        return None
예제 #14
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
예제 #15
0
    def _create_instance_neighbor(self,
                                  entity_event,
                                  attachment,
                                  instance_transformer,
                                  instance_id_property):
        volume_vitrage_id = self._create_entity_key(entity_event)

        instance_id = attachment[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 = \
            instance_transformer.create_placeholder_vertex(
                **properties)

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

        return Neighbor(instance_vertex, relationship_edge)
예제 #16
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
예제 #17
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)
예제 #18
0
    def _create_entity_graph(self, name, num_of_alarms_per_host,
                             num_of_alarms_per_vm,
                             num_of_hosts_per_node,
                             num_of_vms_per_host,
                             num_of_tests_per_host):

        start = time.time()
        g = create_graph(name)
        g.add_vertex(v_node)
        g.add_vertex(v_switch)
        g.add_edge(e_node_to_switch)

        # Add Hosts
        for host_id in xrange(num_of_hosts_per_node):
            host_to_add = add_connected_vertex(g, RESOURCE, HOST, host_id,
                                               ELabel.CONTAINS, v_node, True)

            g.add_edge(graph_utils.create_edge(host_to_add.vertex_id,
                                               v_switch.vertex_id, 'USES'))

            # Add Host Alarms
            for j in xrange(num_of_alarms_per_host):
                add_connected_vertex(g, ALARM, ALARM_ON_HOST,
                                     self.host_alarm_id, ELabel.ON,
                                     host_to_add)
                self.host_alarm_id += 1

            # Add Host Tests
            for j in xrange(num_of_tests_per_host):
                add_connected_vertex(g, TEST, TEST_ON_HOST, self.host_test_id,
                                     ELabel.ON, host_to_add)
                self.host_test_id += 1

            # Add Host Vms
            for j in xrange(num_of_vms_per_host):
                vm_to_add = add_connected_vertex(g, RESOURCE, INSTANCE,
                                                 self.vm_id, ELabel.CONTAINS,
                                                 host_to_add, True)
                self.vm_id += 1
                self.vms.append(vm_to_add)

                # Add Instance Alarms
                for k in xrange(num_of_alarms_per_vm):
                    add_connected_vertex(g, ALARM, ALARM_ON_VM,
                                         self.vm_alarm_id, ELabel.ON,
                                         vm_to_add)
                    self.vm_alarm_id += 1

        end = time.time()
        LOG.debug('Graph creation took ' + str(end - start) +
                  ' seconds, size is: ' + str(len(g)))
        expected_graph_size = \
            2 + num_of_hosts_per_node + num_of_hosts_per_node * \
            num_of_alarms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host * num_of_alarms_per_vm + num_of_tests_per_host * \
            num_of_hosts_per_node
        assert expected_graph_size == len(g), 'Graph size'
        return g
예제 #19
0
    def _create_cluster_neighbor(zone_vertex_id):

        cluster_vertex = tbase.create_cluster_placeholder_vertex()

        relation_edge = graph_utils.create_edge(
            source_id=cluster_vertex.vertex_id,
            target_id=zone_vertex_id,
            relationship_type=EdgeLabel.CONTAINS)
        return tbase.Neighbor(cluster_vertex, relation_edge)
예제 #20
0
    def _create_cluster_neighbor(zone_vertex_id):

        cluster_vertex = tbase.create_cluster_placeholder_vertex()

        relation_edge = graph_utils.create_edge(
            source_id=cluster_vertex.vertex_id,
            target_id=zone_vertex_id,
            relationship_type=EdgeLabel.CONTAINS)
        return tbase.Neighbor(cluster_vertex, relation_edge)
예제 #21
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
예제 #22
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
예제 #23
0
    def _create_node_neighbor(self, zone_vertex_id):

        node_vertex = base.create_node_placeholder_vertex()

        relation_edge = graph_utils.create_edge(
            source_id=node_vertex.vertex_id,
            target_id=zone_vertex_id,
            relationship_type=EdgeLabels.CONTAINS
        )
        return base.Neighbor(node_vertex, relation_edge)
예제 #24
0
    def test_union(self):
        v1 = v_node
        v2 = v_host
        v3 = v_instance
        v4 = v_alarm

        e_v1_v2 = utils.create_edge(source_id=v1.vertex_id,
                                    target_id=v2.vertex_id,
                                    relationship_type='KUKU_v1_v2')
        e_v2_v3 = utils.create_edge(source_id=v2.vertex_id,
                                    target_id=v3.vertex_id,
                                    relationship_type='KUKU_v2_v3')
        e_v3_v4 = utils.create_edge(source_id=v3.vertex_id,
                                    target_id=v4.vertex_id,
                                    relationship_type='KUKU_v3_v4')

        g1 = NXGraph('test_union')
        g1.add_vertex(v1)
        g1.add_vertex(v2)
        g1.add_vertex(v3)
        g1.add_edge(e_v1_v2)
        g1.add_edge(e_v2_v3)

        g2 = NXGraph('test_union_')
        g2.add_vertex(v3)
        g2.add_vertex(v4)
        g2.add_edge(e_v3_v4)

        g1.union(g2)
        self.assertThat(g1, matchers.HasLength(4),
                        'incorrect graph len after union')

        e = g1.get_edge(e_v3_v4.source_id, e_v3_v4.target_id, e_v3_v4.label)
        self.assertIsNotNone(e, 'Edge missing after graphs union')

        e = g1.get_edge(e_v2_v3.source_id, e_v2_v3.target_id, e_v2_v3.label)
        self.assertIsNotNone(e, 'Edge missing after graphs union')

        e = g1.get_vertex(v3.vertex_id)
        self.assertIsNotNone(e, 'Vertex missing after graphs union')
예제 #25
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)
예제 #26
0
def add_connected_vertex(graph, entity_type, entity_subtype, entity_id,
                         edge_type, other_vertex, reverse=False):
    vertex = graph_utils.create_vertex(
        vertex_id=entity_subtype + str(entity_id),
        entity_id=entity_id,
        entity_category=entity_type,
        entity_type=entity_subtype)
    edge = graph_utils.create_edge(
        source_id=other_vertex.vertex_id if reverse else vertex.vertex_id,
        target_id=vertex.vertex_id if reverse else other_vertex.vertex_id,
        relationship_type=edge_type)
    graph.add_vertex(vertex)
    graph.add_edge(edge)
    return vertex
예제 #27
0
def add_connected_vertex(graph, entity_type, entity_subtype, entity_id,
                         edge_type, other_vertex, reverse=False):
    vertex = graph_utils.create_vertex(
        vitrage_id=entity_subtype + str(entity_id),
        entity_id=entity_id,
        entity_category=entity_type,
        entity_type=entity_subtype)
    edge = graph_utils.create_edge(
        source_id=other_vertex.vertex_id if reverse else vertex.vertex_id,
        target_id=vertex.vertex_id if reverse else other_vertex.vertex_id,
        relationship_type=edge_type)
    graph.add_vertex(vertex)
    graph.add_edge(edge)
    return vertex
예제 #28
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)
예제 #29
0
    def _create_host_neighbor(self, zone_id, host_name, host_state, timestamp):

        host_transformer = self.transformers['nova.host']

        host_vertex = graph_utils.create_vertex(
            base.build_key(host_transformer._key_values([host_name])),
            entity_id=host_name,
            entity_category=EntityTypes.RESOURCE,
            entity_type=self.ZONE_TYPE,
            entity_state=host_state,
            update_timestamp=timestamp,
        )

        relation_edge = graph_utils.create_edge(
            source_id=zone_id,
            target_id=host_vertex.vertex_id,
            relationship_type=EdgeLabels.CONTAINS
        )
        return base.Neighbor(host_vertex, relation_edge)
예제 #30
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())
예제 #31
0
    def _create_host_neighbor(
            self,
            vertex_id,
            host_name,
            timestamp,
            host_transformer
    ):

        host_vertex = host_transformer.create_placeholder_vertex(
            host_name,
            timestamp
        )

        relation_edge = graph_utils.create_edge(
            source_id=host_vertex.vertex_id,
            target_id=vertex_id,
            relationship_type=EdgeLabels.CONTAINS
        )
        return base.Neighbor(host_vertex, relation_edge)
예제 #32
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)
예제 #33
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())
예제 #34
0
    def _create_network_neighbor(self, entity_event, net_id_property):
        port_vitrage_id = self._create_entity_key(entity_event)

        net_id = extract_field_value(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)
예제 #35
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)
예제 #36
0
    def _create_host_neighbor(self, zone_id, host_name, host_state,
                              sample_timestamp):

        host_transformer = self.transformers[NOVA_HOST_DATASOURCE]

        properties = {
            VProps.ID: host_name,
            VProps.SAMPLE_TIMESTAMP: sample_timestamp,
            VProps.TYPE: NOVA_HOST_DATASOURCE
        }
        host_neighbor = \
            host_transformer.create_placeholder_vertex(**properties)
        host_neighbor[VProps.STATE] = host_state
        host_neighbor[VProps.IS_PLACEHOLDER] = False

        relation_edge = graph_utils.create_edge(
            source_id=zone_id,
            target_id=host_neighbor.vertex_id,
            relationship_type=EdgeLabel.CONTAINS)

        return tbase.Neighbor(host_neighbor, relation_edge)
예제 #37
0
    def _create_host_neighbor(self, zone_id, host_name,
                              host_state, sample_timestamp):

        host_transformer = self.transformers[NOVA_HOST_DATASOURCE]

        properties = {
            VProps.ID: host_name,
            VProps.SAMPLE_TIMESTAMP: sample_timestamp,
            VProps.TYPE: NOVA_HOST_DATASOURCE
        }
        host_neighbor = \
            host_transformer.create_placeholder_vertex(**properties)
        host_neighbor[VProps.STATE] = host_state
        host_neighbor[VProps.IS_PLACEHOLDER] = False

        relation_edge = graph_utils.create_edge(
            source_id=zone_id,
            target_id=host_neighbor.vertex_id,
            relationship_type=EdgeLabel.CONTAINS)

        return tbase.Neighbor(host_neighbor, relation_edge)
예제 #38
0
    def _create_instance_neighbor(self,
                                  entity_event,
                                  instance_id_property):
        port_vitrage_id = self._create_entity_key(entity_event)

        instance_id = extract_field_value(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)
예제 #39
0
    def _create_zone_neighbor(
            self, entity_event, timestamp, host_vertex_id, zone_name_path):

        zone_transformer = self.transformers['nova.zone']

        if zone_transformer:

            zone_name = extract_field_value(entity_event, zone_name_path)

            zone_neighbor = zone_transformer.create_placeholder_vertex(
                zone_name,
                timestamp
            )
            relation_edge = graph_utils.create_edge(
                source_id=zone_neighbor.vertex_id,
                target_id=host_vertex_id,
                relationship_type=EdgeLabels.CONTAINS
            )
            return base.Neighbor(zone_neighbor, relation_edge)
        else:
            LOG.warning('Cannot find zone transformer')

        return None
예제 #40
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(None, new_edge)]

        # action
        processor.delete_relationship(None, new_neighbors)

        # test assertions
        self.assertEqual(2, processor.entity_graph.num_edges())
예제 #41
0
    def test_edge_crud(self):
        g = NXGraph('test_edge_crud')
        g.add_vertex(v_node)
        g.add_vertex(v_host)
        g.add_edge(e_node_to_host)
        self.assertEqual(1, g.num_edges(), 'graph __len__ after add edge')
        label = e_node_to_host[EProps.RELATIONSHIP_TYPE]
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, label)
        self.assertEqual(e_node_to_host[EProps.RELATIONSHIP_TYPE],
                         e[EProps.RELATIONSHIP_TYPE],
                         'edge properties are saved')
        self.assertEqual(e_node_to_host.source_id, e.source_id,
                         'edge vertex_id is saved')
        self.assertEqual(e_node_to_host.target_id, e.target_id,
                         'edge vertex_id is saved')

        # Edge is correct
        v_node_neig = g.neighbors(v_node.vertex_id, direction=Direction.OUT)
        self.assertEqual(1, len(v_node_neig), 'v_node OUT neighbor count')
        self.assertEqual(v_host.vertex_id,
                         v_node_neig.pop().vertex_id,
                         'v_node OUT neighbor is v_host')
        v_node_neig = g.neighbors(v_node.vertex_id, direction=Direction.IN)
        self.assertEqual(0, len(v_node_neig), 'v_node IN neighbor count')
        v_host_neig = g.neighbors(v_host.vertex_id, direction=Direction.OUT)
        self.assertEqual(0, len(v_host_neig), 'v_host OUT neighbor count')
        v_host_neig = g.neighbors(v_host.vertex_id, direction=Direction.IN)
        self.assertEqual(1, len(v_host_neig), 'v_host IN neighbor count')
        self.assertEqual(v_node.vertex_id,
                         v_host_neig.pop().vertex_id,
                         'v_host IN neighbor is v_node')

        # Changing the referenced item
        updated_e = e
        updated_e[EProps.VITRAGE_IS_DELETED] = 'KUKU'
        updated_e[EProps.UPDATE_TIMESTAMP] = 'CHANGED'

        # Get it again
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, label)
        self.assertFalse(e.get(EProps.VITRAGE_IS_DELETED, None),
                         'Change should not affect graph item')
        self.assertEqual(e_node_to_host[EProps.UPDATE_TIMESTAMP],
                         e[EProps.UPDATE_TIMESTAMP],
                         'Change should not affect graph item')
        # Update the graph item and see changes take place
        g.update_edge(updated_e)
        # Get it again
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, label)
        self.assertEqual(updated_e[EProps.VITRAGE_IS_DELETED],
                         e[EProps.VITRAGE_IS_DELETED],
                         'Graph item should change after update')
        self.assertEqual(updated_e[EProps.UPDATE_TIMESTAMP],
                         e[EProps.UPDATE_TIMESTAMP],
                         'Graph item should change after update')

        # Update the graph item and see changes take place
        updated_e[EProps.VITRAGE_IS_DELETED] = None
        g.update_edge(updated_e)
        # Get it again
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, label)
        self.assertNotIn(
            EProps.VITRAGE_IS_DELETED, e.properties,
            'Update value to None should entirely remove the key')

        # check metadata
        another_label = 'ANOTHER_LABEL'
        another_edge = utils.create_edge(source_id=v_node.vertex_id,
                                         target_id=v_host.vertex_id,
                                         relationship_type=another_label,
                                         metadata={'some_meta': 'DATA'})
        g.add_edge(another_edge)
        self.assertEqual(2, g.num_edges(), 'graph __len__ after add edge')
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, another_label)
        self.assertEqual(another_edge[EProps.RELATIONSHIP_TYPE],
                         e[EProps.RELATIONSHIP_TYPE],
                         'edge properties are saved')
        self.assertEqual('DATA', e['some_meta'], 'edge properties are saved')

        # Remove the item
        g.remove_edge(another_edge)
        self.assertEqual(1, g.num_edges(), 'graph __len__ after remove edge')
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, another_label)
        self.assertIsNone(e, 'removed edge not in graph')

        # Check get_edge returns None when item is missing
        edge = g.get_edge(v_host.vertex_id, 'ddd', '333')
        self.assertIsNone(edge)
        edge = g.get_edge('eee', v_node.vertex_id, '333')
        self.assertIsNone(edge)
        edge = g.get_edge(v_host.vertex_id, v_node.vertex_id, None)
        self.assertIsNone(edge)
        edge = g.get_edge(None, v_node.vertex_id, '333')
        self.assertIsNone(edge)
예제 #42
0
파일: base.py 프로젝트: ngohoa211/vitrage-1
    def _create_entity_graph(cls, name, num_of_alarms_per_host,
                             num_of_alarms_per_vm,
                             num_of_hosts_per_node,
                             num_of_vms_per_host,
                             num_of_tests_per_host):

        start = time.time()
        g = NXGraph(name)
        g.add_vertex(v_node)
        g.add_vertex(v_switch)
        g.add_edge(e_node_to_switch)

        # Add Hosts
        for host_id in range(num_of_hosts_per_node):
            host_to_add = add_connected_vertex(g,
                                               RESOURCE,
                                               NOVA_HOST_DATASOURCE,
                                               host_id,
                                               ELabel.CONTAINS,
                                               v_node,
                                               True)

            g.add_edge(graph_utils.create_edge(host_to_add.vertex_id,
                                               v_switch.vertex_id, 'USES'))

            # Add Host Alarms
            for j in range(num_of_alarms_per_host):
                add_connected_vertex(g, ALARM, ALARM_ON_HOST,
                                     cls.host_alarm_id, ELabel.ON,
                                     host_to_add, False,
                                     {VProps.RESOURCE_ID: host_id,
                                      VProps.NAME: host_id})
                cls.host_alarm_id += 1

            # Add Host Tests
            for j in range(num_of_tests_per_host):
                add_connected_vertex(g, TEST, TEST_ON_HOST, cls.host_test_id,
                                     ELabel.ON, host_to_add)
                cls.host_test_id += 1

            # Add Host Vms
            for j in range(num_of_vms_per_host):
                vm_to_add = add_connected_vertex(g,
                                                 RESOURCE,
                                                 NOVA_INSTANCE_DATASOURCE,
                                                 cls.vm_id,
                                                 ELabel.CONTAINS,
                                                 host_to_add,
                                                 True)
                cls.vm_id += 1
                cls.vms.append(vm_to_add)

                # Add Instance Alarms
                for k in range(num_of_alarms_per_vm):
                    add_connected_vertex(g, ALARM, ALARM_ON_VM,
                                         cls.vm_alarm_id, ELabel.ON,
                                         vm_to_add, False,
                                         {VProps.RESOURCE_ID: cls.vm_id - 1,
                                          VProps.NAME: cls.vm_id - 1})
                    cls.vm_alarm_id += 1

        end = time.time()
        LOG.debug('Graph creation took ' + str(end - start) +
                  ' seconds, size is: ' + str(len(g)))
        expected_graph_size = \
            2 + num_of_hosts_per_node + num_of_hosts_per_node * \
            num_of_alarms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host * num_of_alarms_per_vm + \
            num_of_tests_per_host * num_of_hosts_per_node
        if not expected_graph_size == len(g):
            raise VitrageError('Init failed, graph size unexpected {0} != {1}'
                               .format(expected_graph_size, len(g)))
        return g
예제 #43
0
파일: base.py 프로젝트: ngohoa211/vitrage-1
v_alarm = graph_utils.create_vertex(
    vitrage_id=ALARM + '444444444444',
    vitrage_category=ALARM,
    vitrage_type=ALARM_ON_VM,
    entity_id='444444444444',
    metadata={VProps.RESOURCE_ID: '333333333333',
              VProps.NAME: 'anotheralarm'})
v_switch = graph_utils.create_vertex(
    vitrage_id='switch1212121212',
    vitrage_category=RESOURCE,
    vitrage_type='switch',
    entity_id='1212121212')

e_node_to_host = graph_utils.create_edge(
    source_id=v_node.vertex_id,
    target_id=v_host.vertex_id,
    relationship_type=ELabel.CONTAINS,
    update_timestamp='123')

e_node_to_switch = graph_utils.create_edge(
    source_id=v_node.vertex_id,
    target_id=v_switch.vertex_id,
    relationship_type=ELabel.CONTAINS)


def add_connected_vertex(graph, entity_type, entity_subtype, entity_id,
                         edge_type, other_vertex, reverse=False,
                         metadata=None):
    vertex = graph_utils.create_vertex(
        vitrage_id=entity_subtype + str(entity_id),
        vitrage_category=entity_type,
예제 #44
0
    def test_neighbors(self):
        relationship_a = 'RELATIONSHIP_A'
        relationship_b = 'RELATIONSHIP_B'
        relationship_c = 'RELATIONSHIP_C'

        v1 = v_node
        v2 = v_host
        v3 = v_instance
        v4 = v_alarm
        v5 = utils.create_vertex(
            vertex_id='kuku',
            entity_category=HOST)

        g = create_graph('test_neighbors')
        g.add_vertex(v1)
        g.add_vertex(v2)
        g.add_vertex(v3)
        g.add_vertex(v4)
        g.add_vertex(v5)

        g.add_edge(utils.create_edge(source_id=v1.vertex_id,
                                     target_id=v2.vertex_id,
                                     relationship_type=relationship_a))
        g.add_edge(utils.create_edge(source_id=v1.vertex_id,
                                     target_id=v2.vertex_id,
                                     relationship_type=relationship_b))
        g.add_edge(utils.create_edge(source_id=v1.vertex_id,
                                     target_id=v4.vertex_id,
                                     relationship_type=relationship_a))
        g.add_edge(utils.create_edge(source_id=v1.vertex_id,
                                     target_id=v4.vertex_id,
                                     relationship_type=relationship_b))
        g.add_edge(utils.create_edge(source_id=v2.vertex_id,
                                     target_id=v1.vertex_id,
                                     relationship_type=relationship_c))
        g.add_edge(utils.create_edge(source_id=v2.vertex_id,
                                     target_id=v3.vertex_id,
                                     relationship_type=relationship_a))
        g.add_edge(utils.create_edge(source_id=v2.vertex_id,
                                     target_id=v3.vertex_id,
                                     relationship_type=relationship_b))
        g.add_edge(utils.create_edge(source_id=v2.vertex_id,
                                     target_id=v4.vertex_id,
                                     relationship_type=relationship_a))
        g.add_edge(utils.create_edge(source_id=v4.vertex_id,
                                     target_id=v1.vertex_id,
                                     relationship_type=relationship_c))

        # CHECK V1

        v1_neighbors = g.neighbors(v_id=v1.vertex_id)
        self._assert_set_equal({v2, v4}, v1_neighbors, 'Check V1 neighbors')

        v1_neighbors = g.neighbors(
            v_id=v1.vertex_id,
            vertex_attr_filter={VProps.TYPE: HOST})
        self._assert_set_equal({v2}, v1_neighbors,
                               'Check V1 neighbors, vertex property filter')

        v1_neighbors = g.neighbors(
            v_id=v1.vertex_id,
            edge_attr_filter={EProps.RELATIONSHIP_NAME: relationship_a})
        self._assert_set_equal({v2, v4}, v1_neighbors,
                               'Check V1 neighbors, edge property filter')

        v1_neighbors = g.neighbors(v_id=v1.vertex_id,
                                   direction=Direction.IN)
        self._assert_set_equal({v2, v4}, v1_neighbors,
                               'Check V1 neighbors, direction IN')

        v1_neighbors = g.neighbors(v_id=v1.vertex_id,
                                   direction=Direction.OUT)
        self._assert_set_equal({v2, v4}, v1_neighbors,
                               'Check V1 neighbors, direction OUT')

        v1_neighbors = g.neighbors(v_id=v1.vertex_id,
                                   direction=Direction.BOTH)
        self._assert_set_equal({v2, v4}, v1_neighbors,
                               'Check V1 neighbors, direction BOTH')

        v1_neighbors = g.neighbors(
            v_id=v1.vertex_id,
            direction=Direction.IN,
            edge_attr_filter={EProps.RELATIONSHIP_NAME: relationship_c},
            vertex_attr_filter={VProps.TYPE: HOST})
        self._assert_set_equal(
            {v2}, v1_neighbors,
            'Check V1 neighbors, vertex/edge property filter and direction')

        # CHECK V2

        v2_neighbors = g.neighbors(v_id=v2.vertex_id)
        self._assert_set_equal({v1, v3, v4}, v2_neighbors,
                               'Check v2 neighbors')

        v2_neighbors = g.neighbors(
            v_id=v2.vertex_id,
            vertex_attr_filter={VProps.CATEGORY: HOST})
        self._assert_set_equal({}, v2_neighbors,
                               'Check v2 neighbors, vertex property filter')

        v2_neighbors = g.neighbors(
            v_id=v2.vertex_id,
            vertex_attr_filter={VProps.CATEGORY: [HOST, ALARM]})
        self._assert_set_equal({v4}, v2_neighbors,
                               'Check v2 neighbors, vertex property filter')

        v2_neighbors = g.neighbors(
            v_id=v2.vertex_id,
            edge_attr_filter={
                EProps.RELATIONSHIP_NAME: [relationship_a, relationship_b]
            },
            vertex_attr_filter={
                VProps.CATEGORY: [RESOURCE, ALARM],
                VProps.TYPE: [HOST, INSTANCE, ALARM_ON_VM, ALARM_ON_HOST]
            }
        )
        self._assert_set_equal({v3, v4}, v2_neighbors,
                               'Check v2 neighbors, edge property filter')

        # CHECK V3

        v3_neighbors = g.neighbors(v_id=v3.vertex_id, direction=Direction.OUT)
        self._assert_set_equal({}, v3_neighbors,
                               'Check v3 neighbors, direction OUT')

        v3_neighbors = g.neighbors(
            v_id=v3.vertex_id,
            vertex_attr_filter={VProps.CATEGORY: HOST},
            direction=Direction.OUT)
        self._assert_set_equal({}, v3_neighbors,
                               'Check neighbors for vertex without any')
        v5_neighbors = g.neighbors(
            v_id=v5.vertex_id,
            vertex_attr_filter={VProps.CATEGORY: HOST})
        self._assert_set_equal({}, v5_neighbors,
                               'Check neighbors for not connected vertex')
예제 #45
0
    def _create_graph(self):
        graph = NXGraph('Multi tenancy graph')

        # create vertices
        cluster_vertex = self._create_resource('RESOURCE:openstack.cluster',
                                               OPENSTACK_CLUSTER)
        zone_vertex = self._create_resource('zone_1',
                                            NOVA_ZONE_DATASOURCE)
        host_vertex = self._create_resource('host_1',
                                            NOVA_HOST_DATASOURCE)
        instance_1_vertex = self._create_resource('instance_1',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_1')
        instance_2_vertex = self._create_resource('instance_2',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_1')
        instance_3_vertex = self._create_resource('instance_3',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_2')
        instance_4_vertex = self._create_resource('instance_4',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_2')
        alarm_on_host_vertex = self._create_alarm('alarm_on_host',
                                                  'alarm_on_host')
        alarm_on_instance_1_vertex = self._create_alarm('alarm_on_instance_1',
                                                        'deduced_alarm',
                                                        project_id='project_1')
        alarm_on_instance_2_vertex = self._create_alarm('alarm_on_instance_2',
                                                        'deduced_alarm')
        alarm_on_instance_3_vertex = self._create_alarm('alarm_on_instance_3',
                                                        'deduced_alarm',
                                                        project_id='project_2')
        alarm_on_instance_4_vertex = self._create_alarm('alarm_on_instance_4',
                                                        'deduced_alarm')

        # create links
        edges = list()
        edges.append(graph_utils.create_edge(
            cluster_vertex.vertex_id,
            zone_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            zone_vertex.vertex_id,
            host_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            host_vertex.vertex_id,
            instance_1_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            host_vertex.vertex_id,
            instance_2_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            host_vertex.vertex_id,
            instance_3_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            host_vertex.vertex_id,
            instance_4_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            host_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_instance_1_vertex.vertex_id,
            instance_1_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_instance_2_vertex.vertex_id,
            instance_2_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_instance_3_vertex.vertex_id,
            instance_3_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_instance_4_vertex.vertex_id,
            instance_4_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            alarm_on_instance_1_vertex.vertex_id,
            'causes'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            alarm_on_instance_2_vertex.vertex_id,
            'causes'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            alarm_on_instance_3_vertex.vertex_id,
            'causes'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            alarm_on_instance_4_vertex.vertex_id,
            'causes'))

        # add vertices to graph
        graph.add_vertex(cluster_vertex)
        graph.add_vertex(zone_vertex)
        graph.add_vertex(host_vertex)
        graph.add_vertex(instance_1_vertex)
        graph.add_vertex(instance_2_vertex)
        graph.add_vertex(instance_3_vertex)
        graph.add_vertex(instance_4_vertex)
        graph.add_vertex(alarm_on_host_vertex)
        graph.add_vertex(alarm_on_instance_1_vertex)
        graph.add_vertex(alarm_on_instance_2_vertex)
        graph.add_vertex(alarm_on_instance_3_vertex)
        graph.add_vertex(alarm_on_instance_4_vertex)

        # add links to graph
        for edge in edges:
            graph.add_edge(edge)

        return graph
예제 #46
0
    def _create_graph(self):
        graph = NXGraph('Multi tenancy graph')
        self._add_alarm_persistency_subscription(graph)

        # create vertices
        cluster_vertex = create_cluster_placeholder_vertex()
        zone_vertex = self._create_resource('zone_1', NOVA_ZONE_DATASOURCE)
        host_vertex = self._create_resource('host_1', NOVA_HOST_DATASOURCE)
        instance_1_vertex = self._create_resource('instance_1',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_1')
        instance_2_vertex = self._create_resource('instance_2',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_1')
        instance_3_vertex = self._create_resource('instance_3',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_2')
        instance_4_vertex = self._create_resource('instance_4',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_2')
        alarm_on_host_vertex = self._create_alarm(
            'alarm_on_host',
            'alarm_on_host',
            metadata={
                VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE,
                VProps.NAME: 'host_1',
                VProps.RESOURCE_ID: 'host_1',
                VProps.VITRAGE_OPERATIONAL_SEVERITY:
                OperationalAlarmSeverity.SEVERE,
                VProps.VITRAGE_AGGREGATED_SEVERITY:
                OperationalAlarmSeverity.SEVERE
            })
        alarm_on_instance_1_vertex = self._create_alarm(
            'alarm_on_instance_1',
            'deduced_alarm',
            project_id='project_1',
            vitrage_resource_project_id='project_1',
            metadata={
                VProps.VITRAGE_TYPE: NOVA_INSTANCE_DATASOURCE,
                VProps.NAME: 'instance_1',
                VProps.RESOURCE_ID: 'sdg7849ythksjdg',
                VProps.VITRAGE_OPERATIONAL_SEVERITY:
                OperationalAlarmSeverity.SEVERE,
                VProps.VITRAGE_AGGREGATED_SEVERITY:
                OperationalAlarmSeverity.SEVERE
            })
        alarm_on_instance_2_vertex = self._create_alarm(
            'alarm_on_instance_2',
            'deduced_alarm',
            vitrage_resource_project_id='project_1',
            metadata={
                VProps.VITRAGE_TYPE:
                NOVA_INSTANCE_DATASOURCE,
                VProps.NAME:
                'instance_2',
                VProps.RESOURCE_ID:
                'nbfhsdugf',
                VProps.VITRAGE_OPERATIONAL_SEVERITY:
                OperationalAlarmSeverity.WARNING,
                VProps.VITRAGE_AGGREGATED_SEVERITY:
                OperationalAlarmSeverity.WARNING
            })
        alarm_on_instance_3_vertex = self._create_alarm(
            'alarm_on_instance_3',
            'deduced_alarm',
            project_id='project_2',
            vitrage_resource_project_id='project_2',
            metadata={
                VProps.VITRAGE_TYPE:
                NOVA_INSTANCE_DATASOURCE,
                VProps.NAME:
                'instance_3',
                VProps.RESOURCE_ID:
                'nbffhsdasdugf',
                VProps.VITRAGE_OPERATIONAL_SEVERITY:
                OperationalAlarmSeverity.CRITICAL,
                VProps.VITRAGE_AGGREGATED_SEVERITY:
                OperationalAlarmSeverity.CRITICAL
            })
        alarm_on_instance_4_vertex = self._create_alarm(
            'alarm_on_instance_4',
            'deduced_alarm',
            vitrage_resource_project_id='project_2',
            metadata={
                VProps.VITRAGE_TYPE:
                NOVA_INSTANCE_DATASOURCE,
                VProps.NAME:
                'instance_4',
                VProps.RESOURCE_ID:
                'ngsuy76hgd87f',
                VProps.VITRAGE_OPERATIONAL_SEVERITY:
                OperationalAlarmSeverity.WARNING,
                VProps.VITRAGE_AGGREGATED_SEVERITY:
                OperationalAlarmSeverity.WARNING
            })

        # create links
        edges = list()
        edges.append(
            graph_utils.create_edge(cluster_vertex.vertex_id,
                                    zone_vertex.vertex_id,
                                    EdgeLabel.CONTAINS,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(zone_vertex.vertex_id,
                                    host_vertex.vertex_id,
                                    EdgeLabel.CONTAINS,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(host_vertex.vertex_id,
                                    instance_1_vertex.vertex_id,
                                    EdgeLabel.CONTAINS,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(host_vertex.vertex_id,
                                    instance_2_vertex.vertex_id,
                                    EdgeLabel.CONTAINS,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(host_vertex.vertex_id,
                                    instance_3_vertex.vertex_id,
                                    EdgeLabel.CONTAINS,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(host_vertex.vertex_id,
                                    instance_4_vertex.vertex_id,
                                    EdgeLabel.CONTAINS,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    host_vertex.vertex_id,
                                    EdgeLabel.ON,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(alarm_on_instance_1_vertex.vertex_id,
                                    instance_1_vertex.vertex_id,
                                    EdgeLabel.ON,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(alarm_on_instance_2_vertex.vertex_id,
                                    instance_2_vertex.vertex_id,
                                    EdgeLabel.ON,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(alarm_on_instance_3_vertex.vertex_id,
                                    instance_3_vertex.vertex_id,
                                    EdgeLabel.ON,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(alarm_on_instance_4_vertex.vertex_id,
                                    instance_4_vertex.vertex_id,
                                    EdgeLabel.ON,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    alarm_on_instance_1_vertex.vertex_id,
                                    EdgeLabel.CAUSES,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    alarm_on_instance_2_vertex.vertex_id,
                                    EdgeLabel.CAUSES,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    alarm_on_instance_3_vertex.vertex_id,
                                    EdgeLabel.CAUSES,
                                    update_timestamp=str(utcnow())))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    alarm_on_instance_4_vertex.vertex_id,
                                    EdgeLabel.CAUSES,
                                    update_timestamp=str(utcnow())))

        # add vertices to graph
        graph.add_vertex(cluster_vertex)
        graph.add_vertex(zone_vertex)
        graph.add_vertex(host_vertex)
        graph.add_vertex(instance_1_vertex)
        graph.add_vertex(instance_2_vertex)
        graph.add_vertex(instance_3_vertex)
        graph.add_vertex(instance_4_vertex)
        graph.add_vertex(alarm_on_host_vertex)
        graph.add_vertex(alarm_on_instance_1_vertex)
        graph.add_vertex(alarm_on_instance_2_vertex)
        graph.add_vertex(alarm_on_instance_3_vertex)
        graph.add_vertex(alarm_on_instance_4_vertex)

        # add links to graph
        for edge in edges:
            graph.add_edge(edge)

        return graph
예제 #47
0
    entity_type=INSTANCE,
    entity_category=RESOURCE)
v_alarm = graph_utils.create_vertex(
    vertex_id=ALARM + '444444444444',
    entity_id='444444444444',
    entity_type=ALARM_ON_VM,
    entity_category=ALARM)
v_switch = graph_utils.create_vertex(
    vertex_id=SWITCH + '1212121212',
    entity_id='1212121212',
    entity_type=SWITCH,
    entity_category=RESOURCE)

e_node_to_host = graph_utils.create_edge(
    source_id=v_node.vertex_id,
    target_id=v_host.vertex_id,
    relationship_type=ELabel.CONTAINS,
    update_timestamp='123')

e_node_to_switch = graph_utils.create_edge(
    source_id=v_node.vertex_id,
    target_id=v_switch.vertex_id,
    relationship_type=ELabel.CONTAINS)


def add_connected_vertex(graph, entity_type, entity_subtype, entity_id,
                         edge_type, other_vertex, reverse=False):
    vertex = graph_utils.create_vertex(
        vertex_id=entity_subtype + str(entity_id),
        entity_id=entity_id,
        entity_category=entity_type,
예제 #48
0
    def _create_graph(self):
        graph = NXGraph('Multi tenancy graph')

        # create vertices
        cluster_vertex = self._create_resource('RESOURCE:openstack.cluster',
                                               OPENSTACK_CLUSTER)
        zone_vertex = self._create_resource('zone_1', NOVA_ZONE_DATASOURCE)
        host_vertex = self._create_resource('host_1', NOVA_HOST_DATASOURCE)
        instance_1_vertex = self._create_resource('instance_1',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_1')
        instance_2_vertex = self._create_resource('instance_2',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_1')
        instance_3_vertex = self._create_resource('instance_3',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_2')
        instance_4_vertex = self._create_resource('instance_4',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_2')
        alarm_on_host_vertex = self._create_alarm('alarm_on_host',
                                                  'alarm_on_host')
        alarm_on_instance_1_vertex = self._create_alarm('alarm_on_instance_1',
                                                        'deduced_alarm',
                                                        project_id='project_1')
        alarm_on_instance_2_vertex = self._create_alarm(
            'alarm_on_instance_2', 'deduced_alarm')
        alarm_on_instance_3_vertex = self._create_alarm('alarm_on_instance_3',
                                                        'deduced_alarm',
                                                        project_id='project_2')
        alarm_on_instance_4_vertex = self._create_alarm(
            'alarm_on_instance_4', 'deduced_alarm')

        # create links
        edges = list()
        edges.append(
            graph_utils.create_edge(cluster_vertex.vertex_id,
                                    zone_vertex.vertex_id, 'contains'))
        edges.append(
            graph_utils.create_edge(zone_vertex.vertex_id,
                                    host_vertex.vertex_id, 'contains'))
        edges.append(
            graph_utils.create_edge(host_vertex.vertex_id,
                                    instance_1_vertex.vertex_id, 'contains'))
        edges.append(
            graph_utils.create_edge(host_vertex.vertex_id,
                                    instance_2_vertex.vertex_id, 'contains'))
        edges.append(
            graph_utils.create_edge(host_vertex.vertex_id,
                                    instance_3_vertex.vertex_id, 'contains'))
        edges.append(
            graph_utils.create_edge(host_vertex.vertex_id,
                                    instance_4_vertex.vertex_id, 'contains'))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    host_vertex.vertex_id, 'on'))
        edges.append(
            graph_utils.create_edge(alarm_on_instance_1_vertex.vertex_id,
                                    instance_1_vertex.vertex_id, 'on'))
        edges.append(
            graph_utils.create_edge(alarm_on_instance_2_vertex.vertex_id,
                                    instance_2_vertex.vertex_id, 'on'))
        edges.append(
            graph_utils.create_edge(alarm_on_instance_3_vertex.vertex_id,
                                    instance_3_vertex.vertex_id, 'on'))
        edges.append(
            graph_utils.create_edge(alarm_on_instance_4_vertex.vertex_id,
                                    instance_4_vertex.vertex_id, 'on'))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    alarm_on_instance_1_vertex.vertex_id,
                                    'causes'))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    alarm_on_instance_2_vertex.vertex_id,
                                    'causes'))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    alarm_on_instance_3_vertex.vertex_id,
                                    'causes'))
        edges.append(
            graph_utils.create_edge(alarm_on_host_vertex.vertex_id,
                                    alarm_on_instance_4_vertex.vertex_id,
                                    'causes'))

        # add vertices to graph
        graph.add_vertex(cluster_vertex)
        graph.add_vertex(zone_vertex)
        graph.add_vertex(host_vertex)
        graph.add_vertex(instance_1_vertex)
        graph.add_vertex(instance_2_vertex)
        graph.add_vertex(instance_3_vertex)
        graph.add_vertex(instance_4_vertex)
        graph.add_vertex(alarm_on_host_vertex)
        graph.add_vertex(alarm_on_instance_1_vertex)
        graph.add_vertex(alarm_on_instance_2_vertex)
        graph.add_vertex(alarm_on_instance_3_vertex)
        graph.add_vertex(alarm_on_instance_4_vertex)

        # add links to graph
        for edge in edges:
            graph.add_edge(edge)

        return graph
예제 #49
0
    def _create_graph(self):
        graph = NXGraph('Multi tenancy graph', uuid=True)

        # create vertices
        cluster_vertex = create_cluster_placeholder_vertex()
        zone_vertex = self._create_resource('zone_1',
                                            NOVA_ZONE_DATASOURCE)
        host_vertex = self._create_resource('host_1',
                                            NOVA_HOST_DATASOURCE)
        instance_1_vertex = self._create_resource('instance_1',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_1')
        instance_2_vertex = self._create_resource('instance_2',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_1')
        instance_3_vertex = self._create_resource('instance_3',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_2')
        instance_4_vertex = self._create_resource('instance_4',
                                                  NOVA_INSTANCE_DATASOURCE,
                                                  project_id='project_2')
        alarm_on_host_vertex = self._create_alarm(
            'alarm_on_host',
            'alarm_on_host',
            metadata={'type': 'nova.host',
                      'name': 'host_1',
                      'resource_id': 'host_1'})
        alarm_on_instance_1_vertex = self._create_alarm(
            'alarm_on_instance_1',
            'deduced_alarm',
            project_id='project_1',
            metadata={'type': 'nova.instance',
                      'name': 'instance_1',
                      'resource_id': 'sdg7849ythksjdg'})
        alarm_on_instance_2_vertex = self._create_alarm(
            'alarm_on_instance_2',
            'deduced_alarm',
            metadata={'type': 'nova.instance',
                      'name': 'instance_2',
                      'resource_id': 'nbfhsdugf'})
        alarm_on_instance_3_vertex = self._create_alarm(
            'alarm_on_instance_3',
            'deduced_alarm',
            project_id='project_2',
            metadata={'type': 'nova.instance',
                      'name': 'instance_3',
                      'resource_id': 'nbffhsdasdugf'})
        alarm_on_instance_4_vertex = self._create_alarm(
            'alarm_on_instance_4',
            'deduced_alarm',
            metadata={'type': 'nova.instance',
                      'name': 'instance_4',
                      'resource_id': 'ngsuy76hgd87f'})

        # create links
        edges = list()
        edges.append(graph_utils.create_edge(
            cluster_vertex.vertex_id,
            zone_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            zone_vertex.vertex_id,
            host_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            host_vertex.vertex_id,
            instance_1_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            host_vertex.vertex_id,
            instance_2_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            host_vertex.vertex_id,
            instance_3_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            host_vertex.vertex_id,
            instance_4_vertex.vertex_id,
            'contains'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            host_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_instance_1_vertex.vertex_id,
            instance_1_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_instance_2_vertex.vertex_id,
            instance_2_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_instance_3_vertex.vertex_id,
            instance_3_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_instance_4_vertex.vertex_id,
            instance_4_vertex.vertex_id,
            'on'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            alarm_on_instance_1_vertex.vertex_id,
            'causes'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            alarm_on_instance_2_vertex.vertex_id,
            'causes'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            alarm_on_instance_3_vertex.vertex_id,
            'causes'))
        edges.append(graph_utils.create_edge(
            alarm_on_host_vertex.vertex_id,
            alarm_on_instance_4_vertex.vertex_id,
            'causes'))

        # add vertices to graph
        graph.add_vertex(cluster_vertex)
        graph.add_vertex(zone_vertex)
        graph.add_vertex(host_vertex)
        graph.add_vertex(instance_1_vertex)
        graph.add_vertex(instance_2_vertex)
        graph.add_vertex(instance_3_vertex)
        graph.add_vertex(instance_4_vertex)
        graph.add_vertex(alarm_on_host_vertex)
        graph.add_vertex(alarm_on_instance_1_vertex)
        graph.add_vertex(alarm_on_instance_2_vertex)
        graph.add_vertex(alarm_on_instance_3_vertex)
        graph.add_vertex(alarm_on_instance_4_vertex)

        # add links to graph
        for edge in edges:
            graph.add_edge(edge)

        return graph
예제 #50
0
    def test_neighbors(self):
        relationship_a = 'RELATIONSHIP_A'
        relationship_b = 'RELATIONSHIP_B'
        relationship_c = 'RELATIONSHIP_C'

        v1 = v_node
        v2 = v_host
        v3 = v_instance
        v4 = v_alarm
        v5 = utils.create_vertex(vitrage_id='kuku',
                                 vitrage_category=EntityCategory.RESOURCE,
                                 vitrage_type=NOVA_HOST_DATASOURCE)

        g = NXGraph('test_neighbors')
        g.add_vertex(v1)
        g.add_vertex(v2)
        g.add_vertex(v3)
        g.add_vertex(v4)
        g.add_vertex(v5)

        g.add_edge(
            utils.create_edge(source_id=v1.vertex_id,
                              target_id=v2.vertex_id,
                              relationship_type=relationship_a))
        g.add_edge(
            utils.create_edge(source_id=v1.vertex_id,
                              target_id=v2.vertex_id,
                              relationship_type=relationship_b))
        g.add_edge(
            utils.create_edge(source_id=v1.vertex_id,
                              target_id=v4.vertex_id,
                              relationship_type=relationship_a))
        g.add_edge(
            utils.create_edge(source_id=v1.vertex_id,
                              target_id=v4.vertex_id,
                              relationship_type=relationship_b))
        g.add_edge(
            utils.create_edge(source_id=v2.vertex_id,
                              target_id=v1.vertex_id,
                              relationship_type=relationship_c))
        g.add_edge(
            utils.create_edge(source_id=v2.vertex_id,
                              target_id=v3.vertex_id,
                              relationship_type=relationship_a))
        g.add_edge(
            utils.create_edge(source_id=v2.vertex_id,
                              target_id=v3.vertex_id,
                              relationship_type=relationship_b))
        g.add_edge(
            utils.create_edge(source_id=v2.vertex_id,
                              target_id=v4.vertex_id,
                              relationship_type=relationship_a))
        g.add_edge(
            utils.create_edge(source_id=v4.vertex_id,
                              target_id=v1.vertex_id,
                              relationship_type=relationship_c))

        # CHECK V1

        v1_neighbors = g.neighbors(v_id=v1.vertex_id)
        self._assert_set_equal({v2, v4}, v1_neighbors, 'Check V1 neighbors')

        v1_neighbors = g.neighbors(
            v_id=v1.vertex_id,
            vertex_attr_filter={VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE})
        self._assert_set_equal({v2}, v1_neighbors,
                               'Check V1 neighbors, vertex property filter')

        v1_neighbors = g.neighbors(
            v_id=v1.vertex_id,
            edge_attr_filter={EProps.RELATIONSHIP_TYPE: relationship_a})
        self._assert_set_equal({v2, v4}, v1_neighbors,
                               'Check V1 neighbors, edge property filter')

        v1_neighbors = g.neighbors(v_id=v1.vertex_id, direction=Direction.IN)
        self._assert_set_equal({v2, v4}, v1_neighbors,
                               'Check V1 neighbors, direction IN')

        v1_neighbors = g.neighbors(v_id=v1.vertex_id, direction=Direction.OUT)
        self._assert_set_equal({v2, v4}, v1_neighbors,
                               'Check V1 neighbors, direction OUT')

        v1_neighbors = g.neighbors(v_id=v1.vertex_id, direction=Direction.BOTH)
        self._assert_set_equal({v2, v4}, v1_neighbors,
                               'Check V1 neighbors, direction BOTH')

        v1_neighbors = g.neighbors(
            v_id=v1.vertex_id,
            direction=Direction.IN,
            edge_attr_filter={EProps.RELATIONSHIP_TYPE: relationship_c},
            vertex_attr_filter={VProps.VITRAGE_TYPE: NOVA_HOST_DATASOURCE})
        self._assert_set_equal(
            {v2}, v1_neighbors,
            'Check V1 neighbors, vertex/edge property filter and direction')

        # CHECK V2

        v2_neighbors = g.neighbors(v_id=v2.vertex_id)
        self._assert_set_equal({v1, v3, v4}, v2_neighbors,
                               'Check v2 neighbors')

        v2_neighbors = g.neighbors(
            v_id=v2.vertex_id,
            vertex_attr_filter={VProps.VITRAGE_CATEGORY: NOVA_HOST_DATASOURCE})
        self._assert_set_equal({}, v2_neighbors,
                               'Check v2 neighbors, vertex property filter')

        v2_neighbors = g.neighbors(v_id=v2.vertex_id,
                                   vertex_attr_filter={
                                       VProps.VITRAGE_CATEGORY:
                                       [NOVA_HOST_DATASOURCE, ALARM]
                                   })
        self._assert_set_equal({v4}, v2_neighbors,
                               'Check v2 neighbors, vertex property filter')

        v2_neighbors = g.neighbors(v_id=v2.vertex_id,
                                   edge_attr_filter={
                                       EProps.RELATIONSHIP_TYPE:
                                       [relationship_a, relationship_b]
                                   },
                                   vertex_attr_filter={
                                       VProps.VITRAGE_CATEGORY:
                                       [RESOURCE, ALARM],
                                       VProps.VITRAGE_TYPE: [
                                           NOVA_HOST_DATASOURCE,
                                           NOVA_INSTANCE_DATASOURCE,
                                           ALARM_ON_VM, ALARM_ON_HOST
                                       ]
                                   })
        self._assert_set_equal({v3, v4}, v2_neighbors,
                               'Check v2 neighbors, edge property filter')

        # CHECK V3

        v3_neighbors = g.neighbors(v_id=v3.vertex_id, direction=Direction.OUT)
        self._assert_set_equal({}, v3_neighbors,
                               'Check v3 neighbors, direction OUT')

        v3_neighbors = g.neighbors(
            v_id=v3.vertex_id,
            vertex_attr_filter={VProps.VITRAGE_CATEGORY: NOVA_HOST_DATASOURCE},
            direction=Direction.OUT)
        self._assert_set_equal({}, v3_neighbors,
                               'Check neighbors for vertex without any')
        v5_neighbors = g.neighbors(
            v_id=v5.vertex_id,
            vertex_attr_filter={VProps.VITRAGE_CATEGORY: NOVA_HOST_DATASOURCE})
        self._assert_set_equal({}, v5_neighbors,
                               'Check neighbors for not connected vertex')
예제 #51
0
    def test_edge_crud(self):
        g = create_graph('test_edge_crud')
        g.add_vertex(v_node)
        g.add_vertex(v_host)
        g.add_edge(e_node_to_host)
        self.assertEqual(1, g.num_edges(), 'graph __len__ after add edge')
        label = e_node_to_host[EProps.RELATIONSHIP_NAME]
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, label)
        self.assertEqual(e_node_to_host[EProps.RELATIONSHIP_NAME],
                         e[EProps.RELATIONSHIP_NAME],
                         'edge properties are saved')
        self.assertEqual(e_node_to_host.source_id, e.source_id,
                         'edge vertex_id is saved')
        self.assertEqual(e_node_to_host.target_id, e.target_id,
                         'edge vertex_id is saved')

        # Edge is correct
        v_node_neig = g.neighbors(v_node.vertex_id, direction=Direction.OUT)
        self.assertEqual(1, len(v_node_neig),
                         'v_node OUT neighbor count')
        self.assertEqual(v_host.vertex_id, v_node_neig.pop().vertex_id,
                         'v_node OUT neighbor is v_host')
        v_node_neig = g.neighbors(v_node.vertex_id, direction=Direction.IN)
        self.assertEqual(0, len(v_node_neig),
                         'v_node IN neighbor count')
        v_host_neig = g.neighbors(v_host.vertex_id, direction=Direction.OUT)
        self.assertEqual(0, len(v_host_neig),
                         'v_host OUT neighbor count')
        v_host_neig = g.neighbors(v_host.vertex_id, direction=Direction.IN)
        self.assertEqual(1, len(v_host_neig),
                         'v_host IN neighbor count')
        self.assertEqual(v_node.vertex_id, v_host_neig.pop().vertex_id,
                         'v_host IN neighbor is v_node')

        # Changing the referenced item
        updated_e = e
        updated_e[EProps.IS_DELETED] = 'KUKU'
        updated_e[EProps.UPDATE_TIMESTAMP] = 'CHANGED'

        # Get it again
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, label)
        self.assertFalse(e.get(EProps.IS_DELETED, None),
                         'Change should not affect graph item')
        self.assertEqual(e_node_to_host[EProps.UPDATE_TIMESTAMP],
                         e[EProps.UPDATE_TIMESTAMP],
                         'Change should not affect graph item')
        # Update the graph item and see changes take place
        g.update_edge(updated_e)
        # Get it again
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, label)
        self.assertEqual(updated_e[EProps.IS_DELETED],
                         e[EProps.IS_DELETED],
                         'Graph item should change after update')
        self.assertEqual(updated_e[EProps.UPDATE_TIMESTAMP],
                         e[EProps.UPDATE_TIMESTAMP],
                         'Graph item should change after update')

        # check metadata
        another_label = 'ANOTHER_LABEL'
        another_edge = utils.create_edge(
            source_id=v_node.vertex_id,
            target_id=v_host.vertex_id,
            relationship_type=another_label,
            metadata={'some_meta': 'DATA'})
        g.add_edge(another_edge)
        self.assertEqual(2, g.num_edges(), 'graph __len__ after add edge')
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, another_label)
        self.assertEqual(another_edge[EProps.RELATIONSHIP_NAME],
                         e[EProps.RELATIONSHIP_NAME],
                         'edge properties are saved')
        self.assertEqual('DATA', e['some_meta'],
                         'edge properties are saved')

        # Remove the item
        g.remove_edge(another_edge)
        self.assertEqual(1, g.num_edges(), 'graph __len__ after remove edge')
        e = g.get_edge(v_node.vertex_id, v_host.vertex_id, another_label)
        self.assertIsNone(e, 'removed edge not in graph')

        # Check get_edge returns None when item is missing
        edge = g.get_edge(v_host.vertex_id, 'ddd', '333')
        self.assertIsNone(edge)
        edge = g.get_edge('eee', v_node.vertex_id, '333')
        self.assertIsNone(edge)
        edge = g.get_edge(v_host.vertex_id, v_node.vertex_id, None)
        self.assertIsNone(edge)
        edge = g.get_edge(None, v_node.vertex_id, '333')
        self.assertIsNone(edge)
예제 #52
0
    def _create_entity_graph(self, name, num_of_alarms_per_host,
                             num_of_alarms_per_vm,
                             num_of_hosts_per_node,
                             num_of_vms_per_host,
                             num_of_tests_per_host):

        start = time.time()
        g = create_graph(name, EntityCategory.RESOURCE + ':' +
                         OPENSTACK_CLUSTER)
        g.add_vertex(v_node)
        g.add_vertex(v_switch)
        g.add_edge(e_node_to_switch)

        # Add Hosts
        for host_id in range(num_of_hosts_per_node):
            host_to_add = add_connected_vertex(g,
                                               RESOURCE,
                                               NOVA_HOST_DATASOURCE,
                                               host_id,
                                               ELabel.CONTAINS,
                                               v_node,
                                               True)

            g.add_edge(graph_utils.create_edge(host_to_add.vertex_id,
                                               v_switch.vertex_id, 'USES'))

            # Add Host Alarms
            for j in range(num_of_alarms_per_host):
                add_connected_vertex(g, ALARM, ALARM_ON_HOST,
                                     self.host_alarm_id, ELabel.ON,
                                     host_to_add)
                self.host_alarm_id += 1

            # Add Host Tests
            for j in range(num_of_tests_per_host):
                add_connected_vertex(g, TEST, TEST_ON_HOST, self.host_test_id,
                                     ELabel.ON, host_to_add)
                self.host_test_id += 1

            # Add Host Vms
            for j in range(num_of_vms_per_host):
                vm_to_add = add_connected_vertex(g,
                                                 RESOURCE,
                                                 NOVA_INSTANCE_DATASOURCE,
                                                 self.vm_id,
                                                 ELabel.CONTAINS,
                                                 host_to_add,
                                                 True)
                self.vm_id += 1
                self.vms.append(vm_to_add)

                # Add Instance Alarms
                for k in range(num_of_alarms_per_vm):
                    add_connected_vertex(g, ALARM, ALARM_ON_VM,
                                         self.vm_alarm_id, ELabel.ON,
                                         vm_to_add)
                    self.vm_alarm_id += 1

        end = time.time()
        LOG.debug('Graph creation took ' + str(end - start) +
                  ' seconds, size is: ' + str(len(g)))
        expected_graph_size = \
            2 + num_of_hosts_per_node + num_of_hosts_per_node * \
            num_of_alarms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host + num_of_hosts_per_node * \
            num_of_vms_per_host * num_of_alarms_per_vm + \
            num_of_tests_per_host * num_of_hosts_per_node
        assert expected_graph_size == len(g), 'Graph size'
        return g