diff --git a/SAS/MoM/MoMQueryService/momqueryrpc.py b/SAS/MoM/MoMQueryService/momqueryrpc.py index 408b920e545486bec1658186398df694afe2b1c8..8949c6be70d6f823daf7a3c26b94c2956dde1324 100644 --- a/SAS/MoM/MoMQueryService/momqueryrpc.py +++ b/SAS/MoM/MoMQueryService/momqueryrpc.py @@ -32,6 +32,7 @@ class MoMQueryRPC(RPCWrapper): logger.info("Requesting details for mom objects: %s" % (str(ids_string))) result = self.rpc('GetProjectDetails', mom_ids=ids_string) + result = convertStringDigitKeysToInt(result) logger.info("Received details for %s mom objects" % (len(result))) return result @@ -86,21 +87,27 @@ class MoMQueryRPC(RPCWrapper): def getDataProducts(self, ids): logger.debug("getDataProducts(%s)", 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())) return result def getMoMIdsForOTDBIds(self, otdb_ids): '''reverse lookup from otdb_id(s) to mom2id(s) 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) result = self.rpc('GetMoMIdsForOTDBIds', otdb_ids=otdb_ids) + result = convertStringDigitKeysToInt(result) return result - def getMoMIdsForOTDBIds(self, otdb_ids): - '''reverse lookup from otdb_id(s) to mom2id(s) - returns: dict with otdb_id(s) in keys, mom2id(s) as values''' - logger.debug("getMoMIdsForOTDBIds(%s)", otdb_ids) - result = self.rpc('GetMoMIdsForOTDBIds', otdb_ids=otdb_ids) + 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 isinstance(mom_ids, int) or isinstance(mom_ids, str): + mom_ids = [mom_ids] + logger.debug("getOTDBIdsForMoMIds(%s)", mom_ids) + result = self.rpc('GetOTDBIdsForMoMIds', mom_ids=mom_ids) result = convertStringDigitKeysToInt(result) return result @@ -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('-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('-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') (options, args) = parser.parse_args() @@ -193,10 +201,16 @@ def main(): print 'No results' if options.otdb_id: - results = rpc.getMoMIdsForOTDBIds([options.otdb_id]) - print results - if results and str(options.otdb_id) in results: - print 'mom2id=%s for otdb_id=%s' % (results[str(options.otdb_id)], options.otdb_id) + results = rpc.getMoMIdsForOTDBIds(options.otdb_id) + if results and options.otdb_id in results: + print 'mom2id=%s for otdb_id=%s' % (results[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: print 'No results' diff --git a/SAS/MoM/MoMQueryService/momqueryservice.py b/SAS/MoM/MoMQueryService/momqueryservice.py index 564005a60b488f6e70e5b95d38db2c441f38bb24..19f431c066939a19b7d97451dd88d80df1af80e5 100755 --- a/SAS/MoM/MoMQueryService/momqueryservice.py +++ b/SAS/MoM/MoMQueryService/momqueryservice.py @@ -452,6 +452,47 @@ class MoMDatabaseWrapper: 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): if not mom_ids: return {} @@ -510,6 +551,7 @@ class ProjectDetailsQueryHandler(MessageHandlerInterface): 'GetDataProducts': self.getDataProducts, 'GetProjectTaskIds': self.getProjectTaskIds, 'GetMoMIdsForOTDBIds': self.getMoMIdsForOTDBIds, + 'GetOTDBIdsForMoMIds': self.getOTDBIdsForMoMIds, 'GetTaskIdsGraph': self.getTaskIdsGraph } @@ -546,6 +588,9 @@ class ProjectDetailsQueryHandler(MessageHandlerInterface): def getMoMIdsForOTDBIds(self, 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): return convertIntKeysToString(self.momdb.getTaskIdsGraph(mom2id)) diff --git a/SAS/MoM/MoMQueryService/test/test_momqueryservice.py b/SAS/MoM/MoMQueryService/test/test_momqueryservice.py index 3d60a9a19aedca7e65b160bc9f310eb26128f0e5..f1afab3d8dfbeade998525344ae7154ebf9b241a 100755 --- a/SAS/MoM/MoMQueryService/test/test_momqueryservice.py +++ b/SAS/MoM/MoMQueryService/test/test_momqueryservice.py @@ -48,7 +48,7 @@ try: # and we don't need the momdb passwd class MockMoMDatabaseWrapper: 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): def prepare_loop(self): diff --git a/SAS/ResourceAssignment/RAtoOTDBTaskSpecificationPropagator/lib/propagator.py b/SAS/ResourceAssignment/RAtoOTDBTaskSpecificationPropagator/lib/propagator.py index 42cf5c22b21415f0597e49dbaf80b1eb39433fd6..4ed54cac1f6504408a61257c188f1a17034332fe 100755 --- a/SAS/ResourceAssignment/RAtoOTDBTaskSpecificationPropagator/lib/propagator.py +++ b/SAS/ResourceAssignment/RAtoOTDBTaskSpecificationPropagator/lib/propagator.py @@ -141,7 +141,7 @@ class RAtoOTDBPropagator(): try: project = self.momrpc.getProjectDetails(mom_id) 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: 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.") diff --git a/SAS/ResourceAssignment/ResourceAssigner/lib/schedulechecker.py b/SAS/ResourceAssignment/ResourceAssigner/lib/schedulechecker.py index fa025466cbcad20dcaa36aa1acedf56835e6d2f5..0a137743f139a04bf677c32891ae716ae4c7cee1 100644 --- a/SAS/ResourceAssignment/ResourceAssigner/lib/schedulechecker.py +++ b/SAS/ResourceAssignment/ResourceAssigner/lib/schedulechecker.py @@ -166,8 +166,8 @@ class ScheduleChecker(): mom_details = self._momrpc.getProjectDetails(mom_ids) for task in approved_tasks: - if (str(task['mom_id']) not in mom_details or - mom_details[str(task['mom_id'])]['object_status'] == 'opened'): + if (task['mom_id'] not in mom_details or + 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']) self._radbrpc.deleteSpecification(task['specification_id']) diff --git a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/mom.py b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/mom.py index 909490e31b797a2c987b15f1962648833bedda2f..5480aa9f57774659cfd3ebd486f96b8ba13a3d74 100644 --- a/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/mom.py +++ b/SAS/ResourceAssignment/ResourceAssignmentEditor/lib/mom.py @@ -56,7 +56,7 @@ def updateTaskMomDetails(task, momrpc): details = momrpc.getProjectDetails(momIds) for t in tasklist: - mom_id = str(t['mom_id']) + mom_id = t['mom_id'] if mom_id in details: m = details[mom_id] t['name'] = m['object_name']