mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
workload files can now require version via min_version or version_regex
This commit is contained in:
parent
c55bbfc127
commit
359edac3aa
adapters-api/src/main/java/io/nosqlbench/engine/api
@ -17,12 +17,10 @@
|
||||
package io.nosqlbench.engine.api.activityconfig.rawyaml;
|
||||
|
||||
import io.nosqlbench.engine.api.util.AdaptersApiVersionInfo;
|
||||
import io.nosqlbench.nb.api.errors.OpConfigError;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* A statements doc can have both a list of statement blocks and/or a
|
||||
@ -52,15 +50,13 @@ public class RawStmtsDoc extends StatementsOwner {
|
||||
public void setFieldsByReflection(Map<String, Object> properties) {
|
||||
if (properties.containsKey("version_regex")) {
|
||||
String versionRegex = properties.remove("version_regex").toString();
|
||||
if (versionRegex!=null) {
|
||||
Pattern versionpattern = Pattern.compile(versionRegex);
|
||||
String version = new AdaptersApiVersionInfo().getVersion();
|
||||
if (!versionpattern.matcher(version).matches()) {
|
||||
throw new OpConfigError("Unable to load yaml with this version '" + version + " since " +
|
||||
"the required version doesn't match version_regex '" + versionRegex + "' from yaml.");
|
||||
}
|
||||
}
|
||||
new AdaptersApiVersionInfo().assertVersionPattern(versionRegex);
|
||||
}
|
||||
if (properties.containsKey("min_version")) {
|
||||
String min_version = properties.remove("min_version").toString();
|
||||
new AdaptersApiVersionInfo().assertNewer(min_version);
|
||||
}
|
||||
|
||||
Object blocksObjects = properties.remove("blocks");
|
||||
if (blocksObjects instanceof List) {
|
||||
List<Object> blockList = ((List<Object>) blocksObjects);
|
||||
|
@ -16,9 +16,12 @@
|
||||
|
||||
package io.nosqlbench.engine.api.util;
|
||||
|
||||
import io.nosqlbench.nb.api.errors.OpConfigError;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Properties;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class AdaptersApiVersionInfo {
|
||||
|
||||
@ -53,4 +56,37 @@ public class AdaptersApiVersionInfo {
|
||||
"</dependency>";
|
||||
}
|
||||
|
||||
public void assertNewer(String min_version) {
|
||||
String[] min_components = min_version.split("\\.|-|_");
|
||||
String[] current_components = getVersion().split("\\.|-|_");
|
||||
for (int i = 0; i < min_components.length; i++) {
|
||||
String minField = min_components[i];
|
||||
String currentField = current_components[i];
|
||||
if (minField.matches("\\d+")) {
|
||||
if (currentField.matches("\\d+")) {
|
||||
if (Integer.parseInt(currentField)<Integer.parseInt(minField)) {
|
||||
throw new OpConfigError("This workload can only be loaded by a NoSQLBench runtime version " + min_version + " or higher." +
|
||||
" You are running version " + getVersion());
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new OpConfigError("could not compare min_version '" + min_version + " to current version " + getVersion());
|
||||
}
|
||||
} else {
|
||||
throw new OpConfigError("It is impossible to compare min_version " + min_version + " numerically with " + getVersion());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void assertVersionPattern(String versionRegex) {
|
||||
if (versionRegex!=null) {
|
||||
Pattern versionpattern = Pattern.compile(versionRegex);
|
||||
String version = new AdaptersApiVersionInfo().getVersion();
|
||||
if (!versionpattern.matcher(version).matches()) {
|
||||
throw new OpConfigError("Unable to load yaml with this version '" + version + " since " +
|
||||
"the required version doesn't match version_regex '" + versionRegex + "' from yaml.");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user