From 477df334d8f682bcf8e0988b2334a06419732df1 Mon Sep 17 00:00:00 2001 From: Nikolay Stanchev <ns17@it-innovation.soton.ac.uk> Date: Thu, 21 Feb 2019 14:07:24 +0000 Subject: [PATCH] Implements and tests an addition to the response of the build request for a temporal graph - now the list of endpoints is also returned --- src/service/clmcservice/graphapi/tests.py | 2 ++ src/service/clmcservice/graphapi/utilities.py | 8 +++++--- src/service/clmcservice/graphapi/views.py | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/service/clmcservice/graphapi/tests.py b/src/service/clmcservice/graphapi/tests.py index c06d4af..70e0464 100644 --- a/src/service/clmcservice/graphapi/tests.py +++ b/src/service/clmcservice/graphapi/tests.py @@ -144,6 +144,7 @@ class TestGraphAPI(object): assert graph_subresponse["uuid"] == self.graph_1_test_id, "Request UUID must be attached to the response." assert graph_subresponse["time_range"]["from"] == from_timestamp * 10**9 # timestamp returned in nanoseconds assert graph_subresponse["time_range"]["to"] == to_timestamp * 10**9 # timestamp returned in nanoseconds + assert set(graph_subresponse["endpoints"]) == {"minio_1_ep1", "nginx_1_ep1", "nginx_1_ep2"}, "Wrong list of new endpoints was returned by the build request" request_id = graph_subresponse["uuid"] # check that the appropriate nodes have been created @@ -208,6 +209,7 @@ class TestGraphAPI(object): assert graph_subresponse["uuid"] == self.graph_2_test_id, "Request UUID must be attached to the response." assert graph_subresponse["time_range"]["from"] == from_timestamp * 10**9 # timestamp returned in nanoseconds assert graph_subresponse["time_range"]["to"] == to_timestamp * 10**9 # timestamp returned in nanoseconds + assert set(graph_subresponse["endpoints"]) == {"minio_2_ep1", "apache_1_ep1"}, "Wrong list of new endpoints was returned by the build request" request_id = graph_subresponse["uuid"] # check the new nodes have been created diff --git a/src/service/clmcservice/graphapi/utilities.py b/src/service/clmcservice/graphapi/utilities.py index 2988c19..a974698 100644 --- a/src/service/clmcservice/graphapi/utilities.py +++ b/src/service/clmcservice/graphapi/utilities.py @@ -221,6 +221,8 @@ def build_temporal_subgraph(request_id, from_timestamp, to_timestamp, json_queri :param json_queries: the JSON object containing the query data for each service function :param graph: the graph DB object :param influx_client: the influx DB client object + + :return: the list of names of the endpoint nodes related to the new temporal graph """ global INFLUX_QUERY_TEMPLATE @@ -243,7 +245,7 @@ def build_temporal_subgraph(request_id, from_timestamp, to_timestamp, json_queri # create a instanceOf edge if it doesn't exist find_or_create_edge(graph, "instanceOf", service_function_chain_instance_node, service_function_chain_node) - compute_nodes = set() # a set is used to keep track of all compute nodes that are found while building the graph, which is then used to retrieve the network latencies + endpoints_names = set() # keep track of the names of the endpoint nodes that are created # traverse the list of service functions for service_function_package in json_queries["service_functions"]: @@ -291,15 +293,15 @@ def build_temporal_subgraph(request_id, from_timestamp, to_timestamp, json_queri ipendpoint_node = find_or_create_node(graph, "Endpoint", name=tags["flame_sfe"], response_time=response_time, request_size=request_size, response_size=response_size, uuid=request_id) # create an edge between the service function and the endpoint (if it is not already created) find_or_create_edge(graph, "realisedBy", service_function_node, ipendpoint_node) + endpoints_names.add(tags["flame_sfe"]) # create a Cluster node from the tag value (if it is not already created) compute_node = find_or_create_node(graph, "Cluster", name=tags["flame_location"]) # create an edge between the endpoint and the compute node (if it is not already created) find_or_create_edge(graph, "hostedBy", ipendpoint_node, compute_node) - compute_nodes.add(compute_node) # add the compute node to the set of compute nodes - log.info("Finished building graph for service function chain {0} from database {1} with retention policy {2}".format(sfci, db, rp)) + return list(endpoints_names) def delete_temporal_subgraph(graph, subgraph_id): diff --git a/src/service/clmcservice/graphapi/views.py b/src/service/clmcservice/graphapi/views.py index 4cf2610..041232d 100644 --- a/src/service/clmcservice/graphapi/views.py +++ b/src/service/clmcservice/graphapi/views.py @@ -82,9 +82,9 @@ class GraphAPI(object): request_id = str(uuid4()) - build_temporal_subgraph(request_id, from_timestamp, to_timestamp, json_queries, graph, influx_client) + endpoints_names = build_temporal_subgraph(request_id, from_timestamp, to_timestamp, json_queries, graph, influx_client) - json_response = {"database": database_name, 'graph': {"uuid": request_id, "time_range": {"from": from_timestamp, "to": to_timestamp}}} + json_response = {"database": database_name, 'graph': {"uuid": request_id, "endpoints": endpoints_names, "time_range": {"from": from_timestamp, "to": to_timestamp}}} return json_response -- GitLab