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
This commit is contained in:
Kurt Griffiths 2013-02-26 17:12:26 -05:00 committed by Flaper Fesp
parent 0651435b88
commit 8e72773c65
12 changed files with 187 additions and 22 deletions

View File

@ -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()

View File

@ -1 +1,3 @@
""" Marconi Storage Drivers """
from .driver_base import DriverBase # NOQA

View File

@ -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

View File

@ -3,3 +3,5 @@
Useful for automated testing and for prototyping storage driver concepts.
"""
from .driver import Driver # NOQA

View File

@ -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

View File

@ -1,6 +1,6 @@
[drivers]
transport = wsgi
storage = memory
storage = reference
[drivers:transport:wsgi]
port = 8888

View File

@ -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)

View File

@ -1 +1,3 @@
""" Marconi Transport Modules """
from .driver_base import DriverBase # NOQA

View File

@ -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

View File

@ -1 +1,3 @@
""" WSGI Transport """
""" WSGI Transport Driver"""
from .driver import Driver # NOQA

View File

@ -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

View File

@ -1,5 +1,5 @@
[tox]
envlist = py26,py27,pep8
envlist = py27,pep8
[testenv]
setenv = VIRTUAL_ENV={envdir}