diff --git a/src/service/clmcservice/graphapi/utilities.py b/src/service/clmcservice/graphapi/utilities.py index 95ff87e3a13260073c60705a51b3e8e17937cb61..4117b22976ef8330c69c9599ab810fae3d0d7520 100644 --- a/src/service/clmcservice/graphapi/utilities.py +++ b/src/service/clmcservice/graphapi/utilities.py @@ -27,7 +27,7 @@ from py2neo import Node, Relationship import logging -GRAPH_ROUND_TRIP_TIME_URL_PARAMS = ("compute_node", "endpoint") +GRAPH_ROUND_TRIP_TIME_URL_PARAMS = ("startpoint", "endpoint") GRAPH_BUILD_URL_PARAMS = ("from", "to") GRAPH_BUILD_QUERY_PARAMS = {"service_function_chain", "service_function_chain_instance", "service_functions"} @@ -38,8 +38,8 @@ INFLUX_QUERY_TEMPLATE = 'SELECT {0} AS mean_response_time, {1} AS mean_request_s # in cypher the syntax is {name: 'value'}, here we use {{name: 'value'}} to escape the curly braces when applying the python format function RTT_CYPHER_QUERY_TEMPLATE = """ -MATCH (dc:Cluster {{ name: '{0}' }}),(endpoint:Endpoint {{ name: '{1}', uuid: '{2}'}}), -path = shortestPath((dc)-[*]-(endpoint)) +MATCH (startpoint:{0} {{ name: '{1}' }}),(endpoint:Endpoint {{ name: '{2}', uuid: '{3}'}}), +path = shortestPath((startpoint)-[*]-(endpoint)) WHERE ALL(r IN relationships(path) WHERE type(r)='linkedTo' or type(r)='hostedBy' ) WITH extract(y in filter(x in relationships(path) WHERE type(x) = 'linkedTo') | y.latency) as latencies, endpoint.response_time as response_time, endpoint.request_size as request_size, endpoint.response_size as response_size RETURN latencies as forward_latencies, reverse(latencies) as reverse_latencies, response_time, request_size, response_size diff --git a/src/service/clmcservice/graphapi/views.py b/src/service/clmcservice/graphapi/views.py index 15cf0702c027ea4821f1e3f0ee1430c086e68728..b60ccf2e2c1d6cd1c4a9897552fe2a4d8525bc80 100644 --- a/src/service/clmcservice/graphapi/views.py +++ b/src/service/clmcservice/graphapi/views.py @@ -125,7 +125,7 @@ class GraphAPI(object): except AssertionError as e: raise HTTPBadRequest("Request URL format is incorrect: {0}".format(e.args)) - compute_node_label = params["compute_node"] + startpoint_node_label = params["startpoint"] endpoint_node_label = params["endpoint"] graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password']) # connect to the neo4j graph db @@ -136,24 +136,20 @@ class GraphAPI(object): if reference_node is None: raise HTTPNotFound("No subgraph found associated with the request ID {0}".format(graph_id)) - compute_node = all_nodes.match("Cluster", name=compute_node_label).first() - if compute_node is None: - raise HTTPNotFound("Compute node {0} doesn't exist.".format(compute_node_label)) + startpoint_node = all_nodes.match("Switch", "Cluster", name=startpoint_node_label).first() # match a switch or cluster node as a path start point + if startpoint_node is None: + raise HTTPNotFound("Starting point node {0} doesn't exist.".format(startpoint_node_label)) endpoint_node = all_nodes.match("Endpoint", name=endpoint_node_label, uuid=graph_id).first() if endpoint_node is None: raise HTTPNotFound("Endpoint node {0} doesn't exist.".format(endpoint_node_label)) - # check if the endpoint is hosted by the compute node before running the RTT cypher query - hosted_by_node = graph.relationships.match(nodes=(endpoint_node, None), r_type="hostedBy").first().end_node - if hosted_by_node["name"] == compute_node["name"]: - result = {"forward_latencies": [], "reverse_latencies": [], "response_time": endpoint_node["response_time"], - "request_size": endpoint_node["request_size"], "response_size": endpoint_node["response_size"]} - else: - query_to_execute = RTT_CYPHER_QUERY_TEMPLATE.format(compute_node_label, endpoint_node_label, graph_id) - log.info("Executing cypher query: {0}".format(query_to_execute)) - data = graph.run(query_to_execute).data() # returns a list of dictionaries, each dictionary represents a row in the result - result = data[0] + startpoint_node_type = "Cluster" if startpoint_node.has_label("Cluster") else "Switch" + + query_to_execute = RTT_CYPHER_QUERY_TEMPLATE.format(startpoint_node_type, startpoint_node_label, endpoint_node_label, graph_id) + log.info("Executing cypher query: {0}".format(query_to_execute)) + data = graph.run(query_to_execute).data() # returns a list of dictionaries, each dictionary represents a row in the result + result = data[0] sf_node = graph.match(nodes=(None, endpoint_node), r_type="realisedBy").first().start_node if sf_node is None: