Skip to content

Commit

Permalink
Allow additional scylla.version formats
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Bouncheck committed Dec 11, 2024
1 parent 95fa50b commit e095a13
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 9 deletions.
56 changes: 51 additions & 5 deletions driver-core/src/test/java/com/datastax/driver/core/CCMBridge.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ public class CCMBridge implements CCMAccess {
static {
String inputCassandraVersion = System.getProperty("cassandra.version");
String inputScyllaVersion = System.getProperty("scylla.version");
GLOBAL_SCYLLA_VERSION_NUMBER = parseScyllaInputVersion(inputScyllaVersion);

String installDirectory = System.getProperty("cassandra.directory");
String branch = System.getProperty("cassandra.branch");
Expand All @@ -206,8 +207,11 @@ public class CCMBridge implements CCMAccess {
installArgs.add("-v git:" + branch.trim().replaceAll("\"", ""));
} else if (inputScyllaVersion != null && !inputScyllaVersion.trim().isEmpty()) {
installArgs.add(" --scylla ");
installArgs.add("-v release:" + inputScyllaVersion);

if (isVersionNumber(inputScyllaVersion)) {
installArgs.add("-v release:" + inputScyllaVersion);
} else {
installArgs.add("-v " + inputScyllaVersion);
}
// Detect Scylla Enterprise - it should start with
// a 4-digit year.
if (inputScyllaVersion.matches("\\d{4}\\..*")) {
Expand Down Expand Up @@ -246,8 +250,6 @@ public class CCMBridge implements CCMAccess {
}
ENVIRONMENT_MAP = ImmutableMap.copyOf(envMap);

GLOBAL_SCYLLA_VERSION_NUMBER = VersionNumber.parse(inputScyllaVersion);

if (isDse()) {
GLOBAL_DSE_VERSION_NUMBER = VersionNumber.parse(inputCassandraVersion);
GLOBAL_CASSANDRA_VERSION_NUMBER = CCMBridge.getCassandraVersion(GLOBAL_DSE_VERSION_NUMBER);
Expand Down Expand Up @@ -338,6 +340,28 @@ public static boolean isWindows() {
return osName != null && osName.startsWith("Windows");
}

private static boolean isVersionNumber(String versionString) {
try {
VersionNumber.parse(versionString);
} catch (IllegalArgumentException e) {
return false;
}
return true;
}

private static VersionNumber parseScyllaInputVersion(String versionString) {
VersionNumber parsedScyllaVersionNumber = null;
try {
parsedScyllaVersionNumber = VersionNumber.parse(versionString);
} catch (IllegalArgumentException e) {
logger.warn(
"Failed to parse scylla.version: " + versionString + ". Trying to get it through CCM.",
e);
parsedScyllaVersionNumber = getScyllaVersionThroughCcm(versionString);
}
return parsedScyllaVersionNumber;
}

private final String clusterName;

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

private String execute(String command, Object... args) {
private static VersionNumber getScyllaVersionThroughCcm(String versionString) {
File configDir = Files.createTempDir();
try {
execute(configDir, "ccm create get_version -n 1 --scylla --version %s", versionString);
String versionOutput = execute(configDir, "ccm node1 versionfrombuild");
return VersionNumber.parse(versionOutput.replace("ccmout> ", "").trim());
} catch (RuntimeException cause) {
throw new RuntimeException(
"Error during getting Scylla version through ccm commands.", cause);
} finally {
try {
execute(configDir, "ccm remove get_version");
} catch (Exception ignored) {
}
}
}

private static String execute(File ccmDir, String command, Object... args) {
Logger logger = CCMBridge.logger;
String fullCommand = String.format(command, args) + " --config-dir=" + ccmDir;
Closer closer = Closer.create();
// 10 minutes timeout
Expand Down Expand Up @@ -856,6 +898,10 @@ protected void processLine(String line, int logLevel) {
return sw.toString();
}

private String execute(String command, Object... args) {
return execute(this.ccmDir, command, args);
}

/**
* Waits for a host to be up by pinging the TCP socket directly, without using the Java driver's
* API.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public void replace_cluster_test() {
logger.info("Queried node has broadcast_address: {}}", address);
System.out.flush();
} finally {
assert bridgeA != null;
bridgeA.close();
if (bridgeA != null) bridgeA.close();
}

CCMBridge bridgeB = null;
Expand All @@ -72,8 +71,7 @@ public void replace_cluster_test() {
} catch (InterruptedException e) {
throw new RuntimeException(e);
} finally {
assert bridgeB != null;
bridgeB.close();
if (bridgeB != null) bridgeB.close();
}
}

Expand Down

0 comments on commit e095a13

Please sign in to comment.