Merge "Wrap abstract method with base methods"
This commit is contained in:
commit
7e94de24e3
@ -27,6 +27,7 @@ import six
|
|||||||
|
|
||||||
import zaqar.openstack.common.log as logging
|
import zaqar.openstack.common.log as logging
|
||||||
|
|
||||||
|
|
||||||
DEFAULT_QUEUES_PER_PAGE = 10
|
DEFAULT_QUEUES_PER_PAGE = 10
|
||||||
DEFAULT_MESSAGES_PER_PAGE = 10
|
DEFAULT_MESSAGES_PER_PAGE = 10
|
||||||
DEFAULT_POOLS_PER_PAGE = 10
|
DEFAULT_POOLS_PER_PAGE = 10
|
||||||
@ -279,7 +280,6 @@ class Queue(ControllerBase):
|
|||||||
numbers of queues.
|
numbers of queues.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def list(self, project=None, marker=None,
|
def list(self, project=None, marker=None,
|
||||||
limit=DEFAULT_QUEUES_PER_PAGE, detailed=False):
|
limit=DEFAULT_QUEUES_PER_PAGE, detailed=False):
|
||||||
"""Base method for listing queues.
|
"""Base method for listing queues.
|
||||||
@ -292,9 +292,10 @@ class Queue(ControllerBase):
|
|||||||
:returns: An iterator giving a sequence of queues
|
:returns: An iterator giving a sequence of queues
|
||||||
and the marker of the next page.
|
and the marker of the next page.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
return self._list(project, marker, limit, detailed)
|
||||||
|
|
||||||
|
_list = abc.abstractmethod(lambda x: None)
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def get(self, name, project=None):
|
def get(self, name, project=None):
|
||||||
"""Base method for queue metadata retrieval.
|
"""Base method for queue metadata retrieval.
|
||||||
|
|
||||||
@ -304,7 +305,9 @@ class Queue(ControllerBase):
|
|||||||
:returns: Dictionary containing queue metadata
|
:returns: Dictionary containing queue metadata
|
||||||
:raises: DoesNotExist
|
:raises: DoesNotExist
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
return self._get(name, project)
|
||||||
|
|
||||||
|
_get = abc.abstractmethod(lambda x: None)
|
||||||
|
|
||||||
def get_metadata(self, name, project=None):
|
def get_metadata(self, name, project=None):
|
||||||
"""Base method for queue metadata retrieval.
|
"""Base method for queue metadata retrieval.
|
||||||
@ -317,28 +320,6 @@ class Queue(ControllerBase):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def create(self, name, metadata=None, project=None):
|
|
||||||
"""Base method for queue creation.
|
|
||||||
|
|
||||||
:param name: The queue name
|
|
||||||
:param project: Project id
|
|
||||||
:returns: True if a queue was created and False
|
|
||||||
if it was updated.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def exists(self, name, project=None):
|
|
||||||
"""Base method for testing queue existence.
|
|
||||||
|
|
||||||
:param name: The queue name
|
|
||||||
:param project: Project id
|
|
||||||
:returns: True if a queue exists and False
|
|
||||||
if it does not.
|
|
||||||
"""
|
|
||||||
raise NotImplementedError
|
|
||||||
|
|
||||||
def set_metadata(self, name, metadata, project=None):
|
def set_metadata(self, name, metadata, project=None):
|
||||||
"""Base method for updating a queue metadata.
|
"""Base method for updating a queue metadata.
|
||||||
|
|
||||||
@ -349,16 +330,40 @@ class Queue(ControllerBase):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
@abc.abstractmethod
|
def create(self, name, metadata=None, project=None):
|
||||||
|
"""Base method for queue creation.
|
||||||
|
|
||||||
|
:param name: The queue name
|
||||||
|
:param project: Project id
|
||||||
|
:returns: True if a queue was created and False
|
||||||
|
if it was updated.
|
||||||
|
"""
|
||||||
|
return self._create(name, metadata, project)
|
||||||
|
|
||||||
|
_create = abc.abstractmethod(lambda x: None)
|
||||||
|
|
||||||
|
def exists(self, name, project=None):
|
||||||
|
"""Base method for testing queue existence.
|
||||||
|
|
||||||
|
:param name: The queue name
|
||||||
|
:param project: Project id
|
||||||
|
:returns: True if a queue exists and False
|
||||||
|
if it does not.
|
||||||
|
"""
|
||||||
|
return self._exists(name, project)
|
||||||
|
|
||||||
|
_exists = abc.abstractmethod(lambda x: None)
|
||||||
|
|
||||||
def delete(self, name, project=None):
|
def delete(self, name, project=None):
|
||||||
"""Base method for deleting a queue.
|
"""Base method for deleting a queue.
|
||||||
|
|
||||||
:param name: The queue name
|
:param name: The queue name
|
||||||
:param project: Project id
|
:param project: Project id
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
return self._delete(name, project)
|
||||||
|
|
||||||
|
_delete = abc.abstractmethod(lambda x: None)
|
||||||
|
|
||||||
@abc.abstractmethod
|
|
||||||
def stats(self, name, project=None):
|
def stats(self, name, project=None):
|
||||||
"""Base method for queue stats.
|
"""Base method for queue stats.
|
||||||
|
|
||||||
@ -367,7 +372,9 @@ class Queue(ControllerBase):
|
|||||||
:returns: Dictionary with the
|
:returns: Dictionary with the
|
||||||
queue stats
|
queue stats
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
return self._stats(name, project)
|
||||||
|
|
||||||
|
_stats = abc.abstractmethod(lambda x: None)
|
||||||
|
|
||||||
|
|
||||||
@six.add_metaclass(abc.ABCMeta)
|
@six.add_metaclass(abc.ABCMeta)
|
||||||
|
@ -188,14 +188,14 @@ class QueueController(storage.Queue):
|
|||||||
# Interface
|
# Interface
|
||||||
# ----------------------------------------------------------------------
|
# ----------------------------------------------------------------------
|
||||||
|
|
||||||
def get(self, name, project=None):
|
def _get(self, name, project=None):
|
||||||
try:
|
try:
|
||||||
return self.get_metadata(name, project)
|
return self.get_metadata(name, project)
|
||||||
except errors.QueueDoesNotExist:
|
except errors.QueueDoesNotExist:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def list(self, project=None, marker=None,
|
def _list(self, project=None, marker=None,
|
||||||
limit=storage.DEFAULT_QUEUES_PER_PAGE, detailed=False):
|
limit=storage.DEFAULT_QUEUES_PER_PAGE, detailed=False):
|
||||||
|
|
||||||
query = utils.scoped_query(marker, project)
|
query = utils.scoped_query(marker, project)
|
||||||
|
|
||||||
@ -229,7 +229,7 @@ class QueueController(storage.Queue):
|
|||||||
|
|
||||||
@utils.raises_conn_error
|
@utils.raises_conn_error
|
||||||
# @utils.retries_on_autoreconnect
|
# @utils.retries_on_autoreconnect
|
||||||
def create(self, name, metadata=None, project=None):
|
def _create(self, name, metadata=None, project=None):
|
||||||
# NOTE(flaper87): If the connection fails after it was called
|
# NOTE(flaper87): If the connection fails after it was called
|
||||||
# and we retry to insert the queue, we could end up returning
|
# and we retry to insert the queue, we could end up returning
|
||||||
# `False` because of the `DuplicatedKeyError` although the
|
# `False` because of the `DuplicatedKeyError` although the
|
||||||
@ -259,7 +259,7 @@ class QueueController(storage.Queue):
|
|||||||
@utils.raises_conn_error
|
@utils.raises_conn_error
|
||||||
@utils.retries_on_autoreconnect
|
@utils.retries_on_autoreconnect
|
||||||
@decorators.caches(_queue_exists_key, _QUEUE_CACHE_TTL, lambda v: v)
|
@decorators.caches(_queue_exists_key, _QUEUE_CACHE_TTL, lambda v: v)
|
||||||
def exists(self, name, project=None):
|
def _exists(self, name, project=None):
|
||||||
query = _get_scoped_query(name, project)
|
query = _get_scoped_query(name, project)
|
||||||
return self._collection.find_one(query) is not None
|
return self._collection.find_one(query) is not None
|
||||||
|
|
||||||
@ -276,14 +276,14 @@ class QueueController(storage.Queue):
|
|||||||
|
|
||||||
@utils.raises_conn_error
|
@utils.raises_conn_error
|
||||||
@utils.retries_on_autoreconnect
|
@utils.retries_on_autoreconnect
|
||||||
@exists.purges
|
@_exists.purges
|
||||||
def delete(self, name, project=None):
|
def _delete(self, name, project=None):
|
||||||
self.driver.message_controller._purge_queue(name, project)
|
self.driver.message_controller._purge_queue(name, project)
|
||||||
self._collection.remove(_get_scoped_query(name, project))
|
self._collection.remove(_get_scoped_query(name, project))
|
||||||
|
|
||||||
@utils.raises_conn_error
|
@utils.raises_conn_error
|
||||||
@utils.retries_on_autoreconnect
|
@utils.retries_on_autoreconnect
|
||||||
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 errors.QueueDoesNotExist(name, project)
|
raise errors.QueueDoesNotExist(name, project)
|
||||||
|
|
||||||
|
@ -86,8 +86,8 @@ class QueueController(storage.Queue):
|
|||||||
|
|
||||||
@utils.raises_conn_error
|
@utils.raises_conn_error
|
||||||
@utils.retries_on_connection_error
|
@utils.retries_on_connection_error
|
||||||
def list(self, project=None, marker=None,
|
def _list(self, project=None, marker=None,
|
||||||
limit=storage.DEFAULT_QUEUES_PER_PAGE, detailed=False):
|
limit=storage.DEFAULT_QUEUES_PER_PAGE, detailed=False):
|
||||||
client = self._client
|
client = self._client
|
||||||
qset_key = utils.scope_queue_name(QUEUES_SET_STORE_NAME, project)
|
qset_key = utils.scope_queue_name(QUEUES_SET_STORE_NAME, project)
|
||||||
marker = utils.scope_queue_name(marker, project)
|
marker = utils.scope_queue_name(marker, project)
|
||||||
@ -109,12 +109,12 @@ class QueueController(storage.Queue):
|
|||||||
yield utils.QueueListCursor(self._client, cursor, denormalizer)
|
yield utils.QueueListCursor(self._client, cursor, denormalizer)
|
||||||
yield marker_next and marker_next['next']
|
yield marker_next and marker_next['next']
|
||||||
|
|
||||||
def get(self, name, project=None):
|
def _get(self, name, project=None):
|
||||||
"""Obtain the metadata from the queue."""
|
"""Obtain the metadata from the queue."""
|
||||||
return self.get_metadata(name, project)
|
return self.get_metadata(name, project)
|
||||||
|
|
||||||
@utils.raises_conn_error
|
@utils.raises_conn_error
|
||||||
def create(self, name, metadata=None, project=None):
|
def _create(self, name, metadata=None, project=None):
|
||||||
# TODO(prashanthr_): Implement as a lua script.
|
# TODO(prashanthr_): Implement as a lua script.
|
||||||
queue_key = utils.scope_queue_name(name, project)
|
queue_key = utils.scope_queue_name(name, project)
|
||||||
qset_key = utils.scope_queue_name(QUEUES_SET_STORE_NAME, project)
|
qset_key = utils.scope_queue_name(QUEUES_SET_STORE_NAME, project)
|
||||||
@ -144,7 +144,7 @@ class QueueController(storage.Queue):
|
|||||||
|
|
||||||
@utils.raises_conn_error
|
@utils.raises_conn_error
|
||||||
@utils.retries_on_connection_error
|
@utils.retries_on_connection_error
|
||||||
def exists(self, name, project=None):
|
def _exists(self, name, project=None):
|
||||||
# TODO(prashanthr_): Cache this lookup
|
# TODO(prashanthr_): Cache this lookup
|
||||||
queue_key = utils.scope_queue_name(name, project)
|
queue_key = utils.scope_queue_name(name, project)
|
||||||
qset_key = utils.scope_queue_name(QUEUES_SET_STORE_NAME, project)
|
qset_key = utils.scope_queue_name(QUEUES_SET_STORE_NAME, project)
|
||||||
@ -175,7 +175,7 @@ class QueueController(storage.Queue):
|
|||||||
|
|
||||||
@utils.raises_conn_error
|
@utils.raises_conn_error
|
||||||
@utils.retries_on_connection_error
|
@utils.retries_on_connection_error
|
||||||
def delete(self, name, project=None):
|
def _delete(self, name, project=None):
|
||||||
queue_key = utils.scope_queue_name(name, project)
|
queue_key = utils.scope_queue_name(name, project)
|
||||||
qset_key = utils.scope_queue_name(QUEUES_SET_STORE_NAME, project)
|
qset_key = utils.scope_queue_name(QUEUES_SET_STORE_NAME, project)
|
||||||
|
|
||||||
@ -190,7 +190,7 @@ class QueueController(storage.Queue):
|
|||||||
|
|
||||||
@utils.raises_conn_error
|
@utils.raises_conn_error
|
||||||
@utils.retries_on_connection_error
|
@utils.retries_on_connection_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 errors.QueueDoesNotExist(name, project)
|
raise errors.QueueDoesNotExist(name, project)
|
||||||
|
|
||||||
|
@ -23,8 +23,8 @@ from zaqar.storage.sqlalchemy import utils
|
|||||||
|
|
||||||
class QueueController(storage.Queue):
|
class QueueController(storage.Queue):
|
||||||
|
|
||||||
def list(self, project, marker=None,
|
def _list(self, project, marker=None,
|
||||||
limit=storage.DEFAULT_QUEUES_PER_PAGE, detailed=False):
|
limit=storage.DEFAULT_QUEUES_PER_PAGE, detailed=False):
|
||||||
|
|
||||||
if project is None:
|
if project is None:
|
||||||
project = ''
|
project = ''
|
||||||
@ -68,13 +68,13 @@ class QueueController(storage.Queue):
|
|||||||
except utils.NoResult:
|
except utils.NoResult:
|
||||||
raise errors.QueueDoesNotExist(name, project)
|
raise errors.QueueDoesNotExist(name, project)
|
||||||
|
|
||||||
def get(self, name, project=None):
|
def _get(self, name, project=None):
|
||||||
try:
|
try:
|
||||||
return self.get_metadata(name, project)
|
return self.get_metadata(name, project)
|
||||||
except errors.QueueDoesNotExist:
|
except errors.QueueDoesNotExist:
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def create(self, name, metadata=None, project=None):
|
def _create(self, name, metadata=None, project=None):
|
||||||
if project is None:
|
if project is None:
|
||||||
project = ''
|
project = ''
|
||||||
|
|
||||||
@ -89,7 +89,7 @@ class QueueController(storage.Queue):
|
|||||||
|
|
||||||
return res.rowcount == 1
|
return res.rowcount == 1
|
||||||
|
|
||||||
def exists(self, name, project):
|
def _exists(self, name, project):
|
||||||
if project is None:
|
if project is None:
|
||||||
project = ''
|
project = ''
|
||||||
|
|
||||||
@ -120,7 +120,7 @@ class QueueController(storage.Queue):
|
|||||||
finally:
|
finally:
|
||||||
res.close()
|
res.close()
|
||||||
|
|
||||||
def delete(self, name, project):
|
def _delete(self, name, project):
|
||||||
if project is None:
|
if project is None:
|
||||||
project = ''
|
project = ''
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ class QueueController(storage.Queue):
|
|||||||
tables.Queues.c.name == name))
|
tables.Queues.c.name == name))
|
||||||
self.driver.run(dlt)
|
self.driver.run(dlt)
|
||||||
|
|
||||||
def stats(self, name, project):
|
def _stats(self, name, project):
|
||||||
if project is None:
|
if project is None:
|
||||||
project = ''
|
project = ''
|
||||||
|
|
||||||
|
@ -69,28 +69,28 @@ class QueueController(storage.Queue):
|
|||||||
def __init__(self, driver):
|
def __init__(self, driver):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def list(self, project=None):
|
def _list(self, project=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def get(self, name, project=None):
|
def _get(self, name, project=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def get_metadata(self, name, project=None):
|
def get_metadata(self, name, project=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def create(self, name, metadata=None, project=None):
|
def _create(self, name, metadata=None, project=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def exists(self, name, project=None):
|
def _exists(self, name, project=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def set_metadata(self, name, metadata, project=None):
|
def set_metadata(self, name, metadata, project=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def delete(self, name, project=None):
|
def _delete(self, name, project=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
def stats(self, name, project=None):
|
def _stats(self, name, project=None):
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user