def do_off(self, line): """switches the selected pods off""" tokens = line.split(' ') if line else ['*'] for token in tokens: def _query(zk): return fire(zk, token, 'control/off') run(proxy, _query)
def do_reset(self, line): """fully resets the selected pods without impacting their sub-process""" tokens = line.split(' ') if line else ['*'] for token in tokens: def _query(zk): return fire(zk, token, 'reset') run(proxy, _query)
def do_grep(self, line): """displays a quick summary for the selected pods""" tokens = line.split(' ') if line else ['*'] for token in tokens: def _query(zk): out = {} responses = fire(zk, token, 'info') for pod, (_, hints, code) in responses.items(): if code == 200: out[pod] = '[%s / %s] @ %s (%s)' % \ (hints['state'], hints['process'], hints['node'], hints['public']) return len(responses), out total, js = run(proxy, _query) if not total: logger.info('\n<%s> no pods found' % token) else: pct = (len(js) * 100) / total unrolled = [ '%s %s' % (k, js[k]) for k in sorted(js.keys()) ] logger.info( '\n<%s> %d%% replies (%d pods total) ->\n\n- %s\n' % (token, pct, total, '\n- '.join(unrolled)))
def body(self, args, proxy): def _query(zk): responses = fire(zk, '*', 'info') return {key: hints['process'] for key, (_, hints, code) in responses.items() if code == 200} js = run(proxy, _query) if not js: logger.info('no pods detected (make sure you point to the right zookeeper)') else: running = [pod for pod, state in js.items() if state == 'running'] pct = int((100 * len(running)) / len(js)) logger.info('%d pods total, %d%% running ->\n - %s' % (len(js), pct, '\n - '.join(sorted(running))))
def body(self, args, proxy): port = str(args.port[0]) for cluster in args.clusters: def _query(zk): responses = fire(zk, cluster, 'info') return {key: '%d\t\t%s' % (hints['ports'][port], hints['public']) for key, (_, hints, code) in responses.items() if code == 200 and port in hints['ports']} js = run(proxy, _query) if js: unrolled = ['%s\t\t%s' % (ip, node) for node, ip in js.items()] logger.info('%s (%d pods exposing %s) ->\n - %s' % (cluster, len(js), port, '\n - '.join(unrolled)))
def do_log(self, line): """retrieve the last 32 lines of log for each selected pod""" tokens = line.split(' ') if line else ['*'] for token in tokens: def _query(zk): return fire(zk, token, 'log') js = run(proxy, _query) for pod in sorted(js.keys()): _, log, code = js[pod] if code == 200: logger.info('\n%s ->\n\n- %s' % (pod, '- '.join(log[-32:])))
def do_info(self, line): """displays full information for the selected pods""" tokens = line.split(' ') if line else ['*'] for token in tokens: def _query(zk): responses = fire(zk, token, 'info') return { key: hints for key, (_, hints, code) in responses.items() if code == 200 } js = run(proxy, _query) unrolled = ['%s\n%s\n' % \ (k, json.dumps(js[k], indent=4, separators=(',', ': '))) for k in sorted(js.keys())] logger.info('\n<%s> %d pods ->\n\n- %s' % (token, len(js), '\n- '.join(unrolled)))
def body(self, _, proxy): def _query(zk): # # - this closure will run in our zookeeper proxy actor # - in this case we'll HTTP POST a /info query to all our pods (you can use a glob pattern) # - fire() will figure out where the pods are running from and what their control port is # - we simply return the number of pods who answered with HTTP 200 # - please note all the I/O is done on parallel for each pod and the outcome aggregated for you # responses = fire(zk, '*', 'info') return sum(1 for key, (_, _, code) in responses.items() if code == 200) # # - run our query using the closure above # - this call will block and return whatever _query() returns # total = run(proxy, _query) logger.info('%d pods' % total)
def body(self, args, proxy): def _query(zk): responses = fire(zk, '*', 'info') return { key: hints['process'] for key, (_, hints, code) in responses.items() if code == 200 } js = run(proxy, _query) if not js: logger.info( 'no pods detected (make sure you point to the right zookeeper)' ) else: running = [ pod for pod, state in js.items() if state == 'running' ] pct = int((100 * len(running)) / len(js)) logger.info('%d pods total, %d%% running ->\n - %s' % (len(js), pct, '\n - '.join(sorted(running))))
def body(self, args, proxy): port = str(args.port[0]) for cluster in args.clusters: def _query(zk): responses = fire(zk, cluster, 'info') return { key: '%d\t\t%s' % (hints['ports'][port], hints['public']) for key, (_, hints, code) in responses.items() if code == 200 and port in hints['ports'] } js = run(proxy, _query) if js: unrolled = [ '%s\t\t%s' % (ip, node) for node, ip in js.items() ] logger.info( '%s (%d pods exposing %s) ->\n - %s' % (cluster, len(js), port, '\n - '.join(unrolled)))