forked from hazelcast/client-compatibility-suites
-
Notifications
You must be signed in to change notification settings - Fork 0
/
start_rc.py
111 lines (90 loc) · 2.88 KB
/
start_rc.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
104
105
106
107
108
109
110
111
import argparse
import os
import socket
import subprocess
import time
from contextlib import closing
from os import path
from util import (
SNAPSHOT_REPO,
RELEASE_REPO,
download_via_maven,
IS_ON_WINDOWS,
ServerKind,
)
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Starts the remote controller")
parser.add_argument(
"--rc-version",
dest="rc_version",
action="store",
type=str,
required=True,
help="Remote controller version",
)
parser.add_argument(
"--jars",
dest="jars",
action="store",
type=str,
required=True,
help="The name of the folder that will contain the JAR files",
)
parser.add_argument(
"--server-kind",
dest="server_kind",
action="store",
type=str,
required=True,
choices=[kind.name.lower() for kind in ServerKind],
help="The Hazelcast server type that the tests should be running for",
)
parser.add_argument(
"--use-simple-server",
dest="use_simple_server",
action="store_true",
default=False,
required=False,
help="Use the RC in simple server mode",
)
return parser.parse_args()
def start_rc(
rc_version: str, dst_folder: str, use_simple_server: bool, server_kind: ServerKind
) -> None:
if rc_version.upper().endswith("-SNAPSHOT"):
rc_repo = SNAPSHOT_REPO
else:
rc_repo = RELEASE_REPO
download_via_maven(rc_repo, "hazelcast-remote-controller", rc_version, dst_folder)
class_path = path.join(dst_folder, "*")
args = [
"java",
"-cp",
class_path,
"com.hazelcast.remotecontroller.Main",
]
if use_simple_server:
args.append("--use-simple-server")
enterprise_key = os.environ.get("HAZELCAST_ENTERPRISE_KEY", None)
if server_kind == ServerKind.ENTERPRISE and enterprise_key:
args.insert(1, "-Dhazelcast.enterprise.license.key=" + enterprise_key)
rc_stdout = open("rc_stdout.log", "w")
rc_stderr = open("rc_stderr.log", "w")
subprocess.Popen(args=args, stdout=rc_stdout, stderr=rc_stderr, shell=IS_ON_WINDOWS)
def wait_until_rc_is_ready() -> None:
timeout = 300 + time.time()
while time.time() < timeout:
with closing(socket.socket()) as sock:
if sock.connect_ex(("localhost", 9701)) == 0:
return
print("Remote controller is not ready yet. Sleeping 1 second.")
time.sleep(1)
raise Exception("Remote controller failed to start.")
if __name__ == "__main__":
args = parse_args()
rc_version = args.rc_version
jars = args.jars
server_kind = ServerKind[args.server_kind.upper()]
use_simple_server = args.use_simple_server
start_rc(rc_version, jars, use_simple_server, server_kind)
wait_until_rc_is_ready()