Skip to content
Snippets Groups Projects
Commit 477df334 authored by Nikolay Stanchev's avatar Nikolay Stanchev
Browse files

Implements and tests an addition to the response of the build request for a...

Implements and tests an addition to the response of the build request for a temporal graph - now the list of endpoints is also returned
parent 32fd433b
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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):
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment