Ejemplo n.º 1
0
    def _execute(self):
        """Private function that finds out the handler and execute it."""

        action_name = self.action.lower()
        method_name = action_name.replace('user', 'do')
        method = getattr(self, method_name, None)

        if method is None:
            reason = _('Unsupported action: %s') % self.action
            EVENT.error(self.context, self.user, self.action, 'Failed', reason)
            return self.RES_ERROR, reason

        return method()
Ejemplo n.º 2
0
    def set_status(self, result, reason=None):
        """Set action status based on return value from execute."""

        timestamp = wallclock()

        if result == self.RES_OK:
            status = self.SUCCEEDED
            db_api.action_mark_succeeded(self.context, self.id, timestamp)

        elif result == self.RES_ERROR:
            status = self.FAILED
            db_api.action_mark_failed(self.context, self.id, timestamp,
                                      reason=reason or 'ERROR')

        elif result == self.RES_TIMEOUT:
            status = self.FAILED
            db_api.action_mark_failed(self.context, self.id, timestamp,
                                      reason=reason or 'TIMEOUT')

        elif result == self.RES_CANCEL:
            status = self.CANCELLED
            db_api.action_mark_cancelled(self.context, self.id, timestamp)

        else:  # result == self.RES_RETRY:
            status = self.READY
            # Action failed at the moment, but can be retried
            # We abandon it and then notify other dispatchers to execute it
            db_api.action_abandon(self.context, self.id)

        if status == self.SUCCEEDED:
            EVENT.info(self.context, self, self.action, status, reason)
        elif status == self.READY:
            EVENT.warning(self.context, self, self.action, status, reason)
        else:
            EVENT.error(self.context, self, self.action, status, reason)

        self.status = status
        self.status_reason = reason
Ejemplo n.º 3
0
    def signal(self, cmd):
        '''Send a signal to the action.'''
        if cmd not in self.COMMANDS:
            return

        if cmd == self.SIG_CANCEL:
            expected_statuses = (self.INIT, self.WAITING, self.READY,
                                 self.RUNNING)
        elif cmd == self.SIG_SUSPEND:
            expected_statuses = (self.RUNNING)
        else:     # SIG_RESUME
            expected_statuses = (self.SUSPENDED)

        if self.status not in expected_statuses:
            reason = _("Action (%(action)s) is in unexpected status "
                       "(%(actual)s) while expected status should be one of "
                       "(%(expected)s).") % dict(action=self.id,
                                                 expected=expected_statuses,
                                                 actual=self.status)
            EVENT.error(self.context, self, cmd, status_reason=reason)
            return

        db_api.action_signal(self.context, self.id, cmd)