Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/lazaroDevelop' into lazaroDevelop
Browse files Browse the repository at this point in the history
  • Loading branch information
lazarocosta committed May 26, 2020
2 parents cb10cc4 + a125722 commit 830592d
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 22 deletions.
14 changes: 13 additions & 1 deletion conf/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,19 @@ nvm use v10
echo "Starting archgraph server at $ROOT_DIR"
cd "$ROOT_DIR"

python "$ROOT_DIR/src/Routes/routes.py" --neo4j="$NEO4J_CONNECTION_STRING" --mongodb="$MONGODB_CONNECTION_STRING" &
if [[ "$NEO4J_CONNECTION_STRING" != "" ]]; then
echo "Neo4j Server at $NEO4J_CONNECTION_STRING";
fi

if [[ "$MONGODB_CONNECTION_STRING" != "" ]]; then
echo "MongoDB Server at $MONGODB_CONNECTION_STRING";
fi

if [[ "$CUSTOM_HOST_FOR_SERVER_BIND" != "" ]]; then
echo "Flask Server binding to host with address $CUSTOM_HOST_FOR_SERVER_BIND";
fi

python "$ROOT_DIR/src/Routes/routes.py" --neo4j="$NEO4J_CONNECTION_STRING" --mongodb="$MONGODB_CONNECTION_STRING" --host="$CUSTOM_HOST_FOR_SERVER_BIND" &
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 @@ -35,8 +35,9 @@ services:
PRELOAD_GRAPH: "true"
context: .
environment:
- "NEO4J_CONNECTION_STRING=bolt://neo4j:password@neo4j:7687"
- "MONGODB_CONNECTION_STRING=mongodb://root:rootpassword@mongodb:27017"
- "NEO4J_CONNECTION_STRING=bolt://neo4j:password@archgraph-neo4j:7687"
- "MONGODB_CONNECTION_STRING=mongodb://root:rootpassword@archgraph-mongodb:27017"
- "CUSTOM_HOST_FOR_SERVER_BIND=0.0.0.0"
- "RUN_IN_PRODUCTION=1"
ports:
- published: 4200
Expand Down
22 changes: 13 additions & 9 deletions src/Routes/mongo.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import json
from datetime import datetime
from pymongo import MongoClient
import argparse
from pymongo import MongoClient, uri_parser

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()
import src.Utils.ArgParser as ArgParser
args = ArgParser.parse()

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

if args.mongodb is not None and args.mongodb != "":
# mongodb_arguments = uri_parser.parse_uri(args.mongodb)
# client = MongoClient(host=mongodb_arguments.nodelist.first(),
# port= mongodb_arguments.port,
# username=mongodb_arguments.username,
# password=mongodb_arguments.password,
# server_selection_timeout=1
# )
MONGODB_URL = args.mongodb
else:
MONGODB_URL = "mongodb://root:rootpassword@localhost:27017"

client = MongoClient(MONGODB_URL)
db = client.mydatabase
Expand Down
32 changes: 22 additions & 10 deletions src/Routes/routes.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import json
from pathlib import Path
import os, sys
import argparse


# returns the project root path (assumes that the script is started from src/Routes/routes.py)
Expand All @@ -15,10 +14,6 @@ def get_project_root():
print("Archgraph running at " + get_project_root().as_posix())
sys.path.append(get_project_root().as_posix())

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 @@ -28,20 +23,35 @@ def get_project_root():
from src.Utils.JsonEncoder import search_cidoc, search_specific_cidoc
from src.Utils.Utils import get_node_by_uid, build_next_json, updated_node, make_result

if args.neo4j:
import src.Utils.ArgParser as ArgParser
args = ArgParser.parse()

if args.neo4j and args.neo4j != "":
config.DATABASE_URL = args.neo4j
else:
config.DATABASE_URL = "bolt://neo4j:password@localhost:7687"

from src.Routes.mongo import insert_template_in_mongo, get_all_records_from_collection, get_schema_from_mongo, \
get_templates_from_mongo_by_classes_name
from src.Routes.mongo import insert_template_in_mongo, get_all_records_from_collection, get_schema_from_mongo, get_templates_from_mongo_by_classes_name

app = Flask(__name__)

CORS(app)
cors = CORS(app, resources={r"/*": {"origins": "*"}})
app = Flask(__name__, static_url_path="")
app.debug = True

@app.before_request
def log_request_info():
app.logger.debug('Headers: %s', request.headers)
app.logger.debug('Body: %s', request.get_data())

@app.after_request
def after(response):
# todo with response
print(response.status)
print(response.headers)
print(response.get_data())
return response

@app.route("/favicon.ico")
def favicon():
Expand Down Expand Up @@ -234,6 +244,8 @@ def search_specific(class_name, query):
# json = read_file("../Utils/defaultTemplates.json")
# populate_template_collection(json)
# get_all_records_from_collection("createdTemplate")

if __name__ == "__main__":
app.run(host='127.0.0.1')
if args.host is not None and args.host != "":
app.run(host=args.host)
else:
app.run(host='127.0.0.1')
16 changes: 16 additions & 0 deletions src/Utils/ArgParser.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import argparse


def parse():
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")
parser.add_argument("--host", nargs="?", help="Address of the neo4j server")

args = parser.parse_args()

return args


class ArgParser:
pass

0 comments on commit 830592d

Please sign in to comment.