Beispiel #1
0
    def _get_workload_subgraph(self, stack_name, ts_from=None, ts_to=None):
        res = None
        try:
            # Get the node ID for the stack_name and query the landscape

            properties = [("stack_name", stack_name)]
            try:
                time_window = ts_to - ts_from
            except:
                time_window = 600
            landscape_res = landscape.get_node_by_properties(
                properties, ts_from, time_window)

            if not landscape_res:
                LOG.info("No graph for a stack returned from analytics")
                # try a service name
                properties = [("service_name", stack_name)]
                landscape_res = landscape.get_node_by_properties(
                    properties, ts_from, time_window)
                if not landscape_res:
                    LOG.info("No graph for a service returned from analytics")
                    return None

            res = landscape.get_subgraph(landscape_res.nodes()[0], ts_from,
                                         time_window)
        except Exception as e:
            LOG.debug('Something went seriously wrong.')
            LOG.error(e)

        for node in res.nodes(data=True):
            attrs = InfoGraphNode.get_attributes(node)
            attrs = InfoGraphUtilities.str_to_dict(attrs)
            InfoGraphNode.set_attributes(node, attrs)
        return res
Beispiel #2
0
    def _get_compute_node_subgraph(self,
                                   compute_node,
                                   ts_from=None,
                                   ts_to=None):

        res = self.db.\
            get_subgraph('type', 'machine', timestamp=ts_to)

        for node in res.nodes(data=True):
            attrs = InfoGraphNode.get_attributes(node)
            attrs = InfoGraphUtilities.str_to_dict(attrs)
            InfoGraphNode.set_attributes(node, attrs)
        return res
Beispiel #3
0
    def get_node_subgraph(self, node_id, ts_from=None, ts_to=None):
        try:
            time_window = ts_to - ts_from
        except:
            time_window = 600
        landscape_res = landscape.get_subgraph(node_id, ts_from, time_window)

        for node in landscape_res.nodes(data=True):
            attrs = InfoGraphNode.get_attributes(node)
            attrs = InfoGraphUtilities.str_to_dict(attrs)
            InfoGraphNode.set_attributes(node, attrs)

        return landscape_res
Beispiel #4
0
    def extract_infrastructure_graph(workload_name, ts_from, ts_to):
        """
        Returns the entire landscape at the current time

        :return:
        """
        landscape_ip = ConfigHelper.get("LANDSCAPE", "host")
        landscape_port = ConfigHelper.get("LANDSCAPE", "port")
        subgraph_extraction = SubGraphExtraction(landscape_ip=landscape_ip,
                                                 landscape_port=landscape_port)
        # res = subgraph_extraction.get_workload_view_graph(
        #     workload_name, int(ts_from), int(ts_to),
        #     name_filtering_support=True)
        res = landscape.get_graph()
        #PARALLEL = True
        if PARALLEL:
            i = 0
            threads = []
            cpu_count = multiprocessing.cpu_count()
            all_node = res.nodes(data=True)
            no_node_thread = len(res.nodes()) / cpu_count
            node_pool = []

            for node in all_node:
                if i < no_node_thread:
                    node_pool.append(node)
                    i = i + 1
                else:
                    thread1 = ParallelLandscape(
                        i, "Thread-{}".format(InfoGraphNode.get_name(node)), i,
                        node_pool)
                    # thread1 = ParallelTelemetryAnnotation(i, "Thread-{}".format(InfoGraphNode.get_name(node)), i,
                    #                                       node_pool, internal_graph, self.telemetry, ts_to, ts_from)
                    thread1.start()
                    threads.append(thread1)
                    i = 0
                    node_pool = []
            if len(node_pool) != 0:
                thread1 = ParallelLandscape(
                    i, "Thread-{}".format(InfoGraphNode.get_name(node)), i,
                    node_pool)
                thread1.start()
                threads.append(thread1)

            [t.join() for t in threads]
        else:
            for node in res.nodes(data=True):
                attrs = InfoGraphNode.get_attributes(node)
                attrs = InfoGraphUtilities.str_to_dict(attrs)
                InfoGraphNode.set_attributes(node, attrs)
        return res
Beispiel #5
0
    def filter_graph(graph):
        """
        Returns the graph filtered removing all the nodes with no telemetry
        """
        template_mapping = dict()

        res = graph.copy()
        for node in res.nodes(data=True):
            # for p in node[1]['attributes']:
            #     p = str(p)
            template = node[1]['attributes']['template'] \
                if 'template' in node[1]['attributes'] else None

            # If node is a service node, need to remove the template
            if template:
                template_mapping[InfoGraphNode.get_name(node)] = template
                node[1]['attributes'].pop('template')

            # Fix format for conversion to JSON (happening in analytics)
            node[1]['attributes'] = \
                str(misc.convert_unicode_dict_to_string(node[1]['attributes'])).\
                    replace("'", '"')

        for node in res.nodes(data=True):
            node_name = InfoGraphNode.get_name(node)
            telemetry = InfoGraphNode.get_telemetry_data(node)
            layer = InfoGraphNode.get_layer(node)
            # if len(telemetry.columns.values) <= 1:

            if len(telemetry.columns) <= 1 and \
                    not layer == InfoGraphNodeLayer.SERVICE:
                InfoGraphNode.set_telemetry_data(node, dict())
                res.filter_nodes('node_name', node_name)

        # Convert attributes back to dict()
        for node in res.nodes(data=True):
            string = InfoGraphNode.get_attributes(node)
            attrs = InfoGraphUtilities.str_to_dict(string)
            if InfoGraphNode.get_type(node) == \
                    InfoGraphNodeType.SERVICE_COMPUTE:
                attrs['template'] = \
                    template_mapping[InfoGraphNode.get_name(node)]
            InfoGraphNode.set_attributes(node, attrs)
        return res
Beispiel #6
0
    def _get_network_subgraph(self, ts_from=None, ts_to=None):
        # TODO - URGENT: Wait for the network information to be in the graph and test this again
        properties = [
            ("type", "switch"),
        ]
        try:
            time_window = ts_to - ts_from
        except:
            time_window = 600
        landscape_res = landscape.get_node_by_properties(
            properties, ts_from, time_window)

        subgs = list()
        for lr in landscape_res:
            subgs.append(
                landscape.get_subgraph(lr.nodes()[0], ts_from, time_window))
            for subg in subgs:
                for node in subg.nodes(data=True):
                    attrs = InfoGraphNode.get_attributes(node)
                    attrs = InfoGraphUtilities.str_to_dict(attrs)
                    InfoGraphNode.set_attributes(node, attrs)
        return subgs
Beispiel #7
0
 def run(self):
     for node in self.node_pool:
         attrs = InfoGraphNode.get_attributes(node)
         attrs = InfoGraphUtilities.str_to_dict(attrs)
         InfoGraphNode.set_attributes(node, attrs)