kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 5d6cb1282caad378785da4bbc1652f1627d7fdf8ce7ab4e4848dd69ac7f9db21 |
|---|---|
| Author | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-06-04 15:16 +02:00 |
| Committer | Olivier Michallat <olim7t@users.noreply.github.com> · 2015-06-04 15:16 +02:00 |
| Parents | e2e0cf1fb095, 670ea718fdf5 |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java +52 −26
| @@ -83,6 +83,11 @@ | ||
| 83 | 83 | */ |
| 84 | 84 | private static final Map<String,String> ENVIRONMENT_MAP; |
| 85 | 85 | |
| 86 | + /** | |
| 87 | + * The command to use to launch CCM | |
| 88 | + */ | |
| 89 | + private static final String CCM_COMMAND; | |
| 90 | + | |
| 86 | 91 | static { |
| 87 | 92 | // Inherit the current environment. |
| 88 | 93 | Map<String,String> envMap = Maps.newHashMap(new ProcessBuilder().environment()); |
| @@ -93,8 +98,15 @@ | ||
| 93 | 98 | if(existingPath == null) { |
| 94 | 99 | existingPath = ""; |
| 95 | 100 | } |
| 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"; | |
| 97 | 108 | } |
| 109 | + | |
| 98 | 110 | // If ccm.java.home is set, override the JAVA_HOME variable with it. |
| 99 | 111 | String ccmJavaHome = System.getProperty("ccm.java.home"); |
| 100 | 112 | if(ccmJavaHome != null) { |
| @@ -103,6 +115,19 @@ | ||
| 103 | 115 | ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap); |
| 104 | 116 | } |
| 105 | 117 | |
| 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 | + | |
| 106 | 131 | static final File CASSANDRA_DIR; |
| 107 | 132 | static final String CASSANDRA_VERSION; |
| 108 | 133 | |
| @@ -170,7 +195,7 @@ | ||
| 170 | 195 | checkArgument(!"current".equals(name.toLowerCase()), |
| 171 | 196 | "cluster can't be called \"current\""); |
| 172 | 197 | 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); | |
| 174 | 199 | return bridge; |
| 175 | 200 | } |
| 176 | 201 | |
| @@ -178,7 +203,7 @@ | ||
| 178 | 203 | checkArgument(!"current".equals(name.toLowerCase()), |
| 179 | 204 | "cluster can't be called \"current\""); |
| 180 | 205 | 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); | |
| 182 | 207 | return bridge; |
| 183 | 208 | } |
| 184 | 209 | |
| @@ -186,7 +211,7 @@ | ||
| 186 | 211 | checkArgument(!"current".equals(name.toLowerCase()), |
| 187 | 212 | "cluster can't be called \"current\""); |
| 188 | 213 | 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); | |
| 190 | 215 | return bridge; |
| 191 | 216 | } |
| 192 | 217 | |
| @@ -194,7 +219,7 @@ | ||
| 194 | 219 | checkArgument(!"current".equals(name.toLowerCase()), |
| 195 | 220 | "cluster can't be called \"current\""); |
| 196 | 221 | 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); | |
| 198 | 223 | return bridge; |
| 199 | 224 | } |
| 200 | 225 | |
| @@ -207,55 +232,55 @@ | ||
| 207 | 232 | } |
| 208 | 233 | |
| 209 | 234 | 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"); | |
| 211 | 236 | } |
| 212 | 237 | |
| 213 | 238 | public void stop() { |
| 214 | - execute("ccm stop"); | |
| 239 | + execute(CCM_COMMAND + " stop"); | |
| 215 | 240 | } |
| 216 | 241 | |
| 217 | 242 | public void forceStop() { |
| 218 | - execute("ccm stop --not-gently"); | |
| 243 | + execute(CCM_COMMAND + " stop --not-gently"); | |
| 219 | 244 | } |
| 220 | 245 | |
| 221 | 246 | public void start(int n) { |
| 222 | 247 | 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); | |
| 224 | 249 | } |
| 225 | 250 | |
| 226 | 251 | public void start(int n, String option) { |
| 227 | 252 | 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); | |
| 229 | 254 | } |
| 230 | 255 | |
| 231 | 256 | public void stop(int n) { |
| 232 | 257 | logger.info("Stopping: " + IP_PREFIX + n); |
| 233 | - execute("ccm node%d stop", n); | |
| 258 | + execute(CCM_COMMAND + " node%d stop", n); | |
| 234 | 259 | } |
| 235 | 260 | |
| 236 | 261 | public void stop(String clusterName) { |
| 237 | 262 | logger.info("Stopping Cluster : "+clusterName); |
| 238 | - execute("ccm stop "+clusterName); | |
| 263 | + execute(CCM_COMMAND + " stop "+clusterName); | |
| 239 | 264 | } |
| 240 | 265 | |
| 241 | 266 | public void forceStop(int n) { |
| 242 | 267 | 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); | |
| 244 | 269 | } |
| 245 | 270 | |
| 246 | 271 | public void remove() { |
| 247 | 272 | stop(); |
| 248 | - execute("ccm remove"); | |
| 273 | + execute(CCM_COMMAND + " remove"); | |
| 249 | 274 | } |
| 250 | 275 | |
| 251 | 276 | public void remove(String clusterName) { |
| 252 | 277 | stop(clusterName); |
| 253 | - execute("ccm remove " + clusterName); | |
| 278 | + execute(CCM_COMMAND + " remove " + clusterName); | |
| 254 | 279 | } |
| 255 | 280 | |
| 256 | 281 | public void remove(int n) { |
| 257 | 282 | logger.info("Removing: " + IP_PREFIX + n); |
| 258 | - execute("ccm node%d remove", n); | |
| 283 | + execute(CCM_COMMAND + " node%d remove", n); | |
| 259 | 284 | } |
| 260 | 285 | |
| 261 | 286 | public void bootstrapNode(int n) { |
| @@ -264,10 +289,10 @@ | ||
| 264 | 289 | |
| 265 | 290 | public void bootstrapNode(int n, String dc) { |
| 266 | 291 | 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); | |
| 268 | 293 | 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); | |
| 271 | 296 | } |
| 272 | 297 | |
| 273 | 298 | public void bootstrapNodeWithPorts(int n, int thriftPort, int storagePort, int binaryPort, int jmxPort, int remoteDebugPort) { |
| @@ -275,13 +300,13 @@ | ||
| 275 | 300 | String storageItf = IP_PREFIX + n + ":" + storagePort; |
| 276 | 301 | String binaryItf = IP_PREFIX + n + ":" + binaryPort; |
| 277 | 302 | 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", | |
| 279 | 304 | 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); | |
| 281 | 306 | } |
| 282 | 307 | |
| 283 | 308 | public void decommissionNode(int n) { |
| 284 | - execute("ccm node%d decommission", n); | |
| 309 | + execute(CCM_COMMAND + " node%d decommission", n); | |
| 285 | 310 | } |
| 286 | 311 | |
| 287 | 312 | public void updateConfig(String name, String value) { |
| @@ -293,16 +318,17 @@ | ||
| 293 | 318 | for (Map.Entry<String, String> entry : configs.entrySet()) { |
| 294 | 319 | confStr.append(entry.getKey() + ":" + entry.getValue() + " "); |
| 295 | 320 | } |
| 296 | - execute("ccm updateconf " + confStr); | |
| 321 | + execute(CCM_COMMAND + " updateconf " + confStr); | |
| 297 | 322 | } |
| 298 | 323 | |
| 299 | 324 | 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); | |
| 301 | 326 | } |
| 302 | 327 | |
| 303 | 328 | private void execute(String command, Object... args) { |
| 329 | + | |
| 330 | + String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; | |
| 304 | 331 | try { |
| 305 | - String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir; | |
| 306 | 332 | logger.debug("Executing: " + fullCommand); |
| 307 | 333 | CommandLine cli = CommandLine.parse(fullCommand); |
| 308 | 334 | Executor executor = new DefaultExecutor(); |
| @@ -327,7 +353,7 @@ | ||
| 327 | 353 | throw new RuntimeException(); |
| 328 | 354 | } |
| 329 | 355 | } catch (IOException e) { |
| 330 | - throw new RuntimeException(e); | |
| 356 | + throw new RuntimeException(String.format("The command %s failed to execute", fullCommand), e); | |
| 331 | 357 | } |
| 332 | 358 | } |
| 333 | 359 |