def _insert(self, project, queue, pool): queue_key = utils.scope_queue_name(queue, project) catalogue_project_key = utils.scope_pool_catalogue( project, CATALOGUE_SUFFIX) catalogue_queue_key = utils.scope_pool_catalogue( queue_key, CATALOGUE_SUFFIX) # Check if the queue already exists. if self._exists(queue, project): return False catalogue = {'p': project, 'p_q': queue, 'p_p': pool} # Pipeline ensures atomic inserts. with self._client.pipeline() as pipe: pipe.zadd(catalogue_project_key, {queue_key: 1}) pipe.hmset(catalogue_queue_key, catalogue) try: pipe.execute() except redis.exceptions.ResponseError: msgtmpl = _(u'CatalogueController:insert %(prj)s:' '%(queue)s %(pool)s failed') LOG.exception(msgtmpl, { 'prj': project, 'queue': queue, 'pool': pool }) return False msgtmpl = _(u'CatalogueController:insert %(prj)s:%(queue)s' ':%(pool)s, success') LOG.info(msgtmpl, {'prj': project, 'queue': queue, 'pool': pool}) return True
def _insert(self, project, queue, pool): queue_key = utils.scope_queue_name(queue, project) catalogue_project_key = utils.scope_pool_catalogue(project, CATALOGUE_SUFFIX) catalogue_queue_key = utils.scope_pool_catalogue(queue_key, CATALOGUE_SUFFIX) # Check if the queue already exists. if self._exists(queue, project): return False catalogue = { 'p': project, 'p_q': queue, 'p_p': pool } # Pipeline ensures atomic inserts. with self._client.pipeline() as pipe: pipe.zadd(catalogue_project_key, {queue_key: 1}) pipe.hmset(catalogue_queue_key, catalogue) try: pipe.execute() except redis.exceptions.ResponseError: msgtmpl = _(u'CatalogueController:insert %(prj)s:' '%(queue)s %(pool)s failed') LOG.exception(msgtmpl, {'prj': project, 'queue': queue, 'pool': pool}) return False msgtmpl = _(u'CatalogueController:insert %(prj)s:%(queue)s' ':%(pool)s, success') LOG.info(msgtmpl, {'prj': project, 'queue': queue, 'pool': pool}) return True
def delete(self, project, queue): # (gengchc): Check if the queue already exists. if not self._exists(project, queue): return True queue_key = utils.scope_queue_name(queue, project) catalogue_project_key = utils.scope_pool_catalogue(project, CATALOGUE_SUFFIX) catalogue_queue_key = utils.scope_pool_catalogue(queue_key, CATALOGUE_SUFFIX) # (gengchc) Pipeline ensures atomic inserts. with self._client.pipeline() as pipe: pipe.zrem(catalogue_project_key, queue_key) pipe.delete(catalogue_queue_key) try: pipe.execute() except redis.exceptions.ResponseError: msgtmpl = _(u'CatalogueController:delete %(prj)s' ':%(queue)s failed') LOG.info(msgtmpl, {'prj': project, 'queue': queue}) return False msgtmpl = _(u'CatalogueController:delete %(prj)s:%(queue)s success') LOG.info(msgtmpl, {'prj': project, 'queue': queue})
def get(self, project, queue): queue_key = utils.scope_queue_name(queue, project) catalogue_queue_key = \ utils.scope_pool_catalogue(queue_key, CATALOGUE_SUFFIX) ctlg = self._client.hgetall(catalogue_queue_key) if ctlg is None or len(ctlg) == 0: raise errors.QueueNotMapped(queue, project) return _normalize(ctlg)
def get(self, project, queue): queue_key = utils.scope_queue_name(queue, project) catalogue_queue_key = \ utils.scope_pool_catalogue(queue_key, CATALOGUE_SUFFIX) ctlg = self._client.hgetall(catalogue_queue_key) if ctlg is None or len(ctlg) == 0: raise errors.QueueNotMapped(queue, project) return _normalize(ctlg)
def list(self, project): catalogue_project_key = utils.scope_pool_catalogue( project, CATALOGUE_SUFFIX) ctlgs = [] offset = 0 while True: queues = self._client.zrange(catalogue_project_key, offset, offset + COUNTING_BATCH_SIZE - 1) if not queues: break offset += len(queues) for queue in queues: catalogue_queue_key =\ utils.scope_pool_catalogue(queue, CATALOGUE_SUFFIX) ctlg = self._client.hgetall(catalogue_queue_key) ctlgs.append(ctlg) return (_normalize(v) for v in ctlgs)
def list(self, project): catalogue_project_key = utils.scope_pool_catalogue(project, CATALOGUE_SUFFIX) ctlgs = [] offset = 0 while True: queues = self._client.zrange(catalogue_project_key, offset, offset + COUNTING_BATCH_SIZE - 1) if not queues: break offset += len(queues) for queue in queues: catalogue_queue_key =\ utils.scope_pool_catalogue(queue, CATALOGUE_SUFFIX) ctlg = self._client.hgetall(catalogue_queue_key) ctlgs.append(ctlg) return (_normalize(v) for v in ctlgs)
def delete(self, project, queue): # (gengchc): Check if the queue already exists. if not self._exists(project, queue): return True queue_key = utils.scope_queue_name(queue, project) catalogue_project_key = utils.scope_pool_catalogue( project, CATALOGUE_SUFFIX) catalogue_queue_key = utils.scope_pool_catalogue( queue_key, CATALOGUE_SUFFIX) # (gengchc) Pipeline ensures atomic inserts. with self._client.pipeline() as pipe: pipe.zrem(catalogue_project_key, queue_key) pipe.delete(catalogue_queue_key) try: pipe.execute() except redis.exceptions.ResponseError: msgtmpl = _(u'CatalogueController:delete %(prj)s' ':%(queue)s failed') LOG.info(msgtmpl, {'prj': project, 'queue': queue}) return False msgtmpl = _(u'CatalogueController:delete %(prj)s:%(queue)s success') LOG.info(msgtmpl, {'prj': project, 'queue': queue})
def _update(self, project, queue, pool): # Check if the queue already exists. if not self._exists(project, queue): raise errors.QueueNotMapped(queue, project) queue_key = utils.scope_queue_name(queue, project) catalogue_queue_key = utils.scope_pool_catalogue(queue_key, CATALOGUE_SUFFIX) with self._client.pipeline() as pipe: pipe.hset(catalogue_queue_key, "pl", pool) try: pipe.execute() except redis.exceptions.ResponseError: msgtmpl = _(u'CatalogueController:_update %(prj)s' ':%(queue)s:%(pool)s failed') LOG.exception(msgtmpl, {'prj': project, 'queue': queue, 'pool': pool}) return False msgtmpl = _(u'CatalogueController:_update %(prj)s:%(queue)s' ':%(pool)s') LOG.info(msgtmpl, {'prj': project, 'queue': queue, 'pool': pool})
def _update(self, project, queue, pool): # Check if the queue already exists. if not self._exists(project, queue): raise errors.QueueNotMapped(queue, project) queue_key = utils.scope_queue_name(queue, project) catalogue_queue_key = utils.scope_pool_catalogue( queue_key, CATALOGUE_SUFFIX) with self._client.pipeline() as pipe: pipe.hset(catalogue_queue_key, "pl", pool) try: pipe.execute() except redis.exceptions.ResponseError: msgtmpl = _(u'CatalogueController:_update %(prj)s' ':%(queue)s:%(pool)s failed') LOG.exception(msgtmpl, { 'prj': project, 'queue': queue, 'pool': pool }) return False msgtmpl = _(u'CatalogueController:_update %(prj)s:%(queue)s' ':%(pool)s') LOG.info(msgtmpl, {'prj': project, 'queue': queue, 'pool': pool})
def _exists(self, project, queue): queue_key = utils.scope_queue_name(queue, project) catalogue_queue_key = \ utils.scope_pool_catalogue(queue_key, CATALOGUE_SUFFIX) return self._client.exists(catalogue_queue_key)
def _exists(self, project, queue): queue_key = utils.scope_queue_name(queue, project) catalogue_queue_key = \ utils.scope_pool_catalogue(queue_key, CATALOGUE_SUFFIX) return self._client.exists(catalogue_queue_key)