class ReplyManager(Listener): CTAG = "AGENTHUB__REPLY" def __init__(self, url): queue = Queue(self.CTAG) self.consumer = ReplyConsumer(queue, url=url) def start(self, watchdog): self.consumer.start(self, watchdog=watchdog) log.info("reply: started") def succeeded(self, reply): log.info("succeeded: %s", reply) any = Options(reply.any) body = dict(sn=reply.sn, any=any.any, status=(200, HTTP_CODES[200]), reply=reply.retval, exception=None) nj = NotifyJournal() nj.write(reply.sn, any.replyto, body) def failed(self, reply): log.info("failed: %s", reply) any = Options(reply.any) body = dict( sn=reply.sn, any=any.any, status=status(reply.exval), exception=exdict(reply.exval, reply), reply=None ) nj = NotifyJournal() nj.write(reply.sn, any.replyto, body) def status(self, reply): pass
class ReplyHandler(Listener): """ The async RMI reply handler. @ivar consumer: The reply consumer. @type consumer: L{ReplyConsumer} """ def __init__(self, url): queue = Queue(Services.CTAG) self.consumer = ReplyConsumer(queue, url=url) def start(self, watchdog): self.consumer.start(self, watchdog=watchdog) log.info('Task reply handler, started.') def succeeded(self, reply): log.info('Task RMI (succeeded)\n%s', reply) taskid = reply.any result = reply.retval coordinator = factory.coordinator() coordinator.complete_call_success(taskid, result) def failed(self, reply): log.info('Task RMI (failed)\n%s', reply) taskid = reply.any exception = reply.exval traceback = reply.xstate['trace'] coordinator = factory.coordinator() coordinator.complete_call_failure(taskid, exception, traceback) def status(self, reply): pass
class ReplyHandler(Listener): """ The async RMI reply handler. @ivar consumer: The reply consumer. @type consumer: L{ReplyConsumer} """ def __init__(self, url): queue = Queue(Services.CTAG) self.consumer = ReplyConsumer(queue, url=url) def start(self, watchdog): """ Start the reply handler (thread) @param watchdog: A watchdog object used to synthesize timeouts. @type watchdog: L{gofer.rmi.async.WatchDog} """ self.consumer.start(self, watchdog=watchdog) log.info('Task reply handler, started.') def succeeded(self, reply): """ Notification (reply) indicating an RMI succeeded. This information is relayed to the task coordinator. @param reply: A successful reply object. @type reply: L{gofer.rmi.async.Succeeded} """ log.info('Task RMI (succeeded)\n%s', reply) taskid = reply.any result = reply.retval coordinator = factory.coordinator() coordinator.complete_call_success(taskid, result) def failed(self, reply): """ Notification (reply) indicating an RMI failed. This information is relayed to the task coordinator. @param reply: A failure reply object. @type reply: L{gofer.rmi.async.Failed} """ log.info('Task RMI (failed)\n%s', reply) taskid = reply.any exception = reply.exval traceback = reply.xstate['trace'] coordinator = factory.coordinator() coordinator.complete_call_failure(taskid, exception, traceback) def progress(self, reply): """ Notification (reply) indicating an RMI has reported status. This information is relayed to the task coordinator. @param reply: A progress reply object. @type reply: L{gofer.rmi.async.Progress} """ log.info('Task RMI (progress)\n%s', reply) taskid = reply.any coordinator = factory.coordinator() coordinator.report_call_progress(taskid, reply.details)
def __init__(self, url): """ :param url: The broker URL. :type url: str """ queue = Queue(ReplyHandler.REPLY_QUEUE) queue.durable = True queue.declare(url) self.consumer = ReplyConsumer(queue, url=url, authenticator=Authenticator())
def __init__(self, url, transport): """ :param url: The broker URL. :type url: str :param transport: The gofer transport. :type transport: str """ queue = Queue(Services.REPLY_QUEUE, transport=transport) self.consumer = ReplyConsumer(queue, url=url, transport=transport, authenticator=Authenticator())
def __init__(self, url): """ :param url: The broker URL. :type url: str """ queue = Queue(ReplyHandler.REPLY_QUEUE) self.consumer = ReplyConsumer(queue, url=url, authenticator=Authenticator())
class ReplyManager(Listener): CTAG = 'AGENTHUB__REPLY' def __init__(self, url): queue = Queue(self.CTAG) self.consumer = ReplyConsumer(queue, url=url) def start(self, watchdog): self.consumer.start(self, watchdog=watchdog) log.info('reply: started') def succeeded(self, reply): log.info('succeeded: %s', reply) any = Options(reply.any) body = dict(sn=reply.sn, any=any.any, status=(200, HTTP_CODES[200]), reply=reply.retval, exception=None) nj = NotifyJournal() nj.write(reply.sn, any.replyto, body) def failed(self, reply): log.info('failed: %s', reply) any = Options(reply.any) body = dict(sn=reply.sn, any=any.any, status=status(reply.exval), exception=exdict(reply.exval, reply), reply=None) nj = NotifyJournal() nj.write(reply.sn, any.replyto, body) def status(self, reply): pass
class ReplyHandler(Listener): """ The async RMI reply handler. :cvar REPLY_QUEUE: The agent RMI reply queue. :type REPLY_QUEUE: str :ivar consumer: The reply consumer. :type consumer: ReplyConsumer """ REPLY_QUEUE = 'pulp.task' @staticmethod def _bind_succeeded(action_id, call_context): """ Bind succeeded. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_succeeded(consumer_id, repo_id, distributor_id, action_id) @staticmethod def _unbind_succeeded(call_context): """ Update the bind action. :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.delete(consumer_id, repo_id, distributor_id, force=True) @staticmethod def _bind_failed(action_id, call_context): """ The bind failed. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_failed(consumer_id, repo_id, distributor_id, action_id) # added for clarity _unbind_failed = _bind_failed def __init__(self, url): """ :param url: The broker URL. :type url: str """ queue = Queue(ReplyHandler.REPLY_QUEUE) queue.durable = True queue.declare(url) self.consumer = ReplyConsumer(queue, url=url, authenticator=Authenticator()) def start(self): """ Start the reply handler (thread) """ self.consumer.start(self) _logger.info(_('Task reply handler, started.')) def accepted(self, reply): """ Notification that an RMI has started executing in the agent. The task status is updated in the pulp DB. :param reply: A status reply object. :type reply: gofer.rmi.async.Accepted """ _logger.debug(_('Task RMI (accepted): %(r)s'), {'r': reply}) call_context = dict(reply.data) task_id = call_context['task_id'] TaskStatus.objects(task_id=task_id, state=constants.CALL_WAITING_STATE).\ update_one(set__state=constants.CALL_ACCEPTED_STATE) def started(self, reply): """ Notification that an RMI has started executing in the agent. The task status is updated in the pulp DB. :param reply: A status reply object. :type reply: gofer.rmi.async.Started """ _logger.debug(_('Task RMI (started): %(r)s'), {'r': reply}) call_context = dict(reply.data) task_id = call_context['task_id'] started = reply.timestamp if not started: now = datetime.now(dateutils.utc_tz()) started = dateutils.format_iso8601_datetime(now) TaskStatus.objects(task_id=task_id).update_one(set__start_time=started) TaskStatus.objects(task_id=task_id, state__in=[constants.CALL_WAITING_STATE, constants.CALL_ACCEPTED_STATE]).\ update_one(set__state=constants.CALL_RUNNING_STATE) def rejected(self, reply): """ Notification (reply) indicating an RMI request has been rejected. This information used to update the task status. :param reply: A rejected reply object. :type reply: gofer.rmi.async.Rejected """ _logger.warn(_('Task RMI (rejected): %(r)s'), {'r': reply}) call_context = dict(reply.data) action = call_context.get('action') task_id = call_context['task_id'] finished = reply.timestamp if not finished: now = datetime.now(dateutils.utc_tz()) finished = dateutils.format_iso8601_datetime(now) TaskStatus.objects(task_id=task_id).update_one(set__finish_time=finished, set__state=constants.CALL_ERROR_STATE) if action == 'bind': ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': ReplyHandler._unbind_failed(task_id, call_context) return def succeeded(self, reply): """ Notification (reply) indicating an RMI succeeded. This information is relayed to the task coordinator. :param reply: A successful reply object. :type reply: gofer.rmi.async.Succeeded """ _logger.info(_('Task RMI (succeeded): %(r)s'), {'r': reply}) call_context = dict(reply.data) action = call_context.get('action') task_id = call_context['task_id'] result = dict(reply.retval) finished = reply.timestamp if not finished: now = datetime.now(dateutils.utc_tz()) finished = dateutils.format_iso8601_datetime(now) TaskStatus.objects(task_id=task_id).update_one(set__finish_time=finished, set__state=constants.CALL_FINISHED_STATE, set__result=result) if action == 'bind': if result['succeeded']: ReplyHandler._bind_succeeded(task_id, call_context) else: ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': if result['succeeded']: ReplyHandler._unbind_succeeded(call_context) else: ReplyHandler._unbind_failed(task_id, call_context) return def failed(self, reply): """ Notification (reply) indicating an RMI failed. This information used to update the task status. :param reply: A failure reply object. :type reply: gofer.rmi.async.Failed """ _logger.info(_('Task RMI (failed): %(r)s'), {'r': reply}) call_context = dict(reply.data) action = call_context.get('action') task_id = call_context['task_id'] traceback = reply.xstate['trace'] finished = reply.timestamp if not finished: now = datetime.now(dateutils.utc_tz()) finished = dateutils.format_iso8601_datetime(now) TaskStatus.objects(task_id=task_id).update_one(set__finish_time=finished, set__state=constants.CALL_ERROR_STATE, set__traceback=traceback) if action == 'bind': ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': ReplyHandler._unbind_failed(task_id, call_context) return def progress(self, reply): """ Notification (reply) indicating an RMI has reported status. This information is relayed to the task coordinator. :param reply: A progress reply object. :type reply: gofer.rmi.async.Progress """ call_context = dict(reply.data) task_id = call_context['task_id'] TaskStatus.objects(task_id=task_id).update_one(set__progress_report=reply.details)
class ReplyHandler(Listener): """ The async RMI reply handler. :ivar consumer: The reply consumer. :type consumer: ReplyConsumer """ # --- action post-processing --------------------------------------------- @staticmethod def _bind_succeeded(action_id, call_context): """ Bind succeeded. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_succeeded(consumer_id, repo_id, distributor_id, action_id) @staticmethod def _unbind_succeeded(call_context): """ Update the bind action. :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.delete(consumer_id, repo_id, distributor_id, force=True) @staticmethod def _bind_failed(action_id, call_context): """ The bind failed. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_failed(consumer_id, repo_id, distributor_id, action_id) # added for clarity _unbind_failed = _bind_failed def __init__(self, url, transport): """ :param url: The broker URL. :type url: str :param transport: The gofer transport. :type transport: str """ queue = Queue(Services.REPLY_QUEUE, transport=transport) self.consumer = ReplyConsumer(queue, url=url, transport=transport, authenticator=Authenticator()) # --- agent replies ------------------------------------------------------ def start(self): """ Start the reply handler (thread) """ self.consumer.start(self) log.info('Task reply handler, started.') def accepted(self, reply): """ Notification that an RMI has started executing in the agent. The task status is updated in the pulp DB. :param reply: A status reply object. :type reply: gofer.rmi.async.Started """ call_context = reply.any task_id = call_context['task_id'] TaskStatusManager.set_task_accepted(task_id) def started(self, reply): """ Notification that an RMI has started executing in the agent. The task status is updated in the pulp DB. :param reply: A status reply object. :type reply: gofer.rmi.async.Started """ call_context = reply.any task_id = call_context['task_id'] TaskStatusManager.set_task_started(task_id) def rejected(self, reply): """ Notification (reply) indicating an RMI request has been rejected. This information used to update the task status. :param reply: A rejected reply object. :type reply: gofer.rmi.async.Rejected """ log.info('Task RMI (rejected)\n%s', reply) call_context = dict(reply.any) action = call_context.get('action') task_id = call_context['task_id'] TaskStatusManager.set_task_failed(task_id) if action == 'bind': ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': ReplyHandler._unbind_failed(task_id, call_context) return def succeeded(self, reply): """ Notification (reply) indicating an RMI succeeded. This information is relayed to the task coordinator. :param reply: A successful reply object. :type reply: gofer.rmi.async.Succeeded """ log.info('Task RMI (succeeded)\n%s', reply) call_context = dict(reply.any) action = call_context.get('action') task_id = call_context['task_id'] result = dict(reply.retval) TaskStatusManager.set_task_succeeded(task_id, result) if action == 'bind': if result['succeeded']: ReplyHandler._bind_succeeded(task_id, call_context) else: ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': if result['succeeded']: ReplyHandler._unbind_succeeded(call_context) else: ReplyHandler._unbind_failed(task_id, call_context) return def failed(self, reply): """ Notification (reply) indicating an RMI failed. This information used to update the task status. :param reply: A failure reply object. :type reply: gofer.rmi.async.Failed """ log.info('Task RMI (failed)\n%s', reply) call_context = dict(reply.any) action = call_context.get('action') task_id = call_context['task_id'] traceback = reply.xstate['trace'] TaskStatusManager.set_task_failed(task_id, traceback) if action == 'bind': ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': ReplyHandler._unbind_failed(task_id, call_context) return def progress(self, reply): """ Notification (reply) indicating an RMI has reported status. This information is relayed to the task coordinator. :param reply: A progress reply object. :type reply: gofer.rmi.async.Progress """ call_context = dict(reply.any) task_id = call_context['task_id'] delta = {'progress_report': reply.details} TaskStatusManager.update_task_status(task_id, delta)
else: authenticator = None Agent.url = url Agent.address = address Agent.base_options['authenticator'] = authenticator # test_plugin_shutdown(1) # test_zombie() # test_memory() test_forked() queue = Queue(address.split('/')[-1].upper()) queue.durable = False queue.declare(url) reply_consumer = ReplyConsumer(queue, url=url, authenticator=authenticator) reply_consumer.start(on_reply) test_cancel() demo_progress() # demo_authentication(yp) smoke_test() demo_constructors() test_triggers() demo_getitem() demo(Agent()) n_threads = int(options.threads) if n_threads: print('======= RUNNING {} THREADS ============'.format(n_threads))
class ReplyHandler(Listener): """ The async RMI reply handler. :ivar consumer: The reply consumer. :type consumer: ReplyConsumer """ # --- action post-processing --------------------------------------------- @staticmethod def _bind_succeeded(action_id, call_context): """ Bind succeeded. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_succeeded(consumer_id, repo_id, distributor_id, action_id) @staticmethod def _unbind_succeeded(call_context): """ Update the bind action. :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.delete(consumer_id, repo_id, distributor_id, force=True) @staticmethod def _bind_failed(action_id, call_context): """ The bind failed. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_failed(consumer_id, repo_id, distributor_id, action_id) # added for clarity _unbind_failed = _bind_failed def __init__(self, url, transport): """ :param url: The broker URL. :type url: str :param transport: The gofer transport. :type transport: str """ queue = Queue(Services.REPLY_QUEUE, transport=transport) self.consumer = ReplyConsumer(queue, url=url, transport=transport, authenticator=Authenticator()) # --- agent replies ------------------------------------------------------ def start(self): """ Start the reply handler (thread) """ self.consumer.start(self) log.info(_('Task reply handler, started.')) def accepted(self, reply): """ Notification that an RMI has started executing in the agent. The task status is updated in the pulp DB. :param reply: A status reply object. :type reply: gofer.rmi.async.Accepted """ log.debug(_('Task RMI (accepted): %(r)s'), {'r': reply}) call_context = dict(reply.any) task_id = call_context['task_id'] TaskStatusManager.set_task_accepted(task_id) def started(self, reply): """ Notification that an RMI has started executing in the agent. The task status is updated in the pulp DB. :param reply: A status reply object. :type reply: gofer.rmi.async.Started """ log.debug(_('Task RMI (started): %(r)s'), {'r': reply}) call_context = dict(reply.any) task_id = call_context['task_id'] TaskStatusManager.set_task_started(task_id, timestamp=reply.timestamp) def rejected(self, reply): """ Notification (reply) indicating an RMI request has been rejected. This information used to update the task status. :param reply: A rejected reply object. :type reply: gofer.rmi.async.Rejected """ log.warn(_('Task RMI (rejected): %(r)s'), {'r': reply}) call_context = dict(reply.any) action = call_context.get('action') task_id = call_context['task_id'] TaskStatusManager.set_task_failed(task_id, timestamp=reply.timestamp) if action == 'bind': ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': ReplyHandler._unbind_failed(task_id, call_context) return def succeeded(self, reply): """ Notification (reply) indicating an RMI succeeded. This information is relayed to the task coordinator. :param reply: A successful reply object. :type reply: gofer.rmi.async.Succeeded """ log.info(_('Task RMI (succeeded): %(r)s'), {'r': reply}) call_context = dict(reply.any) action = call_context.get('action') task_id = call_context['task_id'] result = dict(reply.retval) TaskStatusManager.set_task_succeeded(task_id, result=result, timestamp=reply.timestamp) if action == 'bind': if result['succeeded']: ReplyHandler._bind_succeeded(task_id, call_context) else: ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': if result['succeeded']: ReplyHandler._unbind_succeeded(call_context) else: ReplyHandler._unbind_failed(task_id, call_context) return def failed(self, reply): """ Notification (reply) indicating an RMI failed. This information used to update the task status. :param reply: A failure reply object. :type reply: gofer.rmi.async.Failed """ log.info(_('Task RMI (failed): %(r)s'), {'r': reply}) call_context = dict(reply.any) action = call_context.get('action') task_id = call_context['task_id'] traceback = reply.xstate['trace'] TaskStatusManager.set_task_failed(task_id, traceback=traceback, timestamp=reply.timestamp) if action == 'bind': ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': ReplyHandler._unbind_failed(task_id, call_context) return def progress(self, reply): """ Notification (reply) indicating an RMI has reported status. This information is relayed to the task coordinator. :param reply: A progress reply object. :type reply: gofer.rmi.async.Progress """ call_context = dict(reply.any) task_id = call_context['task_id'] delta = {'progress_report': reply.details} TaskStatusManager.update_task_status(task_id, delta)
def testBasic(self): listener = Mock() watchdog = Mock() routing = (0,1) reply = ReplyConsumer(REPLYTO) reply.start(listener, watchdog) watchdog.track(SN) # started reply.dispatch( Envelope(sn=SN, routing=routing, any=ANY, status='started')) self.assertTrue(watchdog.started.called_with_args([SN,])) self.assertTrue(listener.called) arg = listener.call_args[0][0] self.assertEquals(arg.sn, SN) self.assertEquals(arg.origin, routing[0]) self.assertEquals(arg.any, ANY) # progress reply.dispatch( Envelope(sn=SN, routing=routing, any=ANY, status='progress')) self.assertTrue(watchdog.progress.called_with_args([SN,])) self.assertTrue(listener.called) arg = listener.call_args[0][0] self.assertEquals(arg.sn, SN) self.assertEquals(arg.origin, routing[0]) self.assertEquals(arg.any, ANY) # succeeded retval = 123 reply.dispatch( Envelope(sn=SN, routing=routing, any=ANY, result=Envelope(retval=retval))) self.assertTrue(watchdog.completed.called_with_args([SN,])) self.assertTrue(listener.called) arg = listener.call_args[0][0] self.assertEquals(arg.sn, SN) self.assertEquals(arg.origin, routing[0]) self.assertEquals(arg.any, ANY) self.assertEquals(arg.retval, retval) # failed reply.blacklist = set() # reset the blacklist exval = 123 reply.dispatch( Envelope(sn=SN, routing=routing, any=ANY, result=Envelope(exval=exval))) self.assertTrue(watchdog.completed.called_with_args([SN,])) self.assertTrue(listener.called) arg = listener.call_args[0][0] self.assertEquals(arg.sn, SN) self.assertEquals(arg.origin, routing[0]) self.assertEquals(arg.any, ANY) self.assertEquals(arg.exval.message, exval)
def __init__(self, url): queue = Queue(Services.CTAG) self.consumer = ReplyConsumer(queue, url=url)
def __init__(self, url): queue = Queue(self.CTAG) self.consumer = ReplyConsumer(queue, url=url)
class ReplyHandler(Listener): """ The async RMI reply handler. :cvar REPLY_QUEUE: The agent RMI reply queue. :type REPLY_QUEUE: str :ivar consumer: The reply consumer. :type consumer: ReplyConsumer """ REPLY_QUEUE = 'pulp.task' @staticmethod def _bind_succeeded(action_id, call_context): """ Bind succeeded. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_succeeded(consumer_id, repo_id, distributor_id, action_id) @staticmethod def _unbind_succeeded(call_context): """ Update the bind action. :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.delete(consumer_id, repo_id, distributor_id, force=True) @staticmethod def _bind_failed(action_id, call_context): """ The bind failed. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_failed(consumer_id, repo_id, distributor_id, action_id) # added for clarity _unbind_failed = _bind_failed def __init__(self, url): """ :param url: The broker URL. :type url: str """ queue = Queue(ReplyHandler.REPLY_QUEUE) queue.durable = True queue.declare(url) self.consumer = ReplyConsumer(queue, url=url, authenticator=Authenticator()) def start(self): """ Start the reply handler (thread) """ self.consumer.start(self) _logger.info(_('Task reply handler, started.')) def accepted(self, reply): """ Notification that an RMI has started executing in the agent. The task status is updated in the pulp DB. :param reply: A status reply object. :type reply: gofer.rmi.async.Accepted """ _logger.debug(_('Task RMI (accepted): %(r)s'), {'r': reply}) call_context = dict(reply.data) task_id = call_context['task_id'] TaskStatus.objects(task_id=task_id, state=constants.CALL_WAITING_STATE).\ update_one(set__state=constants.CALL_ACCEPTED_STATE) def started(self, reply): """ Notification that an RMI has started executing in the agent. The task status is updated in the pulp DB. :param reply: A status reply object. :type reply: gofer.rmi.async.Started """ _logger.debug(_('Task RMI (started): %(r)s'), {'r': reply}) call_context = dict(reply.data) task_id = call_context['task_id'] started = reply.timestamp if not started: now = datetime.now(dateutils.utc_tz()) started = dateutils.format_iso8601_datetime(now) TaskStatus.objects(task_id=task_id).update_one(set__start_time=started) TaskStatus.objects(task_id=task_id, state__in=[constants.CALL_WAITING_STATE, constants.CALL_ACCEPTED_STATE]).\ update_one(set__state=constants.CALL_RUNNING_STATE) def rejected(self, reply): """ Notification (reply) indicating an RMI request has been rejected. This information used to update the task status. :param reply: A rejected reply object. :type reply: gofer.rmi.async.Rejected """ _logger.warn(_('Task RMI (rejected): %(r)s'), {'r': reply}) call_context = dict(reply.data) action = call_context.get('action') task_id = call_context['task_id'] finished = reply.timestamp if not finished: now = datetime.now(dateutils.utc_tz()) finished = dateutils.format_iso8601_datetime(now) TaskStatus.objects(task_id=task_id).update_one( set__finish_time=finished, set__state=constants.CALL_ERROR_STATE) if action == 'bind': ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': ReplyHandler._unbind_failed(task_id, call_context) return def succeeded(self, reply): """ Notification (reply) indicating an RMI succeeded. This information is relayed to the task coordinator. :param reply: A successful reply object. :type reply: gofer.rmi.async.Succeeded """ _logger.info(_('Task RMI (succeeded): %(r)s'), {'r': reply}) call_context = dict(reply.data) action = call_context.get('action') task_id = call_context['task_id'] result = dict(reply.retval) finished = reply.timestamp if not finished: now = datetime.now(dateutils.utc_tz()) finished = dateutils.format_iso8601_datetime(now) TaskStatus.objects(task_id=task_id).update_one( set__finish_time=finished, set__state=constants.CALL_FINISHED_STATE, set__result=result) if action == 'bind': if result['succeeded']: ReplyHandler._bind_succeeded(task_id, call_context) else: ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': if result['succeeded']: ReplyHandler._unbind_succeeded(call_context) else: ReplyHandler._unbind_failed(task_id, call_context) return def failed(self, reply): """ Notification (reply) indicating an RMI failed. This information used to update the task status. :param reply: A failure reply object. :type reply: gofer.rmi.async.Failed """ _logger.info(_('Task RMI (failed): %(r)s'), {'r': reply}) call_context = dict(reply.data) action = call_context.get('action') task_id = call_context['task_id'] traceback = reply.xstate['trace'] finished = reply.timestamp if not finished: now = datetime.now(dateutils.utc_tz()) finished = dateutils.format_iso8601_datetime(now) TaskStatus.objects(task_id=task_id).update_one( set__finish_time=finished, set__state=constants.CALL_ERROR_STATE, set__traceback=traceback) if action == 'bind': ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': ReplyHandler._unbind_failed(task_id, call_context) return def progress(self, reply): """ Notification (reply) indicating an RMI has reported status. This information is relayed to the task coordinator. :param reply: A progress reply object. :type reply: gofer.rmi.async.Progress """ call_context = dict(reply.data) task_id = call_context['task_id'] TaskStatus.objects(task_id=task_id).update_one( set__progress_report=reply.details)
class ReplyHandler(Listener): """ The async RMI reply handler. :ivar consumer: The reply consumer. :type consumer: ReplyConsumer """ # --- action post-processing --------------------------------------------- @staticmethod def _bind_succeeded(action_id, call_context): """ Bind succeeded. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_succeeded(consumer_id, repo_id, distributor_id, action_id) @staticmethod def _unbind_succeeded(call_context): """ Update the bind action. :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.delete(consumer_id, repo_id, distributor_id, force=True) @staticmethod def _bind_failed(action_id, call_context): """ The bind failed. Update the bind action. :param action_id: The action ID (basically the task_id). :type action_id: str :param call_context: The information about the bind call that was passed to the agent to be round tripped back here. :type call_context: dict """ manager = managers.consumer_bind_manager() consumer_id = call_context['consumer_id'] repo_id = call_context['repo_id'] distributor_id = call_context['distributor_id'] manager.action_failed(consumer_id, repo_id, distributor_id, action_id) # added for clarity _unbind_failed = _bind_failed def __init__(self, url): queue = Queue(Services.REPLY_QUEUE) self.consumer = ReplyConsumer(queue, url=url) # --- agent replies ------------------------------------------------------ def start(self, watchdog): """ Start the reply handler (thread) :param watchdog: A watchdog object used to synthesize timeouts. :type watchdog: Watchdog """ self.consumer.start(self, watchdog=watchdog) log.info('Task reply handler, started.') def started(self, reply): """ Notification that an RMI has started executing in the agent. The task status is updated in the pulp DB. :param reply: A status reply object. :type reply: gofer.rmi.async.Started """ call_context = reply.any task_id = call_context['task_id'] TaskStatusManager.set_task_started(task_id) def succeeded(self, reply): """ Notification (reply) indicating an RMI succeeded. This information is relayed to the task coordinator. :param reply: A successful reply object. :type reply: gofer.rmi.async.Succeeded """ log.info('Task RMI (succeeded)\n%s', reply) call_context = dict(reply.any) action = call_context.get('action') task_id = call_context['task_id'] result = dict(reply.retval) TaskStatusManager.set_task_succeeded(task_id, result) if action == 'bind': if result['succeeded']: ReplyHandler._bind_succeeded(task_id, call_context) else: ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': if result['succeeded']: ReplyHandler._unbind_succeeded(call_context) else: ReplyHandler._unbind_failed(task_id, call_context) return def failed(self, reply): """ Notification (reply) indicating an RMI failed. This information used to update the task status. :param reply: A failure reply object. :type reply: gofer.rmi.async.Failed """ log.info('Task RMI (failed)\n%s', reply) call_context = dict(reply.any) action = call_context.get('action') task_id = call_context['task_id'] traceback = reply.xstate['trace'] TaskStatusManager.set_task_failed(task_id, traceback) if action == 'bind': ReplyHandler._bind_failed(task_id, call_context) return if action == 'unbind': ReplyHandler._unbind_failed(task_id, call_context) return def progress(self, reply): """ Notification (reply) indicating an RMI has reported status. This information is relayed to the task coordinator. :param reply: A progress reply object. :type reply: gofer.rmi.async.Progress """ call_context = dict(reply.any) task_id = call_context['task_id'] delta = {'progress_report': reply.details} TaskStatusManager.update_task_status(task_id, delta)
def __init__(self, url): queue = Queue(Services.REPLY_QUEUE) self.consumer = ReplyConsumer(queue, url=url)
if options.auth: authenticator = TestAuthenticator() else: authenticator = None Agent.url = url Agent.address = address Agent.base_options['authenticator'] = authenticator # test_memory() queue = Queue(address.split('/')[-1].upper()) queue.durable = False queue.declare(url) reply_consumer = ReplyConsumer(queue, url=url, authenticator=authenticator) reply_consumer.start(on_reply) # demo_progress(1) # test_performance() demo_authentication(yp) smoke_test() demo_constructors() test_triggers() demo_getitem() n_threads = int(options.threads) if n_threads: print '======= RUNNING %d THREADS ============' % n_threads sleep(2)
print dog.bark("hello again") # watchdog print "(watchdog) asynchronous" agent = Agent(uuid, ctag=tag) dog = agent.Dog(watchdog=watchdog, timeout=3, any="jeff") dog.bark("who you calling a watchdog?") dog.sleep(5) if __name__ == "__main__": uuid = "xyz" yp = {} yp["root"] = sys.argv[1] yp["jortel"] = sys.argv[2] rcon = ReplyConsumer(Queue(uuid.upper())) rcon.start(onReply, watchdog=watchdog) # demoProgress(uuid, 1) # demoWindow(uuid, 1) # perftest(uuid) # demoperftest(uuid) # demoWatchdog(uuid, 1) demogetItem(uuid) demoauth(uuid, yp) democonst(uuid) triggertest(uuid) if len(sys.argv) > 3: n = int(sys.argv[3]) print "======= RUNNING %d THREADS ============" % n sleep(2) last = threads(uuid, n)