"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "zaqar/api/v2/endpoints.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).

endpoints.py  (zaqar-9.0.0):endpoints.py  (zaqar-10.0.0)
skipping to change at line 74 skipping to change at line 74
self._validate.queue_listing(**kwargs) self._validate.queue_listing(**kwargs)
results = self._queue_controller.list( results = self._queue_controller.list(
project=project_id, **kwargs) project=project_id, **kwargs)
# Buffer list of queues. Can raise NoPoolFound error. # Buffer list of queues. Can raise NoPoolFound error.
queues = list(next(results)) queues = list(next(results))
except (ValueError, validation.ValidationFailed) as ex: except (ValueError, validation.ValidationFailed) as ex:
LOG.debug(ex) LOG.debug(ex)
headers = {'status': 400} headers = {'status': 400}
return api_utils.error_response(req, ex, headers) return api_utils.error_response(req, ex, headers)
except storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex)
error = 'Queues could not be listed.' error = 'Queues could not be listed.'
headers = {'status': 503} headers = {'status': 503}
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
# Got some. Prepare the response. # Got some. Prepare the response.
body = {'queues': queues} body = {'queues': queues}
headers = {'status': 200} headers = {'status': 200}
return response.Response(req, body, headers) return response.Response(req, body, headers)
@api_utils.on_exception_sends_500 @api_utils.on_exception_sends_500
def queue_create(self, req): def queue_create(self, req):
skipping to change at line 114 skipping to change at line 114
self._validate.queue_metadata_length(len(str(metadata))) self._validate.queue_metadata_length(len(str(metadata)))
self._validate.queue_metadata_putting(metadata) self._validate.queue_metadata_putting(metadata)
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 validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
LOG.debug(ex) LOG.debug(ex)
headers = {'status': 400} headers = {'status': 400}
return api_utils.error_response(req, ex, headers) return api_utils.error_response(req, ex, headers)
except storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex)
error = _('Queue %s could not be created.') % queue_name error = _('Queue %s could not be created.') % queue_name
headers = {'status': 503} headers = {'status': 503}
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
else: else:
body = _('Queue %s created.') % queue_name body = _('Queue %s created.') % queue_name
headers = {'status': 201} if created else {'status': 204} headers = {'status': 201} if created else {'status': 204}
return response.Response(req, body, headers) return response.Response(req, body, headers)
@api_utils.on_exception_sends_500 @api_utils.on_exception_sends_500
def queue_delete(self, req): def queue_delete(self, req):
"""Deletes a queue """Deletes a queue
skipping to change at line 140 skipping to change at line 140
:type: resp: `api.common.Response` :type: resp: `api.common.Response`
""" """
project_id = req._headers.get('X-Project-ID') project_id = req._headers.get('X-Project-ID')
queue_name = req._body.get('queue_name') queue_name = req._body.get('queue_name')
LOG.debug(u'Queue delete - queue: %(queue)s, project: %(project)s', LOG.debug(u'Queue delete - queue: %(queue)s, 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 storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex)
error = _('Queue %s could not be deleted.') % queue_name error = _('Queue %s could not be deleted.') % queue_name
headers = {'status': 503} headers = {'status': 503}
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
else: else:
body = _('Queue %s removed.') % queue_name body = _('Queue %s removed.') % queue_name
headers = {'status': 204} headers = {'status': 204}
return response.Response(req, body, headers) return response.Response(req, body, headers)
@api_utils.on_exception_sends_500 @api_utils.on_exception_sends_500
def queue_get(self, req): def queue_get(self, req):
"""Gets a queue """Gets a queue
skipping to change at line 174 skipping to change at line 174
try: try:
resp_dict = self._queue_controller.get(queue_name, resp_dict = self._queue_controller.get(queue_name,
project=project_id) project=project_id)
except storage_errors.DoesNotExist as ex: except storage_errors.DoesNotExist as ex:
LOG.debug(ex) LOG.debug(ex)
error = _('Queue %s does not exist.') % queue_name error = _('Queue %s does not exist.') % queue_name
headers = {'status': 404} headers = {'status': 404}
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
except storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex)
headers = {'status': 503} headers = {'status': 503}
error = _('Cannot retrieve queue %s.') % queue_name error = _('Cannot retrieve queue %s.') % queue_name
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
else: else:
body = resp_dict body = resp_dict
headers = {'status': 200} headers = {'status': 200}
return response.Response(req, body, headers) return response.Response(req, body, headers)
@api_utils.on_exception_sends_500 @api_utils.on_exception_sends_500
def queue_get_stats(self, req): def queue_get_stats(self, req):
"""Gets queue stats """Gets queue stats
skipping to change at line 203 skipping to change at line 203
queue_name = req._body.get('queue_name') queue_name = req._body.get('queue_name')
LOG.debug(u'Get queue stats - queue: %(queue)s, ' LOG.debug(u'Get queue stats - 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:
resp_dict = self._queue_controller.stats(queue_name, resp_dict = self._queue_controller.stats(queue_name,
project=project_id) project=project_id)
body = resp_dict body = resp_dict
except storage_errors.QueueDoesNotExist as ex: except storage_errors.QueueDoesNotExist:
LOG.exception(ex) LOG.exception('Queue "%s" does not exist', queue_name)
resp_dict = { resp_dict = {
'messages': { 'messages': {
'claimed': 0, 'claimed': 0,
'free': 0, 'free': 0,
'total': 0 'total': 0
} }
} }
body = resp_dict body = resp_dict
headers = {'status': 404} headers = {'status': 404}
return response.Response(req, body, headers) return response.Response(req, body, headers)
except storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex)
error = _('Cannot retrieve queue %s stats.') % queue_name error = _('Cannot retrieve queue %s stats.') % queue_name
headers = {'status': 503} headers = {'status': 503}
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
else: else:
headers = {'status': 200} headers = {'status': 200}
return response.Response(req, body, headers) return response.Response(req, body, headers)
@api_utils.on_exception_sends_500 @api_utils.on_exception_sends_500
def queue_purge(self, req): def queue_purge(self, req):
"""Purge queue """Purge queue
:param req: Request instance ready to be sent. :param req: Request instance ready to be sent.
skipping to change at line 264 skipping to change at line 264
queue_name) queue_name)
resp = self._subscription_controller.list(queue_name, resp = self._subscription_controller.list(queue_name,
project=project_id) project=project_id)
subscriptions = list(next(resp)) subscriptions = list(next(resp))
for sub in subscriptions: for sub in subscriptions:
self._subscription_controller.delete(queue_name, self._subscription_controller.delete(queue_name,
sub['id'], sub['id'],
project=project_id) project=project_id)
except storage_errors.QueueDoesNotExist as ex: except storage_errors.QueueDoesNotExist as ex:
LOG.exception(ex) LOG.exception('Queue "%s" does not exist', queue_name)
headers = {'status': 404} headers = {'status': 404}
return api_utils.error_response(req, ex, headers) return api_utils.error_response(req, ex, headers)
except storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex) LOG.exception('Error deleting queue "%s".', queue_name)
headers = {'status': 503} headers = {'status': 503}
return api_utils.error_response(req, ex, headers) return api_utils.error_response(req, ex, headers)
else: else:
headers = {'status': 204} headers = {'status': 204}
return response.Response(req, {}, headers) return response.Response(req, {}, headers)
# Messages # Messages
@api_utils.on_exception_sends_500 @api_utils.on_exception_sends_500
def message_list(self, req): def message_list(self, req):
"""Gets a list of messages on a queue """Gets a list of messages on a queue
skipping to change at line 491 skipping to change at line 491
except (ValueError, api_errors.BadRequest, except (ValueError, api_errors.BadRequest,
validation.ValidationFailed) as ex: validation.ValidationFailed) as ex:
LOG.debug(ex) LOG.debug(ex)
headers = {'status': 400} headers = {'status': 400}
return api_utils.error_response(req, ex, headers) return api_utils.error_response(req, ex, headers)
except storage_errors.DoesNotExist as ex: except storage_errors.DoesNotExist as ex:
LOG.debug(ex) LOG.debug(ex)
headers = {'status': 404} headers = {'status': 404}
return api_utils.error_response(req, ex, headers) return api_utils.error_response(req, ex, headers)
except storage_errors.MessageConflict as ex: except storage_errors.MessageConflict as ex:
LOG.exception(ex)
error = _(u'No messages could be enqueued.') error = _(u'No messages could be enqueued.')
headers = {'status': 500} headers = {'status': 500}
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
# Prepare the response # Prepare the response
headers = {'status': 201} headers = {'status': 201}
body = {'message_ids': message_ids} body = {'message_ids': message_ids}
return response.Response(req, body, headers) return response.Response(req, body, headers)
@api_utils.on_exception_sends_500 @api_utils.on_exception_sends_500
def message_delete(self, req): def message_delete(self, req):
skipping to change at line 837 skipping to change at line 837
self._validate.subscription_listing(**kwargs) self._validate.subscription_listing(**kwargs)
results = self._subscription_controller.list( results = self._subscription_controller.list(
queue_name, project=project_id, **kwargs) queue_name, project=project_id, **kwargs)
# Buffer list of subscriptions. Can raise NoPoolFound error. # Buffer list of subscriptions. Can raise NoPoolFound error.
subscriptions = list(next(results)) subscriptions = list(next(results))
except (ValueError, validation.ValidationFailed) as ex: except (ValueError, validation.ValidationFailed) as ex:
LOG.debug(ex) LOG.debug(ex)
headers = {'status': 400} headers = {'status': 400}
return api_utils.error_response(req, ex, headers) return api_utils.error_response(req, ex, headers)
except storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex)
error = 'Subscriptions could not be listed.' error = 'Subscriptions could not be listed.'
headers = {'status': 503} headers = {'status': 503}
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
# Got some. Prepare the response. # Got some. Prepare the response.
body = {'subscriptions': subscriptions} body = {'subscriptions': subscriptions}
headers = {'status': 200} headers = {'status': 200}
return response.Response(req, body, headers) return response.Response(req, body, headers)
@api_utils.on_exception_sends_500 @api_utils.on_exception_sends_500
def subscription_create(self, req, subscriber): def subscription_create(self, req, subscriber):
skipping to change at line 891 skipping to change at line 891
created = self._subscription_controller.create(queue_name, created = self._subscription_controller.create(queue_name,
subscriber, subscriber,
data['ttl'], data['ttl'],
data['options'], data['options'],
project=project_id) project=project_id)
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
LOG.debug(ex) LOG.debug(ex)
headers = {'status': 400} headers = {'status': 400}
return api_utils.error_response(req, ex, headers) return api_utils.error_response(req, ex, headers)
except storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex)
error = _('Subscription %s could not be created.') % queue_name error = _('Subscription %s could not be created.') % queue_name
headers = {'status': 503} headers = {'status': 503}
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
else: else:
if created: if created:
msg = _('Subscription %s created.') % queue_name msg = _('Subscription %s created.') % queue_name
body = {'subscription_id': str(created), 'message': msg} body = {'subscription_id': str(created), 'message': msg}
headers = {'status': 201} headers = {'status': 201}
else: else:
body = _('Subscription %s not created.') % queue_name body = _('Subscription %s not created.') % queue_name
headers = {'status': 409} headers = {'status': 409}
return response.Response(req, body, headers) return response.Response(req, body, headers)
skipping to change at line 926 skipping to change at line 926
subscription_id = req._body.get('subscription_id') subscription_id = req._body.get('subscription_id')
LOG.debug( LOG.debug(
u'Subscription delete - queue: %(queue)s, project: %(project)s', u'Subscription delete - queue: %(queue)s, project: %(project)s',
{'queue': queue_name, 'project': project_id}) {'queue': queue_name, 'project': project_id})
try: try:
self._subscription_controller.delete(queue_name, self._subscription_controller.delete(queue_name,
subscription_id, subscription_id,
project=project_id) project=project_id)
except storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex)
error = _('Subscription %(subscription)s for queue %(queue)s ' error = _('Subscription %(subscription)s for queue %(queue)s '
'could not be deleted.') % { 'could not be deleted.') % {
'subscription': subscription_id, 'queue': queue_name} 'subscription': subscription_id, 'queue': queue_name}
headers = {'status': 503} headers = {'status': 503}
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
else: else:
body = _('Subscription %s removed.') % subscription_id body = _('Subscription %s removed.') % subscription_id
headers = {'status': 204} headers = {'status': 204}
return response.Response(req, body, headers) return response.Response(req, body, headers)
@api_utils.on_exception_sends_500 @api_utils.on_exception_sends_500
def subscription_get(self, req): def subscription_get(self, req):
"""Retrieve details about an existing subscription. """Retrieve details about an existing subscription.
skipping to change at line 966 skipping to change at line 966
subscription_id, subscription_id,
project=project_id) project=project_id)
except storage_errors.DoesNotExist as ex: except storage_errors.DoesNotExist as ex:
LOG.debug(ex) LOG.debug(ex)
error = _('Subscription %(subscription)s for queue %(queue)s ' error = _('Subscription %(subscription)s for queue %(queue)s '
'does not exist.') % { 'does not exist.') % {
'subscription': subscription_id, 'queue': queue_name} 'subscription': subscription_id, 'queue': queue_name}
headers = {'status': 404} headers = {'status': 404}
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
except storage_errors.ExceptionBase as ex: except storage_errors.ExceptionBase as ex:
LOG.exception(ex)
headers = {'status': 503} headers = {'status': 503}
error = _('Cannot retrieve subscription %s.') % subscription_id error = _('Cannot retrieve subscription %s.') % subscription_id
LOG.exception(error)
return api_utils.error_response(req, ex, headers, error) return api_utils.error_response(req, ex, headers, error)
else: else:
body = resp_dict body = resp_dict
headers = {'status': 200} headers = {'status': 200}
return response.Response(req, body, headers) return response.Response(req, body, headers)
 End of changes. 23 change blocks. 
14 lines changed or deleted 14 lines changed or added

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