def _get_by_id(self, base_path, project_id, queue_name, ids): """Returns one or more messages from the queue by ID.""" try: validate.message_listing(limit=len(ids)) messages = self.message_controller.bulk_get(queue_name, message_ids=ids, project=project_id) except input_exceptions.ValidationFailed as ex: raise wsgi_exceptions.HTTPBadRequestBody(str(ex)) except Exception as ex: LOG.exception(ex) description = _(u'Message could not be retrieved.') raise wsgi_exceptions.HTTPServiceUnavailable(description) # Prepare response messages = list(messages) if not messages: return None base_path += '/' for each_message in messages: each_message['href'] = base_path + each_message['id'] del each_message['id'] return messages
def _get_by_id(self, base_path, project_id, queue_name, ids): """Returns one or more messages from the queue by ID.""" try: validate.message_listing(limit=len(ids)) messages = self.message_controller.bulk_get( queue_name, message_ids=ids, project=project_id) except input_exceptions.ValidationFailed as ex: raise wsgi_exceptions.HTTPBadRequestBody(str(ex)) except Exception as ex: LOG.exception(ex) description = _(u'Message could not be retrieved.') raise wsgi_exceptions.HTTPServiceUnavailable(description) # Prepare response messages = list(messages) if not messages: return None base_path += '/' for each_message in messages: each_message['href'] = base_path + each_message['id'] del each_message['id'] return messages
def _get(self, req, project_id, queue_name): uuid = req.get_header('Client-ID', required=True) 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: validate.message_listing(**kwargs) results = self.message_controller.list( queue_name, project=project_id, client_uuid=uuid, **kwargs) # Buffer messages cursor = next(results) messages = list(cursor) except input_exceptions.ValidationFailed as ex: raise wsgi_exceptions.HTTPBadRequestBody(str(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) } ] }
def _get(self, req, project_id, queue_name): uuid = req.get_header('Client-ID', required=True) 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: validate.message_listing(**kwargs) results = self.message_controller.list(queue_name, project=project_id, client_uuid=uuid, **kwargs) # Buffer messages cursor = next(results) messages = list(cursor) except input_exceptions.ValidationFailed as ex: raise wsgi_exceptions.HTTPBadRequestBody(str(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) }] }
def on_delete(self, req, resp, project_id, queue_name): # NOTE(zyuan): Attempt to delete the whole message collection # (without an "ids" parameter) is not allowed ids = req.get_param_as_list('ids', required=True) try: validate.message_listing(limit=len(ids)) self.message_controller.bulk_delete(queue_name, message_ids=ids, project=project_id) except input_exceptions.ValidationFailed as ex: raise wsgi_exceptions.HTTPBadRequestBody(str(ex)) except Exception as ex: LOG.exception(ex) description = _(u'Messages could not be deleted.') raise wsgi_exceptions.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204
def on_delete(self, req, resp, project_id, queue_name): # NOTE(zyuan): Attempt to delete the whole message collection # (without an "ids" parameter) is not allowed ids = req.get_param_as_list('ids', required=True) try: validate.message_listing(limit=len(ids)) self.message_controller.bulk_delete( queue_name, message_ids=ids, project=project_id) except input_exceptions.ValidationFailed as ex: raise wsgi_exceptions.HTTPBadRequestBody(str(ex)) except Exception as ex: LOG.exception(ex) description = _(u'Messages could not be deleted.') raise wsgi_exceptions.HTTPServiceUnavailable(description) resp.status = falcon.HTTP_204