Elffuss BraidHub

kikocis/java-driver public

Merge pull request #344 from blerer/AddWindowsSupportToCCMBridge

Adds Windows support to CCMBridge
Changeset5d6cb1282caad378785da4bbc1652f1627d7fdf8ce7ab4e4848dd69ac7f9db21
AuthorOlivier Michallat <olim7t@users.noreply.github.com> · 2015-06-04 15:16 +02:00
CommitterOlivier Michallat <olim7t@users.noreply.github.com> · 2015-06-04 15:16 +02:00
Parentse2e0cf1fb095, 670ea718fdf5

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +52 −26
@@ -83,6 +83,11 @@
8383 */
8484 private static final Map<String,String> ENVIRONMENT_MAP;
8585
86+ /**
87+ * The command to use to launch CCM
88+ */
89+ private static final String CCM_COMMAND;
90+
8691 static {
8792 // Inherit the current environment.
8893 Map<String,String> envMap = Maps.newHashMap(new ProcessBuilder().environment());
@@ -93,8 +98,15 @@
9398 if(existingPath == null) {
9499 existingPath = "";
95100 }
96- envMap.put("PATH", ccmPath + ":" + existingPath);
101+ envMap.put("PATH", ccmPath + File.pathSeparator + existingPath);
102+ }
103+
104+ if (isWindows()) {
105+ CCM_COMMAND = "cmd /c ccm.py";
106+ } else {
107+ CCM_COMMAND = "ccm";
97108 }
109+
98110 // If ccm.java.home is set, override the JAVA_HOME variable with it.
99111 String ccmJavaHome = System.getProperty("ccm.java.home");
100112 if(ccmJavaHome != null) {
@@ -103,6 +115,19 @@
103115 ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap);
104116 }
105117
118+ /**
119+ * Checks if the operating system is a Windows one
120+ * @return <code>true</code> if the operating system is a Windows one, <code>false</code> otherwise.
121+ */
122+ private static boolean isWindows() {
123+
124+ String osName = System.getProperty("os.name");
125+ if (osName == null) {
126+ return false;
127+ }
128+ return osName.startsWith("Windows");
129+ }
130+
106131 static final File CASSANDRA_DIR;
107132 static final String CASSANDRA_VERSION;
108133
@@ -170,7 +195,7 @@
170195 checkArgument(!"current".equals(name.toLowerCase()),
171196 "cluster can't be called \"current\"");
172197 CCMBridge bridge = new CCMBridge();
173- bridge.execute("ccm create %s -b -i %s %s " + Joiner.on(" ").join(options), name, IP_PREFIX, CASSANDRA_VERSION);
198+ bridge.execute(CCM_COMMAND + " create %s -b -i %s %s " + Joiner.on(" ").join(options), name, IP_PREFIX, CASSANDRA_VERSION);
174199 return bridge;
175200 }
176201
@@ -178,7 +203,7 @@
178203 checkArgument(!"current".equals(name.toLowerCase()),
179204 "cluster can't be called \"current\"");
180205 CCMBridge bridge = new CCMBridge();
181- bridge.execute("ccm create %s -n %d -s -i %s -b %s " + Joiner.on(" ").join(options), name, nbNodes, IP_PREFIX, CASSANDRA_VERSION);
206+ bridge.execute(CCM_COMMAND + " create %s -n %d -s -i %s -b %s " + Joiner.on(" ").join(options), name, nbNodes, IP_PREFIX, CASSANDRA_VERSION);
182207 return bridge;
183208 }
184209
@@ -186,7 +211,7 @@
186211 checkArgument(!"current".equals(name.toLowerCase()),
187212 "cluster can't be called \"current\"");
188213 CCMBridge bridge = new CCMBridge();
189- bridge.execute("ccm create %s -n %d -s -i %s -b -v %s ", name, nbNodes, IP_PREFIX, cassandraVersion);
214+ bridge.execute(CCM_COMMAND + " create %s -n %d -s -i %s -b -v %s ", name, nbNodes, IP_PREFIX, cassandraVersion);
190215 return bridge;
191216 }
192217
@@ -194,7 +219,7 @@
194219 checkArgument(!"current".equals(name.toLowerCase()),
195220 "cluster can't be called \"current\"");
196221 CCMBridge bridge = new CCMBridge();
197- bridge.execute("ccm create %s -n %d:%d -s -i %s -b %s", name, nbNodesDC1, nbNodesDC2, IP_PREFIX, CASSANDRA_VERSION);
222+ bridge.execute(CCM_COMMAND + " create %s -n %d:%d -s -i %s -b %s", name, nbNodesDC1, nbNodesDC2, IP_PREFIX, CASSANDRA_VERSION);
198223 return bridge;
199224 }
200225
@@ -207,55 +232,55 @@
207232 }
208233
209234 public void start() {
210- execute("ccm start --wait-other-notice --wait-for-binary-proto");
235+ execute(CCM_COMMAND + " start --wait-other-notice --wait-for-binary-proto");
211236 }
212237
213238 public void stop() {
214- execute("ccm stop");
239+ execute(CCM_COMMAND + " stop");
215240 }
216241
217242 public void forceStop() {
218- execute("ccm stop --not-gently");
243+ execute(CCM_COMMAND + " stop --not-gently");
219244 }
220245
221246 public void start(int n) {
222247 logger.info("Starting: " + IP_PREFIX + n);
223- execute("ccm node%d start --wait-other-notice --wait-for-binary-proto", n);
248+ execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n);
224249 }
225250
226251 public void start(int n, String option) {
227252 logger.info("Starting: " + IP_PREFIX + n + " with " + option);
228- execute("ccm node%d start --wait-other-notice --wait-for-binary-proto --jvm_arg=%s", n, option);
253+ execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto --jvm_arg=%s", n, option);
229254 }
230255
231256 public void stop(int n) {
232257 logger.info("Stopping: " + IP_PREFIX + n);
233- execute("ccm node%d stop", n);
258+ execute(CCM_COMMAND + " node%d stop", n);
234259 }
235260
236261 public void stop(String clusterName) {
237262 logger.info("Stopping Cluster : "+clusterName);
238- execute("ccm stop "+clusterName);
263+ execute(CCM_COMMAND + " stop "+clusterName);
239264 }
240265
241266 public void forceStop(int n) {
242267 logger.info("Force stopping: " + IP_PREFIX + n);
243- execute("ccm node%d stop --not-gently", n);
268+ execute(CCM_COMMAND + " node%d stop --not-gently", n);
244269 }
245270
246271 public void remove() {
247272 stop();
248- execute("ccm remove");
273+ execute(CCM_COMMAND + " remove");
249274 }
250275
251276 public void remove(String clusterName) {
252277 stop(clusterName);
253- execute("ccm remove " + clusterName);
278+ execute(CCM_COMMAND + " remove " + clusterName);
254279 }
255280
256281 public void remove(int n) {
257282 logger.info("Removing: " + IP_PREFIX + n);
258- execute("ccm node%d remove", n);
283+ execute(CCM_COMMAND + " node%d remove", n);
259284 }
260285
261286 public void bootstrapNode(int n) {
@@ -264,10 +289,10 @@
264289
265290 public void bootstrapNode(int n, String dc) {
266291 if (dc == null)
267- execute("ccm add node%d -i %s%d -j %d -r %d -b -s", n, IP_PREFIX, n, 7000 + 100 * n, 8000 + 100 * n);
292+ execute(CCM_COMMAND + " add node%d -i %s%d -j %d -r %d -b -s", n, IP_PREFIX, n, 7000 + 100 * n, 8000 + 100 * n);
268293 else
269- execute("ccm add node%d -i %s%d -j %d -b -d %s -s", n, IP_PREFIX, n, 7000 + 100 * n, dc);
270- execute("ccm node%d start --wait-other-notice --wait-for-binary-proto", n);
294+ execute(CCM_COMMAND + " add node%d -i %s%d -j %d -b -d %s -s", n, IP_PREFIX, n, 7000 + 100 * n, dc);
295+ execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n);
271296 }
272297
273298 public void bootstrapNodeWithPorts(int n, int thriftPort, int storagePort, int binaryPort, int jmxPort, int remoteDebugPort) {
@@ -275,13 +300,13 @@
275300 String storageItf = IP_PREFIX + n + ":" + storagePort;
276301 String binaryItf = IP_PREFIX + n + ":" + binaryPort;
277302 String remoteLogItf = IP_PREFIX + n + ":" + remoteDebugPort;
278- execute("ccm add node%d -i %s%d -b -t %s -l %s --binary-itf %s -j %d -r %s -s",
303+ execute(CCM_COMMAND + " add node%d -i %s%d -b -t %s -l %s --binary-itf %s -j %d -r %s -s",
279304 n, IP_PREFIX, n, thriftItf, storageItf, binaryItf, jmxPort, remoteLogItf);
280- execute("ccm node%d start --wait-other-notice --wait-for-binary-proto", n);
305+ execute(CCM_COMMAND + " node%d start --wait-other-notice --wait-for-binary-proto", n);
281306 }
282307
283308 public void decommissionNode(int n) {
284- execute("ccm node%d decommission", n);
309+ execute(CCM_COMMAND + " node%d decommission", n);
285310 }
286311
287312 public void updateConfig(String name, String value) {
@@ -293,16 +318,17 @@
293318 for (Map.Entry<String, String> entry : configs.entrySet()) {
294319 confStr.append(entry.getKey() + ":" + entry.getValue() + " ");
295320 }
296- execute("ccm updateconf " + confStr);
321+ execute(CCM_COMMAND + " updateconf " + confStr);
297322 }
298323
299324 public void populate(int n) {
300- execute("ccm populate -n %d -i %s", n, IP_PREFIX);
325+ execute(CCM_COMMAND + " populate -n %d -i %s", n, IP_PREFIX);
301326 }
302327
303328 private void execute(String command, Object... args) {
329+
330+ String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir;
304331 try {
305- String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir;
306332 logger.debug("Executing: " + fullCommand);
307333 CommandLine cli = CommandLine.parse(fullCommand);
308334 Executor executor = new DefaultExecutor();
@@ -327,7 +353,7 @@
327353 throw new RuntimeException();
328354 }
329355 } catch (IOException e) {
330- throw new RuntimeException(e);
356+ throw new RuntimeException(String.format("The command %s failed to execute", fullCommand), e);
331357 }
332358 }
333359