Use default pool for queue listing

While we're properly use a default pool when manipulating a specific
queue, we don't use it when actually listing queues. This fixes it by
using the same mechanism.

Change-Id: Ie2329389bf92793af0c8d7a676fcada757fd26d7
Closes-Bug: #1533668
This commit is contained in:
Thomas Herve 2016-01-18 17:08:19 +01:00
parent edfb7ec3b8
commit 460ecce2ec
4 changed files with 44 additions and 39 deletions

View File

@ -152,16 +152,14 @@ class QueueController(storage.Queue):
limit=storage.DEFAULT_QUEUES_PER_PAGE, detailed=False):
def all_pages():
cursor = self._pool_catalog._pools_ctrl.list(limit=0)
pools_list = list(next(cursor))
anypool = pools_list and pools_list[0]
if anypool:
yield next(self._pool_catalog.get_driver(anypool['name'])
.queue_controller.list(
project=project,
marker=marker,
limit=limit,
detailed=detailed))
pool = self._pool_catalog.get_default_pool()
if pool is None:
raise errors.NoPoolFound()
yield next(pool.queue_controller.list(
project=project,
marker=marker,
limit=limit,
detailed=detailed))
# make a heap compared with 'name'
ls = heapq.merge(*[
@ -589,27 +587,14 @@ class Catalog(object):
target = self.lookup(queue, project)
return target and target.subscription_controller
def lookup(self, queue, project=None):
"""Lookup a pool driver for the given queue and project.
:param queue: Name of the queue for which to find a pool
:param project: Project to which the queue belongs, or
None to specify the "global" or "generic" project.
:returns: A storage driver instance for the appropriate pool. If
the driver does not exist yet, it is created and cached. If the
queue is not mapped, returns None.
:rtype: Maybe DataDriver
"""
try:
pool_id = self._pool_id(queue, project)
except errors.QueueNotMapped as ex:
LOG.debug(ex)
if not self._catalog_conf.enable_virtual_pool:
return None
def get_default_pool(self, use_listing=True):
if use_listing:
cursor = self._pools_ctrl.list(limit=0)
pools_list = list(next(cursor))
if pools_list:
return self.get_driver(pools_list[0]['name'])
if self._catalog_conf.enable_virtual_pool:
conf_section = ('drivers:message_store:%s' %
self._conf.drivers.message_store)
@ -643,6 +628,26 @@ class Catalog(object):
# store.
return self.get_driver(None, pool_conf)
def lookup(self, queue, project=None):
"""Lookup a pool driver for the given queue and project.
:param queue: Name of the queue for which to find a pool
:param project: Project to which the queue belongs, or
None to specify the "global" or "generic" project.
:returns: A storage driver instance for the appropriate pool. If
the driver does not exist yet, it is created and cached. If the
queue is not mapped, returns None.
:rtype: Maybe DataDriver
"""
try:
pool_id = self._pool_id(queue, project)
except errors.QueueNotMapped as ex:
LOG.debug(ex)
return self.get_default_pool(use_listing=False)
return self.get_driver(pool_id)
def get_driver(self, pool_id, pool_conf=None):

View File

@ -96,6 +96,9 @@ class CollectionResource(object):
self._validate.queue_listing(**kwargs)
results = self._queue_controller.list(project=project_id, **kwargs)
# Buffer list of queues
queues = list(next(results))
except validation.ValidationFailed as ex:
LOG.debug(ex)
raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
@ -105,9 +108,6 @@ class CollectionResource(object):
description = _(u'Queues could not be listed.')
raise wsgi_errors.HTTPServiceUnavailable(description)
# Buffer list of queues
queues = list(next(results))
# Check for an empty list
if len(queues) == 0:
resp.status = falcon.HTTP_204

View File

@ -123,6 +123,9 @@ class CollectionResource(object):
self._validate.queue_listing(**kwargs)
results = self._queue_controller.list(project=project_id, **kwargs)
# Buffer list of queues
queues = list(next(results))
except validation.ValidationFailed as ex:
LOG.debug(ex)
raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
@ -132,9 +135,6 @@ class CollectionResource(object):
description = _(u'Queues could not be listed.')
raise wsgi_errors.HTTPServiceUnavailable(description)
# Buffer list of queues
queues = list(next(results))
# Got some. Prepare the response.
kwargs['marker'] = next(results) or kwargs.get('marker', '')
for each_queue in queues:

View File

@ -130,6 +130,9 @@ class CollectionResource(object):
self._validate.queue_listing(**kwargs)
results = self._queue_controller.list(project=project_id, **kwargs)
# Buffer list of queues
queues = list(next(results))
except validation.ValidationFailed as ex:
LOG.debug(ex)
raise wsgi_errors.HTTPBadRequestAPI(six.text_type(ex))
@ -139,9 +142,6 @@ class CollectionResource(object):
description = _(u'Queues could not be listed.')
raise wsgi_errors.HTTPServiceUnavailable(description)
# Buffer list of queues
queues = list(next(results))
# Got some. Prepare the response.
kwargs['marker'] = next(results) or kwargs.get('marker', '')
for each_queue in queues: