Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

3.x: Allow additional scylla.version formats #396

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
dkropachev marked this conversation as resolved.
Show resolved Hide resolved

/**
* 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