Example #1
0
    def process(self, *args, **kwargs):
        """A template method for all asynchronous tasks.

        This method should not be overridden by sub-classes. Rather the
        abstract methods below should be overridden.

        :param args: List of arguments passed in from the client.
        :param kwargs: Dict of arguments passed in from the client.
        :return: Returns :class:`FollowOnProcessingStatusDTO` if follow-on
                 processing (such as retrying this or another task) is
                 required, otherwise a None return indicates that no
                 follow-on processing is required.
        """
        name = self.get_name()
        result = None

        # Retrieve the target entity (such as an models.Order instance).
        try:
            entity = self.retrieve_entity(*args, **kwargs)
        except Exception:
            # Serious error!
            LOG.exception(
                u._LE("Could not retrieve information needed to "
                      "process task '%s'."), name)
            raise

        # Process the target entity.
        try:
            result = self.handle_processing(entity, *args, **kwargs)
        except Exception as e_orig:
            LOG.exception(
                u._LE("Could not perform processing for "
                      "task '%s'."), name)

            # Handle failure to process entity.
            try:
                status, message = api.generate_safe_exception_message(
                    name, e_orig)
                self.handle_error(entity, status, message, e_orig, *args,
                                  **kwargs)
            except Exception:
                LOG.exception(
                    u._LE("Problem handling an error for task '%s', "
                          "raising original "
                          "exception."), name)
            raise e_orig

        # Handle successful conclusion of processing.
        try:
            self.handle_success(entity, result, *args, **kwargs)
        except Exception:
            LOG.exception(
                u._LE("Could not process after successfully "
                      "executing task '%s'."), name)
            raise

        return result
Example #2
0
 def handler(inst, req, resp, *args, **kwargs):
     try:
         fn(inst, req, resp, *args, **kwargs)
     except falcon.HTTPError as f:
         LOG.exception('Falcon error seen')
         raise f  # Already converted to Falcon exception, just reraise
     except Exception as e:
         status, message = api.generate_safe_exception_message(
             operation_name, e)
         LOG.exception(message)
         api.abort(status, message, req, resp)
Example #3
0
 def handler(inst, *args, **kwargs):
     try:
         return fn(inst, *args, **kwargs)
     except exc.HTTPError as f:
         LOG.exception('Webob error seen')
         raise f  # Already converted to Webob exception, just reraise
     except Exception as e:
         status, message = api.generate_safe_exception_message(
             operation_name, e)
         LOG.exception(message)
         pecan.abort(status, message)
Example #4
0
 def handler(inst, *args, **kwargs):
     try:
         return fn(inst, *args, **kwargs)
     except exc.HTTPError as f:
         LOG.exception('Webob error seen')
         raise f  # Already converted to Webob exception, just reraise
     except Exception as e:
         status, message = api.generate_safe_exception_message(
             operation_name, e)
         LOG.exception(message)
         pecan.abort(status, message)
Example #5
0
 def handler(inst, req, resp, *args, **kwargs):
     try:
         fn(inst, req, resp, *args, **kwargs)
     except falcon.HTTPError as f:
         LOG.exception('Falcon error seen')
         raise f  # Already converted to Falcon exception, just reraise
     except Exception as e:
         status, message = api.generate_safe_exception_message(
             operation_name, e)
         LOG.exception(message)
         api.abort(status, message, req, resp)
Example #6
0
    def process(self, *args, **kwargs):
        """A template method for all asynchronous tasks.

        This method should not be overridden by sub-classes. Rather the
        abstract methods below should be overridden.

        :param args: List of arguments passed in from the client.
        :param kwargs: Dict of arguments passed in from the client.
        :return: Returns :class:`FollowOnProcessingStatusDTO` if follow-on
                 processing (such as retrying this or another task) is
                 required, otherwise a None return indicates that no
                 follow-on processing is required.
        """
        name = self.get_name()
        result = None

        # Retrieve the target entity (such as an models.Order instance).
        try:
            entity = self.retrieve_entity(*args, **kwargs)
        except Exception as e:
            # Serious error!
            LOG.exception(u._LE("Could not retrieve information needed to "
                                "process task '%s'."), name)
            raise e

        # Process the target entity.
        try:
            result = self.handle_processing(entity, *args, **kwargs)
        except Exception as e_orig:
            LOG.exception(u._LE("Could not perform processing for "
                                "task '%s'."), name)

            # Handle failure to process entity.
            try:
                status, message = api.generate_safe_exception_message(name,
                                                                      e_orig)
                self.handle_error(entity, status, message, e_orig,
                                  *args, **kwargs)
            except Exception:
                LOG.exception(u._LE("Problem handling an error for task '%s', "
                                    "raising original "
                                    "exception."), name)
            raise e_orig

        # Handle successful conclusion of processing.
        try:
            self.handle_success(entity, result, *args, **kwargs)
        except Exception as e:
            LOG.exception(u._LE("Could not process after successfully "
                                "executing task '%s'."), name)
            raise e

        return result
