def __init__(self, exchange=DEFAULT_BUSNAME, broker=DEFAULT_BROKER): """ Creates a TaskInfoCache instance, which listens for OTDB task status events, and then fetches and caches relevant info for the current active task(s). :param exchange: :param broker: """ # the internal cache is a dict with a mapping of otdb_id->TaskInfo self._cache = {} # the internal project cache is a dict with a mapping of project_name->project_info_dict self._project_cache = {} # the internal stations cache is a list of the currently used stations self._stations_cache = [] # internal rpc's to fetch the needed information self._otdbrpc = OTDBRPC.create(exchange=exchange, broker=broker, timeout=DEFAULT_RPC_TIMEOUT) self._momrpc = MoMQueryRPC.create(exchange=exchange, broker=broker, timeout=DEFAULT_RPC_TIMEOUT) self._radbrpc = RADBRPC.create(exchange=exchange, broker=broker, timeout=DEFAULT_RPC_TIMEOUT)
def __init__(self, exchange=DEFAULT_BUSNAME, broker=DEFAULT_BROKER, radb_dbcreds=None): """ Creates a ResourceAssigner instance :param exchange: name of the bus on which the services listen (default: lofar) :param ra_notification_prefix: prefix used in notification message subject (default: ResourceAssigner.) :param broker: Valid Qpid broker host (default: None, which means localhost) :param radb_dbcreds: the credentials to be used for accessing the RADB (default: None, which means default) """ self.radb = RADatabase(dbcreds=radb_dbcreds) self.rerpc = ResourceEstimatorRPC.create(exchange=exchange, broker=broker) self.otdbrpc = OTDBRPC.create(exchange=exchange, broker=broker) self.momrpc = MoMQueryRPC.create(exchange=exchange, broker=broker) self.sqrpc = StorageQueryRPC.create(exchange=exchange, broker=broker) self.curpc = CleanupRPC.create(exchange=exchange, broker=broker) self.ra_notification_bus = ToBus(exchange=exchange, broker=broker) self.obscontrol = ObservationControlRPCClient.create(exchange=exchange, broker=broker) self.resource_availability_checker = ResourceAvailabilityChecker( self.radb) # For the DwellScheduler instances created during run-time we store the following variables self.radb_creds = radb_dbcreds self.broker = broker
def _send_filtered_event_message(self, otdb_id: int, modificationTime: datetime, state: str): try: with OTDBRPC.create(exchange=self.exchange, broker=self.broker, timeout=2) as otdbrpc: parset = parameterset( otdbrpc.taskGetSpecification(otdb_id=otdb_id).get( "specification", '')) task_type = parset.get("ObsSW.Observation.processType") priority = 6 if task_type == "Observation" else 2 except Exception as e: logger.warning( 'Could not determine task type for otdb_id=%s, using default priority=4: %s', otdb_id, e) priority = 4 try: content = { "treeID": otdb_id, "state": state, "time_of_change": modificationTime } msg = EventMessage( subject=DEFAULT_FILTERED_OTDB_NOTIFICATION_SUBJECT, content=content, priority=priority) logger.info( 'sending filtered event message subject:\'%s\' content: %s', msg.subject, content) self.send(msg) except Exception as e: logger.error('Could not send event message: %s', e)
def __init__(self, exchange, broker): super(PipelineControlHandler, self).__init__() logger.info('PipelineControl busname=%s', exchange) self.exchange = exchange self.otdbrpc = OTDBRPC.create(exchange=exchange, broker=broker) self.dependencies = PipelineDependencies(exchange=exchange, broker=broker) self.slurm = Slurm()
def do_qa(self, otdb_id): ''' try to do all qa (quality assurance) steps for the given otdb_id resulting in an h5 MS-extract file and inspection plots :param int otdb_id: observation/pipeline otdb id for which the conversion needs to be done. :return: None ''' hdf5_file_path = None with OTDBRPC.create(exchange=self.exchange, broker=self.broker, timeout=5) as otdbrpc: parset = parameterset( otdbrpc.taskGetSpecification(otdb_id=otdb_id).get( "specification", '')) if not parset: logger.warning("could not find a parset for otdb_id %s.", otdb_id) return if parset.getBool( 'ObsSW.Observation.DataProducts.Output_Correlated.enabled' ): hdf5_file_path = self._convert_ms2hdf5(otdb_id) elif parset.getBool( 'ObsSW.Observation.DataProducts.Output_CoherentStokes.enabled' ): hdf5_file_path = self._convert_bf2hdf5(otdb_id) else: logger.info( "No uv or cs dataproducts avaiblable to convert for otdb_id %s", otdb_id) return if hdf5_file_path: # keep a note of where the h5 file was stored for this unfinished otdb_id self._unfinished_otdb_id_map[otdb_id] = hdf5_file_path # cluster it self._cluster_h5_file(hdf5_file_path, otdb_id) self._copy_hdf5_to_nfs_dir(hdf5_file_path) plot_dir_path = self._create_plots_for_h5_file( hdf5_file_path, otdb_id) plot_dir_path = self._move_plots_to_nfs_dir(plot_dir_path) # and notify that we're finished self._send_event_message( 'Finished', { 'otdb_id': otdb_id, 'hdf5_file_path': hdf5_file_path, 'plot_dir_path': plot_dir_path or '' })
def __init__(self, exchange=DEFAULT_BUSNAME, broker=DEFAULT_BROKER): """ :param exchange: name of the exchange to listen on. :param broker: name of the broker to connect to. """ super().__init__() self.otdbrpc = OTDBRPC.create(exchange=exchange, broker=broker) self.radbrpc = RADBRPC.create(exchange=exchange, broker=broker) self.momrpc = MoMQueryRPC.create(exchange=exchange, broker=broker) self.send_bus = ToBus(exchange=exchange, broker=broker)
def __init__(self, exchange=DEFAULT_BUSNAME, broker=DEFAULT_BROKER): """ RAtoOTDBPropagator updates tasks in the OTDB after the ResourceAssigner is done with them. :param exchange: exchange on which the services listen (default: lofar) :param broker: Valid Qpid broker host (default: None, which means localhost) """ self.radbrpc = RADBRPC.create(exchange=exchange, broker=broker) self.otdbrpc = OTDBRPC.create(exchange=exchange, broker=broker) self.momrpc = MoMQueryRPC.create(exchange=exchange, broker=broker) self.translator = RAtoOTDBTranslator()
def __init__(self, exchange=DEFAULT_BUSNAME, broker=DEFAULT_BROKER): """ """ self._thread = None self._running = False self._radbrpc = RADBRPC.create(exchange=exchange, broker=broker) self._momrpc = MoMQueryRPC.create(exchange=exchange, broker=broker) self._curpc = CleanupRPC.create(exchange=exchange, broker=broker) self._otdbrpc = OTDBRPC.create(exchange=exchange, broker=broker, timeout=180)
def init_tobus(self, exchange: str = DEFAULT_BUSNAME, broker: str = DEFAULT_BROKER): super().init_tobus(exchange, broker) self.otdb = OTDBRPC.create(exchange=exchange, broker=broker) self.radb = RADBRPC.create(exchange=exchange, broker=broker)
def __init__(self, exchange=DEFAULT_BUSNAME, broker=DEFAULT_BROKER): super().__init__() self.otdbrpc = OTDBRPC.create(exchange=exchange, broker=broker) self.momquery = MoMQueryRPC.create(exchange=exchange, broker=broker) self.radb = RADatabase()
def main(): # make sure we run in UTC timezone import os os.environ['TZ'] = 'UTC' # Check the invocation arguments parser = OptionParser( '%prog [options]', description='run the resource assignment editor web service') parser.add_option( '--webserver_port', dest='webserver_port', type='int', default=7412, help='port number on which to host the webservice, default: %default') parser.add_option('-q', '--broker', dest='broker', type='string', default=DEFAULT_BROKER, help='Address of the qpid broker, default: %default') parser.add_option( '--exchange', dest='exchange', type='string', default=DEFAULT_BUSNAME, help='Name of the bus exchange on the qpid broker, default: %default') parser.add_option('-V', '--verbose', dest='verbose', action='store_true', help='verbose logging') parser.add_option_group(dbcredentials.options_group(parser)) parser.set_defaults(dbcredentials="RADB") (options, args) = parser.parse_args() logging.basicConfig( format='%(asctime)s %(levelname)s %(message)s', level=logging.DEBUG if options.verbose else logging.INFO) global _radb_dbcreds _radb_dbcreds = dbcredentials.parse_options(options) if _radb_dbcreds.database: logger.info("Using dbcreds for direct RADB access: %s" % _radb_dbcreds.stringWithHiddenPassword()) else: _radb_dbcreds = None global rarpc rarpc = RADBRPC.create(exchange=options.exchange, broker=options.broker) global otdbrpc otdbrpc = OTDBRPC.create(exchange=options.exchange, broker=options.broker) global curpc curpc = CleanupRPC.create(exchange=options.exchange, broker=options.broker) global sqrpc sqrpc = StorageQueryRPC.create(exchange=options.exchange, timeout=10, broker=options.broker) global momqueryrpc momqueryrpc = MoMQueryRPC.create(exchange=options.exchange, timeout=10, broker=options.broker) global changeshandler changeshandler = ChangesHandler(exchange=options.exchange, broker=options.broker, momqueryrpc=momqueryrpc, radbrpc=rarpc, sqrpc=sqrpc) with changeshandler, rarpc, otdbrpc, curpc, sqrpc, momqueryrpc: '''Start the webserver''' app.run(debug=options.verbose, threaded=True, host='0.0.0.0', port=options.webserver_port)
def __init__(self, exchange=DEFAULT_BUSNAME, broker=DEFAULT_BROKER): self.rarpc = RADBRPC.create(exchange=exchange, broker=broker) logger.info('PipelineDependencies busname=%s', exchange) self.otdbrpc = OTDBRPC.create(exchange=exchange, broker=broker)