Renamed "exceptions" module to "errors"

Changes exceptions.py into error.py

Renaming exception-related code to errors
because most of the conditions handled by
marconi are errorneous rather than exceptional.

Closes-Bug:#1232074

Change-Id: Ie3509236b07a372a44d97f97e5f3fe183b409606
This commit is contained in:
cpallares 2013-10-28 10:49:27 -05:00
parent 4f5de4b23f
commit 5624bf1a14
40 changed files with 183 additions and 182 deletions

View File

@ -19,7 +19,7 @@ import jsonschema
from marconi.openstack.common import log from marconi.openstack.common import log
from marconi.queues.transport import utils as json_utils from marconi.queues.transport import utils as json_utils
from marconi.queues.transport.wsgi import exceptions as wsgi_errors from marconi.queues.transport.wsgi import errors as wsgi_errors
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)

View File

@ -19,7 +19,7 @@ from stevedore import driver
from marconi.common import access from marconi.common import access
from marconi.common.cache import cache as oslo_cache from marconi.common.cache import cache as oslo_cache
from marconi.common import decorators from marconi.common import decorators
from marconi.common import exceptions from marconi.common import errors
from marconi.openstack.common import log from marconi.openstack.common import log
from marconi.proxy import transport # NOQA from marconi.proxy import transport # NOQA
@ -68,7 +68,7 @@ class Bootstrap(object):
return mgr.driver return mgr.driver
except RuntimeError as exc: except RuntimeError as exc:
LOG.exception(exc) LOG.exception(exc)
raise exceptions.InvalidDriver(exc) raise errors.InvalidDriver(exc)
@decorators.lazy_property(write=False) @decorators.lazy_property(write=False)
def cache(self): def cache(self):
@ -78,7 +78,7 @@ class Bootstrap(object):
return mgr return mgr
except RuntimeError as exc: except RuntimeError as exc:
LOG.exception(exc) LOG.exception(exc)
raise exceptions.InvalidDriver(exc) raise errors.InvalidDriver(exc)
@decorators.lazy_property(write=False) @decorators.lazy_property(write=False)
def transport(self): def transport(self):
@ -92,7 +92,7 @@ class Bootstrap(object):
return mgr.driver return mgr.driver
except RuntimeError as exc: except RuntimeError as exc:
LOG.exception(exc) LOG.exception(exc)
raise exceptions.InvalidDriver(exc) raise errors.InvalidDriver(exc)
def run(self): def run(self):
self.transport.listen() self.transport.listen()

View File

@ -1,7 +1,7 @@
"""Marconi proxy storage drivers""" """Marconi proxy storage drivers"""
from marconi.proxy.storage import base from marconi.proxy.storage import base
from marconi.proxy.storage import exceptions # NOQA from marconi.proxy.storage import errors # NOQA
# NOTE(cpp-cabrera): Hoist classes into package namespace # NOTE(cpp-cabrera): Hoist classes into package namespace
CatalogueBase = base.CatalogueBase CatalogueBase = base.CatalogueBase

View File

@ -15,7 +15,7 @@
import six import six
from marconi.proxy.storage import base from marconi.proxy.storage import base
from marconi.proxy.storage import exceptions from marconi.proxy.storage import errors
def _idx(project, queue): def _idx(project, queue):
@ -37,7 +37,7 @@ class CatalogueController(base.CatalogueBase):
try: try:
entry = self._col[_idx(project, queue)] entry = self._col[_idx(project, queue)]
except KeyError: except KeyError:
raise exceptions.EntryNotFound(project, queue) raise errors.EntryNotFound(project, queue)
return _normalize(entry) return _normalize(entry)

View File

@ -16,7 +16,7 @@
import six import six
from marconi.proxy.storage import base from marconi.proxy.storage import base
from marconi.proxy.storage import exceptions from marconi.proxy.storage import errors
class PartitionsController(base.PartitionsBase): class PartitionsController(base.PartitionsBase):
@ -33,7 +33,7 @@ class PartitionsController(base.PartitionsBase):
try: try:
entry = self._col[name] entry = self._col[name]
except KeyError: except KeyError:
raise exceptions.PartitionNotFound(name) raise errors.PartitionNotFound(name)
return _normalize(entry) return _normalize(entry)
@ -52,7 +52,7 @@ class PartitionsController(base.PartitionsBase):
try: try:
self._col[name].update(fields) self._col[name].update(fields)
except KeyError: except KeyError:
raise exceptions.PartitionNotFound(name) raise errors.PartitionNotFound(name)
def delete(self, name): def delete(self, name):
try: try:

View File

@ -29,7 +29,7 @@ from pymongo import errors
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.proxy.storage import base from marconi.proxy.storage import base
from marconi.proxy.storage import exceptions from marconi.proxy.storage import errors as storage_errors
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
@ -64,7 +64,7 @@ class CatalogueController(base.CatalogueBase):
fields=fields) fields=fields)
if entry is None: if entry is None:
raise exceptions.EntryNotFound(project, queue) raise storage_errors.EntryNotFound(project, queue)
return _normalize(entry) return _normalize(entry)

View File

@ -25,7 +25,7 @@ Schema:
""" """
from marconi.proxy.storage import base from marconi.proxy.storage import base
from marconi.proxy.storage import exceptions from marconi.proxy.storage import errors
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
@ -55,7 +55,7 @@ class PartitionsController(base.PartitionsBase):
fields=fields) fields=fields)
if partition is None: if partition is None:
raise exceptions.PartitionNotFound(name) raise errors.PartitionNotFound(name)
return _normalize(partition) return _normalize(partition)
@ -94,7 +94,7 @@ class PartitionsController(base.PartitionsBase):
{'$set': fields}, {'$set': fields},
upsert=False) upsert=False)
if not res['updatedExisting']: if not res['updatedExisting']:
raise exceptions.PartitionNotFound(name) raise errors.PartitionNotFound(name)
def _normalize(entry): def _normalize(entry):

View File

@ -21,7 +21,7 @@ import json
import falcon import falcon
from marconi.openstack.common import log from marconi.openstack.common import log
from marconi.proxy.storage import exceptions from marconi.proxy.storage import errors
from marconi.proxy.utils import helpers from marconi.proxy.utils import helpers
@ -66,7 +66,7 @@ class Resource(object):
entry = None entry = None
try: try:
entry = self._catalogue.get(project, queue) entry = self._catalogue.get(project, queue)
except exceptions.EntryNotFound: except errors.EntryNotFound:
LOG.debug('Entry not found') LOG.debug('Entry not found')
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()

View File

@ -34,10 +34,10 @@ import six
from marconi.common.transport.wsgi import utils from marconi.common.transport.wsgi import utils
from marconi.openstack.common import log from marconi.openstack.common import log
from marconi.proxy.storage import exceptions from marconi.proxy.storage import errors
from marconi.proxy.transport import schema from marconi.proxy.transport import schema
from marconi.proxy.utils import lookup from marconi.proxy.utils import lookup
from marconi.queues.transport.wsgi import exceptions as wsgi_errors from marconi.queues.transport.wsgi import errors as wsgi_errors
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@ -96,7 +96,7 @@ class Resource(object):
data = None data = None
try: try:
data = self._ctrl.get(partition) data = self._ctrl.get(partition)
except exceptions.PartitionNotFound as ex: except errors.PartitionNotFound as ex:
LOG.exception(ex) LOG.exception(ex)
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
@ -163,6 +163,6 @@ class Resource(object):
and v is not None) and v is not None)
self._ctrl.update(partition, **fields) self._ctrl.update(partition, **fields)
except exceptions.PartitionNotFound as ex: except errors.PartitionNotFound as ex:
LOG.exception(ex) LOG.exception(ex)
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()

View File

