def graph_mode(client: MasterApiClient, args): if args.action == 'create': name, rev = client.create_graph( graph_struct=_prepare_graph_struct(args.name, args.graph, args.hosts, args.format), graph_name=args.name ) print('Created graph "{}", revision {}.'.format(name, rev)) elif args.action == 'info': if args.list_all: print(json.dumps([_.to_json() for _ in client.list_graphs(args.name, args.revision)], indent=2, ensure_ascii=False)) else: assert args.name, 'Graph name should be set' print(json.dumps(client.read_graph(args.name, args.revision).to_json(), indent=2, ensure_ascii=False)) elif args.action == 'launch': print('Created new graph instance: {}'.format(client.launch_graph(args.name, args.revision))) else: logging.error('Not supported action for graph mode: %s', args.action) exit(1)
def main(args): cli = MasterApiClient(master_host=args.server, master_port=args.port) graph_name, graph_rev = cli.create_graph(graph_struct=json.load(open(args.path)), graph_name='test_graph') print('Created graph: {}, rev: {}'.format(graph_name, graph_rev)) instance_id = cli.launch_graph(graph_name, int(graph_rev)) print('Created instance: {}'.format(instance_id)) old_state, new_state = cli.start_instance(instance_id) print('State: {} -> {}'.format(old_state.name, new_state.name)) while True: sleep(1) data = cli.read_instance(instance_id) state = data.exec_stats.state print('#'*10) print('State:', state.name) for task_name, task_info in data.exec_stats.per_task_execution_info.items(): print('Task', task_name) print('\n'.join('\tHost {}: {}'.format(host, info.state.name) for host, info in task_info.per_host_info.items())) if state.is_terminal: print('*' * 20) if state.name == GraphInstanceState.failed: print('Failed!') if data.exec_stats.fail_msg: print('Fail msg: {}'.format(data.exec_stats.fail_msg)) elif state.name == GraphInstanceState.finished: print('Success!') print('LOGS:') for task_name, task_info in data.exec_stats.per_task_execution_info.items(): print(' Task', task_name) for host in task_info.per_host_info.keys(): out = cli.instance_logs(instance_id, task_name, host, 'out') err = cli.instance_logs(instance_id, task_name, host, 'err') print(' Host', host) if out: print(' Out:') print(''.join('+++>{}'.format(_) for _ in out.strip().splitlines(keepends=True))) if err: print(' Err:') print(''.join('--->{}'.format(_) for _ in err.strip().splitlines(keepends=True))) print('-' * 10) break