basic archives support

This commit is contained in:
Sandy Walsh 2014-06-13 18:07:40 +00:00
parent 296892a195
commit ae40dff06e
5 changed files with 64 additions and 23 deletions

View File

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

View File

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

View File

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

View File

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

View File

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