def run_bolts(command, parser, cl_args, unknown_args): """ run bolts subcommand """ cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ'] topology = cl_args['topology-name'] try: result = tracker_access.get_topology_info(cluster, env, topology, role) bolts = result['physical_plan']['bolts'].keys() bolt_name = cl_args['bolt'] if bolt_name: if bolt_name in bolts: bolts = [bolt_name] else: Log.error('Unknown bolt: \'%s\'' % bolt_name) raise except Exception: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False bolts_result = [] for bolt in bolts: try: metrics = tracker_access.get_component_metrics(bolt, cluster, env, topology, role) stat, header = to_table(metrics) bolts_result.append((bolt, stat, header)) except Exception: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False for i, (bolt, stat, header) in enumerate(bolts_result): if i != 0: print '' print '\'%s\' metrics:' % bolt print tabulate(stat, headers=header) return True
def run_metrics(command, parser, cl_args, unknown_args): """ run metrics subcommand """ cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ'] topology = cl_args['topology-name'] try: result = tracker_access.get_topology_info(cluster, env, topology, role) spouts = result['physical_plan']['spouts'].keys() bolts = result['physical_plan']['bolts'].keys() components = spouts + bolts cname = cl_args['component'] if cname: if cname in components: components = [cname] else: Log.error('Unknown component: \'%s\'' % cname) raise except Exception: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False cresult = [] for comp in components: try: metrics = tracker_access.get_component_metrics(comp, cluster, env, topology, role) except: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False stat, header = to_table(metrics) cresult.append((comp, stat, header)) for i, (comp, stat, header) in enumerate(cresult): if i != 0: print '' print '\'%s\' metrics:' % comp print tabulate(stat, headers=header) return True
def run_metrics(command, parser, cl_args, unknown_args): """ run metrics subcommand """ cluster, role, env = cl_args["cluster"], cl_args["role"], cl_args["environ"] topology = cl_args["topology-name"] try: result = tracker_access.get_topology_info(cluster, env, topology, role) spouts = result["physical_plan"]["spouts"].keys() bolts = result["physical_plan"]["bolts"].keys() components = spouts + bolts cname = cl_args["component"] if cname: if cname in components: components = [cname] else: Log.error("Unknown component: '%s'" % cname) raise except Exception: Log.error("Fail to connect to tracker: '%s'", cl_args["tracker_url"]) return False cresult = [] for comp in components: try: metrics = tracker_access.get_component_metrics(comp, cluster, env, topology, role) except: Log.error("Fail to connect to tracker: '%s'", cl_args["tracker_url"]) return False stat, header = to_table(metrics) cresult.append((comp, stat, header)) for i, (comp, stat, header) in enumerate(cresult): if i != 0: print "" print "'%s' metrics:" % comp print tabulate(stat, headers=header) return True
def run_bolts(command, parser, cl_args, unknown_args): """ run bolts subcommand """ cluster, role, env = cl_args["cluster"], cl_args["role"], cl_args["environ"] topology = cl_args["topology-name"] try: result = tracker_access.get_topology_info(cluster, env, topology, role) bolts = result["physical_plan"]["bolts"].keys() bolt_name = cl_args["bolt"] if bolt_name: if bolt_name in bolts: bolts = [bolt_name] else: Log.error("Unknown bolt: '%s'" % bolt_name) raise except Exception: Log.error("Fail to connect to tracker: '%s'", cl_args["tracker_url"]) return False bolts_result = [] for bolt in bolts: try: metrics = tracker_access.get_component_metrics(bolt, cluster, env, topology, role) stat, header = to_table(metrics) bolts_result.append((bolt, stat, header)) except Exception: Log.error("Fail to connect to tracker: '%s'", cl_args["tracker_url"]) return False for i, (bolt, stat, header) in enumerate(bolts_result): if i != 0: print "" print "'%s' metrics:" % bolt print tabulate(stat, headers=header) return True
def run_metrics(command, parser, cl_args, unknown_args): """ run metrics subcommand """ cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ'] topology = cl_args['topology-name'] try: result = tracker_access.get_topology_info(cluster, env, topology, role) spouts = result['physical_plan']['spouts'].keys() bolts = result['physical_plan']['bolts'].keys() components = spouts + bolts cname = cl_args['component'] if cname: if cname in components: components = [cname] else: Log.error('Unknown component: \'%s\'' % cname) raise except Exception: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False cresult = [] for comp in components: try: metrics = tracker_access.get_component_metrics(comp, cluster, env, topology, role) except: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False stat, header = to_table(metrics) cresult.append((comp, stat, header)) for i, (comp, stat, header) in enumerate(cresult): if i != 0: print('') print('\'%s\' metrics:' % comp) print(tabulate(stat, headers=header)) return True
def run_bolts(command, parser, cl_args, unknown_args): """ run bolts subcommand """ cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ'] topology = cl_args['topology-name'] try: result = tracker_access.get_topology_info(cluster, env, topology, role) bolts = result['physical_plan']['bolts'].keys() bolt_name = cl_args['bolt'] if bolt_name: if bolt_name in bolts: bolts = [bolt_name] else: Log.error('Unknown bolt: \'%s\'' % bolt_name) raise except Exception: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False bolts_result = [] for bolt in bolts: try: metrics = tracker_access.get_component_metrics(bolt, cluster, env, topology, role) stat, header = to_table(metrics) bolts_result.append((bolt, stat, header)) except Exception: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False for i, (bolt, stat, header) in enumerate(bolts_result): if i != 0: print('') print('\'%s\' metrics:' % bolt) print(tabulate(stat, headers=header)) return True
def run(component_type: str, cluster: str, role: str, environment: str, topology: str): """ run command """ try: components = tracker_access.get_logical_plan(cluster, environment, topology, role) topo_info = tracker_access.get_topology_info(cluster, environment, topology, role) except: Log.error("Fail to connect to tracker") sys.exit(1) table, header = to_table(components, topo_info, component_type) print(tabulate(table, headers=header))
def run_containers(command, parser, cl_args, unknown_args): """ run containers subcommand """ cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args[ 'environ'] topology = cl_args['topology-name'] container_id = cl_args['id'] try: result = tracker_access.get_topology_info(cluster, env, topology, role) except: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False containers = result['physical_plan']['stmgrs'] all_bolts, all_spouts = set(), set() for _, bolts in result['physical_plan']['bolts'].items(): all_bolts = all_bolts | set(bolts) for _, spouts in result['physical_plan']['spouts'].items(): all_spouts = all_spouts | set(spouts) stmgrs = containers.keys() stmgrs.sort() if container_id is not None: try: normalized_cid = container_id - 1 if normalized_cid < 0: raise stmgrs = [stmgrs[normalized_cid]] except: Log.error('Invalid container id: %d' % container_id) return False table = [] for sid, name in enumerate(stmgrs): cid = sid + 1 host = containers[name]["host"] port = containers[name]["port"] pid = containers[name]["pid"] instances = containers[name]["instance_ids"] bolt_nums = len( [instance for instance in instances if instance in all_bolts]) spout_nums = len( [instance for instance in instances if instance in all_spouts]) table.append( [cid, host, port, pid, bolt_nums, spout_nums, len(instances)]) headers = [ "container", "host", "port", "pid", "#bolt", "#spout", "#instance" ] sys.stdout.flush() print(tabulate(table, headers=headers)) return True
def run_containers(command, parser, cl_args, unknown_args): """ run containers subcommand """ cluster, role, env = cl_args["cluster"], cl_args["role"], cl_args["environ"] topology = cl_args["topology-name"] container_id = cl_args["id"] try: result = tracker_access.get_topology_info(cluster, env, topology, role) except: Log.error("Fail to connect to tracker: '%s'", cl_args["tracker_url"]) return False containers = result["physical_plan"]["stmgrs"] all_bolts, all_spouts = set(), set() for _, bolts in result["physical_plan"]["bolts"].items(): all_bolts = all_bolts | set(bolts) for _, spouts in result["physical_plan"]["spouts"].items(): all_spouts = all_spouts | set(spouts) stmgrs = containers.keys() stmgrs.sort() if container_id is not None: try: normalized_cid = container_id - 1 if normalized_cid < 0: raise stmgrs = [stmgrs[normalized_cid]] except: Log.error("Invalid container id: %d" % container_id) return False table = [] for sid, name in enumerate(stmgrs): cid = sid + 1 host = containers[name]["host"] port = containers[name]["port"] pid = containers[name]["pid"] instances = containers[name]["instance_ids"] bolt_nums = len([instance for instance in instances if instance in all_bolts]) spout_nums = len([instance for instance in instances if instance in all_spouts]) table.append([cid, host, port, pid, bolt_nums, spout_nums, len(instances)]) headers = ["container", "host", "port", "pid", "#bolt", "#spout", "#instance"] sys.stdout.flush() print tabulate(table, headers=headers) return True
def run(cl_args, compo_type): """ run command """ cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ'] topology = cl_args['topology-name'] spouts_only, bolts_only = cl_args['spout'], cl_args['bolt'] try: components = tracker_access.get_logical_plan(cluster, env, topology, role) topo_info = tracker_access.get_topology_info(cluster, env, topology, role) table, header = to_table(components, topo_info) if spouts_only == bolts_only: print tabulate(table, headers=header) elif spouts_only: table, header = filter_spouts(table, header) print tabulate(table, headers=header) else: table, header = filter_bolts(table, header) print tabulate(table, headers=header) return True except: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False
def run(cl_args, compo_type): """ run command """ cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ'] topology = cl_args['topology-name'] spouts_only, bolts_only = cl_args['spout'], cl_args['bolt'] try: components = tracker_access.get_logical_plan(cluster, env, topology, role) topo_info = tracker_access.get_topology_info(cluster, env, topology, role) table, header = to_table(components, topo_info) if spouts_only == bolts_only: print(tabulate(table, headers=header)) elif spouts_only: table, header = filter_spouts(table, header) print(tabulate(table, headers=header)) else: table, header = filter_bolts(table, header) print(tabulate(table, headers=header)) return True except: Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"]) return False
def run_containers( cluster: str, role: str, environment: str, topology: str, container_id: str, ) -> None: """Render a table of container information.""" try: result = tracker_access.get_topology_info(cluster, environment, topology, role) except: Log.error("Fail to connect to tracker") sys.exit(1) containers = result['physical_plan']['stmgrs'] all_bolts, all_spouts = set(), set() for bolts in result['physical_plan']['bolts'].values(): all_bolts |= set(bolts) for spouts in result['physical_plan']['spouts'].values(): all_spouts |= set(spouts) stmgrs = sorted(containers.keys()) if container_id is not None: stmgrs = [stmgrs[container_id]] table = [] for cid, name in enumerate(stmgrs, (container_id + 1 if container_id else 1)): instances = containers[name]["instance_ids"] table.append([ cid, containers[name]["host"], containers[name]["port"], containers[name]["pid"], len([1 for instance in instances if instance in all_bolts]), len([1 for instance in instances if instance in all_spouts]), len(instances), ]) headers = [ "container", "host", "port", "pid", "#bolt", "#spout", "#instance" ] print(tabulate(table, headers=headers))
def run_metrics( cluster: str, role: str, environment: str, topology: str, component: str, ) -> None: """Render a table of metrics.""" try: result = tracker_access.get_topology_info(cluster, environment, topology, role) except Exception: Log.error("Fail to connect to tracker") sys.exit(1) spouts = list(result['physical_plan']['spouts'].keys()) bolts = list(result['physical_plan']['bolts'].keys()) components = spouts + bolts if component: if component in components: components = [component] else: Log.error(f"Unknown component: {component!r}") sys.exit(1) cresult = [] for comp in components: try: metrics = tracker_access.get_component_metrics( comp, cluster, environment, topology, role) except: Log.error("Fail to connect to tracker") sys.exit(1) stat, header = to_table(metrics) cresult.append((comp, stat, header)) for i, (c, stat, header) in enumerate(cresult): if i != 0: print('') print(f"{c!r} metrics:") print(tabulate(stat, headers=header))