enable runtime version check via version_regex yaml property

This commit is contained in:
Jonathan Shook 2022-06-28 18:23:25 -05:00
parent a05dbc834a
commit db327b29e9
5 changed files with 119 additions and 2 deletions

View File

@ -57,4 +57,13 @@
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
</project>

View File

@ -16,9 +16,13 @@
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
@ -33,6 +37,7 @@ public class RawStmtsDoc extends StatementsOwner {
private RawScenarios scenarios = new RawScenarios();
private final List<RawStmtsBlock> blocks = new ArrayList<>();
private String versionRegex = ".+";
// no-args ctor is required
public RawStmtsDoc() {
@ -45,6 +50,17 @@ 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.");
}
}
}
Object blocksObjects = properties.remove("blocks");
if (blocksObjects instanceof List) {
List<Object> blockList = ((List<Object>) blocksObjects);
@ -79,7 +95,6 @@ public class RawStmtsDoc extends StatementsOwner {
}
Object scenariosData = properties.remove("scenarios");
if (scenariosData != null) {
scenarios.setPropertiesByReflection(scenariosData);
}
@ -121,4 +136,12 @@ public class RawStmtsDoc extends StatementsOwner {
this.scenarios = scenarios;
}
public String getVersionRegex() {
return this.versionRegex;
}
public void setVersionRegex(String regex) {
this.versionRegex = regex;
}
}

View File

@ -17,13 +17,18 @@
package io.nosqlbench.engine.api.activityconfig.yaml;
import io.nosqlbench.engine.api.activityconfig.StatementsLoader;
import io.nosqlbench.engine.api.activityconfig.rawyaml.RawStmtsDoc;
import io.nosqlbench.engine.api.activityconfig.rawyaml.RawStmtsDocList;
import io.nosqlbench.engine.api.util.TagFilter;
import io.nosqlbench.nb.api.config.standard.*;
import io.nosqlbench.nb.api.config.standard.ConfigModel;
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
import io.nosqlbench.nb.api.config.standard.NBConfigModelExpander;
import io.nosqlbench.nb.api.config.standard.Param;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import java.util.*;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
public class StmtsDocList implements Iterable<StmtsDoc> {
@ -156,4 +161,9 @@ public class StmtsDocList implements Iterable<StmtsDoc> {
StmtsDocList loaded = StatementsLoader.loadPath(logger, (String) workload, "activities");
return loaded.getConfigModel();
};
public Pattern getVersionRegex() {
List<RawStmtsDoc> stmtDocs = rawStmtsDocList.getStmtsDocs();
return Pattern.compile(stmtDocs.size()>0 ? stmtDocs.get(0).getVersionRegex() : ".*");
}
}

View File

@ -0,0 +1,56 @@
/*
* Copyright (c) 2022 nosqlbench
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.nosqlbench.engine.api.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class AdaptersApiVersionInfo {
private final Properties versionProperties = new Properties();
public AdaptersApiVersionInfo() {
InputStream versionStream = getClass().getResourceAsStream("/version.properties");
try {
versionProperties.load(versionStream);
} catch (IOException e) {
throw new RuntimeException("unable to read version properties:" + e);
}
}
public String getVersion() {
return versionProperties.getProperty("version");
}
public String getArtifactId() {
return versionProperties.getProperty("artifactId");
}
public String getGroupId() {
return versionProperties.getProperty("groupId");
}
public String getArtifactCoordinates() {
return "<dependency>\n" +
" <groupId>" + getGroupId() + "</groupId>\n" +
" <artifactId>"+ getArtifactId() + "</artifactId>\n" +
" <version>" + getVersion() + "</version>\n" +
"</dependency>";
}
}

View File

@ -0,0 +1,19 @@
#
# Copyright (c) 2022 nosqlbench
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
version=${project.version}
groupId=${project.groupId}
artifactId=${project.artifactId}