From 0a93354f295031dfe0abdaf9ba5d1eb64dc2f12f Mon Sep 17 00:00:00 2001 From: Nikolay Stanchev <ns17@it-innovation.soton.ac.uk> Date: Fri, 22 Feb 2019 15:10:26 +0000 Subject: [PATCH] Updates graph-pipeline script and modifies install script to copy pipeline script in /usr/local/bin --- .../{test/pipeline.sh => clmc-service/graph-pipeline.sh} | 1 + scripts/clmc-service/install-clmc-service.sh | 5 ++++- src/service/clmcservice/graphapi/tests.py | 4 ++-- src/service/clmcservice/graphapi/views.py | 8 ++++++-- 4 files changed, 13 insertions(+), 5 deletions(-) rename scripts/{test/pipeline.sh => clmc-service/graph-pipeline.sh} (98%) diff --git a/scripts/test/pipeline.sh b/scripts/clmc-service/graph-pipeline.sh similarity index 98% rename from scripts/test/pipeline.sh rename to scripts/clmc-service/graph-pipeline.sh index 6042ce8..1f03150 100644 --- a/scripts/test/pipeline.sh +++ b/scripts/clmc-service/graph-pipeline.sh @@ -37,6 +37,7 @@ read query_period db_name results_measurement <<< ${fields} JSON_CONFIG=$(echo ${JSON_CONFIG} | jq 'del(.query_period, .results_measurement_name)') +# TODO this shouldn't be in the script maybe move it to the clmc isntall script echo "Building network subgraph..." response=$(curl -s -X POST http://${CLMC_IP}/clmc-service/graph/network) echo ${response} diff --git a/scripts/clmc-service/install-clmc-service.sh b/scripts/clmc-service/install-clmc-service.sh index a815007..83cefd1 100755 --- a/scripts/clmc-service/install-clmc-service.sh +++ b/scripts/clmc-service/install-clmc-service.sh @@ -35,7 +35,7 @@ sudo -u postgres bash -c "psql -c \"GRANT ALL PRIVILEGES ON DATABASE \"whoamidb\ # install virtualenvwrapper to manage python environments - and check echo "----> Installing Python3, Pip3 and curl" -apt-get install -y python3 python3-pip curl +apt-get install -y python3 python3-pip curl jq update-alternatives --install /usr/bin/python python /usr/bin/python3 10 echo "----> Installing virtualenv and wrapper" @@ -161,3 +161,6 @@ done apt-get install nginx -y 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 diff --git a/src/service/clmcservice/graphapi/tests.py b/src/service/clmcservice/graphapi/tests.py index 70e0464..78ec6b5 100644 --- a/src/service/clmcservice/graphapi/tests.py +++ b/src/service/clmcservice/graphapi/tests.py @@ -529,7 +529,7 @@ class TestGraphAPI(object): response = GraphAPI(request).execute_graph_pipeline() assert response == {"uuid": uuid_mock.return_value, "database": "test_sfc"} - popen_mock.assert_called_once_with(["./graph_pipeline.sh", body]) # assert that the graph pipeline script is ran with the JSON config that was received in the request + popen_mock.assert_called_once_with(["graph-pipeline.sh", body]) # assert that the graph pipeline script is ran with the JSON config that was received in the request pid_property_mock.assert_called_once_with() # assert that the process ID attribute was called and saved returncode_property_mock.assert_called_once_with() # assert that the process return code attribute was called to check if the process has started successfully @@ -544,7 +544,7 @@ class TestGraphAPI(object): error_raised = True assert error_raised, "Expecting a 500 HTTP error if the process terminated immediately after it was started" - popen_mock.assert_called_with(["./graph_pipeline.sh", body]) # assert that the graph pipeline script is ran with the JSON config that was received in the request + popen_mock.assert_called_with(["graph-pipeline.sh", body]) # assert that the graph pipeline script is ran with the JSON config that was received in the request pid_property_mock.assert_called_with() # assert that the process ID attribute was called and saved returncode_property_mock.assert_called_with() # assert that the process return code attribute was called to check if the process has started successfully diff --git a/src/service/clmcservice/graphapi/views.py b/src/service/clmcservice/graphapi/views.py index 041232d..e562bdf 100644 --- a/src/service/clmcservice/graphapi/views.py +++ b/src/service/clmcservice/graphapi/views.py @@ -154,7 +154,11 @@ class GraphAPI(object): 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] + try: + result = data[0] + except Exception as e: + log.error("Unexpected error occurred while executing RTT cypher query for graph with UUID {0} - {1}".format(graph_id, e)) + raise HTTPBadRequest("The Neo4j cypher query didn't return a valid result for the temporal graph with ID {0}".format(graph_id)) sf_node = graph.match(nodes=(None, endpoint_node), r_type="realisedBy").first().start_node if sf_node is None: @@ -362,7 +366,7 @@ class GraphAPI(object): request_uuid = str(uuid4()) sfc = json_queries["service_function_chain"] - process = Popen(["./graph_pipeline.sh", body]) + process = Popen(["graph-pipeline.sh", body]) process_pid = process.pid process_return_code = process.returncode -- GitLab