Skip to content

Commit

Permalink
Merge pull request #75 from feup-infolab/lazaroDevelop
Browse files Browse the repository at this point in the history
Lazaro develop
  • Loading branch information
lazarocosta authored May 8, 2020
2 parents 0b374cc + 79418fb commit 789e991
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 20 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
FROM ubuntu:18.04 as dependencies_ready
ENV PRELOAD_GRAPH ""
ARG PRELOAD_GRAPH
ENV PRELOAD_GRAPH "$PRELOAD_GRAPH"

RUN apt-get update -qq
RUN apt-get install -y -qq git curl wget build-essential
Expand Down
4 changes: 3 additions & 1 deletion conf/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ npm config set python "$PYTHON27_PATH"
npm install

# preload graph
if [ "$PRELOAD_GRAPH" != "" ] ; then
if [ -z "$PRELOAD_GRAPH" ] ; then
echo "Preload graph flag is not active, skipping tests"
else
echo "Preload graph flag is active, loading graph through tests"
coverage run -m unittest discover test || true
fi
2 changes: 1 addition & 1 deletion conf/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ nvm use v10
echo "Starting archgraph server at $ROOT_DIR"
cd "$ROOT_DIR"

python "$ROOT_DIR/src/Routes/routes.py" --neo4j="$NEO4J_CONNECTION_STRING" &
python "$ROOT_DIR/src/Routes/routes.py" --neo4j="$NEO4J_CONNECTION_STRING" --mongodb="$MONGODB_CONNECTION_STRING" &
SERVER_PID=$!
cd "$ROOT_DIR/frontend" || ( echo "folder missing " && exit 1 )
if [[ "$RUN_IN_PRODUCTION" != "" ]] ; then
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@ services:
build:
dockerfile: Dockerfile
args:
- "SOURCE_BRANCH=master"
- "PRELOAD_GRAPH=1"
SOURCE_BRANCH: master
PRELOAD_GRAPH: "true"
context: .
environment:
- "NEO4J_CONNECTION_STRING=bolt://neo4j:password@neo4j:7687"
- "MONGODB_CONNECTION_STRING=mongodb://root:rootpassword@mongodb:27017"
- "RUN_IN_PRODUCTION=1"
ports:
- published: 4200
Expand Down
14 changes: 13 additions & 1 deletion src/Routes/mongo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
import json
from datetime import datetime
from pymongo import MongoClient
import argparse

client = MongoClient(port=27017, username="root", password="rootpassword")
parser = argparse.ArgumentParser(description="Starts the archgraph server.")
parser.add_argument("--mongodb", nargs="?", help="Address of the mongodb server")
parser.add_argument("--neo4j", nargs="?", help="Address of the neo4j server")

args = parser.parse_args()

if args.mongodb is not None:
MONGODB_URL = args.mongodb
else:
MONGODB_URL = "mongodb://root:rootpassword@localhost:27017"

client = MongoClient(MONGODB_URL)
db = client.mydatabase
date_now = datetime.now().strftime("%Y-%m-%d, %H:%M:%S")

Expand Down
13 changes: 5 additions & 8 deletions src/Routes/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,9 @@ def get_project_root():
print("Archgraph running at " + get_project_root().as_posix())
sys.path.append(get_project_root().as_posix())

from src.Routes.mongo import insert_template_in_mongo, get_all_records_from_collection, update_data_in_mongo, \
get_record_from_collection, add_record_to_collection, get_schema_from_mongo, \
delete_collection, get_templates_from_mongo_by_classes_name

parser = argparse.ArgumentParser(description="Starts the archgraph server.")

parser.add_argument("--neo4j", nargs="?", help="Address of the neo4j server")

parser.add_argument("--mongodb", nargs="?", help="Address of the mongodb server")

args = parser.parse_args()

from flask import Flask, Response, jsonify, make_response, request, send_from_directory
Expand All @@ -38,6 +31,10 @@ def get_project_root():
else:
config.DATABASE_URL = "bolt://neo4j:password@localhost:7687"

from src.Routes.mongo import insert_template_in_mongo, get_all_records_from_collection, update_data_in_mongo, \
get_record_from_collection, add_record_to_collection, get_schema_from_mongo, \
delete_collection, get_templates_from_mongo_by_classes_name

app = Flask(__name__)

CORS(app)
Expand Down Expand Up @@ -247,4 +244,4 @@ def search_specific(class_name, query):
# get_all_records_from_collection("createdTemplate")

if __name__ == "__main__":
app.run()
app.run(host='0.0.0.0')
9 changes: 3 additions & 6 deletions test/Unit/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,12 @@ def test_insert_template(self):
"has_value": "DataObject",
}
}
template2 = {'E52_Time_Span': {'P86_falls_within': 'E52_Time_Span'}}
template3 = {'E52_Time_Span': {}}
class_name =['E52_Time_Span', 'E1_CRM_Entity']
class_name = ['E52_Time_Span', 'E1_CRM_Entity']
schema = e52.get_schema_with_template(template)
schema2 = e52.get_schema_with_template(template2)
schema3 = e52.get_schema_with_template(template3)
templates = [{"classes_name": class_name, "template": template, "schema": json.dumps(schema) },
{"classes_name": class_name, "template": template2, "schema": json.dumps(schema2) },
{"classes_name": class_name, "template": template3, "schema": json.dumps(schema3) }]
templates = [{"classes_name": class_name, "template": template, "schema": json.dumps(schema)},
{"classes_name": class_name, "template": template3, "schema": json.dumps(schema3)}]
insert_default_templates(templates)
get_all_records_from_collection("defaultTemplate")

Expand Down

0 comments on commit 789e991

Please sign in to comment.