From 8e72773c65f5cabbf34b3ecb69048c4d6ceb42f6 Mon Sep 17 00:00:00 2001 From: Kurt Griffiths Date: Tue, 26 Feb 2013 17:12:26 -0500 Subject: [PATCH] feat(Kernel): Demonstrate wiring up endpoints Add just enough code to show how the kernel might use endpoint controllers as the uniform interface between transport and storage drivers. Change-Id: Id359986a4e45850266e64b06dae4544b52c8f93c Implements: blueprint endpoints --- marconi/common/kernel.py | 33 +++++++------- marconi/storage/__init__.py | 2 + marconi/storage/driver_base.py | 36 +++++++++++++++ marconi/storage/reference/__init__.py | 2 + marconi/storage/reference/driver.py | 39 ++++++++++++++++ .../{wsgi_memory.conf => wsgi_reference.conf} | 2 +- marconi/tests/test_simple.py | 13 ++++-- marconi/transport/__init__.py | 2 + marconi/transport/driver_base.py | 30 +++++++++++++ marconi/transport/wsgi/__init__.py | 4 +- marconi/transport/wsgi/driver.py | 44 +++++++++++++++++++ tox.ini | 2 +- 12 files changed, 187 insertions(+), 22 deletions(-) create mode 100644 marconi/storage/driver_base.py create mode 100644 marconi/storage/reference/driver.py rename marconi/tests/etc/{wsgi_memory.conf => wsgi_reference.conf} (76%) create mode 100644 marconi/transport/driver_base.py create mode 100644 marconi/transport/wsgi/driver.py diff --git a/marconi/common/kernel.py b/marconi/common/kernel.py index a8359b4c8..7ca5be7b4 100644 --- a/marconi/common/kernel.py +++ b/marconi/common/kernel.py @@ -1,18 +1,19 @@ # vim: tabstop=4 shiftwidth=4 softtabstop=4 -# Copyright 2012 Rackspace, Inc. +# Copyright (c) 2013 Rackspace, 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 +# 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 +# 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. +# 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. """Defines the Marconi Kernel @@ -24,19 +25,21 @@ lifetimes. from ConfigParser import SafeConfigParser import marconi.transport.wsgi as wsgi -import marconi.storage.mongodb as mongodb +import marconi.storage.reference as reference class Kernel(object): def __init__(self, config_file): - # @todo error handling + # TODO(kgriffs) Error handling cfg = SafeConfigParser() cfg.read(config_file) - # @todo Determine driver types from cfg - self.storage = mongodb.Driver(cfg) - self.transport = wsgi.Driver(self.storage, cfg) + # TODO(kgriffs) Determine driver types from cfg + self.storage = reference.Driver(cfg) + self.transport = wsgi.Driver(cfg, self.storage.queue_controller, + self.storage.message_controller, + self.storage.claim_controller) def run(self): self.transport.listen() diff --git a/marconi/storage/__init__.py b/marconi/storage/__init__.py index d19148d79..7aea1910e 100644 --- a/marconi/storage/__init__.py +++ b/marconi/storage/__init__.py @@ -1 +1,3 @@ """ Marconi Storage Drivers """ + +from .driver_base import DriverBase # NOQA diff --git a/marconi/storage/driver_base.py b/marconi/storage/driver_base.py new file mode 100644 index 000000000..e2034343a --- /dev/null +++ b/marconi/storage/driver_base.py @@ -0,0 +1,36 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2013 Rackspace, 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. + +"""Implements the DriverBase abstract class for Marconi storage drivers.""" + +from abc import ABCMeta, abstractproperty + + +class DriverBase: + __metaclass__ = ABCMeta + + @abstractproperty + def queue_controller(self): + pass + + @abstractproperty + def message_controller(self): + pass + + @abstractproperty + def claim_controller(self): + pass diff --git a/marconi/storage/reference/__init__.py b/marconi/storage/reference/__init__.py index 427509af5..e28074b81 100644 --- a/marconi/storage/reference/__init__.py +++ b/marconi/storage/reference/__init__.py @@ -3,3 +3,5 @@ Useful for automated testing and for prototyping storage driver concepts. """ + +from .driver import Driver # NOQA diff --git a/marconi/storage/reference/driver.py b/marconi/storage/reference/driver.py new file mode 100644 index 000000000..c8fa3db4a --- /dev/null +++ b/marconi/storage/reference/driver.py @@ -0,0 +1,39 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2013 Rackspace, 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. + +import marconi.storage as storage + + +class Driver(storage.DriverBase): + + def __init__(self, cfg): + self._cfg = cfg + + @property + def queue_controller(self): + # TODO(kgriffs): Create base classes for controllers in common/ + return None + + @property + def message_controller(self): + # TODO(kgriffs): Create base classes for controllers in common/ + return None + + @property + def claim_controller(self): + # TODO(kgriffs): Create base classes for controllers in common/ + return None diff --git a/marconi/tests/etc/wsgi_memory.conf b/marconi/tests/etc/wsgi_reference.conf similarity index 76% rename from marconi/tests/etc/wsgi_memory.conf rename to marconi/tests/etc/wsgi_reference.conf index 4cceb283c..a2aaf64e6 100644 --- a/marconi/tests/etc/wsgi_memory.conf +++ b/marconi/tests/etc/wsgi_reference.conf @@ -1,6 +1,6 @@ [drivers] transport = wsgi -storage = memory +storage = reference [drivers:transport:wsgi] port = 8888 diff --git a/marconi/tests/test_simple.py b/marconi/tests/test_simple.py index 19826ecd1..a525f9ae0 100644 --- a/marconi/tests/test_simple.py +++ b/marconi/tests/test_simple.py @@ -1,4 +1,5 @@ -#!/usr/bin/env python +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + # Copyright 2012 Rackspace, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); you may @@ -13,12 +14,16 @@ # License for the specific language governing permissions and limitations # under the License. -import fixtures -import testtools +import marconi.tests.util as util +import marconi.common -class TestSimple(testtools.TestCase): +class TestSimple(util.TestSuite): def test_simple(self): """Doesn't really test much""" + conf_file = self.conf_path('wsgi_reference.conf') + kernel = marconi.common.Kernel(conf_file) + transport = kernel.transport + wsgi_app = transport.app self.assertTrue(True) diff --git a/marconi/transport/__init__.py b/marconi/transport/__init__.py index 4d46dfd22..5fd00c9cf 100644 --- a/marconi/transport/__init__.py +++ b/marconi/transport/__init__.py @@ -1 +1,3 @@ """ Marconi Transport Modules """ + +from .driver_base import DriverBase # NOQA diff --git a/marconi/transport/driver_base.py b/marconi/transport/driver_base.py new file mode 100644 index 000000000..abf7000cf --- /dev/null +++ b/marconi/transport/driver_base.py @@ -0,0 +1,30 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2013 Rackspace, 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. + +"""Implements the DriverBase abstract class for Marconi transport drivers.""" + +from abc import ABCMeta, abstractmethod + + +class DriverBase: + __metaclass__ = ABCMeta + + @abstractmethod + def listen(): + # TODO(kgriffs): If this is all there is to DriverBase, do we + # even need it? + pass diff --git a/marconi/transport/wsgi/__init__.py b/marconi/transport/wsgi/__init__.py index 94e21f255..348eb98ba 100644 --- a/marconi/transport/wsgi/__init__.py +++ b/marconi/transport/wsgi/__init__.py @@ -1 +1,3 @@ -""" WSGI Transport """ +""" WSGI Transport Driver""" + +from .driver import Driver # NOQA diff --git a/marconi/transport/wsgi/driver.py b/marconi/transport/wsgi/driver.py new file mode 100644 index 000000000..f609446b4 --- /dev/null +++ b/marconi/transport/wsgi/driver.py @@ -0,0 +1,44 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2013 Rackspace, 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. + +import marconi.transport as transport + + +class Driver(transport.DriverBase): + + def __init__(self, cfg, queue_controller, message_controller, + claim_controller): + + self._cfg = cfg + + # E.g.: + # + # self._queue_controller.create(tenant_id, queue_name) + # self._queue_controller.set_metadata(tenant_id, queue_name, metadata) + # + self._queue_controller = queue_controller + self._message_controller = message_controller + self._claim_controller = claim_controller + + # self.app = api = falcon.API() + + def listen(self): + pass + + def app(self, env, start_response, exc_info=None): + """This will be replace by falcon.API()""" + pass diff --git a/tox.ini b/tox.ini index 213044795..b1ea689d5 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,5 @@ [tox] -envlist = py26,py27,pep8 +envlist = py27,pep8 [testenv] setenv = VIRTUAL_ENV={envdir}