Skip to content

Commit

Permalink
use isql-api to delete graph
Browse files Browse the repository at this point in the history
  • Loading branch information
xgaia committed Dec 17, 2019
1 parent c8f4a83 commit 102019c
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 3 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -16,10 +16,12 @@ matrix:
- docker pull askomics/virtuoso:7.2.5.1
- docker pull bgruening/galaxy-stable:19.01
- docker pull xgaia/corese:latest
- sudo docker run -d --name virtuoso -p 8891:8890 -e DBA_PASSWORD=dba -e SPARQL_UPDATE=true -e DEFAULT_GRAPH=http://localhost:8891/DAV -t askomics/virtuoso:7.2.5.1
- docker pull xgaia/isql-api:1.0.1
- sudo docker run -d --name virtuoso -p 8891:8890 -p 1112:1111 -e DBA_PASSWORD=dba -e SPARQL_UPDATE=true -e DEFAULT_GRAPH=http://localhost:8891/DAV -t askomics/virtuoso:7.2.5.1
- sudo docker run -d --name redis -p 6380:6379 -t redis:4.0
- sudo docker run -d --name galaxy -p 8081:80 -t bgruening/galaxy-stable:19.01
- sudo docker run -d --name corese -p 8082:8080 -t xgaia/corese:latest /bin/sh -c "netstat -nr | grep '^0\.0\.0\.0' | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | grep -v '^0\.0\.0\.0' | sed 's/$/ askomics-host/' >> /etc/hosts && /corese/start.sh"
- sudo docker run -d --name isql-api -p 5051:5050 -e VIRTUOSO_HOST=askomics-host -e VIRTUOSO_ISQL_PORT=1112 -t xgaia/isql-api:1.0.1 /bin/sh -c "netstat -nr | grep '^0\.0\.0\.0' | grep -oE '((1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.){3}(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])' | grep -v '^0\.0\.0\.0' | sed 's/$/ askomics-host/' >> /etc/hosts && sh /isqlapi/docker-run.sh"
- sleep 1m
script:
- flake8 askomics tests --ignore=E501,W504
Expand Down
33 changes: 31 additions & 2 deletions askomics/libaskomics/DatasetsHandler.py
@@ -1,3 +1,5 @@
import requests

from askomics.libaskomics.Database import Database
from askomics.libaskomics.Dataset import Dataset
from askomics.libaskomics.Params import Params
Expand Down Expand Up @@ -118,11 +120,38 @@ def delete_datasets_in_db(self):

database.execute_sql_query(query, (self.session['user']['id'], ) + tuple(datasets_id))

def delete_graph_isql(self, graph):
"""Delete graph using isql api of virtuoso
Parameters
----------
graph : str
Graph name to delete
"""
isqlapi = self.settings.get("triplestore", "isqlapi")
data = [
"log_enable(3,1)",
"SPARQL CLEAR GRAPH <{}>".format(graph)
]

requests.post(url=isqlapi, json=data)

def delete_datasets(self):
"""delete the datasets from the database and the triplestore"""
sparql = SparqlQueryLauncher(self.app, self.session)
for dataset in self.datasets:
# Delete from triplestore (3 try, 1-2 sec between them)
Utils.redo_if_failure(self.log, 3, 1, sparql.drop_dataset, dataset.graph_name)

# Use isql api if triplestore is virtuoso and api url is set in config file
triplestore = self.settings.get("triplestore", "triplestore")
isqlapi = None
try:
isqlapi = self.settings.get("triplestore", "isqlapi")
except Exception:
pass

if triplestore == "virtuoso" and isqlapi:
Utils.redo_if_failure(self.log, 3, 1, self.delete_graph_isql, dataset.graph_name)
else:
Utils.redo_if_failure(self.log, 3, 1, sparql.drop_dataset, dataset.graph_name)
# Delete from db
dataset.delete_from_db()
3 changes: 3 additions & 0 deletions config/askomics.ini.template
Expand Up @@ -50,6 +50,9 @@ triplestore = virtuoso
endpoint = http://localhost:8890/sparql
# Sparql updatepoint
updatepoint = http://localhost:8890/sparql
# Isql API
# If triplestore is virtuoso, set the (optional) isql api for fastest graph deletion
isqlapi = http://localhost:5050
# If triplestore is fuseki, set the upload url
# fuseki_upload_url = http://localhost:3030/database/upload
# Triplestore credentials
Expand Down
3 changes: 3 additions & 0 deletions config/askomics.test.ini
Expand Up @@ -43,6 +43,9 @@ triplestore = virtuoso
endpoint = http://localhost:8891/sparql
# Sparql updatepoint
updatepoint = http://localhost:8891/sparql
# Isql API
# If triplestore is virtuoso, set the (optional) isql api for fastest graph deletion
isqlapi = http://localhost:5051
# If triplestore is fuseki, set the upload url
# fuseki_upload_url = http://localhost:3030/database/upload
# Triplestore credentials
Expand Down

0 comments on commit 102019c

Please sign in to comment.