@ -42,7 +42,7 @@ from marconi.proxy.utils import (
) )
from marconi.queues.storage import base as storage from marconi.queues.storage import base as storage
from marconi.queues.transport import validation as validate from marconi.queues.transport import validation as validate
from marconi.queues.transport.wsgi import exceptions as wsgi_exceptions from marconi.queues.transport.wsgi import errors as wsgi_errors
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@ -81,7 +81,7 @@ class Listing(object):
try: try:
validate.queue_listing(limit=limit) validate.queue_listing(limit=limit)
except validate.ValidationFailed as ex: except validate.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
for queue in self._catalogue.list(project): for queue in self._catalogue.list(project):
queue_name = queue['name'] queue_name = queue['name']

View File

@ -18,7 +18,7 @@
import msgpack import msgpack
from marconi.openstack.common import log from marconi.openstack.common import log
from marconi.proxy.storage import exceptions from marconi.proxy.storage import errors
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@ -56,7 +56,7 @@ def try_cache_entry(project, queue, catalogue_controller, cache):
try: try:
name = catalogue_controller.get(project, queue)['partition'] name = catalogue_controller.get(project, queue)['partition']
except exceptions.EntryNotFound: except errors.EntryNotFound:
return None return None
cache.set(key, name) cache.set(key, name)
@ -156,7 +156,7 @@ def hosts(name, partitions_controller, cache):
try: try:
hosts = partitions_controller.get(name)['hosts'] hosts = partitions_controller.get(name)['hosts']
except exceptions.PartitionNotFound: except errors.PartitionNotFound:
LOG.debug('Partition not in primary storage: ' + name) LOG.debug('Partition not in primary storage: ' + name)
return None return None

View File

@ -18,7 +18,7 @@ from stevedore import driver
from marconi.common.cache import cache as oslo_cache from marconi.common.cache import cache as oslo_cache
from marconi.common import decorators from marconi.common import decorators
from marconi.common import exceptions from marconi.common import errors
from marconi.openstack.common import log from marconi.openstack.common import log
from marconi.queues.storage import pipeline from marconi.queues.storage import pipeline
from marconi.queues.storage import sharding from marconi.queues.storage import sharding
@ -82,7 +82,7 @@ class Bootstrap(object):
return mgr return mgr
except RuntimeError as exc: except RuntimeError as exc:
LOG.exception(exc) LOG.exception(exc)
raise exceptions.InvalidDriver(exc) raise errors.InvalidDriver(exc)
@decorators.lazy_property(write=False) @decorators.lazy_property(write=False)
def transport(self): def transport(self):
@ -99,7 +99,7 @@ class Bootstrap(object):
return mgr.driver return mgr.driver
except RuntimeError as exc: except RuntimeError as exc:
LOG.exception(exc) LOG.exception(exc)
raise exceptions.InvalidDriver(exc) raise errors.InvalidDriver(exc)
def run(self): def run(self):
self.transport.listen() self.transport.listen()

View File

@ -1,7 +1,7 @@
"""Marconi Storage Drivers""" """Marconi Storage Drivers"""
from marconi.queues.storage import base from marconi.queues.storage import base
from marconi.queues.storage import exceptions # NOQA from marconi.queues.storage import errors # NOQA
# Hoist classes into package namespace # Hoist classes into package namespace
ControlDriverBase = base.ControlDriverBase ControlDriverBase = base.ControlDriverBase

View File

@ -24,7 +24,7 @@ Serves to construct an association between a project + queue -> shard
""" """
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.storage import base, exceptions from marconi.queues.storage import base, errors
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
@ -67,7 +67,7 @@ class CatalogueController(base.CatalogueBase):
fields=fields) fields=fields)
if entry is None: if entry is None:
raise exceptions.QueueNotMapped(project, queue) raise errors.QueueNotMapped(project, queue)
return _normalize(entry) return _normalize(entry)
@ -90,7 +90,7 @@ class CatalogueController(base.CatalogueBase):
res = self._insert(project, queue, shard, upsert=False) res = self._insert(project, queue, shard, upsert=False)
if not res['updatedExisting']: if not res['updatedExisting']:
raise exceptions.QueueNotMapped(project, queue) raise errors.QueueNotMapped(project, queue)
@utils.raises_conn_error @utils.raises_conn_error
def drop_all(self): def drop_all(self):

View File

@ -28,7 +28,7 @@ from bson import objectid
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues import storage from marconi.queues import storage
from marconi.queues.storage import exceptions from marconi.queues.storage import errors
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
@ -64,7 +64,7 @@ class ClaimController(storage.ClaimBase):
now = timeutils.utcnow_ts() now = timeutils.utcnow_ts()
cid = utils.to_oid(claim_id) cid = utils.to_oid(claim_id)
if cid is None: if cid is None:
raise exceptions.ClaimDoesNotExist(queue, project, claim_id) raise errors.ClaimDoesNotExist(queue, project, claim_id)
def messages(msg_iter): def messages(msg_iter):
msg = next(msg_iter) msg = next(msg_iter)
@ -93,7 +93,7 @@ class ClaimController(storage.ClaimBase):
'id': str(claim['id']), 'id': str(claim['id']),
} }
except StopIteration: except StopIteration:
raise exceptions.ClaimDoesNotExist(cid, queue, project) raise errors.ClaimDoesNotExist(cid, queue, project)
return (claim_meta, msgs) return (claim_meta, msgs)
@ -195,7 +195,7 @@ class ClaimController(storage.ClaimBase):
def update(self, queue, claim_id, metadata, project=None): def update(self, queue, claim_id, metadata, project=None):
cid = utils.to_oid(claim_id) cid = utils.to_oid(claim_id)
if cid is None: if cid is None:
raise exceptions.ClaimDoesNotExist(claim_id, queue, project) raise errors.ClaimDoesNotExist(claim_id, queue, project)
now = timeutils.utcnow_ts() now = timeutils.utcnow_ts()
ttl = int(metadata.get('ttl', 60)) ttl = int(metadata.get('ttl', 60))
@ -208,7 +208,7 @@ class ClaimController(storage.ClaimBase):
try: try:
next(claimed) next(claimed)
except StopIteration: except StopIteration:
raise exceptions.ClaimDoesNotExist(claim_id, queue, project) raise errors.ClaimDoesNotExist(claim_id, queue, project)
meta = { meta = {
'id': cid, 'id': cid,

View File

@ -30,7 +30,7 @@ import pymongo.read_preferences
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues import storage from marconi.queues import storage
from marconi.queues.storage import exceptions from marconi.queues.storage import errors
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
@ -391,7 +391,7 @@ class MessageController(storage.MessageBase):
try: try:
message = next(cursor) message = next(cursor)
except StopIteration: except StopIteration:
raise exceptions.QueueIsEmpty(queue_name, project) raise errors.QueueIsEmpty(queue_name, project)
return message return message
@ -399,8 +399,8 @@ class MessageController(storage.MessageBase):
def get(self, queue_name, message_id, project=None): def get(self, queue_name, message_id, project=None):
mid = utils.to_oid(message_id) mid = utils.to_oid(message_id)
if mid is None: if mid is None:
raise exceptions.MessageDoesNotExist(message_id, queue_name, raise errors.MessageDoesNotExist(message_id, queue_name,
project) project)
now = timeutils.utcnow_ts() now = timeutils.utcnow_ts()
@ -413,8 +413,8 @@ class MessageController(storage.MessageBase):
message = list(collection.find(query).limit(1).hint(ID_INDEX_FIELDS)) message = list(collection.find(query).limit(1).hint(ID_INDEX_FIELDS))
if not message: if not message:
raise exceptions.MessageDoesNotExist(message_id, queue_name, raise errors.MessageDoesNotExist(message_id, queue_name,
project) project)
return _basic_message(message[0], now) return _basic_message(message[0], now)
@ -446,7 +446,7 @@ class MessageController(storage.MessageBase):
@utils.raises_conn_error @utils.raises_conn_error
def post(self, queue_name, messages, client_uuid, project=None): def post(self, queue_name, messages, client_uuid, project=None):
if not self._queue_ctrl.exists(queue_name, project): if not self._queue_ctrl.exists(queue_name, project):
raise exceptions.QueueDoesNotExist(queue_name, project) raise errors.QueueDoesNotExist(queue_name, project)
now = timeutils.utcnow_ts() now = timeutils.utcnow_ts()
now_dt = datetime.datetime.utcfromtimestamp(now) now_dt = datetime.datetime.utcfromtimestamp(now)
@ -606,7 +606,8 @@ class MessageController(storage.MessageBase):
project=project)) project=project))
succeeded_ids = [] succeeded_ids = []
raise exceptions.MessageConflict(queue_name, project, succeeded_ids) raise errors.MessageConflict(queue_name, project,
succeeded_ids)
@utils.raises_conn_error @utils.raises_conn_error
def delete(self, queue_name, message_id, project=None, claim=None): def delete(self, queue_name, message_id, project=None, claim=None):
@ -641,11 +642,11 @@ class MessageController(storage.MessageBase):
if claim is None: if claim is None:
if is_claimed: if is_claimed:
raise exceptions.MessageIsClaimed(message_id) raise errors.MessageIsClaimed(message_id)
else: else:
if message['c']['id'] != cid: if message['c']['id'] != cid:
raise exceptions.MessageIsClaimedBy(message_id, claim) raise errors.MessageIsClaimedBy(message_id, claim)
collection.remove(query['_id'], w=0) collection.remove(query['_id'], w=0)

