Пример #1
0
    def _get(self, req, project_id, queue_name):
        client_uuid = wsgi_utils.get_client_uuid(req)
        kwargs = {}

        # NOTE(kgriffs): This syntax ensures that
        # we don't clobber default values with None.
        req.get_param('marker', store=kwargs)
        req.get_param_as_int('limit', store=kwargs)
        req.get_param_as_bool('echo', store=kwargs)
        req.get_param_as_bool('include_claimed', store=kwargs)

        try:
            self._validate.message_listing(**kwargs)
            results = self.message_controller.list(
                queue_name,
                project=project_id,
                client_uuid=client_uuid,
                **kwargs)

            # Buffer messages
            cursor = next(results)
            messages = list(cursor)

        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        except storage_errors.DoesNotExist as ex:
            LOG.debug(ex)
            raise falcon.HTTPNotFound()

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Messages could not be listed.')
            raise wsgi_errors.HTTPServiceUnavailable(description)

        if not messages:
            messages = []

        else:
            # Found some messages, so prepare the response
            kwargs['marker'] = next(results)
            for each_message in messages:
                each_message['href'] = req.path + '/' + each_message['id']
                del each_message['id']

        return {
            'messages': messages,
            'links': [
                {
                    'rel': 'next',
                    'href': req.path + falcon.to_query_str(kwargs)
                }
            ]
        }
Пример #2
0
    def _get(self, req, project_id, queue_name):
        client_uuid = wsgi_utils.get_client_uuid(req)
        kwargs = {}

        # NOTE(kgriffs): This syntax ensures that
        # we don't clobber default values with None.
        req.get_param('marker', store=kwargs)
        req.get_param_as_int('limit', store=kwargs)
        req.get_param_as_bool('echo', store=kwargs)
        req.get_param_as_bool('include_claimed', store=kwargs)

        try:
            self._validate.message_listing(**kwargs)
            results = self.message_controller.list(queue_name,
                                                   project=project_id,
                                                   client_uuid=client_uuid,
                                                   **kwargs)

            # Buffer messages
            cursor = next(results)
            messages = list(cursor)

        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        except storage_errors.DoesNotExist as ex:
            LOG.debug(ex)
            raise falcon.HTTPNotFound()

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Messages could not be listed.')
            raise wsgi_errors.HTTPServiceUnavailable(description)

        if not messages:
            messages = []

        else:
            # Found some messages, so prepare the response
            kwargs['marker'] = next(results)
            for each_message in messages:
                each_message['href'] = req.path + '/' + each_message['id']
                del each_message['id']

        return {
            'messages':
            messages,
            'links': [{
                'rel': 'next',
                'href': req.path + falcon.to_query_str(kwargs)
            }]
        }
Пример #3
0
    def _get(self, req, project_id, queue_name):
        client_uuid = wsgi_utils.get_client_uuid(req)
        kwargs = {}

        # NOTE(kgriffs): This syntax ensures that
        # we don't clobber default values with None.
        req.get_param("marker", store=kwargs)
        req.get_param_as_int("limit", store=kwargs)
        req.get_param_as_bool("echo", store=kwargs)
        req.get_param_as_bool("include_claimed", store=kwargs)

        try:
            self._validate.message_listing(**kwargs)
            results = self.message_controller.list(queue_name, project=project_id, client_uuid=client_uuid, **kwargs)

            # Buffer messages
            cursor = next(results)
            messages = list(cursor)

        except validation.ValidationFailed as ex:
            raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex))

        except storage_exceptions.DoesNotExist:
            raise falcon.HTTPNotFound()

        except Exception as ex:
            LOG.exception(ex)
            description = _(u"Messages could not be listed.")
            raise wsgi_exceptions.HTTPServiceUnavailable(description)

        if not messages:
            return None

        # Found some messages, so prepare the response
        kwargs["marker"] = next(results)
        for each_message in messages:
            each_message["href"] = req.path + "/" + each_message["id"]
            del each_message["id"]

        return {"messages": messages, "links": [{"rel": "next", "href": req.path + falcon.to_query_str(kwargs)}]}
