Skip to content

Commit 05c4824

Browse files
authored
Allow additional scylla.version formats (#396)
Modifies version parsing logic to try passing the `scylla.version` to the CCM when it can't be parsed as VersionNumber. If CCM manages to run `create` with it, then the usual version number is fetched from `ccm node versionfrombuild` output. To do that we introduce a static version of `execute`. The method body is nearly the same. Functionally should be the same. Previous version now calls the static one.
1 parent 204be3a commit 05c4824

File tree

2 files changed

+53
-9
lines changed

2 files changed

+53
-9
lines changed

driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java

Lines changed: 51 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,7 @@ public class CCMBridge implements CCMAccess {
194194
static {
195195
String inputCassandraVersion = System.getProperty("cassandra.version");
196196
String inputScyllaVersion = System.getProperty("scylla.version");
197+
GLOBAL_SCYLLA_VERSION_NUMBER = parseScyllaInputVersion(inputScyllaVersion);
197198

198199
String installDirectory = System.getProperty("cassandra.directory");
199200
String branch = System.getProperty("cassandra.branch");
@@ -206,8 +207,11 @@ public class CCMBridge implements CCMAccess {
206207
installArgs.add("-v git:" + branch.trim().replaceAll("\"", ""));
207208
} else if (inputScyllaVersion != null && !inputScyllaVersion.trim().isEmpty()) {
208209
installArgs.add(" --scylla ");
209-
installArgs.add("-v release:" + inputScyllaVersion);
210-
210+
if (isVersionNumber(inputScyllaVersion)) {
211+
installArgs.add("-v release:" + inputScyllaVersion);
212+
} else {
213+
installArgs.add("-v " + inputScyllaVersion);
214+
}
211215
// Detect Scylla Enterprise - it should start with
212216
// a 4-digit year.
213217
if (inputScyllaVersion.matches("\\d{4}\\..*")) {
@@ -246,8 +250,6 @@ public class CCMBridge implements CCMAccess {
246250
}
247251
ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap);
248252

249-
GLOBAL_SCYLLA_VERSION_NUMBER = VersionNumber.parse(inputScyllaVersion);
250-
251253
if (isDse()) {
252254
GLOBAL_DSE_VERSION_NUMBER = VersionNumber.parse(inputCassandraVersion);
253255
GLOBAL_CASSANDRA_VERSION_NUMBER = CCMBridge.getCassandraVersion(GLOBAL_DSE_VERSION_NUMBER);
@@ -338,6 +340,28 @@ public static boolean isWindows() {
338340
return osName != null && osName.startsWith("Windows");
339341
}
340342

343+
private static boolean isVersionNumber(String versionString) {
344+
try {
345+
VersionNumber.parse(versionString);
346+
} catch (IllegalArgumentException e) {
347+
return false;
348+
}
349+
return true;
350+
}
351+
352+
private static VersionNumber parseScyllaInputVersion(String versionString) {
353+
VersionNumber parsedScyllaVersionNumber = null;
354+
try {
355+
parsedScyllaVersionNumber = VersionNumber.parse(versionString);
356+
} catch (IllegalArgumentException e) {
357+
logger.warn(
358+
"Failed to parse scylla.version: " + versionString + ". Trying to get it through CCM.",
359+
e);
360+
parsedScyllaVersionNumber = getScyllaVersionThroughCcm(versionString);
361+
}
362+
return parsedScyllaVersionNumber;
363+
}
364+
341365
private final String clusterName;
342366

343367
private final VersionNumber cassandraVersion;
@@ -792,7 +816,25 @@ public void setWorkload(int node, Workload... workload) {
792816
execute(CCM_COMMAND + " node%d setworkload %s", node, workloadStr);
793817
}
794818

795-
private String execute(String command, Object... args) {
819+
private static VersionNumber getScyllaVersionThroughCcm(String versionString) {
820+
File configDir = Files.createTempDir();
821+
try {
822+
execute(configDir, "ccm create get_version -n 1 --scylla --version %s", versionString);
823+
String versionOutput = execute(configDir, "ccm node1 versionfrombuild");
824+
return VersionNumber.parse(versionOutput.replace("ccmout> ", "").trim());
825+
} catch (RuntimeException cause) {
826+
throw new RuntimeException(
827+
"Error during getting Scylla version through ccm commands.", cause);
828+
} finally {
829+
try {
830+
execute(configDir, "ccm remove get_version");
831+
} catch (Exception ignored) {
832+
}
833+
}
834+
}
835+
836+
private static String execute(File ccmDir, String command, Object... args) {
837+
Logger logger = CCMBridge.logger;
796838
String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir;
797839
Closer closer = Closer.create();
798840
// 10 minutes timeout
@@ -856,6 +898,10 @@ protected void processLine(String line, int logLevel) {
856898
return sw.toString();
857899
}
858900

901+
private String execute(String command, Object... args) {
902+
return execute(this.ccmDir, command, args);
903+
}
904+
859905
/**
860906
* Waits for a host to be up by pinging the TCP socket directly, without using the Java driver's
861907
* API.

driver-core/src/test/java/com/datastax/driver/core/DnsEndpointTests.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ public void replace_cluster_test() {
4747
logger.info("Queried node has broadcast_address: {}}", address);
4848
System.out.flush();
4949
} finally {
50-
assert bridgeA != null;
51-
bridgeA.close();
50+
if (bridgeA != null) bridgeA.close();
5251
}
5352

5453
CCMBridge bridgeB = null;
@@ -72,8 +71,7 @@ public void replace_cluster_test() {
7271
} catch (InterruptedException e) {
7372
throw new RuntimeException(e);
7473
} finally {
75-
assert bridgeB != null;
76-
bridgeB.close();
74+
if (bridgeB != null) bridgeB.close();
7775
}
7876
}
7977

0 commit comments

Comments
 (0)