View File

@ -26,7 +26,7 @@ import pymongo.errors
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues import storage from marconi.queues import storage
from marconi.queues.storage import exceptions from marconi.queues.storage import errors
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
@ -75,7 +75,7 @@ class QueueController(storage.QueueBase):
queue = self._collection.find_one(_get_scoped_query(name, project), queue = self._collection.find_one(_get_scoped_query(name, project),
fields=fields) fields=fields)
if queue is None: if queue is None:
raise exceptions.QueueDoesNotExist(name, project) raise errors.QueueDoesNotExist(name, project)
return queue return queue
@ -105,7 +105,7 @@ class QueueController(storage.QueueBase):
fields={'c.v': 1, '_id': 0}) fields={'c.v': 1, '_id': 0})
if doc is None: if doc is None:
raise exceptions.QueueDoesNotExist(name, project) raise errors.QueueDoesNotExist(name, project)
return doc['c']['v'] return doc['c']['v']
@ -123,7 +123,7 @@ class QueueController(storage.QueueBase):
was specified, and the counter has already been updated was specified, and the counter has already been updated
within the specified time period. within the specified time period.
:raises: storage.exceptions.QueueDoesNotExist :raises: storage.errors.QueueDoesNotExist
""" """
now = timeutils.utcnow_ts() now = timeutils.utcnow_ts()
@ -147,13 +147,14 @@ class QueueController(storage.QueueBase):
# NOTE(kgriffs): Since we did not filter by a time window, # NOTE(kgriffs): Since we did not filter by a time window,
# the queue should have been found and updated. Perhaps # the queue should have been found and updated. Perhaps
# the queue has been deleted? # the queue has been deleted?
msgtmpl = _(u'Failed to increment the message ' message = _(u'Failed to increment the message '
u'counter for queue %(name)s and ' u'counter for queue %(name)s and '
u'project %(project)s') u'project %(project)s')
message %= dict(name=name, project=project)
LOG.warning(msgtmpl, dict(name=name, project=project)) LOG.warning(message)
raise exceptions.QueueDoesNotExist(name, project) raise errors.QueueDoesNotExist(name, project)
# NOTE(kgriffs): Assume the queue existed, but the counter # NOTE(kgriffs): Assume the queue existed, but the counter
# was recently updated, causing the range query on 'c.t' to # was recently updated, causing the range query on 'c.t' to
@ -227,7 +228,7 @@ class QueueController(storage.QueueBase):
manipulate=False) manipulate=False)
if not rst['updatedExisting']: if not rst['updatedExisting']:
raise exceptions.QueueDoesNotExist(name, project) raise errors.QueueDoesNotExist(name, project)
@utils.raises_conn_error @utils.raises_conn_error
def delete(self, name, project=None): def delete(self, name, project=None):
@ -237,7 +238,7 @@ class QueueController(storage.QueueBase):
@utils.raises_conn_error @utils.raises_conn_error
def stats(self, name, project=None): def stats(self, name, project=None):
if not self.exists(name, project=project): if not self.exists(name, project=project):
raise exceptions.QueueDoesNotExist(name, project) raise errors.QueueDoesNotExist(name, project)
controller = self.driver.message_controller controller = self.driver.message_controller
@ -255,7 +256,7 @@ class QueueController(storage.QueueBase):
try: try:
oldest = controller.first(name, project=project, sort=1) oldest = controller.first(name, project=project, sort=1)
newest = controller.first(name, project=project, sort=-1) newest = controller.first(name, project=project, sort=-1)
except exceptions.QueueIsEmpty: except errors.QueueIsEmpty:
pass pass
else: else:
now = timeutils.utcnow_ts() now = timeutils.utcnow_ts()

View File

@ -25,7 +25,7 @@ Schema:
""" """
from marconi.common import utils as common_utils from marconi.common import utils as common_utils
from marconi.queues.storage import base, exceptions from marconi.queues.storage import base, errors
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
SHARDS_INDEX = [ SHARDS_INDEX = [
@ -66,7 +66,7 @@ class ShardsController(base.ShardsBase):
res = self._col.find_one({'n': name}, res = self._col.find_one({'n': name},
_field_spec(detailed)) _field_spec(detailed))
if not res: if not res:
raise exceptions.ShardDoesNotExist(name) raise errors.ShardDoesNotExist(name)
return res return res
@utils.raises_conn_error @utils.raises_conn_error
@ -92,7 +92,7 @@ class ShardsController(base.ShardsBase):
{'$set': fields}, {'$set': fields},
upsert=False) upsert=False)
if not res['updatedExisting']: if not res['updatedExisting']:
raise exceptions.ShardDoesNotExist(name) raise errors.ShardDoesNotExist(name)
@utils.raises_conn_error @utils.raises_conn_error
def delete(self, name): def delete(self, name):

View File

@ -26,7 +26,7 @@ from pymongo import errors
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues.storage import exceptions as storage_exceptions from marconi.queues.storage import errors as storage_errors
# BSON ObjectId gives TZ-aware datetime, so we generate a # BSON ObjectId gives TZ-aware datetime, so we generate a
@ -241,7 +241,7 @@ def raises_conn_error(func):
"""Handles mongodb ConnectionFailure error """Handles mongodb ConnectionFailure error
This decorator catches mongodb's ConnectionFailure This decorator catches mongodb's ConnectionFailure
exceptions and raises Marconi's ConnectionError instead. error and raises Marconi's ConnectionError instead.
""" """
@functools.wraps(func) @functools.wraps(func)
@ -252,7 +252,7 @@ def raises_conn_error(func):
# NOTE(flaper87): Raise the error # NOTE(flaper87): Raise the error
LOG.exception(ex) LOG.exception(ex)
msg = u'ConnectionFailure caught' msg = u'ConnectionFailure caught'
raise storage_exceptions.ConnectionError(msg) raise storage_errors.ConnectionError(msg)
return wrapper return wrapper

View File

