nailing down the layered implementation scheme

This commit is contained in:
Sandy Walsh 2014-06-06 12:05:08 -03:00
parent 94cb40b00c
commit 45564ce45d
7 changed files with 131 additions and 18 deletions

View File

@ -14,23 +14,64 @@
# limitations under the License.
import falcon
import simport
import v1_api
import v2_api
class V1TestImplementation(object):
def get_events(self, resp):
return []
class NotImplemented(Exception):
pass
versions = {1: v1_api.Schema,
2: v2_api.Schema}
def _load_implementations(impl_map, versions, config):
for version in versions:
target = config.get('v%d_impl' % version)
klass = simport.load(target)
impl_map[version] = klass()
enabled_versions = [1, 2]
api = falcon.API()
def _initialize(self, enabled_versions, implementation_map):
# The de facto set of supported versions.
versions = {1: v1_api.Schema,
2: v2_api.Schema}
routes = []
for version in enabled_version:
klass = versions[version]
routes.append(version, klass(api))
api = falcon.API()
routes = []
for version in enabled_version:
klass = versions[version]
impl = implementation_map.get(version)
if not impl:
raise NotImplemented("No implementation available for Quincy"
" version %d" % version)
routes.append(klass(api, impl))
# TODO(sandy): We need to create the /v1
# ...
# /vN
# resources here too.
if __name__ == '__main__':
# There may have been prior versions
# but they could be deprecated and dropped.
# Only the versions specified here define
# the currently supported StackTach.v3 API.
enabled_versions = [1, 2]
# The default implementation is internal and works with
# a fake/static set of data.
local_config = {'v1_impl': 'v1_impl.Impl',
'v2_impl': 'v2_impl.Impl'}
impl_map = {}
_load_implementations(impl_map, enabled_versions, local_config)
# TODO(sandy): Overlay the impl_map with the implementations
# specified in the config file.
# config = ...
# _load_implementations(impl_map, enabled_versions, config)
_initialize(enabled_versions, impl_map)

View File

@ -32,9 +32,9 @@ class Schema(object):
def _v(self):
return "/v%d" % self.version
def __init__(self, version, api):
def __init__(self, version, api, impl):
self.api = api
self.impl = Impl()
self.impl = impl
self.event_collection = EventCollection(impl)
self.event_item = EventItem(impl)
self.version = version

33
quincy/v1_impl.py Normal file
View File

@ -0,0 +1,33 @@
# Copyright (c) 2014 Dark Secret Software 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 datetime
import uuid
class Event(object):
def __init__(self, request_id, name):
self.when = datetime.datetime.utcnow()
self.name = name
self.request_id = request_id
self.message_id = str(uuid.uuid4())
class Impl(object):
def get_events(self, resp):
rid = str(uuid.uuid4())
return [Event(rid, "scheduler.run_instance.start"),
Event(rid, "scheduler.run_instanace.scheduled"),
Event(rid, "scheduler.run_instance.end")]

20
quincy/v2_api.py Normal file
View File

@ -0,0 +1,20 @@
# Copyright (c) 2014 Dark Secret Software 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 v1_api
class Schema(v1_api.Schema):
pass

20
quincy/v2_impl.py Normal file
View File

@ -0,0 +1,20 @@
# Copyright (c) 2014 Dark Secret Software 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 v1_impl
class Impl(v1_impl.Impl):
pass

View File

@ -1,2 +1,3 @@
falcon
json
simport >= 0.0.dev0

View File

@ -3,13 +3,11 @@ envlist = py26,py27
[testenv]
deps =
falcon
json
coverage
nose
mock
notigen
notification_utils
pyrax
python-dateutil
simport
commands = nosetests -d -v --with-coverage --cover-inclusive --cover-package shoebox []
commands = nosetests -d -v --with-coverage --cover-inclusive --cover-package quincy []