
This patchset removes the ability to specify metadata when creating a queue as per the Marconi Weekly Meeting held on July 18th, 2013. It also adds a new endpoint: /v1/queues/{name}/metadata with operations - GET - PUT Removes: - GET /v1/queues/{queue_name} # replaced by metadata ^^ - the request body from PUT /v1/queues/{queue_name} Rationale: The addition of the metadata endpoint increases the extensibility of the API, and decouples metadata updates from queue creation. This makes it easier for us in the future to add other endpoints, say /v1/queues/{name}/config for modifying special values that change the behavior of the queue. With that addition, creating a queue with metadata became slightly more dangerous. In the case where a user accidentally tries to create a queue that already exists, the metadata for the existing queue would be overwritten by the PUT request body. By removing the ability to modify metadata at queue creation time, it also prevents these types of accidents. Tests: New unit tests added to capture expected behavior. Old tests were also updated to reflect new endpoint and behavior. Storage API changes: - storage(queue): get -> get_metadata Change-Id: Ie3a79a63a865035a789609dac770adabe4dc6ed7 Implements: blueprint metadata-resource
115 lines
3.6 KiB
Python
115 lines
3.6 KiB
Python
# Copyright (c) 2013 Rackspace, Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
# implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import falcon
|
|
|
|
import marconi.openstack.common.log as logging
|
|
from marconi.transport import helpers
|
|
from marconi.transport.wsgi import exceptions as wsgi_exceptions
|
|
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
class ItemResource(object):
|
|
|
|
__slots__ = ('queue_controller', 'message_controller')
|
|
|
|
def __init__(self, queue_controller, message_controller):
|
|
self.queue_controller = queue_controller
|
|
self.message_controller = message_controller
|
|
|
|
def on_put(self, req, resp, project_id, queue_name):
|
|
LOG.debug(_("Queue item PUT - queue: %(queue)s, "
|
|
"project: %(project)s") %
|
|
{"queue": queue_name, "project": project_id})
|
|
|
|
try:
|
|
created = self.queue_controller.create(
|
|
queue_name,
|
|
project=project_id)
|
|
|
|
except Exception as ex:
|
|
LOG.exception(ex)
|
|
description = _('Queue could not be created.')
|
|
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
|
|
|
resp.status = falcon.HTTP_201 if created else falcon.HTTP_204
|
|
resp.location = req.path
|
|
|
|
def on_delete(self, req, resp, project_id, queue_name):
|
|
LOG.debug(_("Queue item DELETE - queue: %(queue)s, "
|
|
"project: %(project)s") %
|
|
{"queue": queue_name, "project": project_id})
|
|
try:
|
|
self.queue_controller.delete(queue_name, project=project_id)
|
|
|
|
except Exception as ex:
|
|
LOG.exception(ex)
|
|
description = _('Queue could not be deleted.')
|
|
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
|
|
|
resp.status = falcon.HTTP_204
|
|
|
|
|
|
class CollectionResource(object):
|
|
|
|
__slots__ = ('queue_controller')
|
|
|
|
def __init__(self, queue_controller):
|
|
self.queue_controller = queue_controller
|
|
|
|
def on_get(self, req, resp, project_id):
|
|
# TODO(kgriffs): Optimize
|
|
kwargs = helpers.purge({
|
|
'marker': req.get_param('marker'),
|
|
'limit': req.get_param_as_int('limit'),
|
|
'detailed': req.get_param_as_bool('detailed'),
|
|
})
|
|
|
|
try:
|
|
results = self.queue_controller.list(project=project_id, **kwargs)
|
|
except Exception as ex:
|
|
LOG.exception(ex)
|
|
description = _('Queues could not be listed.')
|
|
raise wsgi_exceptions.HTTPServiceUnavailable(description)
|
|
|
|
# Buffer list of queues
|
|
queues = list(next(results))
|
|
|
|
# Check for an empty list
|
|
if len(queues) == 0:
|
|
resp.status = falcon.HTTP_204
|
|
return
|
|
|
|
# Got some. Prepare the response.
|
|
kwargs['marker'] = next(results)
|
|
for each_queue in queues:
|
|
each_queue['href'] = req.path + '/' + each_queue['name']
|
|
|
|
response_body = {
|
|
'queues': queues,
|
|
'links': [
|
|
{
|
|
'rel': 'next',
|
|
'href': req.path + falcon.to_query_str(kwargs)
|
|
}
|
|
]
|
|
}
|
|
|
|
resp.content_location = req.relative_uri
|
|
resp.body = helpers.to_json(response_body)
|
|
resp.status = falcon.HTTP_200
|