|
| 1 | +import cluster_test_utils as ctu |
| 2 | +import argparse |
| 3 | +import sys |
| 4 | + |
| 5 | +if __name__ == '__main__': |
| 6 | + parser = argparse.ArgumentParser() |
| 7 | + parser.add_argument('--action', '-a', metavar='A', type=str, default="status", |
| 8 | + help="Defines the action to take: status, reset, start, stop") |
| 9 | + parser.add_argument('--nodes', '-n', type=int, default=3, |
| 10 | + help="Number of zk, rc-coordinator, and rc-server instances to bring up. Only relevant when there's no cluster up yet. Default is 3") |
| 11 | + |
| 12 | +args = parser.parse_args() |
| 13 | + |
| 14 | +print("action =",args.action) |
| 15 | +print("nodes =",args.nodes) |
| 16 | +if (args.action == "start"): |
| 17 | + x = ctu.ClusterTest() |
| 18 | + x.setUp(num_nodes = args.nodes) |
| 19 | +elif (args.action == "status"): |
| 20 | + ctu.get_status() |
| 21 | +elif (args.action == "stop"): |
| 22 | + docker_network, docker_containers = ctu.get_status() |
| 23 | + ctu.destroy_network_and_containers(docker_network, docker_containers) |
| 24 | +elif (args.action == "reset"): |
| 25 | + docker_network, docker_containers = ctu.get_status() |
| 26 | + if (not docker_network): |
| 27 | + # No network (or containers), means bring up new cluster |
| 28 | + print("Bringing up new cluster with ", args.nodes, " nodes") |
| 29 | + x = ctu.ClusterTest() |
| 30 | + x.setUp(num_nodes = args.nodes) |
| 31 | + elif (not docker_containers): |
| 32 | + # A network but no containers means no data, so take it down, & bring back up |
| 33 | + print("Inconsistent State") |
| 34 | + print("Bringing up new cluster with ", args.nodes, " nodes") |
| 35 | + ctu.destroy_network_and_containers(docker_network, []) |
| 36 | + x = ctu.ClusterTest() |
| 37 | + x.setUp(num_nodes = args.nodes) |
| 38 | + else: |
| 39 | + # We have a network and containers. Get the ensemble, table names, then drop all tables! |
| 40 | + print("Found a cluster with ", len(docker_containers), " nodes") |
| 41 | + print("Identifying tables") |
| 42 | + ensemble = ctu.get_ensemble(len(docker_containers)) |
| 43 | + table_names = ctu.get_table_names(ensemble) |
| 44 | + print("Table names = ", table_names) |
| 45 | + print("Dropping all tables") |
| 46 | + ctu.drop_tables(ensemble, table_names) |
| 47 | +else: |
| 48 | + parser.print_help() |
0 commit comments