Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Commit 1f79018

Browse files
authored
Deep clean heron-explorer (#3588)
* Deep clean heron-explorer * use click instead of argparse pattern * list all topologies instead of just 20 * not strictly the same CLI argument names but same functionality * add smoke testes for heron-tracker and heron-explorer in local-test-runner * heron-explorer clean PR feedback
1 parent 9d4541b commit 1f79018

File tree

13 files changed

+348
-944
lines changed

13 files changed

+348
-944
lines changed

heron/tools/explorer/src/python/BUILD

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ pex_library(
66
reqs = [
77
"tornado==4.0.2",
88
"tabulate==0.7.4",
9+
"click==7.1.2",
910
],
1011
deps = [
1112
"//heron/common/src/python:common-py",

heron/tools/explorer/src/python/args.py

-141
This file was deleted.

heron/tools/explorer/src/python/clusters.py

-50
This file was deleted.

heron/tools/explorer/src/python/help.py

-64
This file was deleted.

heron/tools/explorer/src/python/logicalplan.py

+17-88
Original file line numberDiff line numberDiff line change
@@ -19,47 +19,18 @@
1919
# under the License.
2020

2121
''' logicalplan.py '''
22-
from collections import defaultdict
23-
from heron.common.src.python.utils.log import Log
24-
import heron.tools.explorer.src.python.args as args
25-
import heron.tools.common.src.python.access.tracker_access as tracker_access
26-
from tabulate import tabulate
27-
22+
import sys
2823

29-
def create_parser(subparsers):
30-
""" create parser """
31-
components_parser = subparsers.add_parser(
32-
'components',
33-
help='Display information of a topology\'s components',
34-
usage="%(prog)s cluster/[role]/[env] topology-name [options]",
35-
add_help=False)
36-
args.add_cluster_role_env(components_parser)
37-
args.add_topology_name(components_parser)
38-
args.add_spouts(components_parser)
39-
args.add_bolts(components_parser)
40-
args.add_verbose(components_parser)
41-
args.add_tracker_url(components_parser)
42-
args.add_config(components_parser)
43-
components_parser.set_defaults(subcommand='components')
24+
from collections import defaultdict
4425

45-
return subparsers
26+
from heron.common.src.python.utils.log import Log
4627

28+
import heron.tools.common.src.python.access.tracker_access as tracker_access
4729

48-
# pylint: disable=misplaced-bare-raise
49-
def parse_topo_loc(cl_args):
50-
""" parse topology location """
51-
try:
52-
topo_loc = cl_args['cluster/[role]/[env]'].split('/')
53-
topo_loc.append(cl_args['topology-name'])
54-
if len(topo_loc) != 4:
55-
raise
56-
return topo_loc
57-
except Exception:
58-
Log.error('Error: invalid topology location')
59-
raise
30+
from tabulate import tabulate
6031

6132

62-
def to_table(components, topo_info):
33+
def to_table(components, topo_info, component_filter):
6334
""" normalize raw logical plan info to table """
6435
inputs, outputs = defaultdict(list), defaultdict(list)
6536
for ctype, component in list(components.items()):
@@ -76,6 +47,10 @@ def to_table(components, topo_info):
7647
# stages is an int so keep going
7748
if ctype == "stages":
7849
continue
50+
if component_filter == "spouts" and ctype != "spouts":
51+
continue
52+
if component_filter == "bolts" and ctype != "bolts":
53+
continue
7954
for component_name, component_info in list(component.items()):
8055
row = [ctype[:-1], component_name]
8156
if ctype == 'spouts':
@@ -89,59 +64,13 @@ def to_table(components, topo_info):
8964
return info, header
9065

9166

92-
def filter_bolts(table, header):
93-
""" filter to keep bolts """
94-
bolts_info = []
95-
for row in table:
96-
if row[0] == 'bolt':
97-
bolts_info.append(row)
98-
return bolts_info, header
99-
100-
101-
def filter_spouts(table, header):
102-
""" filter to keep spouts """
103-
spouts_info = []
104-
for row in table:
105-
if row[0] == 'spout':
106-
spouts_info.append(row)
107-
return spouts_info, header
108-
109-
110-
# pylint: disable=unused-argument,superfluous-parens
111-
def run(cl_args, compo_type):
67+
def run(component_type: str, cluster: str, role: str, environment: str, topology: str):
11268
""" run command """
113-
cluster, role, env = cl_args['cluster'], cl_args['role'], cl_args['environ']
114-
topology = cl_args['topology-name']
115-
spouts_only, bolts_only = cl_args['spout'], cl_args['bolt']
11669
try:
117-
components = tracker_access.get_logical_plan(cluster, env, topology, role)
118-
topo_info = tracker_access.get_topology_info(cluster, env, topology, role)
119-
table, header = to_table(components, topo_info)
120-
if spouts_only == bolts_only:
121-
print(tabulate(table, headers=header))
122-
elif spouts_only:
123-
table, header = filter_spouts(table, header)
124-
print(tabulate(table, headers=header))
125-
else:
126-
table, header = filter_bolts(table, header)
127-
print(tabulate(table, headers=header))
128-
return True
70+
components = tracker_access.get_logical_plan(cluster, environment, topology, role)
71+
topo_info = tracker_access.get_topology_info(cluster, environment, topology, role)
12972
except:
130-
Log.error("Fail to connect to tracker: \'%s\'", cl_args["tracker_url"])
131-
return False
132-
133-
134-
135-
def run_components(command, parser, cl_args, unknown_args):
136-
""" run components command """
137-
return run(cl_args, 'all')
138-
139-
140-
def run_spouts(command, parser, cl_args, unknown_args):
141-
""" run spouts command """
142-
return run(cl_args, 'spouts')
143-
144-
145-
def run_bolts(command, parser, cl_args, unknown_args):
146-
""" run bolts command """
147-
return run(cl_args, 'bolts')
73+
Log.error("Fail to connect to tracker")
74+
sys.exit(1)
75+
table, header = to_table(components, topo_info, component_type)
76+
print(tabulate(table, headers=header))

0 commit comments

Comments
 (0)