diff --git a/adapters-api/pom.xml b/adapters-api/pom.xml index d6f0929c6..910afaed1 100644 --- a/adapters-api/pom.xml +++ b/adapters-api/pom.xml @@ -57,4 +57,13 @@ + + + + src/main/resources + true + + + + diff --git a/adapters-api/src/main/java/io/nosqlbench/engine/api/activityconfig/rawyaml/RawStmtsDoc.java b/adapters-api/src/main/java/io/nosqlbench/engine/api/activityconfig/rawyaml/RawStmtsDoc.java index 6c413e34c..0d6aa3d8d 100644 --- a/adapters-api/src/main/java/io/nosqlbench/engine/api/activityconfig/rawyaml/RawStmtsDoc.java +++ b/adapters-api/src/main/java/io/nosqlbench/engine/api/activityconfig/rawyaml/RawStmtsDoc.java @@ -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 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 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 blockList = ((List) 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; + } + } diff --git a/adapters-api/src/main/java/io/nosqlbench/engine/api/activityconfig/yaml/StmtsDocList.java b/adapters-api/src/main/java/io/nosqlbench/engine/api/activityconfig/yaml/StmtsDocList.java index 67422c8bc..2af520c93 100644 --- a/adapters-api/src/main/java/io/nosqlbench/engine/api/activityconfig/yaml/StmtsDocList.java +++ b/adapters-api/src/main/java/io/nosqlbench/engine/api/activityconfig/yaml/StmtsDocList.java @@ -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 { @@ -156,4 +161,9 @@ public class StmtsDocList implements Iterable { StmtsDocList loaded = StatementsLoader.loadPath(logger, (String) workload, "activities"); return loaded.getConfigModel(); }; + + public Pattern getVersionRegex() { + List stmtDocs = rawStmtsDocList.getStmtsDocs(); + return Pattern.compile(stmtDocs.size()>0 ? stmtDocs.get(0).getVersionRegex() : ".*"); + } } diff --git a/adapters-api/src/main/java/io/nosqlbench/engine/api/util/AdaptersApiVersionInfo.java b/adapters-api/src/main/java/io/nosqlbench/engine/api/util/AdaptersApiVersionInfo.java new file mode 100644 index 000000000..299c55e77 --- /dev/null +++ b/adapters-api/src/main/java/io/nosqlbench/engine/api/util/AdaptersApiVersionInfo.java @@ -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 "\n" + + " " + getGroupId() + "\n" + + " "+ getArtifactId() + "\n" + + " " + getVersion() + "\n" + + ""; + } + +} diff --git a/adapters-api/src/main/resources/version.properties b/adapters-api/src/main/resources/version.properties new file mode 100644 index 000000000..fc4cf67cb --- /dev/null +++ b/adapters-api/src/main/resources/version.properties @@ -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}