Skip to content
Snippets Groups Projects
Commit ba627db6 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

Task #10057: use convertStringDigitKeysToInt where appropriate. added getOTDBIdsForMoMIds

parent f5ca1f5a
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,7 @@ class MoMQueryRPC(RPCWrapper): ...@@ -32,6 +32,7 @@ class MoMQueryRPC(RPCWrapper):
logger.info("Requesting details for mom objects: %s" % (str(ids_string))) logger.info("Requesting details for mom objects: %s" % (str(ids_string)))
result = self.rpc('GetProjectDetails', mom_ids=ids_string) result = self.rpc('GetProjectDetails', mom_ids=ids_string)
result = convertStringDigitKeysToInt(result)
logger.info("Received details for %s mom objects" % (len(result))) logger.info("Received details for %s mom objects" % (len(result)))
return result return result
...@@ -86,21 +87,27 @@ class MoMQueryRPC(RPCWrapper): ...@@ -86,21 +87,27 @@ class MoMQueryRPC(RPCWrapper):
def getDataProducts(self, ids): def getDataProducts(self, ids):
logger.debug("getDataProducts(%s)", ids) logger.debug("getDataProducts(%s)", ids)
result = self.rpc('GetDataProducts', mom_ids=ids) result = self.rpc('GetDataProducts', mom_ids=ids)
result = convertStringDigitKeysToInt(result)
logger.info('Found # dataproducts per mom2id: %s', ', '.join('%s:%s' % (id, len(dps)) for id, dps in result.items())) logger.info('Found # dataproducts per mom2id: %s', ', '.join('%s:%s' % (id, len(dps)) for id, dps in result.items()))
return result return result
def getMoMIdsForOTDBIds(self, otdb_ids): def getMoMIdsForOTDBIds(self, otdb_ids):
'''reverse lookup from otdb_id(s) to mom2id(s) '''reverse lookup from otdb_id(s) to mom2id(s)
returns: dict with otdb_id(s) in keys, mom2id(s) as values''' returns: dict with otdb_id(s) in keys, mom2id(s) as values'''
if isinstance(otdb_ids, int) or isinstance(otdb_ids, str):
otdb_ids = [otdb_ids]
logger.debug("getMoMIdsForOTDBIds(%s)", otdb_ids) logger.debug("getMoMIdsForOTDBIds(%s)", otdb_ids)
result = self.rpc('GetMoMIdsForOTDBIds', otdb_ids=otdb_ids) result = self.rpc('GetMoMIdsForOTDBIds', otdb_ids=otdb_ids)
result = convertStringDigitKeysToInt(result)
return result return result
def getMoMIdsForOTDBIds(self, otdb_ids): def getOTDBIdsForMoMIds(self, mom_ids):
'''reverse lookup from otdb_id(s) to mom2id(s) '''lookup from mom2id(s) to otdb_id(s)
returns: dict with otdb_id(s) in keys, mom2id(s) as values''' returns: dict with mom2id(s) in keys, otdb_id(s) as values'''
logger.debug("getMoMIdsForOTDBIds(%s)", otdb_ids) if isinstance(mom_ids, int) or isinstance(mom_ids, str):
result = self.rpc('GetMoMIdsForOTDBIds', otdb_ids=otdb_ids) mom_ids = [mom_ids]
logger.debug("getOTDBIdsForMoMIds(%s)", mom_ids)
result = self.rpc('GetOTDBIdsForMoMIds', mom_ids=mom_ids)
result = convertStringDigitKeysToInt(result) result = convertStringDigitKeysToInt(result)
return result return result
...@@ -128,6 +135,7 @@ def main(): ...@@ -128,6 +135,7 @@ def main():
parser.add_option('--parent_group', dest='parent_group_id', type='int', help='get the tasks ids in the given parent group mom2id') parser.add_option('--parent_group', dest='parent_group_id', type='int', help='get the tasks ids in the given parent group mom2id')
parser.add_option('-d', '--dataproducts', dest='id_for_dataproducts', type='int', help='get the dataproducts for the given mom2id') parser.add_option('-d', '--dataproducts', dest='id_for_dataproducts', type='int', help='get the dataproducts for the given mom2id')
parser.add_option('-o', '--otdb_id', dest='otdb_id', type='int', help='get the mom2id for the given otdb_id') parser.add_option('-o', '--otdb_id', dest='otdb_id', type='int', help='get the mom2id for the given otdb_id')
parser.add_option('-m', '--mom_id', dest='mom_id', type='int', help='get the otdb_id for the given mom2id')
parser.add_option('-t', '--task_graph', dest='task_graph_mom2id', type='int', help='get the fully connected task graph given any mom2id in that graph') parser.add_option('-t', '--task_graph', dest='task_graph_mom2id', type='int', help='get the fully connected task graph given any mom2id in that graph')
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
...@@ -193,10 +201,16 @@ def main(): ...@@ -193,10 +201,16 @@ def main():
print 'No results' print 'No results'
if options.otdb_id: if options.otdb_id:
results = rpc.getMoMIdsForOTDBIds([options.otdb_id]) results = rpc.getMoMIdsForOTDBIds(options.otdb_id)
print results if results and options.otdb_id in results:
if results and str(options.otdb_id) in results: print 'mom2id=%s for otdb_id=%s' % (results[options.otdb_id], options.otdb_id)
print 'mom2id=%s for otdb_id=%s' % (results[str(options.otdb_id)], options.otdb_id) else:
print 'No results'
if options.mom_id:
results = rpc.getOTDBIdsForMoMIds(options.mom_id)
if results and options.mom_id in results:
print 'otdb_id=%s for mom2id=%s' % (results[options.mom_id], options.mom_id)
else: else:
print 'No results' print 'No results'
......
...@@ -452,6 +452,47 @@ class MoMDatabaseWrapper: ...@@ -452,6 +452,47 @@ class MoMDatabaseWrapper:
return result return result
def getOTDBIdsForMoMIds(self, mom_ids):
'''lookup from mom2id(s) to otdb_id(s)
returns: dict with mom2id(s) in keys, otdb_id(s) as values'''
if not mom_ids:
return {}
ids_str = _toIdsString(mom_ids)
logger.debug("getOTDBIdsForMoMIds for otdb ids: %s" % ids_str)
result = {int(mom_id):None for mom_id in ids_str.split(',')}
#first query all observations
query = '''SELECT obs.observation_id as otdb_id, mo.mom2id as mom2id
FROM lofar_mom3.lofar_observation obs
INNER JOIN lofar_mom3.mom2object mo on mo.id = obs.mom2objectid
WHERE mo.mom2id IN (%s)
''' % (ids_str,)
rows = self._executeQuery(query)
for row in rows:
if row['mom2id'] != None:
result[row['mom2id']] = row['otdb_id']
#then query all pipelines and combine the results
query = '''SELECT pl.pipeline_id as otdb_id, mo.mom2id as mom2id
FROM lofar_mom3.lofar_pipeline pl
INNER JOIN lofar_mom3.mom2object mo on mo.id = pl.mom2objectid
WHERE mo.mom2id IN (%s)
''' % (ids_str,)
rows = self._executeQuery(query)
for row in rows:
if row['mom2id'] != None:
result[row['mom2id']] = row['otdb_id']
logger.info("getOTDBIdsForMoMIds: %s" % result)
return result
def getDataProducts(self, mom_ids): def getDataProducts(self, mom_ids):
if not mom_ids: if not mom_ids:
return {} return {}
...@@ -510,6 +551,7 @@ class ProjectDetailsQueryHandler(MessageHandlerInterface): ...@@ -510,6 +551,7 @@ class ProjectDetailsQueryHandler(MessageHandlerInterface):
'GetDataProducts': self.getDataProducts, 'GetDataProducts': self.getDataProducts,
'GetProjectTaskIds': self.getProjectTaskIds, 'GetProjectTaskIds': self.getProjectTaskIds,
'GetMoMIdsForOTDBIds': self.getMoMIdsForOTDBIds, 'GetMoMIdsForOTDBIds': self.getMoMIdsForOTDBIds,
'GetOTDBIdsForMoMIds': self.getOTDBIdsForMoMIds,
'GetTaskIdsGraph': self.getTaskIdsGraph 'GetTaskIdsGraph': self.getTaskIdsGraph
} }
...@@ -546,6 +588,9 @@ class ProjectDetailsQueryHandler(MessageHandlerInterface): ...@@ -546,6 +588,9 @@ class ProjectDetailsQueryHandler(MessageHandlerInterface):
def getMoMIdsForOTDBIds(self, otdb_ids): def getMoMIdsForOTDBIds(self, otdb_ids):
return convertIntKeysToString(self.momdb.getMoMIdsForOTDBIds(otdb_ids)) return convertIntKeysToString(self.momdb.getMoMIdsForOTDBIds(otdb_ids))
def getOTDBIdsForMoMIds(self, mom_ids):
return convertIntKeysToString(self.momdb.getOTDBIdsForMoMIds(mom_ids))
def getTaskIdsGraph(self, mom2id): def getTaskIdsGraph(self, mom2id):
return convertIntKeysToString(self.momdb.getTaskIdsGraph(mom2id)) return convertIntKeysToString(self.momdb.getTaskIdsGraph(mom2id))
......
...@@ -48,7 +48,7 @@ try: ...@@ -48,7 +48,7 @@ try:
# and we don't need the momdb passwd # and we don't need the momdb passwd
class MockMoMDatabaseWrapper: class MockMoMDatabaseWrapper:
def getProjectDetails(self, mom_ids_str): def getProjectDetails(self, mom_ids_str):
return {str(testid): {'project_mom2id': '4567', 'project_name': 'foo', 'project_description': 'bar', 'object_mom2id': testid}} return { testid: {'project_mom2id': '4567', 'project_name': 'foo', 'project_description': 'bar', 'object_mom2id': testid}}
class MockProjectDetailsQueryHandler(ProjectDetailsQueryHandler): class MockProjectDetailsQueryHandler(ProjectDetailsQueryHandler):
def prepare_loop(self): def prepare_loop(self):
......
...@@ -141,7 +141,7 @@ class RAtoOTDBPropagator(): ...@@ -141,7 +141,7 @@ class RAtoOTDBPropagator():
try: try:
project = self.momrpc.getProjectDetails(mom_id) project = self.momrpc.getProjectDetails(mom_id)
logger.info(project) logger.info(project)
project_name = "_".join(project[str(mom_id)]['project_name'].split()) project_name = "_".join(project[mom_id]['project_name'].split())
except (RPCException, KeyError) as e: except (RPCException, KeyError) as e:
logger.error('Could not get project name from MoM for mom_id %s: %s' % (mom_id, str(e))) logger.error('Could not get project name from MoM for mom_id %s: %s' % (mom_id, str(e)))
logger.info("Using 'unknown' as project name.") logger.info("Using 'unknown' as project name.")
......
...@@ -166,8 +166,8 @@ class ScheduleChecker(): ...@@ -166,8 +166,8 @@ class ScheduleChecker():
mom_details = self._momrpc.getProjectDetails(mom_ids) mom_details = self._momrpc.getProjectDetails(mom_ids)
for task in approved_tasks: for task in approved_tasks:
if (str(task['mom_id']) not in mom_details or if (task['mom_id'] not in mom_details or
mom_details[str(task['mom_id'])]['object_status'] == 'opened'): mom_details[task['mom_id']]['object_status'] == 'opened'):
logger.info('task %s mom_id=%s otdb_id=%s was removed or set to status opened. removing task from rabd', task['id'], task['mom_id'], task['otdb_id']) logger.info('task %s mom_id=%s otdb_id=%s was removed or set to status opened. removing task from rabd', task['id'], task['mom_id'], task['otdb_id'])
self._radbrpc.deleteSpecification(task['specification_id']) self._radbrpc.deleteSpecification(task['specification_id'])
......
...@@ -56,7 +56,7 @@ def updateTaskMomDetails(task, momrpc): ...@@ -56,7 +56,7 @@ def updateTaskMomDetails(task, momrpc):
details = momrpc.getProjectDetails(momIds) details = momrpc.getProjectDetails(momIds)
for t in tasklist: for t in tasklist:
mom_id = str(t['mom_id']) mom_id = t['mom_id']
if mom_id in details: if mom_id in details:
m = details[mom_id] m = details[mom_id]
t['name'] = m['object_name'] t['name'] = m['object_name']
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment