def all_pages(): 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))
def register(self, queue, project=None, flavor=None): """Register a new queue in the pool catalog. This method should be called whenever a new queue is being created, and will create an entry in the pool catalog for the given queue. After using this method to register the queue in the catalog, the caller should call `lookup()` to get a reference to a storage driver which will allow interacting with the queue's assigned backend pool. :param queue: Name of the new queue to assign to a pool :type queue: six.text_type :param project: Project to which the queue belongs, or None for the "global" or "generic" project. :type project: six.text_type :param flavor: Flavor for the queue (OPTIONAL) :type flavor: six.text_type :raises NoPoolFound: if not found """ # NOTE(cpp-cabrera): only register a queue if the entry # doesn't exist if not self._catalogue_ctrl.exists(project, queue): if flavor is not None: flavor = self._flavor_ctrl.get(flavor, project=project) pools = self._pools_ctrl.get_pools_by_group( group=flavor['pool_group'], detailed=True) pool = select.weighted(pools) pool = pool and pool['name'] or None else: # NOTE(flaper87): Get pools assigned to the default # group `None`. We should consider adding a `default_group` # option in the future. pools = self._pools_ctrl.get_pools_by_group(detailed=True) pool = select.weighted(pools) pool = pool and pool['name'] or None if not pool: # NOTE(flaper87): We used to raise NoPoolFound in this # case but we've decided to support automatic pool # creation. Note that we're now returning and the queue # is not being registered in the catalogue. This is done # on purpose since no pool exists and the "dummy" pool # doesn't exist in the storage if self.lookup(queue, project) is not None: return raise errors.NoPoolFound() self._catalogue_ctrl.insert(project, queue, pool)
def subscription_generator(): raise storage_errors.NoPoolFound()
def queue_generator(): raise storage_errors.NoPoolFound()
def topic_generator(): raise storage_errors.NoPoolFound()
def register(self, queue, project=None, flavor=None): """Register a new queue in the pool catalog. This method should be called whenever a new queue is being created, and will create an entry in the pool catalog for the given queue. After using this method to register the queue in the catalog, the caller should call `lookup()` to get a reference to a storage driver which will allow interacting with the queue's assigned backend pool. :param queue: Name of the new queue to assign to a pool :type queue: six.text_type :param project: Project to which the queue belongs, or None for the "global" or "generic" project. :type project: six.text_type :param flavor: Flavor for the queue (OPTIONAL) :type flavor: six.text_type :raises NoPoolFound: if not found """ # NOTE(gengchc): if exist, get queue's pool.flavor: # if queue's pool.flavor is different, first delete it and add it. # Otherwise, if the flavor in the meteredata of the queue is # modified, the catalog will be inconsistent. if self._catalogue_ctrl.exists(project, queue): catalogue = self._catalogue_ctrl.get(project, queue) oldpoolids = catalogue['pool'] oldpool = self._pools_ctrl.get(oldpoolids) oldflavor = oldpool['flavor'] msgtmpl = _(u'regiester queue to pool: old flavor: %(oldflavor)s ' ', new flavor: %(flavor)s') LOG.info(msgtmpl, {'oldflavor': oldflavor, 'flavor': flavor}) if oldpool['flavor'] != flavor: self._catalogue_ctrl.delete(project, queue) if not self._catalogue_ctrl.exists(project, queue): if flavor is not None: flavor = self._flavor_ctrl.get(flavor, project=project) pools = self._pools_ctrl.get_pools_by_flavor(flavor=flavor, detailed=True) pool = select.weighted(pools) pool = pool and pool['name'] or None msgtmpl = _(u'regiester queue to pool: new flavor:%(flavor)s' ' pool_group:%(pool_group)s') LOG.info( msgtmpl, { 'flavor': flavor.get('name', None), 'pool_group': flavor.get('pool_group', None) }) else: # NOTE(flaper87): Get pools assigned to the default # group `None`. We should consider adding a `default_group` # option in the future. pools = self._pools_ctrl.get_pools_by_flavor(detailed=True) pool = select.weighted(pools) pool = pool and pool['name'] or None if not pool: # NOTE(flaper87): We used to raise NoPoolFound in this # case but we've decided to support automatic pool # creation. Note that we're now returning and the queue # is not being registered in the catalogue. This is done # on purpose since no pool exists and the "dummy" pool # doesn't exist in the storage if self.lookup(queue, project) is not None: return raise errors.NoPoolFound() msgtmpl = _(u'regiester queue to pool: new flavor: None') LOG.info(msgtmpl) msgtmpl = _(u'regiester queue: project:%(project)s' ' queue:%(queue)s pool:%(pool)s') LOG.info(msgtmpl, { 'project': project, 'queue': queue, 'pool': pool }) self._catalogue_ctrl.insert(project, queue, pool)