@ -14,7 +14,7 @@
# limitations under the License. # limitations under the License.
from marconi.queues.storage import base from marconi.queues.storage import base
from marconi.queues.storage import exceptions from marconi.queues.storage import errors
from marconi.queues.storage.sqlite import utils from marconi.queues.storage.sqlite import utils
@ -26,7 +26,7 @@ class ClaimController(base.ClaimBase):
cid = utils.cid_decode(claim_id) cid = utils.cid_decode(claim_id)
if cid is None: if cid is None:
raise exceptions.ClaimDoesNotExist(claim_id, queue, project) raise errors.ClaimDoesNotExist(claim_id, queue, project)
with self.driver('deferred'): with self.driver('deferred'):
try: try:
@ -48,7 +48,7 @@ class ClaimController(base.ClaimBase):
) )
except utils.NoResult: except utils.NoResult:
raise exceptions.ClaimDoesNotExist(claim_id, queue, project) raise errors.ClaimDoesNotExist(claim_id, queue, project)
def create(self, queue, metadata, project, limit=None): def create(self, queue, metadata, project, limit=None):
@ -61,7 +61,7 @@ class ClaimController(base.ClaimBase):
with self.driver('immediate'): with self.driver('immediate'):
try: try:
qid = utils.get_qid(self.driver, queue, project) qid = utils.get_qid(self.driver, queue, project)
except exceptions.QueueDoesNotExist: except errors.QueueDoesNotExist:
return None, iter([]) return None, iter([])
# Clean up all expired claims in this queue # Clean up all expired claims in this queue
@ -115,7 +115,7 @@ class ClaimController(base.ClaimBase):
id = utils.cid_decode(claim_id) id = utils.cid_decode(claim_id)
if id is None: if id is None:
raise exceptions.ClaimDoesNotExist(claim_id, queue, project) raise errors.ClaimDoesNotExist(claim_id, queue, project)
with self.driver('deferred'): with self.driver('deferred'):
@ -131,9 +131,7 @@ class ClaimController(base.ClaimBase):
''', metadata['ttl'], id, project, queue) ''', metadata['ttl'], id, project, queue)
if not self.driver.affected: if not self.driver.affected:
raise exceptions.ClaimDoesNotExist(claim_id, raise errors.ClaimDoesNotExist(claim_id, queue, project)
queue,
project)
self.__update_claimed(id, metadata['ttl']) self.__update_claimed(id, metadata['ttl'])

View File

@ -15,7 +15,7 @@
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues.storage import base from marconi.queues.storage import base
from marconi.queues.storage import exceptions from marconi.queues.storage import errors
from marconi.queues.storage.sqlite import utils from marconi.queues.storage.sqlite import utils
@ -27,7 +27,7 @@ class MessageController(base.MessageBase):
mid = utils.msgid_decode(message_id) mid = utils.msgid_decode(message_id)
if mid is None: if mid is None:
raise exceptions.MessageDoesNotExist(message_id, queue, project) raise errors.MessageDoesNotExist(message_id, queue, project)
try: try:
content, ttl, age = self.driver.get(''' content, ttl, age = self.driver.get('''
@ -39,7 +39,7 @@ class MessageController(base.MessageBase):
''', mid, project, queue) ''', mid, project, queue)
except utils.NoResult: except utils.NoResult:
raise exceptions.MessageDoesNotExist(message_id, queue, project) raise errors.MessageDoesNotExist(message_id, queue, project)
return { return {
'id': message_id, 'id': message_id,
@ -101,7 +101,7 @@ class MessageController(base.MessageBase):
try: try:
id, content, ttl, created, age = next(records) id, content, ttl, created, age = next(records)
except StopIteration: except StopIteration:
raise exceptions.QueueIsEmpty(queue, project) raise errors.QueueIsEmpty(queue, project)
created_unix = utils.julian_to_unix(created) created_unix = utils.julian_to_unix(created)
created_iso8601 = timeutils.iso8601_from_timestamp(created_unix) created_iso8601 = timeutils.iso8601_from_timestamp(created_unix)
@ -239,7 +239,7 @@ class MessageController(base.MessageBase):
''', id) ''', id)
if not self.driver.affected: if not self.driver.affected:
raise exceptions.MessageIsClaimed(id) raise errors.MessageIsClaimed(id)
def __delete_claimed(self, id, claim): def __delete_claimed(self, id, claim):
# Precondition: id exists in a specific queue # Precondition: id exists in a specific queue
@ -258,7 +258,7 @@ class MessageController(base.MessageBase):
''', id, cid) ''', id, cid)
if not self.driver.affected: if not self.driver.affected:
raise exceptions.MessageIsClaimedBy(id, claim) raise errors.MessageIsClaimedBy(id, claim)
def bulk_delete(self, queue, message_ids, project): def bulk_delete(self, queue, message_ids, project):
if project is None: if project is None:

View File

@ -15,7 +15,7 @@
# limitations under the License. # limitations under the License.
from marconi.queues.storage import base from marconi.queues.storage import base
from marconi.queues.storage import exceptions from marconi.queues.storage import errors
from marconi.queues.storage.sqlite import utils from marconi.queues.storage.sqlite import utils
@ -71,7 +71,7 @@ class QueueController(base.QueueBase):
where project = ? and name = ?''', project, name)[0] where project = ? and name = ?''', project, name)[0]
except utils.NoResult: except utils.NoResult:
raise exceptions.QueueDoesNotExist(name, project) raise errors.QueueDoesNotExist(name, project)
def create(self, name, project): def create(self, name, project):
if project is None: if project is None:
@ -105,7 +105,7 @@ class QueueController(base.QueueBase):
''', self.driver.pack(metadata), project, name) ''', self.driver.pack(metadata), project, name)
if not self.driver.affected: if not self.driver.affected:
raise exceptions.QueueDoesNotExist(name, project) raise errors.QueueDoesNotExist(name, project)
def delete(self, name, project): def delete(self, name, project):
if project is None: if project is None:
@ -148,7 +148,7 @@ class QueueController(base.QueueBase):
message_controller = self.driver.message_controller message_controller = self.driver.message_controller
oldest = message_controller.first(name, project, sort=1) oldest = message_controller.first(name, project, sort=1)
newest = message_controller.first(name, project, sort=-1) newest = message_controller.first(name, project, sort=-1)
except exceptions.QueueIsEmpty: except errors.QueueIsEmpty:
pass pass
else: else:
message_stats['oldest'] = utils.stat_message(oldest) message_stats['oldest'] = utils.stat_message(oldest)

View File

@ -14,7 +14,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from marconi.queues.storage import exceptions from marconi.queues.storage import errors
UNIX_EPOCH_AS_JULIAN_SEC = 2440587.5 * 86400.0 UNIX_EPOCH_AS_JULIAN_SEC = 2440587.5 * 86400.0
@ -31,7 +31,7 @@ def get_qid(driver, queue, project):
where project = ? and name = ?''', project, queue)[0] where project = ? and name = ?''', project, queue)[0]
except NoResult: except NoResult:
raise exceptions.QueueDoesNotExist(queue, project) raise errors.QueueDoesNotExist(queue, project)
# The utilities below make the database IDs opaque to the users # The utilities below make the database IDs opaque to the users

View File

@ -16,7 +16,7 @@
from stevedore import driver from stevedore import driver
from marconi.common import exceptions from marconi.common import errors
from marconi.openstack.common import log from marconi.openstack.common import log
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@ -40,4 +40,4 @@ def load_storage_driver(conf):
except RuntimeError as exc: except RuntimeError as exc:
LOG.exception(exc) LOG.exception(exc)
raise exceptions.InvalidDriver(exc) raise errors.InvalidDriver(exc)

View File

@ -17,10 +17,10 @@ import falcon
import six import six
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.storage import exceptions as storage_exceptions from marconi.queues.storage import errors as storage_errors
from marconi.queues.transport import utils from marconi.queues.transport import utils
from marconi.queues.transport import validation from marconi.queues.transport import validation
from marconi.queues.transport.wsgi import exceptions as wsgi_exceptions from marconi.queues.transport.wsgi import errors as wsgi_errors
from marconi.queues.transport.wsgi import utils as wsgi_utils from marconi.queues.transport.wsgi import utils as wsgi_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -53,7 +53,7 @@ class CollectionResource(Resource):
# Place JSON size restriction before parsing # Place JSON size restriction before parsing
if req.content_length > self._metadata_max_length: if req.content_length > self._metadata_max_length:
description = _(u'Claim metadata size is too large.') description = _(u'Claim metadata size is too large.')
raise wsgi_exceptions.HTTPBadRequestBody(description) raise wsgi_errors.HTTPBadRequestBody(description)
# Read claim metadata (e.g., TTL) and raise appropriate # Read claim metadata (e.g., TTL) and raise appropriate
# HTTP errors as needed. # HTTP errors as needed.
@ -74,12 +74,12 @@ class CollectionResource(Resource):
resp_msgs = list(msgs) resp_msgs = list(msgs)
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Claim could not be created.') description = _(u'Claim could not be created.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
# Serialize claimed messages, if any. This logic assumes # Serialize claimed messages, if any. This logic assumes
# the storage driver returned well-formed messages. # the storage driver returned well-formed messages.
@ -122,12 +122,12 @@ class ItemResource(Resource):
# TODO(kgriffs): Optimize along with serialization (see below) # TODO(kgriffs): Optimize along with serialization (see below)
meta['messages'] = list(msgs) meta['messages'] = list(msgs)
except storage_exceptions.DoesNotExist: except storage_errors.DoesNotExist:
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Claim could not be queried.') description = _(u'Claim could not be queried.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
# Serialize claimed messages # Serialize claimed messages
# TODO(kgriffs): Optimize # TODO(kgriffs): Optimize
@ -153,7 +153,7 @@ class ItemResource(Resource):
# Place JSON size restriction before parsing # Place JSON size restriction before parsing
if req.content_length > self._metadata_max_length: if req.content_length > self._metadata_max_length:
description = _(u'Claim metadata size is too large.') description = _(u'Claim metadata size is too large.')
raise wsgi_exceptions.HTTPBadRequestBody(description) raise wsgi_errors.HTTPBadRequestBody(description)
# Read claim metadata (e.g., TTL) and raise appropriate # Read claim metadata (e.g., TTL) and raise appropriate
# HTTP errors as needed. # HTTP errors as needed.
@ -170,15 +170,15 @@ class ItemResource(Resource):
resp.status = falcon.HTTP_204 resp.status = falcon.HTTP_204
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except storage_exceptions.DoesNotExist: except storage_errors.DoesNotExist:
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Claim could not be updated.') description = _(u'Claim could not be updated.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
def on_delete(self, req, resp, project_id, queue_name, claim_id): def on_delete(self, req, resp, project_id, queue_name, claim_id):
LOG.debug(_(u'Claim item DELETE - claim: %(claim_id)s, ' LOG.debug(_(u'Claim item DELETE - claim: %(claim_id)s, '
@ -196,7 +196,7 @@ class ItemResource(Resource):
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Claim could not be deleted.') description = _(u'Claim could not be deleted.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
# TODO(kgriffs): Clean up/optimize and move to wsgi.utils # TODO(kgriffs): Clean up/optimize and move to wsgi.utils

View File

@ -17,10 +17,10 @@ import falcon
import six import six
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.storage import exceptions as storage_exceptions from marconi.queues.storage import errors as storage_errors
from marconi.queues.transport import utils from marconi.queues.transport import utils
from marconi.queues.transport import validation from marconi.queues.transport import validation
from marconi.queues.transport.wsgi import exceptions as wsgi_exceptions from marconi.queues.transport.wsgi import errors as wsgi_errors
from marconi.queues.transport.wsgi import utils as wsgi_utils from marconi.queues.transport.wsgi import utils as wsgi_utils
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -51,12 +51,12 @@ class CollectionResource(object):
project=project_id) project=project_id)
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Message could not be retrieved.') description = _(u'Message could not be retrieved.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
# Prepare response # Prepare response
messages = list(messages) messages = list(messages)
@ -94,15 +94,15 @@ class CollectionResource(object):
messages = list(cursor) messages = list(cursor)
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except storage_exceptions.DoesNotExist: except storage_errors.DoesNotExist:
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Messages could not be listed.') description = _(u'Messages could not be listed.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
if not messages: if not messages:
return None return None
@ -137,7 +137,7 @@ class CollectionResource(object):
# Place JSON size restriction before parsing # Place JSON size restriction before parsing
if req.content_length > self._wsgi_conf.content_max_length: if req.content_length > self._wsgi_conf.content_max_length:
description = _(u'Message collection size is too large.') description = _(u'Message collection size is too large.')
raise wsgi_exceptions.HTTPBadRequestBody(description) raise wsgi_errors.HTTPBadRequestBody(description)
# Pull out just the fields we care about # Pull out just the fields we care about
messages = wsgi_utils.filter_stream( messages = wsgi_utils.filter_stream(
@ -164,12 +164,12 @@ class CollectionResource(object):
client_uuid=client_uuid) client_uuid=client_uuid)
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except storage_exceptions.DoesNotExist: except storage_errors.DoesNotExist:
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
except storage_exceptions.MessageConflict as ex: except storage_errors.MessageConflict as ex:
LOG.exception(ex) LOG.exception(ex)
partial = True partial = True
message_ids = ex.succeeded_ids message_ids = ex.succeeded_ids
@ -178,12 +178,12 @@ class CollectionResource(object):
# TODO(kgriffs): Include error code that is different # TODO(kgriffs): Include error code that is different
# from the code used in the generic case, below. # from the code used in the generic case, below.
description = _(u'No messages could be enqueued.') description = _(u'No messages could be enqueued.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Messages could not be enqueued.') description = _(u'Messages could not be enqueued.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
# Prepare the response # Prepare the response
ids_value = ','.join(message_ids) ids_value = ','.join(message_ids)
@ -228,12 +228,12 @@ class CollectionResource(object):
project=project_id) project=project_id)
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Messages could not be deleted.') description = _(u'Messages could not be deleted.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
resp.status = falcon.HTTP_204 resp.status = falcon.HTTP_204
@ -257,13 +257,13 @@ class ItemResource(object):
message_id, message_id,
project=project_id) project=project_id)
except storage_exceptions.DoesNotExist: except storage_errors.DoesNotExist:
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Message could not be retrieved.') description = _(u'Message could not be retrieved.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
# Prepare response # Prepare response
message['href'] = req.path message['href'] = req.path
@ -286,7 +286,7 @@ class ItemResource(object):
project=project_id, project=project_id,
claim=req.get_param('claim_id')) claim=req.get_param('claim_id'))
except storage_exceptions.NotPermitted as ex: except storage_errors.NotPermitted as ex:
LOG.exception(ex) LOG.exception(ex)
title = _(u'Unable to delete') title = _(u'Unable to delete')
description = _(u'This message is claimed; it cannot be ' description = _(u'This message is claimed; it cannot be '
@ -296,7 +296,7 @@ class ItemResource(object):
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Message could not be deleted.') description = _(u'Message could not be deleted.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
# Alles guete # Alles guete
resp.status = falcon.HTTP_204 resp.status = falcon.HTTP_204

View File

@ -17,10 +17,10 @@ import falcon
import six import six
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.storage import exceptions as storage_exceptions from marconi.queues.storage import errors as storage_errors
from marconi.queues.transport import utils from marconi.queues.transport import utils
from marconi.queues.transport import validation from marconi.queues.transport import validation
from marconi.queues.transport.wsgi import exceptions as wsgi_exceptions from marconi.queues.transport.wsgi import errors as wsgi_errors
from marconi.queues.transport.wsgi import utils as wsgi_utils from marconi.queues.transport.wsgi import utils as wsgi_utils
@ -44,13 +44,13 @@ class Resource(object):
resp_dict = self.queue_ctrl.get_metadata(queue_name, resp_dict = self.queue_ctrl.get_metadata(queue_name,
project=project_id) project=project_id)
except storage_exceptions.DoesNotExist: except storage_errors.DoesNotExist:
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Queue metadata could not be retrieved.') description = _(u'Queue metadata could not be retrieved.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
resp.content_location = req.path resp.content_location = req.path
resp.body = utils.to_json(resp_dict) resp.body = utils.to_json(resp_dict)
@ -64,7 +64,7 @@ class Resource(object):
# Place JSON size restriction before parsing # Place JSON size restriction before parsing
if req.content_length > self._wsgi_conf.metadata_max_length: if req.content_length > self._wsgi_conf.metadata_max_length:
description = _(u'Queue metadata size is too large.') description = _(u'Queue metadata size is too large.')
raise wsgi_exceptions.HTTPBadRequestBody(description) raise wsgi_errors.HTTPBadRequestBody(description)
# Deserialize queue metadata # Deserialize queue metadata
metadata, = wsgi_utils.filter_stream(req.stream, metadata, = wsgi_utils.filter_stream(req.stream,
@ -81,15 +81,15 @@ class Resource(object):
project=project_id) project=project_id)
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except storage_exceptions.QueueDoesNotExist: except storage_errors.QueueDoesNotExist:
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Metadata could not be updated.') description = _(u'Metadata could not be updated.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
resp.status = falcon.HTTP_204 resp.status = falcon.HTTP_204
resp.location = req.path resp.location = req.path

View File

@ -19,7 +19,7 @@ import six
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.transport import utils from marconi.queues.transport import utils
from marconi.queues.transport import validation from marconi.queues.transport import validation
from marconi.queues.transport.wsgi import exceptions as wsgi_exceptions from marconi.queues.transport.wsgi import errors as wsgi_errors
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -45,7 +45,7 @@ class ItemResource(object):
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Queue could not be created.') description = _(u'Queue could not be created.')
raise wsgi_exceptions.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
@ -74,7 +74,7 @@ class ItemResource(object):
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Queue could not be deleted.') description = _(u'Queue could not be deleted.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
resp.status = falcon.HTTP_204 resp.status = falcon.HTTP_204
@ -102,12 +102,12 @@ class CollectionResource(object):
results = self.queue_controller.list(project=project_id, **kwargs) results = self.queue_controller.list(project=project_id, **kwargs)
except validation.ValidationFailed as ex: except validation.ValidationFailed as ex:
raise wsgi_exceptions.HTTPBadRequestAPI(six.text_type(ex)) raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Queues could not be listed.') description = _(u'Queues could not be listed.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)
# Buffer list of queues # Buffer list of queues
queues = list(next(results)) queues = list(next(results))

View File

@ -39,9 +39,9 @@ import jsonschema
from marconi.common.schemas import shards as schema from marconi.common.schemas import shards as schema
from marconi.common.transport.wsgi import utils from marconi.common.transport.wsgi import utils
from marconi.openstack.common import log from marconi.openstack.common import log
from marconi.proxy.storage import exceptions from marconi.proxy.storage import errors
from marconi.queues.transport import utils as transport_utils from marconi.queues.transport import utils as transport_utils
from marconi.queues.transport.wsgi import exceptions as wsgi_errors from marconi.queues.transport.wsgi import errors as wsgi_errors
LOG = log.getLogger(__name__) LOG = log.getLogger(__name__)
@ -101,7 +101,7 @@ class Resource(object):
data = None data = None
try: try:
data = self._ctrl.get(shard) data = self._ctrl.get(shard)
except exceptions.ShardDoesNotExist as ex: except errors.ShardDoesNotExist as ex:
LOG.exception(ex) LOG.exception(ex)
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
@ -173,6 +173,6 @@ class Resource(object):
if k in EXPECT and v is not None) if k in EXPECT and v is not None)
self._ctrl.update(shard, **fields) self._ctrl.update(shard, **fields)
except exceptions.ShardDoesNotExist as ex: except errors.ShardDoesNotExist as ex:
LOG.exception(ex) LOG.exception(ex)
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()

View File

@ -16,9 +16,9 @@
import falcon import falcon
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.storage import exceptions as storage_exceptions from marconi.queues.storage import errors as storage_errors
from marconi.queues.transport import utils from marconi.queues.transport import utils
from marconi.queues.transport.wsgi import exceptions as wsgi_exceptions from marconi.queues.transport.wsgi import errors as wsgi_errors
LOG = logging.getLogger(__name__) LOG = logging.getLogger(__name__)
@ -53,10 +53,10 @@ class Resource(object):
resp.body = utils.to_json(resp_dict) resp.body = utils.to_json(resp_dict)
# status defaults to 200 # status defaults to 200
except storage_exceptions.DoesNotExist: except storage_errors.DoesNotExist:
raise falcon.HTTPNotFound() raise falcon.HTTPNotFound()
except Exception as ex: except Exception as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Queue stats could not be read.') description = _(u'Queue stats could not be read.')
raise wsgi_exceptions.HTTPServiceUnavailable(description) raise wsgi_errors.HTTPServiceUnavailable(description)

View File

@ -18,7 +18,7 @@ import uuid
import marconi.openstack.common.log as logging import marconi.openstack.common.log as logging
from marconi.queues.transport import utils from marconi.queues.transport import utils
from marconi.queues.transport.wsgi import exceptions from marconi.queues.transport.wsgi import errors
JSONObject = dict JSONObject = dict
@ -58,7 +58,7 @@ def filter_stream(stream, len, spec=None, doctype=JSONObject):
if len is None: if len is None:
description = _(u'Request body can not be empty') description = _(u'Request body can not be empty')
raise exceptions.HTTPBadRequestBody(description) raise errors.HTTPBadRequestBody(description)
try: try:
# TODO(kgriffs): read_json should stream the resulting list # TODO(kgriffs): read_json should stream the resulting list
@ -69,28 +69,28 @@ def filter_stream(stream, len, spec=None, doctype=JSONObject):
except utils.MalformedJSON as ex: except utils.MalformedJSON as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'Request body could not be parsed.') description = _(u'Request body could not be parsed.')
raise exceptions.HTTPBadRequestBody(description) raise errors.HTTPBadRequestBody(description)
except utils.OverflowedJSONInteger as ex: except utils.OverflowedJSONInteger as ex:
LOG.exception(ex) LOG.exception(ex)
description = _(u'JSON contains integer that is too large.') description = _(u'JSON contains integer that is too large.')
raise exceptions.HTTPBadRequestBody(description) raise errors.HTTPBadRequestBody(description)
except Exception as ex: except Exception as ex:
# Error while reading from the network/server # Error while reading from the network/server
LOG.exception(ex) LOG.exception(ex)
description = _(u'Request body could not be read.') description = _(u'Request body could not be read.')
raise exceptions.HTTPServiceUnavailable(description) raise errors.HTTPServiceUnavailable(description)
if doctype is JSONObject: if doctype is JSONObject:
if not isinstance(document, JSONObject): if not isinstance(document, JSONObject):
raise exceptions.HTTPDocumentTypeNotSupported() raise errors.HTTPDocumentTypeNotSupported()
return (document,) if spec is None else (filter(document, spec),) return (document,) if spec is None else (filter(document, spec),)
if doctype is JSONArray: if doctype is JSONArray:
if not isinstance(document, JSONArray): if not isinstance(document, JSONArray):
raise exceptions.HTTPDocumentTypeNotSupported() raise errors.HTTPDocumentTypeNotSupported()
if spec is None: if spec is None:
return document return document
@ -146,14 +146,14 @@ def get_checked_field(document, name, value_type):
value = document[name] value = document[name]
except KeyError: except KeyError:
description = _(u'Missing "{name}" field.').format(name=name) description = _(u'Missing "{name}" field.').format(name=name)
raise exceptions.HTTPBadRequestBody(description) raise errors.HTTPBadRequestBody(description)
if value_type == '*' or isinstance(value, value_type): if value_type == '*' or isinstance(value, value_type):
return value return value
description = _(u'The value of the "{name}" field must be a {vtype}.') description = _(u'The value of the "{name}" field must be a {vtype}.')
description = description.format(name=name, vtype=value_type.__name__) description = description.format(name=name, vtype=value_type.__name__)
raise exceptions.HTTPBadRequestBody(description) raise errors.HTTPBadRequestBody(description)
def get_client_uuid(req): def get_client_uuid(req):
@ -170,4 +170,4 @@ def get_client_uuid(req):
except ValueError: except ValueError:
description = _(u'Malformed hexadecimal UUID.') description = _(u'Malformed hexadecimal UUID.')
raise exceptions.HTTPBadRequestAPI(description) raise errors.HTTPBadRequestAPI(description)

View File

@ -24,7 +24,7 @@ from testtools import matchers
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues import storage from marconi.queues import storage
from marconi.queues.storage import exceptions from marconi.queues.storage import errors
from marconi import tests as testing from marconi import tests as testing
from marconi.tests import helpers from marconi.tests import helpers
@ -179,10 +179,10 @@ class QueueControllerTest(ControllerBaseTest):
self.assertFalse(self.controller.exists('test', project=self.project)) self.assertFalse(self.controller.exists('test', project=self.project))
# Test DoesNotExist exception # Test DoesNotExist exception
with testing.expect(storage.exceptions.DoesNotExist): with testing.expect(storage.errors.DoesNotExist):
self.controller.get_metadata('test', project=self.project) self.controller.get_metadata('test', project=self.project)
with testing.expect(storage.exceptions.DoesNotExist): with testing.expect(storage.errors.DoesNotExist):
self.controller.set_metadata('test', '{}', project=self.project) self.controller.set_metadata('test', '{}', project=self.project)
def test_stats_for_empty_queue(self): def test_stats_for_empty_queue(self):
@ -251,7 +251,7 @@ class MessageControllerTest(ControllerBaseTest):
self.controller.delete(queue_name, created[0], project=self.project) self.controller.delete(queue_name, created[0], project=self.project)
# Test does not exist # Test does not exist
with testing.expect(storage.exceptions.DoesNotExist): with testing.expect(storage.errors.DoesNotExist):
self.controller.get(queue_name, created[0], project=self.project) self.controller.get(queue_name, created[0], project=self.project)
def test_get_multi(self): def test_get_multi(self):
@ -343,7 +343,7 @@ class MessageControllerTest(ControllerBaseTest):
[msg1, msg2] = msgs [msg1, msg2] = msgs
# A wrong claim does not ensure the message deletion # A wrong claim does not ensure the message deletion
with testing.expect(storage.exceptions.NotPermitted): with testing.expect(storage.errors.NotPermitted):
self.controller.delete(self.queue_name, msg1['id'], self.controller.delete(self.queue_name, msg1['id'],
project=self.project, project=self.project,
claim=another_cid) claim=another_cid)
@ -353,7 +353,7 @@ class MessageControllerTest(ControllerBaseTest):
project=self.project, project=self.project,
claim=cid) claim=cid)
with testing.expect(storage.exceptions.DoesNotExist): with testing.expect(storage.errors.DoesNotExist):
self.controller.get(self.queue_name, msg1['id'], self.controller.get(self.queue_name, msg1['id'],
project=self.project) project=self.project)
@ -366,7 +366,7 @@ class MessageControllerTest(ControllerBaseTest):
self.claim_controller.delete(self.queue_name, cid, self.claim_controller.delete(self.queue_name, cid,
project=self.project) project=self.project)
with testing.expect(storage.exceptions.NotPermitted): with testing.expect(storage.errors.NotPermitted):
self.controller.delete(self.queue_name, msg2['id'], self.controller.delete(self.queue_name, msg2['id'],
project=self.project, project=self.project,
claim=cid) claim=cid)
@ -386,7 +386,7 @@ class MessageControllerTest(ControllerBaseTest):
time.sleep(self.gc_interval) time.sleep(self.gc_interval)
with testing.expect(storage.exceptions.DoesNotExist): with testing.expect(storage.errors.DoesNotExist):
self.controller.get(self.queue_name, msgid, self.controller.get(self.queue_name, msgid,
project=self.project) project=self.project)
@ -406,7 +406,7 @@ class MessageControllerTest(ControllerBaseTest):
bad_message_id, bad_message_id,
project=self.project) project=self.project)
with testing.expect(exceptions.MessageDoesNotExist): with testing.expect(errors.MessageDoesNotExist):
self.controller.get(self.queue_name, self.controller.get(self.queue_name,
bad_message_id, bad_message_id,
project=self.project) project=self.project)
@ -511,7 +511,7 @@ class ClaimControllerTest(ControllerBaseTest):
self.controller.delete(self.queue_name, claim_id, self.controller.delete(self.queue_name, claim_id,
project=self.project) project=self.project)
self.assertRaises(storage.exceptions.ClaimDoesNotExist, self.assertRaises(storage.errors.ClaimDoesNotExist,
self.controller.get, self.queue_name, self.controller.get, self.queue_name,
claim_id, project=self.project) claim_id, project=self.project)
@ -576,11 +576,11 @@ class ClaimControllerTest(ControllerBaseTest):
claim_id, messages = self.controller.create(self.queue_name, meta, claim_id, messages = self.controller.create(self.queue_name, meta,
project=self.project) project=self.project)
with testing.expect(storage.exceptions.DoesNotExist): with testing.expect(storage.errors.DoesNotExist):
self.controller.get(self.queue_name, claim_id, self.controller.get(self.queue_name, claim_id,
project=self.project) project=self.project)
with testing.expect(storage.exceptions.DoesNotExist): with testing.expect(storage.errors.DoesNotExist):
self.controller.update(self.queue_name, claim_id, self.controller.update(self.queue_name, claim_id,
meta, project=self.project) meta, project=self.project)
@ -591,12 +591,12 @@ class ClaimControllerTest(ControllerBaseTest):
'illformed', 'illformed',
project=self.project) project=self.project)
with testing.expect(exceptions.DoesNotExist): with testing.expect(errors.DoesNotExist):
self.controller.get(self.queue_name, self.controller.get(self.queue_name,
'illformed', 'illformed',
project=self.project) project=self.project)
with testing.expect(exceptions.DoesNotExist): with testing.expect(errors.DoesNotExist):
self.controller.update(self.queue_name, self.controller.update(self.queue_name,
'illformed', 'illformed',
{'ttl': 40}, {'ttl': 40},
@ -657,7 +657,7 @@ class ShardsControllerTest(ControllerBaseTest):
self.assertEqual(res['o'], {}) self.assertEqual(res['o'], {})
def test_get_raises_if_not_found(self): def test_get_raises_if_not_found(self):
self.assertRaises(storage.exceptions.ShardDoesNotExist, self.assertRaises(storage.errors.ShardDoesNotExist,
self.shards_controller.get, 'notexists') self.shards_controller.get, 'notexists')
def test_exists(self): def test_exists(self):
@ -781,7 +781,7 @@ class CatalogueControllerTest(ControllerBaseTest):
self._check_value(entry, xqueue=q, xproject=p, xshard=u'b') self._check_value(entry, xqueue=q, xproject=p, xshard=u'b')
def test_update_raises_when_entry_does_not_exist(self): def test_update_raises_when_entry_does_not_exist(self):
self.assertRaises(exceptions.QueueNotMapped, self.assertRaises(errors.QueueNotMapped,
self.controller.update, self.controller.update,
'not', 'not', 'a') 'not', 'not', 'a')
@ -798,13 +798,13 @@ class CatalogueControllerTest(ControllerBaseTest):
self.project, self.project,
self.queue, u'a') as expect: self.queue, u'a') as expect:
p, q, _ = expect p, q, _ = expect
self.assertRaises(exceptions.QueueNotMapped, self.assertRaises(errors.QueueNotMapped,
self.controller.get, self.controller.get,
p, 'non_existing') p, 'non_existing')
self.assertRaises(exceptions.QueueNotMapped, self.assertRaises(errors.QueueNotMapped,
self.controller.get, self.controller.get,
'non_existing', q) 'non_existing', q)
self.assertRaises(exceptions.QueueNotMapped, self.assertRaises(errors.QueueNotMapped,
self.controller.get, self.controller.get,
'non_existing', 'non_existing') 'non_existing', 'non_existing')

View File

@ -18,7 +18,7 @@ import uuid
import six import six
from marconi.proxy import storage from marconi.proxy import storage
from marconi.proxy.storage import exceptions from marconi.proxy.storage import errors
from marconi import tests as testing from marconi import tests as testing
from marconi.tests import helpers from marconi.tests import helpers
@ -110,7 +110,7 @@ class PartitionsControllerTest(ControllerBaseTest):
'a', cat='adorable') 'a', cat='adorable')
def test_update_on_nonexisting_raises(self): def test_update_on_nonexisting_raises(self):
self.assertRaises(exceptions.PartitionNotFound, self.assertRaises(errors.PartitionNotFound,
self.controller.update, self.controller.update,
'a', weight=10) 'a', weight=10)
@ -130,7 +130,7 @@ class PartitionsControllerTest(ControllerBaseTest):
self._check_values(p, xname=n, xweight=w, xhosts=h) self._check_values(p, xname=n, xweight=w, xhosts=h)
def test_get_nonexistent_throws(self): def test_get_nonexistent_throws(self):
self.assertRaises(exceptions.PartitionNotFound, self.assertRaises(errors.PartitionNotFound,
self.controller.get, ('not_found')) self.controller.get, ('not_found'))
def test_exists(self): def test_exists(self):

View File

@ -22,7 +22,7 @@ from testtools import matchers
from marconi.openstack.common import timeutils from marconi.openstack.common import timeutils
from marconi.queues import storage from marconi.queues import storage
from marconi.queues.storage import exceptions from marconi.queues.storage import errors
from marconi.queues.storage import mongodb from marconi.queues.storage import mongodb
from marconi.queues.storage.mongodb import controllers from marconi.queues.storage.mongodb import controllers
from marconi.queues.storage.mongodb import utils from marconi.queues.storage.mongodb import utils
@ -129,7 +129,8 @@ class MongodbQueueTests(base.QueueControllerTest):
method.side_effect = error method.side_effect = error
queues = next(self.controller.list()) queues = next(self.controller.list())
self.assertRaises(storage.exceptions.ConnectionError, queues.next) self.assertRaises(storage.errors.ConnectionError,
queues.next)
@testing.requires_mongodb @testing.requires_mongodb
@ -257,7 +258,7 @@ class MongodbMessageTests(base.MessageControllerTest):
if testing.RUN_SLOW_TESTS: if testing.RUN_SLOW_TESTS:
method.return_value = None method.return_value = None
with testing.expect(exceptions.MessageConflict): with testing.expect(errors.MessageConflict):
self.controller.post(queue_name, messages, uuid) self.controller.post(queue_name, messages, uuid)
created = list(self.controller.post(queue_name, created = list(self.controller.post(queue_name,
@ -281,7 +282,7 @@ class MongodbMessageTests(base.MessageControllerTest):
queue_name = 'empty-queue-test' queue_name = 'empty-queue-test'
self.queue_controller.create(queue_name) self.queue_controller.create(queue_name)
self.assertRaises(storage.exceptions.QueueIsEmpty, self.assertRaises(storage.errors.QueueIsEmpty,
self.controller.first, queue_name) self.controller.first, queue_name)
def test_invalid_sort_option(self): def test_invalid_sort_option(self):
@ -315,7 +316,7 @@ class MongodbClaimTests(base.ClaimControllerTest):
exists and/or has expired. exists and/or has expired.
""" """
epoch = '000000000000000000000000' epoch = '000000000000000000000000'
self.assertRaises(storage.exceptions.ClaimDoesNotExist, self.assertRaises(storage.errors.ClaimDoesNotExist,
self.controller.get, self.queue_name, self.controller.get, self.queue_name,
epoch, project=self.project) epoch, project=self.project)
@ -325,11 +326,11 @@ class MongodbClaimTests(base.ClaimControllerTest):
# Lets let it expire # Lets let it expire
time.sleep(1) time.sleep(1)
self.assertRaises(storage.exceptions.ClaimDoesNotExist, self.assertRaises(storage.errors.ClaimDoesNotExist,
self.controller.update, self.queue_name, self.controller.update, self.queue_name,
claim_id, {}, project=self.project) claim_id, {}, project=self.project)
self.assertRaises(storage.exceptions.ClaimDoesNotExist, self.assertRaises(storage.errors.ClaimDoesNotExist,
self.controller.update, self.queue_name, self.controller.update, self.queue_name,
claim_id, {}, project=self.project) claim_id, {}, project=self.project)

View File

@ -32,7 +32,7 @@ class SQliteMessageTests(base.MessageControllerTest):
queue_name = 'empty-queue-test' queue_name = 'empty-queue-test'
self.queue_controller.create(queue_name, None) self.queue_controller.create(queue_name, None)
self.assertRaises(storage.exceptions.QueueIsEmpty, self.assertRaises(storage.errors.QueueIsEmpty,
self.controller.first, self.controller.first,
queue_name, None, sort=1) queue_name, None, sort=1)

View File

@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
from marconi.common import exceptions from marconi.common import errors
from marconi.queues import bootstrap from marconi.queues import bootstrap
from marconi.queues.storage import pipeline from marconi.queues.storage import pipeline
from marconi.queues.storage import sharding from marconi.queues.storage import sharding
@ -30,7 +30,7 @@ class TestBootstrap(base.TestBase):
def test_storage_invalid(self): def test_storage_invalid(self):
boot = self._bootstrap('etc/drivers_storage_invalid.conf') boot = self._bootstrap('etc/drivers_storage_invalid.conf')
self.assertRaises(exceptions.InvalidDriver, self.assertRaises(errors.InvalidDriver,
lambda: boot.storage) lambda: boot.storage)
def test_storage_sqlite(self): def test_storage_sqlite(self):
@ -45,7 +45,7 @@ class TestBootstrap(base.TestBase):
def test_transport_invalid(self): def test_transport_invalid(self):
boot = self._bootstrap('etc/drivers_transport_invalid.conf') boot = self._bootstrap('etc/drivers_transport_invalid.conf')
self.assertRaises(exceptions.InvalidDriver, self.assertRaises(errors.InvalidDriver,
lambda: boot.transport) lambda: boot.transport)
def test_transport_wsgi(self): def test_transport_wsgi(self):