support for /streams
This commit is contained in:
parent
2692572fcd
commit
6cce25456c
@ -19,61 +19,78 @@ import base
|
|||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
|
|
||||||
|
|
||||||
class Events(object):
|
class Streams(object):
|
||||||
"""usage:
|
"""usage:
|
||||||
klugman.py events [options]
|
klugman.py streams [options]
|
||||||
|
|
||||||
options:
|
options:
|
||||||
-i, --id <id>
|
--id <id>
|
||||||
filter by event ID
|
get stream with id
|
||||||
-r, --request_id <request_id>
|
--state <state>
|
||||||
filter by Request ID
|
return streams in state
|
||||||
-s, --start <start_datetime>
|
--older_than <datetime>
|
||||||
starting datetime range
|
list streams older than datetime
|
||||||
-e, --end <end_datetime>
|
--younger_than <datetime>
|
||||||
ending datetime range
|
list streams younger than datetime
|
||||||
|
--trigger_name <name>
|
||||||
|
list streams with given trigger definition
|
||||||
|
--distinquishing_traits <dtraits>
|
||||||
|
list stream with specific distriquishing traits
|
||||||
|
|
||||||
notes:
|
Stream states:
|
||||||
-r isn't needed if -i is supplied.
|
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):
|
def cmdline(self, version, cmdline):
|
||||||
arguments = docopt(Events.__doc__, argv=cmdline)
|
arguments = docopt(Streams.__doc__, argv=cmdline)
|
||||||
if version.base_args['--debug']:
|
if version.base_args['--debug']:
|
||||||
print arguments
|
print arguments
|
||||||
|
|
||||||
response = self.do_events(version, arguments)
|
response = self.do_streams(version, arguments)
|
||||||
# Handle cmdline output here, not in do_foo()
|
# Handle cmdline output here, not in do_foo()
|
||||||
raw_rows = response.json()
|
raw_rows = response.json()
|
||||||
|
|
||||||
# TODO(sandy): This should come from the server-issued
|
# TODO(sandy): This should come from the server-issued
|
||||||
# schema at some point.
|
# 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)
|
base.dump_response(keys, raw_rows)
|
||||||
|
|
||||||
def do_events(self, version, arguments):
|
def do_streams(self, version, arguments):
|
||||||
eid = arguments.get('--id')
|
sid = arguments.get('--id')
|
||||||
rid = arguments.get('--request_id')
|
state = arguments.get('--state')
|
||||||
start = arguments.get('--start')
|
older = arguments.get('--older_than')
|
||||||
end = arguments.get('--end')
|
younger = arguments.get('--younger_than')
|
||||||
|
trigger = arguments.get('--trigger_name')
|
||||||
|
traits = arguments.get('--distinquishing_traits')
|
||||||
|
|
||||||
cmd = "events"
|
cmd = "streams"
|
||||||
if eid:
|
if sid:
|
||||||
cmd = "events/%d" % eid
|
cmd = "streams/%d" % sid
|
||||||
params = base.remove_empty({'request_id': rid,
|
params = base.remove_empty({'state': state,
|
||||||
'start_ts': start,
|
'older_than': older,
|
||||||
'end_ts': end})
|
'younger_than': younger,
|
||||||
|
'trigger_name': trigger,
|
||||||
|
'distinquishing_traits': traits})
|
||||||
|
|
||||||
return base.get(version.base_url, cmd, params)
|
return base.get(version.base_url, cmd, params)
|
||||||
|
|
||||||
|
|
||||||
class V1(base.Impl):
|
class V1(base.Impl):
|
||||||
"""usage:
|
"""usage:
|
||||||
klugman.py events [options]
|
klugman.py streams [options]
|
||||||
|
|
||||||
-h, --help show command options
|
-h, --help show command options
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, base_url, base_args):
|
def __init__(self, base_url, base_args):
|
||||||
cmds = {'events': Events()}
|
cmds = {'streams': Streams()}
|
||||||
super(V1, self).__init__(base_url, base_args, cmds, V1.__doc__)
|
super(V1, self).__init__(base_url, base_args, cmds, V1.__doc__)
|
||||||
|
@ -60,13 +60,13 @@ class V2(base.Impl):
|
|||||||
# which basically says "anything is acceptable".
|
# which basically says "anything is acceptable".
|
||||||
# We will be more strict in the actual command handler.
|
# We will be more strict in the actual command handler.
|
||||||
"""usage:
|
"""usage:
|
||||||
klugman.py events [options]
|
klugman.py streams [options]
|
||||||
klugman.py archives [<args>...] [options]
|
klugman.py archives [<args>...] [options]
|
||||||
|
|
||||||
-h, --help show command options
|
-h, --help show command options
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, base_url, base_args):
|
def __init__(self, base_url, base_args):
|
||||||
cmds = {'events': v1.Events(),
|
cmds = {'streams': v1.Streams(),
|
||||||
'archives': Archives()}
|
'archives': Archives()}
|
||||||
super(V2, self).__init__(base_url, base_args, cmds, V2.__doc__)
|
super(V2, self).__init__(base_url, base_args, cmds, V2.__doc__)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user