-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathstart_remote_controller.py
128 lines (98 loc) · 3.56 KB
/
start_remote_controller.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import argparse
import os
import subprocess
import sys
from os.path import isfile
SERVER_VERSION = "5.0"
RC_VERSION = "0.8-SNAPSHOT"
RELEASE_REPO = "https://repo1.maven.apache.org/maven2"
ENTERPRISE_RELEASE_REPO = "https://repository.hazelcast.com/release/"
SNAPSHOT_REPO = "https://oss.sonatype.org/content/repositories/snapshots"
ENTERPRISE_SNAPSHOT_REPO = "https://repository.hazelcast.com/snapshot/"
if SERVER_VERSION.endswith("-SNAPSHOT"):
REPO = SNAPSHOT_REPO
ENTERPRISE_REPO = ENTERPRISE_SNAPSHOT_REPO
else:
REPO = RELEASE_REPO
ENTERPRISE_REPO = ENTERPRISE_RELEASE_REPO
if RC_VERSION.endswith("-SNAPSHOT"):
RC_REPO = SNAPSHOT_REPO
else:
RC_REPO = RELEASE_REPO
IS_ON_WINDOWS = os.name == "nt"
CLASS_PATH_SEPARATOR = ";" if IS_ON_WINDOWS else ":"
def parse_args() -> argparse.Namespace:
parser = argparse.ArgumentParser(description="Starts the remote controller")
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 download_if_necessary(repo, artifact_id, version, is_test_artifact=False):
dest_file_name = artifact_id + "-" + version
if is_test_artifact:
dest_file_name += "-tests"
dest_file_name += ".jar"
if isfile(dest_file_name):
print("Not downloading %s, because it already exists." % dest_file_name)
return dest_file_name
print("Downloading " + dest_file_name)
artifact = "com.hazelcast:" + artifact_id + ":" + version
if is_test_artifact:
artifact += ":jar:tests"
args = [
"mvn",
"-q",
"org.apache.maven.plugins:maven-dependency-plugin:2.10:get",
"-Dtransitive=false",
"-DremoteRepositories=" + repo,
"-Dartifact=" + artifact,
"-Ddest=" + dest_file_name,
]
process = subprocess.run(args, shell=IS_ON_WINDOWS)
if process.returncode != 0:
print("Failed to download " + dest_file_name)
sys.exit(1)
return dest_file_name
def start_rc(use_simple_server: bool, stdout=None, stderr=None):
artifacts = []
rc = download_if_necessary(RC_REPO, "hazelcast-remote-controller", RC_VERSION)
tests = download_if_necessary(REPO, "hazelcast", SERVER_VERSION, True)
sql = download_if_necessary(REPO, "hazelcast-sql", SERVER_VERSION)
artifacts.extend([rc, tests, sql])
enterprise_key = os.environ.get("HAZELCAST_ENTERPRISE_KEY", None)
if enterprise_key:
server = download_if_necessary(ENTERPRISE_REPO, "hazelcast-enterprise", SERVER_VERSION)
ep_tests = download_if_necessary(
ENTERPRISE_REPO, "hazelcast-enterprise", SERVER_VERSION, True
)
artifacts.append(server)
artifacts.append(ep_tests)
else:
server = download_if_necessary(REPO, "hazelcast", SERVER_VERSION)
artifacts.append(server)
class_path = CLASS_PATH_SEPARATOR.join(artifacts)
args = [
"java",
"-cp",
class_path,
"com.hazelcast.remotecontroller.Main",
]
if use_simple_server:
args.append("--use-simple-server")
if enterprise_key:
args.insert(1, "-Dhazelcast.enterprise.license.key=" + enterprise_key)
return subprocess.Popen(args=args, stdout=stdout, stderr=stderr, shell=IS_ON_WINDOWS)
if __name__ == "__main__":
args = parse_args()
rc_process = start_rc(args.use_simple_server)
try:
rc_process.wait()
except:
rc_process.kill()
rc_process.wait()
raise