Skip to content

Commit

Permalink
Merge pull request #24 from JunAishima/mongo_uri
Browse files Browse the repository at this point in the history
Use Mongo URI
  • Loading branch information
gwbischof authored Feb 6, 2024
2 parents db7e68c + 4fc725c commit b8b321b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
19 changes: 7 additions & 12 deletions analysisstore/ignition.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,41 +29,36 @@ def start_server(config=None):
if not config:
try:
config = {k: v for k, v in load_configuration('analysisstore', 'ASST',
['mongo_host', 'mongo_port', 'timezone',
['mongo_uri', 'timezone',
'database', 'service_port'],
allow_missing=True).items() if v is not None}
except (KeyError, TypeError):
config = {} # if format is wrong or does not exist, return empty dict
parser = argparse.ArgumentParser()
parser.add_argument('--database', dest='database', type=str,
help='name of database to use')
parser.add_argument('--mongo-host',
dest='mongo_host', type=str,
help='host to use')
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('--mongo-port', dest='mongo_port', type=int,
help='port to use to talk to mongo')
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')
args = parser.parse_args()
if args.database is not None:
config['database'] = args.database
if args.mongo_host is not None:
config['mongo_host'] = args.mongo_host
if args.mongo_uri is not None:
config['mongo_uri'] = args.mongo_uri
if args.timezone is not None:
config['timezone'] = args.timezone
if args.mongo_port is not None:
config['mongo_port'] = args.mongo_port
if args.service_port is not None:
config['service_port'] = args.service_port
if not config:
raise KeyError('No configuration provided. Provide config file or command line args')
tornado.options.parse_command_line({'log_file_prefix': args.log_file_prefix})
cfg = dict(host=config['mongo_host'], port=config['mongo_port'],
database=config['database'])
cfg = dict(uri=config['mongo_uri'], database=config['database'])
astore = AStore(cfg)
application = tornado.web.Application([(r'/analysis_header', AnalysisHeaderHandler),
(r'/data_reference', DataReferenceHandler),
Expand Down
7 changes: 3 additions & 4 deletions analysisstore/server/astore.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,16 @@

class AStore:
def __init__(self, config):
"""Given a database configuration that consists of host, port, and
"""Given a database configuration that consists of uri and
database, instantiate an AStore object that handles the connections
to the database.
Parameters
-----------
config: dict
host, port in integer format, and database
uri in string format, and database
"""
self.client = MongoClient(host=config['host'],
port=config['port'])
self.client = MongoClient(config['uri'])
self.database = self.client[config['database']]
self.database.analysis_header.create_index([('uid', DESCENDING)],
unique=True,
Expand Down
11 changes: 5 additions & 6 deletions analysisstore/test/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
TESTING_CONFIG = dict(host='localhost', port=7601,
timezone='US/Eastern', serviceport=7601,
database='astoretest{0}'.format(str(uuid.uuid4())),
mongouri='mongodb://localhost',
mongohost='localhost',
mongoport=27017)


def astore_setup():
f = os.path.dirname(os.path.realpath(__file__))
proc = Popen(["python", "../../startup.py", "--mongo-host",
TESTING_CONFIG["mongohost"],
"--mongo-port",
str(TESTING_CONFIG['mongoport']),
proc = Popen(["python", "../../startup.py",
"--mongo-uri",
str(TESTING_CONFIG['mongouri']),
"--database", TESTING_CONFIG['database'],
"--timezone", TESTING_CONFIG['timezone'],
"--service-port",
Expand All @@ -32,8 +32,7 @@ def astore_setup():
def astore_teardown(proc):
proc2 = Popen(['kill', '-9', str(proc.pid)])
ttime.sleep(5) # make sure the process is killed
conn = MongoClient(host=TESTING_CONFIG['mongohost'],
port=TESTING_CONFIG['mongoport'])
conn = MongoClient(TESTING_CONFIG['mongouri'])
conn.drop_database(TESTING_CONFIG['database'])
print('\nTearing down the server and dropping the db\n')
ttime.sleep(1.3)

0 comments on commit b8b321b

Please sign in to comment.