stream resource w.i.p.

This commit is contained in:
Sandy Walsh 2014-09-02 20:16:11 -03:00
parent ae40dff06e
commit f176d68ad8
2 changed files with 41 additions and 23 deletions

View File

@ -18,14 +18,30 @@ import json
import common
class EventCollection(common.FalconBase):
class StreamCollection(common.FalconBase):
# HTTP Operations on a stream
# GET - list stream with qualifiers
# DELETE - mark stream for deletion
# POST - move stream to READY or reset error count
# GET Qualifiers:
# older_than
# younger_than
# state
# trigger_name
# id
# distinquishing_traits - find stream by dtrait values.
#
# Actions on a Stream:
# details - get full details on stream (including distriquishing traits)
# events - get the events collected for this stream.
def on_get(self, req, resp):
events = self.impl.get_events(resp)
dicts = [event.to_dict() for event in events]
streams = self.impl.get_streams(resp)
dicts = [stream.to_dict() for stream in streams]
resp.body = json.dumps(dicts)
class EventItem(common.FalconBase):
class StreamItem(common.FalconBase):
pass
@ -38,8 +54,10 @@ class Schema(object):
self.impl = impl
self.version = version
self.event_collection = EventCollection(impl)
self.event_item = EventItem(impl)
self.stream_collection = StreamCollection(impl)
self.stream_item = StreamItem(impl)
self.api.add_route('%s/events' % self._v(), self.event_collection)
self.api.add_route('%s/events/{event_id}' % self._v(), self.event_item)
self.api.add_route('%s/streams' % self._v(),
self.stream_collection)
self.api.add_route('%s/streams/{stream_id}' % self._v(),
self.stream_item)

View File

@ -17,23 +17,23 @@ 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 Stream(object):
def __init__(self, stream_id, trigger_name, state):
self.last_updated = datetime.datetime.utcnow()
self.stream_id = stream_id
self.trigger_name = trigger_name
self.state = state
def to_dict(self):
return {"when": str(self.when),
"name": self.name,
"request_id": self.request_id,
"message_id": self.message_id}
return {"last_updated": str(self.last_updated),
"stream_id": self.stream_id,
"trigger_name": self.trigger_name,
"state": self.state}
class Impl(object):
def get_events(self, resp):
rid = str(uuid.uuid4())
return [Event(rid, "scheduler.run_instance.start"),
Event(rid, "scheduler.run_instance.scheduled"),
Event(rid, "scheduler.run_instance.end")]
def get_stream(self, resp):
sid = str(uuid.uuid4())
return [Stream(sid, "EOD-Exists", "Collecting")
Stream(sid, "EOD-Exists", "Error")
Stream(sid, "Request-ID", "Ready")]