def queue_list(self, req): """Gets a list of queues :param req: Request instance ready to be sent. :type req: `api.common.Request` :return: resp: Response instance :type: resp: `api.common.Response` """ project_id = req._headers.get('X-Project-ID') LOG.debug(u'Queue list - project: %(project)s', {'project': project_id}) try: kwargs = api_utils.get_headers(req) self._validate.queue_listing(**kwargs) results = self._queue_controller.list(project=project_id, **kwargs) # Buffer list of queues. Can raise NoPoolFound error. queues = list(next(results)) except (ValueError, validation.ValidationFailed) as ex: LOG.debug(ex) headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.ExceptionBase as ex: LOG.exception(ex) error = 'Queues could not be listed.' headers = {'status': 503} return api_utils.error_response(req, ex, headers, error) # Got some. Prepare the response. body = {'queues': queues} headers = {'status': 200} return response.Response(req, body, headers)
def message_list(self, req): """Gets a list of messages on a queue :param req: Request instance ready to be sent. :type req: `api.common.Request` :return: resp: Response instance :type: resp: `api.common.Response` """ project_id = req._headers.get('X-Project-ID') queue_name = req._body.get('queue_name') LOG.debug(u'Message list - queue: %(queue)s, ' u'project: %(project)s', { 'queue': queue_name, 'project': project_id }) try: kwargs = api_utils.get_headers(req) self._validate.client_id_uuid_safe(req._headers.get('Client-ID')) client_uuid = api_utils.get_client_uuid(req) 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 (ValueError, api_errors.BadRequest, validation.ValidationFailed) as ex: LOG.debug(ex) headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.DoesNotExist as ex: LOG.debug(ex) headers = {'status': 404} return api_utils.error_response(req, ex, headers) if messages: # Found some messages, so prepare the response kwargs['marker'] = next(results) messages = [ api_utils.format_message(message) for message in messages ] headers = {'status': 200} body = {'messages': messages} return response.Response(req, body, headers)
def message_list(self, req): """Gets a list of messages on a queue :param req: Request instance ready to be sent. :type req: `api.common.Request` :return: resp: Response instance :type: resp: `api.common.Response` """ project_id = req._headers.get('X-Project-ID') queue_name = req._body.get('queue_name') LOG.debug(u'Message list - queue: %(queue)s, ' u'project: %(project)s', {'queue': queue_name, 'project': project_id}) try: kwargs = api_utils.get_headers(req) self._validate.client_id_uuid_safe(req._headers.get('Client-ID')) client_uuid = api_utils.get_client_uuid(req) 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 (ValueError, api_errors.BadRequest, validation.ValidationFailed) as ex: LOG.debug(ex) headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.DoesNotExist as ex: LOG.debug(ex) headers = {'status': 404} return api_utils.error_response(req, ex, headers) if messages: # Found some messages, so prepare the response kwargs['marker'] = next(results) messages = [api_utils.format_message(message) for message in messages] headers = {'status': 200} body = {'messages': messages} return response.Response(req, body, headers)
def subscription_list(self, req): """List all subscriptions for a queue. :param req: Request instance ready to be sent. :type req: `api.common.Request` :return: resp: Response instance :type: resp: `api.common.Response` """ project_id = req._headers.get('X-Project-ID') queue_name = req._body.get('queue_name') LOG.debug(u'Subscription list - project: %(project)s', {'project': project_id}) try: kwargs = api_utils.get_headers(req) self._validate.subscription_listing(**kwargs) results = self._subscription_controller.list(queue_name, project=project_id, **kwargs) except (ValueError, validation.ValidationFailed) as ex: LOG.debug(ex) headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.ExceptionBase as ex: LOG.exception(ex) error = 'Subscriptions could not be listed.' headers = {'status': 503} return api_utils.error_response(req, ex, error, headers) # Buffer list of queues subscriptions = list(next(results)) # Got some. Prepare the response. body = {'subscriptions': subscriptions} headers = {'status': 200} return response.Response(req, body, headers)
def subscription_list(self, req): """List all subscriptions for a queue. :param req: Request instance ready to be sent. :type req: `api.common.Request` :return: resp: Response instance :type: resp: `api.common.Response` """ project_id = req._headers.get('X-Project-ID') queue_name = req._body.get('queue_name') LOG.debug(u'Subscription list - project: %(project)s', {'project': project_id}) try: kwargs = api_utils.get_headers(req) self._validate.subscription_listing(**kwargs) results = self._subscription_controller.list( queue_name, project=project_id, **kwargs) except (ValueError, validation.ValidationFailed) as ex: LOG.debug(ex) headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.ExceptionBase as ex: LOG.exception(ex) error = 'Subscriptions could not be listed.' headers = {'status': 503} return api_utils.error_response(req, ex, error, headers) # Buffer list of queues subscriptions = list(next(results)) # Got some. Prepare the response. body = {'subscriptions': subscriptions} headers = {'status': 200} return response.Response(req, body, headers)
def queue_list(self, req): """Gets a list of queues :param req: Request instance ready to be sent. :type req: `api.common.Request` :return: resp: Response instance :type: resp: `api.common.Response` """ project_id = req._headers.get('X-Project-ID') LOG.debug(u'Queue list - project: %(project)s', {'project': project_id}) try: kwargs = api_utils.get_headers(req) self._validate.queue_listing(**kwargs) results = self._queue_controller.list( project=project_id, **kwargs) # Buffer list of queues. Can raise NoPoolFound error. queues = list(next(results)) except (ValueError, validation.ValidationFailed) as ex: LOG.debug(ex) headers = {'status': 400} return api_utils.error_response(req, ex, headers) except storage_errors.ExceptionBase as ex: LOG.exception(ex) error = 'Queues could not be listed.' headers = {'status': 503} return api_utils.error_response(req, ex, headers, error) # Got some. Prepare the response. body = {'queues': queues} headers = {'status': 200} return response.Response(req, body, headers)
def claim_create(self, req): """Creates a claim :param req: Request instance ready to be sent. :type req: `api.common.Request` :return: resp: Response instance :type: resp: `api.common.Response` """ project_id = req._headers.get('X-Project-ID') queue_name = req._body.get('queue_name') LOG.debug(u'Claims create - queue: %(queue)s, ' u'project: %(project)s', {'queue': queue_name, 'project': project_id}) self._claim_post_spec = ( ('ttl', int, self._defaults.claim_ttl), ('grace', int, self._defaults.claim_grace), ) # Claim some messages # NOTE(vkmc): We build a dict with the ttl and grace # This is the metadata the storage is waiting for kwargs = api_utils.get_headers(req) # Read claim metadata (e.g., ttl) and raise appropriate # errors as needed. metadata = api_utils.sanitize(kwargs, self._claim_post_spec) limit = (None if kwargs.get('limit') is None else kwargs.get('limit')) claim_options = {} if limit is None else {'limit': limit} try: self._validate.claim_creation(metadata, limit=limit) except (ValueError, validation.ValidationFailed) as ex: LOG.debug(ex) headers = {'status': 400} return api_utils.error_response(req, ex, headers) cid, msgs = self._claim_controller.create( queue_name, metadata=metadata, project=project_id, **claim_options) # Buffer claimed messages # TODO(vkmc): optimize, along with serialization (below) resp_msgs = list(msgs) # Serialize claimed messages, if any. This logic assumes # the storage driver returned well-formed messages. if len(resp_msgs) != 0: resp_msgs = [api_utils.format_message(msg, cid) for msg in resp_msgs] headers = {'status': 201} body = {'claim_id': cid, 'messages': resp_msgs} else: headers = {'status': 204} body = {'claim_id': cid} return response.Response(req, body, headers)