diff --git a/quincy/api.py b/quincy/api.py index debc0d3..d9db894 100644 --- a/quincy/api.py +++ b/quincy/api.py @@ -16,7 +16,6 @@ import falcon import simport - import v1_api import v2_api @@ -55,25 +54,23 @@ def _initialize(enabled_versions, implementation_map): return api -if True: # __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] +# 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'} +# 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) +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) - - api = _initialize(enabled_versions, impl_map) +# TODO(sandy): Overlay the impl_map with the implementations +# specified in the config file. +# config = ... +# _load_implementations(impl_map, enabled_versions, config) +api = _initialize(enabled_versions, impl_map) diff --git a/quincy/v1_api.py b/quincy/v1_api.py index dd7b9df..e925d99 100644 --- a/quincy/v1_api.py +++ b/quincy/v1_api.py @@ -36,9 +36,10 @@ class Schema(object): def __init__(self, version, api, impl): self.api = api self.impl = impl + self.version = version + self.event_collection = EventCollection(impl) self.event_item = EventItem(impl) - self.version = version self.api.add_route('%s/events' % self._v(), self.event_collection) self.api.add_route('%s/events/{event_id}' % self._v(), self.event_item) diff --git a/quincy/v1_impl.py b/quincy/v1_impl.py index 54021f5..f0097ad 100644 --- a/quincy/v1_impl.py +++ b/quincy/v1_impl.py @@ -35,5 +35,5 @@ 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.scheduled"), Event(rid, "scheduler.run_instance.end")] diff --git a/quincy/v2_api.py b/quincy/v2_api.py index 0b25c67..4bd2fb6 100644 --- a/quincy/v2_api.py +++ b/quincy/v2_api.py @@ -13,8 +13,30 @@ # See the License for the specific language governing permissions and # limitations under the License. +import json + +import common import v1_api +class ArchiveCollection(common.FalconBase): + def on_get(self, req, resp): + archives = self.impl.get_archives(resp) + dicts = [archive.to_dict() for archive in archives] + resp.body = json.dumps(dicts) + + +class ArchiveItem(common.FalconBase): + def on_get(self, req, resp): + return "{}" + + class Schema(v1_api.Schema): - pass + def __init__(self, version, api, impl): + super(Schema, self).__init__(version, api, impl) + self.archive_collection = ArchiveCollection(impl) + self.archive_item = ArchiveItem(impl) + + self.api.add_route('%s/archives' % self._v(), self.archive_collection) + self.api.add_route('%s/archives/{archive_id}' % self._v(), + self.archive_item) diff --git a/quincy/v2_impl.py b/quincy/v2_impl.py index 206f00e..93e5428 100644 --- a/quincy/v2_impl.py +++ b/quincy/v2_impl.py @@ -13,8 +13,29 @@ # See the License for the specific language governing permissions and # limitations under the License. +import datetime +import uuid + import v1_impl +class Archive(object): + def __init__(self, aid, filename): + self.aid = aid + self.filename = filename + + def to_dict(self): + return {"id": str(self.aid), + "filename": self.filename} + + class Impl(v1_impl.Impl): - pass + def get_archives(self, resp): + filename_template = "events_%Y_%m_%d_%X_%f.dat" + now = datetime.datetime.utcnow() + ret = [] + for _ in range(4): + ret.append(Archive(str(uuid.uuid4()), + now.strftime(filename_template))) + now += datetime.timedelta(hours = 1) + return ret