support for /streams

This commit is contained in:
Sandy Walsh 2014-09-04 15:40:15 +00:00
parent 2692572fcd
commit 6cce25456c
2 changed files with 47 additions and 30 deletions

View File

@ -19,61 +19,78 @@ import base
from docopt import docopt
class Events(object):
class Streams(object):
"""usage:
klugman.py events [options]
klugman.py streams [options]
options:
-i, --id <id>
filter by event ID
-r, --request_id <request_id>
filter by Request ID
-s, --start <start_datetime>
starting datetime range
-e, --end <end_datetime>
ending datetime range
--id <id>
get stream with id
--state <state>
return streams in state
--older_than <datetime>
list streams older than datetime
--younger_than <datetime>
list streams younger than datetime
--trigger_name <name>
list streams with given trigger definition
--distinquishing_traits <dtraits>
list stream with specific distriquishing traits
notes:
-r isn't needed if -i is supplied.
Stream states:
collecting - collecting events
ready - ready for processing
triggered - being processed
processed - processing completed
error - pipeline processing failed
commit_error - pipeline result commit failed
Distinguishing trait format:
"trait:value;trait:value;..."
"""
def cmdline(self, version, cmdline):
arguments = docopt(Events.__doc__, argv=cmdline)
arguments = docopt(Streams.__doc__, argv=cmdline)
if version.base_args['--debug']:
print arguments
response = self.do_events(version, arguments)
response = self.do_streams(version, arguments)
# Handle cmdline output here, not in do_foo()
raw_rows = response.json()
# TODO(sandy): This should come from the server-issued
# schema at some point.
keys = ['message_id', 'request_id', 'when', 'name']
keys = ['stream_id', 'state', 'last_updated', 'trigger_name',
'distinquishing_traits']
base.dump_response(keys, raw_rows)
def do_events(self, version, arguments):
eid = arguments.get('--id')
rid = arguments.get('--request_id')
start = arguments.get('--start')
end = arguments.get('--end')
def do_streams(self, version, arguments):
sid = arguments.get('--id')
state = arguments.get('--state')
older = arguments.get('--older_than')
younger = arguments.get('--younger_than')
trigger = arguments.get('--trigger_name')
traits = arguments.get('--distinquishing_traits')
cmd = "events"
if eid:
cmd = "events/%d" % eid
params = base.remove_empty({'request_id': rid,
'start_ts': start,
'end_ts': end})
cmd = "streams"
if sid:
cmd = "streams/%d" % sid
params = base.remove_empty({'state': state,
'older_than': older,
'younger_than': younger,
'trigger_name': trigger,
'distinquishing_traits': traits})
return base.get(version.base_url, cmd, params)
class V1(base.Impl):
"""usage:
klugman.py events [options]
klugman.py streams [options]
-h, --help show command options
"""
def __init__(self, base_url, base_args):
cmds = {'events': Events()}
cmds = {'streams': Streams()}
super(V1, self).__init__(base_url, base_args, cmds, V1.__doc__)

View File

@ -60,13 +60,13 @@ class V2(base.Impl):
# which basically says "anything is acceptable".
# We will be more strict in the actual command handler.
"""usage:
klugman.py events [options]
klugman.py streams [options]
klugman.py archives [<args>...] [options]
-h, --help show command options
"""
def __init__(self, base_url, base_args):
cmds = {'events': v1.Events(),
cmds = {'streams': v1.Streams(),
'archives': Archives()}
super(V2, self).__init__(base_url, base_args, cmds, V2.__doc__)