Example #7
0
        def handler(inst, *args, **kwargs):
            try:
                return fn(inst, *args, **kwargs)
            except exc.HTTPError:
                LOG.exception(u._LE('Webob error seen'))
                raise  # Already converted to Webob exception, just reraise
            # In case PolicyNotAuthorized, we do not want to expose payload by
            # logging exception, so just LOG.error
            except policy.PolicyNotAuthorized as pna:
                status, message = api.generate_safe_exception_message(
                    operation_name, pna)
                LOG.error(message)
                pecan.abort(status, message)
            except Exception as e:
                # In case intervening modules have disabled logging.
                LOG.logger.disabled = False

                status, message = api.generate_safe_exception_message(
                    operation_name, e)
                LOG.exception(message)
                pecan.abort(status, message)
Example #8
0
        def handler(inst, *args, **kwargs):
            try:
                return fn(inst, *args, **kwargs)
            except exc.HTTPError:
                LOG.exception(u._LE('Webob error seen'))
                raise  # Already converted to Webob exception, just reraise
            # In case PolicyNotAuthorized, we do not want to expose payload by
            # logging exception, so just LOG.error
            except policy.PolicyNotAuthorized as pna:
                status, message = api.generate_safe_exception_message(
                    operation_name, pna)
                LOG.error(message)
                pecan.abort(status, message)
            except Exception as e:
                # In case intervening modules have disabled logging.
                LOG.logger.disabled = False

                status, message = api.generate_safe_exception_message(
                    operation_name, e)
                LOG.exception(message)
                pecan.abort(status, message)
Example #9
0
    def test_handle_secret_content_encoding_not_supported_exception(self):
        operation = 'operation'
        content_encoding = 'application/octet-stream'
        test_excep = secret_store.SecretContentEncodingNotSupportedException(
            content_encoding)

        status, message = api.generate_safe_exception_message(
            operation, test_excep)

        self.assertEqual(400, status)
        self.assertEqual("operation issue seen - content-encoding of "
                         "'application/octet-stream' not "
                         "supported.", message)
Example #10
0
        def handler(inst, *args, **kwargs):
            try:
                return fn(inst, *args, **kwargs)
            except exc.HTTPError as f:
                LOG.exception(u._LE('Webob error seen'))
                raise f  # Already converted to Webob exception, just reraise
            except Exception as e:
                # In case intervening modules have disabled logging.
                LOG.logger.disabled = False

                status, message = api.generate_safe_exception_message(
                    operation_name, e)
                LOG.exception(message)
                pecan.abort(status, message)
Example #11
0
        def handler(inst, *args, **kwargs):
            try:
                return fn(inst, *args, **kwargs)
            except exc.HTTPError:
                LOG.exception(u._LE('Webob error seen'))
                raise  # Already converted to Webob exception, just reraise
            except Exception as e:
                # In case intervening modules have disabled logging.
                LOG.logger.disabled = False

                status, message = api.generate_safe_exception_message(
                    operation_name, e)
                LOG.exception(message)
                pecan.abort(status, message)
Example #12
0
    def process(self, *args, **kwargs):
        """A template method for all asynchronous tasks.

        This method should not be overridden by sub-classes. Rather the
        abstract methods below should be overridden.

        :param args: List of arguments passed in from the client.
        :param kwargs: Dict of arguments passed in from the client.
        :return: None
        """
        name = self.get_name()

        # Retrieve the target entity (such as an models.Order instance).
        try:
            entity = self.retrieve_entity(*args, **kwargs)
        except Exception as e:
            # Serious error!
            LOG.exception(u._("Could not retrieve information needed to " "process task '{0}'.").format(name))
            raise e

        # Process the target entity.
        try:
            self.handle_processing(entity, *args, **kwargs)
        except Exception as e_orig:
            LOG.exception(u._("Could not perform processing for " "task '{0}'.").format(name))

            # Handle failure to process entity.
            try:
                status, message = api.generate_safe_exception_message(name, e_orig)
                self.handle_error(entity, status, message, e_orig, *args, **kwargs)
            except Exception:
                LOG.exception(
                    u._("Problem handling an error for task '{0}', " "raising original " "exception.").format(name)
                )
            raise e_orig

        # Handle successful conclusion of processing.
        try:
            self.handle_success(entity, *args, **kwargs)
        except Exception as e:
            LOG.exception(u._("Could not process after successfully executing" " task '{0}'.").format(name))
            raise e