feat(wsgi): message bulk deletion

The purpose of this feature is to allow the "Location" header
returned from message posting to accept the DELETE method.

    DELETE /queues/q/messages?ids=msgid1,msgid2...

Note that if the "ids" parameter is not present, such an
operation will be denied.

Change-Id: Id8313a675c2427b772f1e9095452dda4d0d67432
Implements: blueprint message-bulk-delete
Fixes: bug #1201649
This commit is contained in:
Zhihao Yuan 2013-07-16 18:11:37 -04:00
parent 9e3d6c980f
commit 20f1576b29
2 changed files with 49 additions and 0 deletions

View File

@ -143,6 +143,36 @@ class MessagesBaseTest(base.TestBase):
self.simulate_get(path + '/' + msg_id, self.project_id)
self.assertEquals(self.srmock.status, falcon.HTTP_404)
# Safe to delete non-existing ones
self.simulate_delete(path + '/' + msg_id, self.project_id)
self.assertEquals(self.srmock.status, falcon.HTTP_204)
def test_bulk_delete(self):
path = self.queue_path + '/messages'
self._post_messages(path, repeat=5)
[target, params] = self.srmock.headers_dict['Location'].split('?')
# Deleting the whole collection is denied
self.simulate_delete(path, self.project_id)
self.assertEquals(self.srmock.status, falcon.HTTP_400)
self.simulate_delete(target, self.project_id, query_string=params)
self.assertEquals(self.srmock.status, falcon.HTTP_204)
self.simulate_get(target, self.project_id, query_string=params)
self.assertEquals(self.srmock.status, falcon.HTTP_404)
# Safe to delete non-existing ones
self.simulate_delete(target, self.project_id, query_string=params)
self.assertEquals(self.srmock.status, falcon.HTTP_204)
# Even after the queue is gone
self.simulate_delete(self.queue_path, self.project_id)
self.assertEquals(self.srmock.status, falcon.HTTP_204)
self.simulate_delete(target, self.project_id, query_string=params)
self.assertEquals(self.srmock.status, falcon.HTTP_204)
def test_list(self):
path = self.queue_path + '/messages'
self._post_messages(path, repeat=10)

View File

@ -210,6 +210,25 @@ class CollectionResource(object):
resp.body = helpers.to_json(response)
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:
self.message_controller.bulk_delete(
queue_name,
message_ids=ids,
project=project_id)
except Exception as ex:
LOG.exception(ex)
description = 'Messages could not be deleted.'
raise wsgi_exceptions.HTTPServiceUnavailable(description)
else:
resp.status = falcon.HTTP_204
class ItemResource(object):