Пример #4
0
    def on_post(self, req, resp, project_id, queue_name):
        LOG.debug(
            _(u"Messages collection POST - queue:  %(queue)s, " u"project: %(project)s"),
            {"queue": queue_name, "project": project_id},
        )

        client_uuid = wsgi_utils.get_client_uuid(req)

        # Place JSON size restriction before parsing
        if req.content_length > self._wsgi_conf.content_max_length:
            description = _(u"Message collection size is too large.")
            raise wsgi_exceptions.HTTPBadRequestBody(description)

        # Pull out just the fields we care about
        messages = wsgi_utils.filter_stream(
            req.stream, req.content_length, MESSAGE_POST_SPEC, doctype=wsgi_utils.JSONArray
        )

        # Enqueue the messages
        partial = False

        try:
            # No need to check each message's size if it
            # can not exceed the request size limit
            self._validate.message_posting(
                messages,
                check_size=(self._validate._limits_conf.message_size_uplimit < self._wsgi_conf.content_max_length),
            )

            message_ids = self.message_controller.post(
                queue_name, messages=messages, project=project_id, client_uuid=client_uuid
            )

        except validation.ValidationFailed as ex:
            raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex))

        except storage_exceptions.DoesNotExist:
            raise falcon.HTTPNotFound()

        except storage_exceptions.MessageConflict as ex:
            LOG.exception(ex)
            partial = True
            message_ids = ex.succeeded_ids

            if not message_ids:
                # TODO(kgriffs): Include error code that is different
                # from the code used in the generic case, below.
                description = _(u"No messages could be enqueued.")
                raise wsgi_exceptions.HTTPServiceUnavailable(description)

        except Exception as ex:
            LOG.exception(ex)
            description = _(u"Messages could not be enqueued.")
            raise wsgi_exceptions.HTTPServiceUnavailable(description)

        # Prepare the response
        ids_value = ",".join(message_ids)
        resp.location = req.path + "?ids=" + ids_value

        hrefs = [req.path + "/" + id for id in message_ids]
        body = {"resources": hrefs, "partial": partial}
        resp.body = utils.to_json(body)
        resp.status = falcon.HTTP_201
Пример #5
0
    def on_post(self, req, resp, project_id, queue_name):
        LOG.debug(_(u'Messages collection POST - queue:  %(queue)s, '
                    u'project: %(project)s'),
                  {'queue': queue_name, 'project': project_id})

        client_uuid = wsgi_utils.get_client_uuid(req)

        try:
            # Place JSON size restriction before parsing
            self._validate.message_length(req.content_length)
        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        # Pull out just the fields we care about
        messages = wsgi_utils.filter_stream(
            req.stream,
            req.content_length,
            MESSAGE_POST_SPEC,
            doctype=wsgi_utils.JSONArray)

        # Enqueue the messages
        partial = False

        try:
            self._validate.message_posting(messages)

            message_ids = self.message_controller.post(
                queue_name,
                messages=messages,
                project=project_id,
                client_uuid=client_uuid)

        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        except storage_errors.DoesNotExist as ex:
            LOG.debug(ex)
            raise falcon.HTTPNotFound()

        except storage_errors.MessageConflict as ex:
            LOG.exception(ex)
            partial = True
            message_ids = ex.succeeded_ids

            if not message_ids:
                # TODO(kgriffs): Include error code that is different
                # from the code used in the generic case, below.
                description = _(u'No messages could be enqueued.')
                raise wsgi_errors.HTTPServiceUnavailable(description)

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Messages could not be enqueued.')
            raise wsgi_errors.HTTPServiceUnavailable(description)

        # Prepare the response
        ids_value = ','.join(message_ids)
        resp.location = req.path + '?ids=' + ids_value

        hrefs = [req.path + '/' + id for id in message_ids]
        body = {'resources': hrefs, 'partial': partial}
        resp.body = utils.to_json(body)
        resp.status = falcon.HTTP_201
Пример #6
0
    def on_post(self, req, resp, project_id, queue_name):
        LOG.debug(
            _(u'Messages collection POST - queue:  %(queue)s, '
              u'project: %(project)s'), {
                  'queue': queue_name,
                  'project': project_id
              })

        client_uuid = wsgi_utils.get_client_uuid(req)

        try:
            # Place JSON size restriction before parsing
            self._validate.message_length(req.content_length)
        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        # Pull out just the fields we care about
        messages = wsgi_utils.filter_stream(req.stream,
                                            req.content_length,
                                            MESSAGE_POST_SPEC,
                                            doctype=wsgi_utils.JSONArray)

        # Enqueue the messages
        partial = False

        try:
            self._validate.message_posting(messages)

            message_ids = self.message_controller.post(queue_name,
                                                       messages=messages,
                                                       project=project_id,
                                                       client_uuid=client_uuid)

        except validation.ValidationFailed as ex:
            LOG.debug(ex)
            raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))

        except storage_errors.DoesNotExist as ex:
            LOG.debug(ex)
            raise falcon.HTTPNotFound()

        except storage_errors.MessageConflict as ex:
            LOG.exception(ex)
            partial = True
            message_ids = ex.succeeded_ids

            if not message_ids:
                # TODO(kgriffs): Include error code that is different
                # from the code used in the generic case, below.
                description = _(u'No messages could be enqueued.')
                raise wsgi_errors.HTTPServiceUnavailable(description)

        except Exception as ex:
            LOG.exception(ex)
            description = _(u'Messages could not be enqueued.')
            raise wsgi_errors.HTTPServiceUnavailable(description)

        # Prepare the response
        ids_value = ','.join(message_ids)
        resp.location = req.path + '?ids=' + ids_value

        hrefs = [req.path + '/' + id for id in message_ids]
        body = {'resources': hrefs, 'partial': partial}
        resp.body = utils.to_json(body)
        resp.status = falcon.HTTP_201