diff --git a/analysisstore/ignition.py b/analysisstore/ignition.py index ee89a02..694fe06 100644 --- a/analysisstore/ignition.py +++ b/analysisstore/ignition.py @@ -37,12 +37,12 @@ def start_server(config=None): parser = argparse.ArgumentParser() parser.add_argument('--database', dest='database', type=str, help='name of database to use') - parser.add_argument('--mongo-uri', + parser.add_argument('--mongo_uri', dest='mongo_uri', type=str, help='uri of Mongo DB') parser.add_argument('--timezone', dest='timezone', type=str, help='Local timezone') - parser.add_argument('--service-port', dest='service_port', type=int, + parser.add_argument('--service_port', dest='service_port', type=int, help='port listen to for clients') parser.add_argument('--log-file_prefix', dest='log_file_prefix', type=str, help='Log file name that tornado logs are dumped') diff --git a/analysisstore/server/astore.py b/analysisstore/server/astore.py index 81c964f..9bf17f7 100644 --- a/analysisstore/server/astore.py +++ b/analysisstore/server/astore.py @@ -1,7 +1,9 @@ from pymongo import MongoClient, DESCENDING +import pymongo import jsonschema import json import six +from .utils import AnalysisstoreException class AStore: @@ -16,7 +18,12 @@ def __init__(self, config, testing=False): uri in string format, and database """ if not testing: - self.client = MongoClient(config["uri"]) + try: + self.client = MongoClient(config["uri"]) + # Proactively check that connection to server is working. + self.client.server_info() + except (pymongo.errors.ConnectionFailure, pymongo.errors.ServerSelectionTimeoutError): + raise AnalysisstoreException("Unable to connect to MongoDB server...") else: import mongomock diff --git a/analysisstore/server/utils.py b/analysisstore/server/utils.py index bc1fc3c..b647eed 100644 --- a/analysisstore/server/utils.py +++ b/analysisstore/server/utils.py @@ -5,6 +5,9 @@ import ujson import pymongo.cursor +class AnalysisstoreException(Exception): + pass + SCHEMA_PATH = 'schemas' SCHEMA_NAMES = {'analysis_header': 'analysis_header.json', @@ -73,4 +76,4 @@ def return2client(handler, payload): except StopIteration: break handler.write(']') - handler.finish() \ No newline at end of file + handler.finish() diff --git a/analysisstore/test/testing.py b/analysisstore/test/testing.py index ad10460..1517e45 100644 --- a/analysisstore/test/testing.py +++ b/analysisstore/test/testing.py @@ -19,11 +19,11 @@ def astore_setup(): f = os.path.dirname(os.path.realpath(__file__)) proc = Popen(["python", "../startup.py", - "--mongo-uri", + "--mongo_uri", str(TESTING_CONFIG['mongouri']), "--database", TESTING_CONFIG['database'], "--timezone", TESTING_CONFIG['timezone'], - "--service-port", + "--service_port", str(TESTING_CONFIG['serviceport'])], cwd=f) ttime.sleep(1.3) # make sure the process is started return proc