From 6e32b87d77e8f9100f103bf41029473ee9e8c8ff Mon Sep 17 00:00:00 2001 From: Jun Aishima Date: Wed, 6 Mar 2024 18:00:39 -0500 Subject: [PATCH 1/5] harmonize arguments for mongo_uri, service_port --- analysisstore/ignition.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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') From 9d33489418783f88df4c8af7164fcd2b37d2679c Mon Sep 17 00:00:00 2001 From: Jun Aishima Date: Wed, 6 Mar 2024 18:01:17 -0500 Subject: [PATCH 2/5] fix test to use new arguments --- analysisstore/test/testing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From c6da609f4215e2b819078a486495aa4851c5cb30 Mon Sep 17 00:00:00 2001 From: Jun Aishima Date: Wed, 6 Mar 2024 18:02:27 -0500 Subject: [PATCH 3/5] create analysisstore-specific exception --- analysisstore/server/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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() From 8a73811d1ebec10a8bb666bc86f95a68f509261b Mon Sep 17 00:00:00 2001 From: Jun Aishima Date: Wed, 6 Mar 2024 18:02:49 -0500 Subject: [PATCH 4/5] make client creation more similar to amostra, conftrak * check client connection with server_info() call * catch known exceptions, throw new analysisstore exception --- analysisstore/server/astore.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/analysisstore/server/astore.py b/analysisstore/server/astore.py index 81c964f..ea984e0 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,11 @@ 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"]) + self.client.server_info() + except (pymongo.errors.ConnectionFailure, pymongo.errors.ServerSelectionTimeoutError): + raise AnalysisstoreException("Unable to connect to MongoDB server...") else: import mongomock From 8082af4167eb7c28f21daa02f435e2461a4e5e90 Mon Sep 17 00:00:00 2001 From: Jun Aishima Date: Thu, 7 Mar 2024 11:58:53 -0500 Subject: [PATCH 5/5] Update analysisstore/server/astore.py Co-authored-by: Garrett Bischof --- analysisstore/server/astore.py | 1 + 1 file changed, 1 insertion(+) diff --git a/analysisstore/server/astore.py b/analysisstore/server/astore.py index ea984e0..9bf17f7 100644 --- a/analysisstore/server/astore.py +++ b/analysisstore/server/astore.py @@ -20,6 +20,7 @@ def __init__(self, config, testing=False): if not testing: 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...")