Permalink
Browse files

feat(v1.1): Plumb v1.1 API in the WSGI transport

This patch creates a copy of the v1.0 API as a starting point for
implementing the v1.1 API. The way that the "admin_mode" config option was
implemented was changed, in order to simplify the grafting of the two API
versions into a single driver. When the mode was implemented via inheritance,
grafting the two API versions required some ugly hacks.

Partially-Implements: blueprint api-v1.1
Change-Id: I0e753315e3171bb5c23a57b8fb3826d08bfd5f26
  • Loading branch information...
1 parent de4aa6b commit be4b3f0b662ffa85a07f44dcb6ef6c108c404ca8 @kgriffs kgriffs committed Feb 17, 2014
@@ -70,8 +70,6 @@ def __init__(self, conf):
self.driver_conf = self.conf[_DRIVER_GROUP]
log.setup('marconi')
- mode = 'admin' if conf.admin_mode else 'public'
- self._transport_type = 'marconi.queues.{0}.transport'.format(mode)
@decorators.lazy_property(write=False)
def storage(self):
@@ -110,9 +108,15 @@ def transport(self):
transport_name = self.driver_conf.transport
LOG.debug(_(u'Loading transport driver: %s'), transport_name)
- args = [self.conf, self.storage, self.cache, self.control]
+ args = [
+ self.conf,
+ self.storage,
+ self.cache,
+ self.control,
+ ]
+
try:
- mgr = driver.DriverManager(self._transport_type,
+ mgr = driver.DriverManager('marconi.queues.transport',
transport_name,
invoke_on_load=True,
invoke_args=args)
@@ -16,4 +16,4 @@
from marconi.queues.transport.wsgi import driver
# Hoist into package namespace
-Driver = driver.DriverBase
+Driver = driver.Driver
@@ -1,34 +0,0 @@
-# Copyright (c) 2013 Rackspace Hosting, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""marconi-queues (admin): interface for managing partitions."""
-
-from marconi.common.transport.wsgi import health
-from marconi.queues.transport.wsgi.public import driver as public_driver
-from marconi.queues.transport.wsgi import shards
-
-
-class Driver(public_driver.Driver):
-
- @property
- def bridge(self):
- shards_controller = self._control.shards_controller
- return super(Driver, self).bridge + [
- ('/shards',
- shards.Listing(shards_controller)),
- ('/shards/{shard}',
- shards.Resource(shards_controller)),
- ('/health',
- health.Resource(self._storage))
- ]
@@ -13,24 +13,23 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-import abc
import functools
import itertools
from wsgiref import simple_server
import falcon
from oslo.config import cfg
-import six
from marconi.common import decorators
-from marconi.common.transport import version
from marconi.common.transport.wsgi import helpers
from marconi.common import utils
from marconi.openstack.common.gettextutils import _
import marconi.openstack.common.log as logging
from marconi.queues import transport
from marconi.queues.transport import auth
from marconi.queues.transport import validation
+from marconi.queues.transport.wsgi import v1_0
+from marconi.queues.transport.wsgi import v1_1
_WSGI_OPTIONS = [
cfg.StrOpt('bind', default='127.0.0.1',
@@ -49,11 +48,10 @@ def _config_options():
return itertools.chain(utils.options_iter(_WSGI_OPTIONS, _WSGI_GROUP))
-@six.add_metaclass(abc.ABCMeta)
-class DriverBase(transport.DriverBase):
+class Driver(transport.DriverBase):
def __init__(self, conf, storage, cache, control):
- super(DriverBase, self).__init__(conf, storage, cache, control)
+ super(Driver, self).__init__(conf, storage, cache, control)
self._conf.register_opts(_WSGI_OPTIONS, group=_WSGI_GROUP)
self._wsgi_conf = self._conf[_WSGI_GROUP]
@@ -77,10 +75,23 @@ def before_hooks(self):
def _init_routes(self):
"""Initialize hooks and URI routes to resources."""
+
+ catalog = [
+ ('/v1', v1_0.public_endpoints(self)),
+ ('/v1.1', v1_1.public_endpoints(self)),
+ ]
+
+ if self._conf.admin_mode:
+ catalog.extend([
+ ('/v1', v1_0.private_endpoints(self)),
+ ('/v1.1', v1_1.private_endpoints(self)),
+ ])
+
self.app = falcon.API(before=self.before_hooks)
- version_path = version.path()
- for route, resource in self.bridge:
- self.app.add_route(version_path + route, resource)
+
+ for version_path, endpoints in catalog:
+ for route, resource in endpoints:
+ self.app.add_route(version_path + route, resource)
def _init_middleware(self):
"""Initialize WSGI middlewarez."""
@@ -90,17 +101,6 @@ def _init_middleware(self):
strategy = auth.strategy(self._conf.auth_strategy)
self.app = strategy.install(self.app, self._conf)
- @abc.abstractproperty
- def bridge(self):
- """Constructs a list of route/responder pairs that can be used to
- establish the functionality of this driver.
-
- Note: the routes should be unversioned.
-
- :rtype: [(str, falcon-compatible responser)]
- """
- raise NotImplementedError
-
def listen(self):
"""Self-host using 'bind' and 'port' from the WSGI config group."""
@@ -1,76 +0,0 @@
-# Copyright (c) 2013 Rackspace Hosting, Inc.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
-# implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-"""marconi-queues public interface.
-
-Handles all the routes for queuing, messaging, and claiming.
-"""
-
-from marconi.common.transport.wsgi import health
-from marconi.queues.transport.wsgi import claims
-from marconi.queues.transport.wsgi import driver
-from marconi.queues.transport.wsgi import messages
-from marconi.queues.transport.wsgi import metadata
-from marconi.queues.transport.wsgi import queues
-from marconi.queues.transport.wsgi import stats
-from marconi.queues.transport.wsgi import v1
-
-
-class Driver(driver.DriverBase):
-
- @property
- def bridge(self):
- queue_controller = self._storage.queue_controller
- message_controller = self._storage.message_controller
- claim_controller = self._storage.claim_controller
- return [
- # Home
- ('/',
- v1.Resource()),
-
- # Queues Endpoints
- ('/queues',
- queues.CollectionResource(self._validate,
- queue_controller)),
- ('/queues/{queue_name}',
- queues.ItemResource(queue_controller,
- message_controller)),
- ('/queues/{queue_name}/stats',
- stats.Resource(queue_controller)),
- ('/queues/{queue_name}/metadata',
- metadata.Resource(self._wsgi_conf, self._validate,
- queue_controller)),
-
- # Messages Endpoints
- ('/queues/{queue_name}/messages',
- messages.CollectionResource(self._wsgi_conf,
- self._validate,
- message_controller)),
- ('/queues/{queue_name}/messages/{message_id}',
- messages.ItemResource(message_controller)),
-
- # Claims Endpoints
- ('/queues/{queue_name}/claims',
- claims.CollectionResource(self._wsgi_conf,
- self._validate,
- claim_controller)),
- ('/queues/{queue_name}/claims/{claim_id}',
- claims.ItemResource(self._wsgi_conf,
- self._validate,
- claim_controller)),
-
- # Health
- ('/health',
- health.Resource(self._storage))
- ]
@@ -0,0 +1,66 @@
+from marconi.queues.transport.wsgi.v1_0 import claims
+from marconi.queues.transport.wsgi.v1_0 import health
+from marconi.queues.transport.wsgi.v1_0 import homedoc
+from marconi.queues.transport.wsgi.v1_0 import messages
+from marconi.queues.transport.wsgi.v1_0 import metadata
+from marconi.queues.transport.wsgi.v1_0 import queues
+from marconi.queues.transport.wsgi.v1_0 import shards
+from marconi.queues.transport.wsgi.v1_0 import stats
+
+
+def public_endpoints(driver):
+ queue_controller = driver._storage.queue_controller
+ message_controller = driver._storage.message_controller
+ claim_controller = driver._storage.claim_controller
+
+ return [
+ # Home
+ ('/',
+ homedoc.Resource()),
+
+ # Queues Endpoints
+ ('/queues',
+ queues.CollectionResource(driver._validate,
+ queue_controller)),
+ ('/queues/{queue_name}',
+ queues.ItemResource(queue_controller,
+ message_controller)),
+ ('/queues/{queue_name}/stats',
+ stats.Resource(queue_controller)),
+ ('/queues/{queue_name}/metadata',
+ metadata.Resource(driver._wsgi_conf, driver._validate,
+ queue_controller)),
+
+ # Messages Endpoints
+ ('/queues/{queue_name}/messages',
+ messages.CollectionResource(driver._wsgi_conf,
+ driver._validate,
+ message_controller)),
+ ('/queues/{queue_name}/messages/{message_id}',
+ messages.ItemResource(message_controller)),
+
+ # Claims Endpoints
+ ('/queues/{queue_name}/claims',
+ claims.CollectionResource(driver._wsgi_conf,
+ driver._validate,
+ claim_controller)),
+ ('/queues/{queue_name}/claims/{claim_id}',
+ claims.ItemResource(driver._wsgi_conf,
+ driver._validate,
+ claim_controller)),
+
+ # Health
+ ('/health',
+ health.Resource(driver._storage))
+ ]
+
+
+def private_endpoints(driver):
+ shards_controller = driver._control.shards_controller
+
+ return [
+ ('/shards',
+ shards.Listing(shards_controller)),
+ ('/shards/{shard}',
+ shards.Resource(shards_controller)),
+ ]
@@ -0,0 +1,66 @@
+from marconi.queues.transport.wsgi.v1_1 import claims
+from marconi.queues.transport.wsgi.v1_1 import health
+from marconi.queues.transport.wsgi.v1_1 import homedoc
+from marconi.queues.transport.wsgi.v1_1 import messages
+from marconi.queues.transport.wsgi.v1_1 import metadata
+from marconi.queues.transport.wsgi.v1_1 import queues
+from marconi.queues.transport.wsgi.v1_1 import shards
+from marconi.queues.transport.wsgi.v1_1 import stats
+
+
+def public_endpoints(driver):
+ queue_controller = driver._storage.queue_controller
+ message_controller = driver._storage.message_controller
+ claim_controller = driver._storage.claim_controller
+
+ return [
+ # Home
+ ('/',
+ homedoc.Resource()),
+
+ # Queues Endpoints
+ ('/queues',
+ queues.CollectionResource(driver._validate,
+ queue_controller)),
+ ('/queues/{queue_name}',
+ queues.ItemResource(queue_controller,
+ message_controller)),
+ ('/queues/{queue_name}/stats',
+ stats.Resource(queue_controller)),
+ ('/queues/{queue_name}/metadata',
+ metadata.Resource(driver._wsgi_conf, driver._validate,
+ queue_controller)),
+
+ # Messages Endpoints
+ ('/queues/{queue_name}/messages',
+ messages.CollectionResource(driver._wsgi_conf,
+ driver._validate,
+ message_controller)),
+ ('/queues/{queue_name}/messages/{message_id}',
+ messages.ItemResource(message_controller)),
+
+ # Claims Endpoints
+ ('/queues/{queue_name}/claims',
+ claims.CollectionResource(driver._wsgi_conf,
+ driver._validate,
+ claim_controller)),
+ ('/queues/{queue_name}/claims/{claim_id}',
+ claims.ItemResource(driver._wsgi_conf,
+ driver._validate,
+ claim_controller)),
+
+ # Health
+ ('/health',
+ health.Resource(driver._storage))
+ ]
+
+
+def private_endpoints(driver):
+ shards_controller = driver._control.shards_controller
+
+ return [
+ ('/shards',
+ shards.Listing(shards_controller)),
+ ('/shards/{shard}',
+ shards.Resource(shards_controller)),
+ ]
Oops, something went wrong.

0 comments on commit be4b3f0

Please sign in to comment.