"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "zaqar/transport/wsgi/v2_0/queues.py" between
zaqar-9.0.0.tar.gz and zaqar-10.0.0.tar.gz

About: OpenStack Zaqar is a multi-tenant cloud messaging and notification service for web and mobile developers.
The "Ussuri" series (latest release).

queues.py  (zaqar-9.0.0):queues.py  (zaqar-10.0.0)
skipping to change at line 69 skipping to change at line 69
try: try:
resp_dict = self._queue_controller.get(queue_name, resp_dict = self._queue_controller.get(queue_name,
project=project_id) project=project_id)
for meta, value in _get_reserved_metadata(self._validate).items(): for meta, value in _get_reserved_metadata(self._validate).items():
if not resp_dict.get(meta): if not resp_dict.get(meta):
resp_dict[meta] = value resp_dict[meta] = value
except storage_errors.DoesNotExist as ex: except storage_errors.DoesNotExist as ex:
LOG.debug(ex) LOG.debug(ex)
raise wsgi_errors.HTTPNotFound(six.text_type(ex)) raise wsgi_errors.HTTPNotFound(six.text_type(ex))
except Exception as ex: except Exception:
LOG.exception(ex)
description = _(u'Queue metadata could not be retrieved.') description = _(u'Queue metadata could not be retrieved.')
LOG.exception(description)
raise wsgi_errors.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
resp.body = utils.to_json(resp_dict) resp.body = utils.to_json(resp_dict)
# status defaults to 200 # status defaults to 200
@decorators.TransportLog("Queues item") @decorators.TransportLog("Queues item")
@acl.enforce("queues:create") @acl.enforce("queues:create")
def on_put(self, req, resp, project_id, queue_name): def on_put(self, req, resp, project_id, queue_name):
try: try:
# Place JSON size restriction before parsing # Place JSON size restriction before parsing
skipping to change at line 100 skipping to change at line 100
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
LOG.debug(ex) LOG.debug(ex)
raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
try: try:
created = self._queue_controller.create(queue_name, created = self._queue_controller.create(queue_name,
metadata=metadata, metadata=metadata,
project=project_id) project=project_id)
except storage_errors.FlavorDoesNotExist as ex: except storage_errors.FlavorDoesNotExist as ex:
LOG.exception(ex) LOG.exception('Flavor "%s" does not exist', queue_name)
raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except Exception as ex: except Exception:
LOG.exception(ex)
description = _(u'Queue could not be created.') description = _(u'Queue could not be created.')
LOG.exception(description)
raise wsgi_errors.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
resp.status = falcon.HTTP_201 if created else falcon.HTTP_204 resp.status = falcon.HTTP_201 if created else falcon.HTTP_204
resp.location = req.path resp.location = req.path
@decorators.TransportLog("Queues item") @decorators.TransportLog("Queues item")
@acl.enforce("queues:delete") @acl.enforce("queues:delete")
def on_delete(self, req, resp, project_id, queue_name): def on_delete(self, req, resp, project_id, queue_name):
LOG.debug(u'Queue item DELETE - queue: %(queue)s, ' LOG.debug(u'Queue item DELETE - queue: %(queue)s, '
u'project: %(project)s', u'project: %(project)s',
{'queue': queue_name, 'project': project_id}) {'queue': queue_name, 'project': project_id})
try: try:
self._queue_controller.delete(queue_name, project=project_id) self._queue_controller.delete(queue_name, project=project_id)
except Exception as ex: except Exception:
LOG.exception(ex)
description = _(u'Queue could not be deleted.') description = _(u'Queue could not be deleted.')
LOG.exception(description)
raise wsgi_errors.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
resp.status = falcon.HTTP_204 resp.status = falcon.HTTP_204
@decorators.TransportLog("Queues item") @decorators.TransportLog("Queues item")
@acl.enforce("queues:update") @acl.enforce("queues:update")
def on_patch(self, req, resp, project_id, queue_name): def on_patch(self, req, resp, project_id, queue_name):
"""Allows one to update a queue's metadata. """Allows one to update a queue's metadata.
This method expects the user to submit a JSON object. There is also This method expects the user to submit a JSON object. There is also
skipping to change at line 174 skipping to change at line 174
except utils.MalformedJSON as ex: except utils.MalformedJSON as ex:
LOG.debug(ex) LOG.debug(ex)
description = _(u'Request body could not be parsed.') description = _(u'Request body could not be parsed.')
raise wsgi_errors.HTTPBadRequestBody(description) raise wsgi_errors.HTTPBadRequestBody(description)
except utils.OverflowedJSONInteger as ex: except utils.OverflowedJSONInteger as ex:
LOG.debug(ex) LOG.debug(ex)
description = _(u'JSON contains integer that is too large.') description = _(u'JSON contains integer that is too large.')
raise wsgi_errors.HTTPBadRequestBody(description) raise wsgi_errors.HTTPBadRequestBody(description)
except Exception as ex: except Exception:
# Error while reading from the network/server # Error while reading from the network/server
LOG.exception(ex)
description = _(u'Request body could not be read.') description = _(u'Request body could not be read.')
LOG.exception(description)
raise wsgi_errors.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
else: else:
msg = _("PATCH body could not be empty for update.") msg = _("PATCH body could not be empty for update.")
LOG.debug(msg) LOG.debug(msg)
raise wsgi_errors.HTTPBadRequestBody(msg) raise wsgi_errors.HTTPBadRequestBody(msg)
try: try:
changes = self._validate.queue_patching(req, changes) changes = self._validate.queue_patching(req, changes)
# NOTE(Eva-i): using 'get_metadata' instead of 'get', so # NOTE(Eva-i): using 'get_metadata' instead of 'get', so
skipping to change at line 210 skipping to change at line 210
self._queue_controller.set_metadata(queue_name, self._queue_controller.set_metadata(queue_name,
metadata, metadata,
project_id) project_id)
except storage_errors.DoesNotExist as ex: except storage_errors.DoesNotExist as ex:
LOG.debug(ex) LOG.debug(ex)
raise wsgi_errors.HTTPNotFound(six.text_type(ex)) raise wsgi_errors.HTTPNotFound(six.text_type(ex))
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
LOG.debug(ex) LOG.debug(ex)
raise wsgi_errors.HTTPBadRequestBody(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestBody(six.text_type(ex))
except wsgi_errors.HTTPConflict as ex: except wsgi_errors.HTTPConflict as ex:
raise ex raise
except Exception as ex: except Exception:
LOG.exception(ex)
description = _(u'Queue could not be updated.') description = _(u'Queue could not be updated.')
LOG.exception(description)
raise wsgi_errors.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
for meta, value in _get_reserved_metadata(self._validate).items(): for meta, value in _get_reserved_metadata(self._validate).items():
if not metadata.get(meta): if not metadata.get(meta):
metadata[meta] = value metadata[meta] = value
resp.body = utils.to_json(metadata) resp.body = utils.to_json(metadata)
def _do_replace(self, req, metadata, reserved_metadata, change): def _do_replace(self, req, metadata, reserved_metadata, change):
path = change['path'] path = change['path']
path_child = path[1] path_child = path[1]
value = change['value'] value = change['value']
skipping to change at line 256 skipping to change at line 256
__slots__ = ('_queue_controller', '_validate', '_reserved_metadata') __slots__ = ('_queue_controller', '_validate', '_reserved_metadata')
def __init__(self, validate, queue_controller): def __init__(self, validate, queue_controller):
self._queue_controller = queue_controller self._queue_controller = queue_controller
self._validate = validate self._validate = validate
def _queue_list(self, project_id, path, kfilter, **kwargs): def _queue_list(self, project_id, path, kfilter, **kwargs):
try: try:
self._validate.queue_listing(**kwargs) self._validate.queue_listing(**kwargs)
with_count = kwargs.pop('with_count', False)
results = self._queue_controller.list(project=project_id, results = self._queue_controller.list(project=project_id,
kfilter=kfilter, **kwargs) kfilter=kfilter, **kwargs)
# Buffer list of queues # Buffer list of queues
queues = list(next(results)) queues = list(next(results))
total_number = None
if with_count:
total_number = self._queue_controller.calculate_resource_count(
project=project_id)
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
LOG.debug(ex) LOG.debug(ex)
raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except Exception as ex: except Exception:
LOG.exception(ex)
description = _(u'Queues could not be listed.') description = _(u'Queues could not be listed.')
LOG.exception(description)
raise wsgi_errors.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
# Got some. Prepare the response. # Got some. Prepare the response.
kwargs['marker'] = next(results) or kwargs.get('marker', '') kwargs['marker'] = next(results) or kwargs.get('marker', '')
reserved_metadata = _get_reserved_metadata(self._validate).items() reserved_metadata = _get_reserved_metadata(self._validate).items()
for each_queue in queues: for each_queue in queues:
each_queue['href'] = path + '/' + each_queue['name'] each_queue['href'] = path + '/' + each_queue['name']
if kwargs.get('detailed'): if kwargs.get('detailed'):
for meta, value in reserved_metadata: for meta, value in reserved_metadata:
if not each_queue.get('metadata', {}).get(meta): if not each_queue.get('metadata', {}).get(meta):
each_queue['metadata'][meta] = value each_queue['metadata'][meta] = value
return queues, kwargs['marker'] return queues, kwargs['marker'], total_number
def _on_get_with_kfilter(self, req, resp, project_id, kfilter={}): def _on_get_with_kfilter(self, req, resp, project_id, kfilter={}):
kwargs = {} kwargs = {}
# NOTE(kgriffs): This syntax ensures that # NOTE(kgriffs): This syntax ensures that
# we don't clobber default values with None. # we don't clobber default values with None.
req.get_param('marker', store=kwargs) req.get_param('marker', store=kwargs)
req.get_param_as_int('limit', store=kwargs) req.get_param_as_int('limit', store=kwargs)
req.get_param_as_bool('detailed', store=kwargs) req.get_param_as_bool('detailed', store=kwargs)
req.get_param('name', store=kwargs) req.get_param('name', store=kwargs)
req.get_param_as_bool('with_count', store=kwargs)
queues, marker = self._queue_list(project_id, queues, marker, total_number = self._queue_list(project_id,
req.path, kfilter, **kwargs) req.path, kfilter,
**kwargs)
links = [] links = []
kwargs['marker'] = marker kwargs['marker'] = marker
if queues: if queues:
links = [ links = [
{ {
'rel': 'next', 'rel': 'next',
'href': req.path + falcon.to_query_str(kwargs) 'href': req.path + falcon.to_query_str(kwargs)
} }
] ]
response_body = { response_body = {
'queues': queues, 'queues': queues,
'links': links 'links': links
} }
if total_number:
response_body['count'] = total_number
resp.body = utils.to_json(response_body) resp.body = utils.to_json(response_body)
# status defaults to 200 # status defaults to 200
@decorators.TransportLog("Queues collection") @decorators.TransportLog("Queues collection")
@acl.enforce("queues:get_all") @acl.enforce("queues:get_all")
def on_get(self, req, resp, project_id): def on_get(self, req, resp, project_id):
field = ('marker', 'limit', 'detailed', 'name') field = ('marker', 'limit', 'detailed', 'name', 'with_count')
kfilter = copy.deepcopy(req.params) kfilter = copy.deepcopy(req.params)
for key in req.params.keys(): for key in req.params.keys():
if key in field: if key in field:
kfilter.pop(key) kfilter.pop(key)
kfilter = kfilter if len(kfilter) > 0 else {} kfilter = kfilter if len(kfilter) > 0 else {}
for key in kfilter.keys(): for key in kfilter.keys():
# Since we get the filter value from URL, so need to # Since we get the filter value from URL, so need to
# turn the string to integer if using integer filter value. # turn the string to integer if using integer filter value.
 End of changes. 21 change blocks. 
18 lines changed or deleted 28 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)