forked from elastic/rally
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrallyd.py
103 lines (87 loc) · 3.8 KB
/
rallyd.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import sys
import time
import logging
import argparse
from esrally import actor, version, exceptions, DOC_LINK, BANNER, PROGRAM_NAME, check_python_version, log
from esrally.utils import console
def start(args):
if actor.actor_system_already_running():
raise exceptions.RallyError("An actor system appears to be already running.")
actor.bootstrap_actor_system(local_ip=args.node_ip, coordinator_ip=args.coordinator_ip)
console.info("Successfully started actor system on node [%s] with coordinator node IP [%s]." % (args.node_ip, args.coordinator_ip))
def stop(raise_errors=True):
if actor.actor_system_already_running():
# noinspection PyBroadException
try:
# TheSpian writes the following warning upon start (at least) on Mac OS X:
#
# WARNING:root:Unable to get address info for address 103.1.168.192.in-addr.arpa (AddressFamily.AF_INET,\
# SocketKind.SOCK_DGRAM, 17, 0): <class 'socket.gaierror'> [Errno 8] nodename nor servname provided, or not known
#
# Therefore, we will not show warnings but only errors.
logging.basicConfig(level=logging.ERROR)
running_system = actor.bootstrap_actor_system(try_join=True)
running_system.shutdown()
# await termination...
console.info("Shutting down actor system.", end="", flush=True)
while actor.actor_system_already_running():
console.println(".", end="", flush=True)
time.sleep(1)
console.println(" [OK]")
except BaseException:
console.error("Could not shut down actor system.")
if raise_errors:
# raise again so user can see the error
raise
elif raise_errors:
console.error("Could not shut down actor system: Actor system is not running.")
sys.exit(1)
def status():
if actor.actor_system_already_running():
console.println("Running")
else:
console.println("Stopped")
def main():
check_python_version()
log.remove_obsolete_default_log_config()
log.install_default_log_config()
log.configure_logging()
console.init()
parser = argparse.ArgumentParser(prog=PROGRAM_NAME,
description=BANNER + "\n\n Rally daemon to support remote benchmarks",
epilog="Find out more about Rally at %s" % console.format.link(DOC_LINK),
formatter_class=argparse.RawDescriptionHelpFormatter)
parser.add_argument('--version', action='version', version="%(prog)s " + version.version())
subparsers = parser.add_subparsers(
title="subcommands",
dest="subcommand",
help="")
subparsers.required = True
start_command = subparsers.add_parser("start", help="Starts the Rally daemon")
restart_command = subparsers.add_parser("restart", help="Restarts the Rally daemon")
for p in [start_command, restart_command]:
p.add_argument(
"--node-ip",
required=True,
help="The IP of this node.")
p.add_argument(
"--coordinator-ip",
required=True,
help="The IP of the coordinator node."
)
subparsers.add_parser("stop", help="Stops the Rally daemon")
subparsers.add_parser("status", help="Shows the current status of the local Rally daemon")
args = parser.parse_args()
if args.subcommand == "start":
start(args)
elif args.subcommand == "stop":
stop()
elif args.subcommand == "status":
status()
elif args.subcommand == "restart":
stop(raise_errors=False)
start(args)
else:
raise exceptions.RallyError("Unknown subcommand [%s]" % args.subcommand)
if __name__ == '__main__':
main()