workload files can now require version via min_version or version_regex

This commit is contained in:
Jonathan Shook 2022-06-29 20:45:31 -05:00
parent c55bbfc127
commit 359edac3aa
2 changed files with 42 additions and 10 deletions
adapters-api/src/main/java/io/nosqlbench/engine/api

View File

@ -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);

View File

@ -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.");
}
}
}
}