Exemple #1
0
    def test_doTaskScheduled_calls_CreateParset_with_correct_info(self):

        # test values
        raid = 1
        otdbid = 2
        momid = 3
        rainfo = {'ra': 'info'}
        mominfo = Specification(None, None, None)
        projectname = 'myproject'
        parset = 'par-set'

        # setup mocks
        prop = RAtoOTDBPropagator()
        prop.getRAinfo = MagicMock(return_value=rainfo)
        prop.getMoMinfo = MagicMock(return_value=mominfo)
        prop.momrpc.getObjectDetails = MagicMock(return_value={momid:{'project_name':projectname}})
        prop.translator.CreateParset = MagicMock(return_value=parset)
        prop.setOTDBinfo = MagicMock()

        # trigger test action
        prop.doTaskScheduled(raid, otdbid, momid)

        # assert info was gathered with correct id and createparsec is called with the returned info
        prop.getRAinfo.assert_called_once_with(raid)
        prop.getMoMinfo.assert_called_once_with(momid)
        prop.momrpc.getObjectDetails.assert_called_once_with(momid)
        prop.translator.CreateParset.assert_called_once_with(otdbid, rainfo, projectname, mominfo)
        prop.setOTDBinfo.assert_called_once_with(otdbid, parset, 'scheduled')
Exemple #2
0
class RATaskStatusChangedListener(RADBBusListener):
    def __init__(self,
                 busname=RA_NOTIFICATION_BUSNAME,
                 subject=RA_NOTIFICATION_PREFIX + 'TaskUpdated',
                 broker=None,
                 propagator=None, ## TODO also give translator?
                 **kwargs):
        """
        RATaskScheduledListener listens on the lofar ?? bus and calls onTaskScheduled or onTaskConclict
        :param busname: valid Qpid address (default: lofar.ra.notification)
        :param broker: valid Qpid broker host (default: None, which means localhost)
        additional parameters in kwargs:
                options=     <dict>    Dictionary of options passed to QPID
                exclusive= <bool>    Create an exclusive binding so no other services can consume duplicate messages (default: False)
                numthreads= <int>    Number of parallel threads processing messages (default: 1)
                verbose=     <bool>    Output extra logging over stdout (default: False)
        """
        super(RATaskStatusChangedListener, self).__init__(busname=busname, subjects=subject, broker=broker, **kwargs)

        self.propagator = propagator
        if not self.propagator:
            self.propagator =  RAtoOTDBPropagator()

    def onTaskUpdated(self, old_task, new_task):
        # override super onTaskUpdated
        # check for status change, and call either onTaskScheduled or onTaskScheduled
        if old_task['status_id'] != new_task['status_id']:
            if new_task['status'] == 'scheduled':
                self.onTaskScheduled(new_task['id'], new_task['otdb_id'], new_task['mom_id'])
            elif new_task['status'] == 'conflict':
                self.onTaskConflict(new_task['id'], new_task['otdb_id'], new_task['mom_id'])

    def onTaskInserted(self, new_task):
        # override super onTaskInserted
        # check for status, and call either onTaskScheduled or onTaskScheduled
        if new_task['status'] == 'scheduled':
            self.onTaskScheduled(new_task['id'], new_task['otdb_id'], new_task['mom_id'])
        elif new_task['status'] == 'conflict':
            self.onTaskConflict(new_task['id'], new_task['otdb_id'], new_task['mom_id'])

    def onTaskScheduled(self, ra_id, otdb_id, mom_id):
        logger.info('onTaskScheduled: ra_id=%s otdb_id=%s mom_id=%s' % (ra_id, otdb_id, mom_id))

        self.propagator.doTaskScheduled(ra_id, otdb_id, mom_id)

    def onTaskConflict(self, ra_id, otdb_id, mom_id):
        logger.info('onTaskConflict: ra_id=%s otdb_id=%s mom_id=%s' % (ra_id, otdb_id, mom_id))

        self.propagator.doTaskConflict(ra_id, otdb_id, mom_id)
Exemple #3
0
class RATaskStatusChangedHandler(RAEventMessageHandler):
    def __init__(self, propagator=None):
        super().__init__()

        self.propagator = propagator
        if not self.propagator:
            self.propagator = RAtoOTDBPropagator()

    def onTaskApproved(self, task_ids):
        radb_id = task_ids.get('radb_id')
        otdb_id = task_ids.get('otdb_id')
        mom_id = task_ids.get('mom_id')
        logger.info('onTaskApproved: radb_id=%s otdb_id=%s mom_id=%s', radb_id,
                    otdb_id, mom_id)

        self.propagator.doTaskApproved(otdb_id, mom_id)

    def onTaskScheduled(self, task_ids):
        radb_id = task_ids.get('radb_id')
        otdb_id = task_ids.get('otdb_id')
        mom_id = task_ids.get('mom_id')
        logger.info('onTaskScheduled: radb_id=%s otdb_id=%s mom_id=%s',
                    radb_id, otdb_id, mom_id)

        self.propagator.doTaskScheduled(radb_id, otdb_id, mom_id)

    def onTaskConflict(self, task_ids):
        radb_id = task_ids.get('radb_id')
        otdb_id = task_ids.get(
            'otdb_id')  #Does this work if one of the Id's is not set?
        mom_id = task_ids.get('mom_id')
        logger.info('onTaskConflict: radb_id=%s otdb_id=%s mom_id=%s', radb_id,
                    otdb_id, mom_id)

        self.propagator.doTaskConflict(otdb_id)

    def onTaskError(self, task_ids):
        radb_id = task_ids.get('radb_id')
        otdb_id = task_ids.get(
            'otdb_id')  #Does this work if one of the Id's is not set?
        mom_id = task_ids.get('mom_id')
        logger.info('onTaskError: radb_id=%s otdb_id=%s mom_id=%s', radb_id,
                    otdb_id, mom_id)

        self.propagator.doTaskError(otdb_id)