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

Updates the graph API to remove any caches before executing the functionality of an API endpoint

parent c7659ac9
No related branches found
No related tags found
No related merge requests found
......@@ -163,4 +163,5 @@ cp ${REPO_ROOT}/scripts/clmc-service/nginx.conf /etc/nginx/nginx.conf
systemctl restart nginx # nginx is already started on installation, to read the new conf it needs to be restarted
# move the graph pipeline script
cp ${REPO_ROOT}/scripts/clmc-service/graph-pipeline.sh /usr/local/bin/
\ No newline at end of file
cp ${REPO_ROOT}/scripts/clmc-service/graph-pipeline.sh /usr/local/bin/
chmod u+x /usr/local/bin/graph-pipeline.sh
\ No newline at end of file
......@@ -203,6 +203,9 @@ def graph_network_topology():
global links, switches, clusters
graph = Graph(host="localhost", password="admin")
graph.node_cache.clear()
graph.relationship_cache.clear()
build_network_graph(graph, switches, links, clusters, ues)
yield
......
......@@ -73,7 +73,7 @@ class GraphAPI(object):
except AssertionError as e:
raise HTTPBadRequest("Bad request content: {0}".format(e.args))
graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password'])
graph = self.get_graph_reference()
influx_client = InfluxDBClient(host=self.request.registry.settings['influx_host'], port=self.request.registry.settings['influx_port'], timeout=10)
database_name = json_queries["service_function_chain"]
......@@ -102,7 +102,7 @@ class GraphAPI(object):
"""
graph_id = self.request.matchdict['graph_id'] # get the UUID of the subgraph from the URL
graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password']) # connect to the neo4j graph db
graph = self.get_graph_reference()
if graph.nodes.match("Reference", uuid=graph_id).first() is None:
raise HTTPNotFound("No subgraph found associated with the request ID {0}".format(graph_id))
......@@ -121,7 +121,7 @@ class GraphAPI(object):
"""
sfc_id = self.request.matchdict['sfc_id'] # get the SFC identifier from the URL
graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password']) # connect to the neo4j graph db
graph = self.get_graph_reference()
# check if this SFC node exists
sfc_node = graph.nodes.match("ServiceFunctionChain", name=sfc_id).first()
......@@ -162,7 +162,7 @@ class GraphAPI(object):
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
graph = self.get_graph_reference()
all_nodes = graph.nodes
......@@ -260,7 +260,7 @@ class GraphAPI(object):
:return: A JSON response with the number of switches, clusters and ues that were built.
"""
graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password']) # connect to the neo4j graph db
graph = self.get_graph_reference()
sdn_controller_ip = self.request.registry.settings['sdn_controller_ip']
sdn_controller_port = self.request.registry.settings['sdn_controller_port']
......@@ -360,7 +360,7 @@ class GraphAPI(object):
:return: A JSON response with the number of switches, clusters and ues that were deleted.
"""
graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password']) # connect to the neo4j graph db
graph = self.get_graph_reference()
deleted_switches, deleted_clusters, deleted_ues = delete_network_graph(graph)
......@@ -388,7 +388,8 @@ class GraphAPI(object):
raise HTTPBadRequest("Database for service function chain {0} not found.".format(database_name))
# get the list of UEs from the Neo4j graph - if no UEs are found, the network topology has not been built yet, so return bad request
graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password'])
graph = self.get_graph_reference()
ue_nodes = graph.nodes.match("UserEquipment")
ues_list = [ue_node["name"] for ue_node in ue_nodes]
# return bad request for empty list of UEs
......@@ -440,3 +441,19 @@ class GraphAPI(object):
MonitoringProcess.delete(request_id)
return response
def get_graph_reference(self):
"""
A utility function to get a Graph DB object reference and clear the cache of py2neo since it might lead to erroneous behaviour
:return: reference to the graph DB object
"""
graph = Graph(host=self.request.registry.settings['neo4j_host'], password=self.request.registry.settings['neo4j_password'])
# TODO we probably need to remove the caching functionality of py2neo and maintain our own version
# NOTE: make sure Py2neo caching is disabled!
graph.node_cache.clear()
graph.relationship_cache.clear()
return graph
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