mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-02-25 18:55:28 -06:00
pre-read yaml to construct config model for template params
This commit is contained in:
parent
ea392ad462
commit
3e0f4c2b4a
@ -19,6 +19,9 @@ package io.nosqlbench.engine.api.activityconfig.yaml;
|
||||
|
||||
import io.nosqlbench.engine.api.activityconfig.rawyaml.RawStmtsDocList;
|
||||
import io.nosqlbench.engine.api.util.TagFilter;
|
||||
import io.nosqlbench.nb.api.config.standard.ConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.NBConfigModel;
|
||||
import io.nosqlbench.nb.api.config.standard.Param;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Collectors;
|
||||
@ -26,6 +29,7 @@ import java.util.stream.Collectors;
|
||||
public class StmtsDocList implements Iterable<StmtsDoc> {
|
||||
|
||||
private final RawStmtsDocList rawStmtsDocList;
|
||||
private final Map<String,String> templateVariables = new LinkedHashMap<>();
|
||||
|
||||
public StmtsDocList(RawStmtsDocList rawStmtsDocList) {
|
||||
this.rawStmtsDocList = rawStmtsDocList;
|
||||
@ -108,4 +112,20 @@ public class StmtsDocList implements Iterable<StmtsDoc> {
|
||||
return this.getStmtDocs().get(0).getDescription();
|
||||
}
|
||||
|
||||
public Map<String,String> getTemplateVariables() {
|
||||
return templateVariables;
|
||||
}
|
||||
|
||||
public void addTemplateVariable(String key, String defaultValue) {
|
||||
this.templateVariables.put(key,defaultValue);
|
||||
}
|
||||
|
||||
public NBConfigModel getConfigModel() {
|
||||
ConfigModel cfgmodel = ConfigModel.of(StmtsDocList.class);
|
||||
getTemplateVariables().forEach((k,v) -> {
|
||||
cfgmodel.add(Param.defaultTo(k,v,"template parameter found in the yaml workload"));
|
||||
});
|
||||
return cfgmodel.asReadOnly();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ public class StrInterpolator implements Function<String, String> {
|
||||
.forEach(multimap::add);
|
||||
}
|
||||
|
||||
public StrInterpolator(Map<String, String> basicMap) {
|
||||
public StrInterpolator(Map<String, ?> basicMap) {
|
||||
multimap.add(basicMap);
|
||||
}
|
||||
|
||||
@ -67,7 +67,7 @@ public class StrInterpolator implements Function<String, String> {
|
||||
return after;
|
||||
}
|
||||
|
||||
public Set<String> checkpointAccesses() {
|
||||
public Map<String,String> checkpointAccesses() {
|
||||
return multimap.checkpointAccesses();
|
||||
}
|
||||
|
||||
@ -79,40 +79,42 @@ public class StrInterpolator implements Function<String, String> {
|
||||
|
||||
public static class MultiMap extends StrLookup<String> {
|
||||
|
||||
private final List<Map<String, String>> maps = new ArrayList<>();
|
||||
private final List<Map<String, ?>> maps = new ArrayList<>();
|
||||
private final String warnPrefix = "UNSET";
|
||||
private final Set<String> accesses = new HashSet<>();
|
||||
private final Map<String,String> accesses = new LinkedHashMap<>();
|
||||
|
||||
public void add(Map<String, String> addedMap) {
|
||||
public void add(Map<String, ?> addedMap) {
|
||||
maps.add(addedMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String lookup(String key) {
|
||||
String defval = null;
|
||||
String value = null;
|
||||
|
||||
String[] parts = key.split("[:,]", 2);
|
||||
if (parts.length == 2) {
|
||||
key = parts[0];
|
||||
defval = parts[1];
|
||||
value = parts[1];
|
||||
}
|
||||
accesses.add(key);
|
||||
|
||||
for (Map<String, String> map : maps) {
|
||||
String val = map.get(key);
|
||||
for (Map<String, ?> map : maps) {
|
||||
Object val = map.get(key);
|
||||
if (val != null) {
|
||||
return val;
|
||||
value = val.toString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
String value = (defval != null) ? defval : warnPrefix + ":" + key;
|
||||
value = (value != null) ? value : warnPrefix + ":" + key;
|
||||
|
||||
accesses.put(key,value);
|
||||
logger.debug("Template parameter '" + key + "' applied as '" + value + "'");
|
||||
return value;
|
||||
|
||||
}
|
||||
|
||||
public Set<String> checkpointAccesses() {
|
||||
HashSet<String> accesses = new HashSet<>(this.accesses);
|
||||
public Map<String,String> checkpointAccesses() {
|
||||
LinkedHashMap<String,String> accesses = new LinkedHashMap<>(this.accesses);
|
||||
logger.info("removed template params after applying:" + accesses);
|
||||
this.accesses.clear();
|
||||
return accesses;
|
||||
|
@ -1,6 +1,8 @@
|
||||
package io.nosqlbench.engine.core.lifecycle;
|
||||
|
||||
import io.nosqlbench.engine.api.activityapi.core.ActivityType;
|
||||
import io.nosqlbench.engine.api.activityconfig.StatementsLoader;
|
||||
import io.nosqlbench.engine.api.activityconfig.yaml.StmtsDocList;
|
||||
import io.nosqlbench.engine.api.activityimpl.ActivityDef;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.DriverAdapter;
|
||||
import io.nosqlbench.engine.api.activityimpl.uniform.StandardActivityType;
|
||||
@ -140,6 +142,11 @@ public class ActivityTypeLoader {
|
||||
activityDef.getParams().remove("driver");
|
||||
if (driverAdapter instanceof NBConfigurable) {
|
||||
NBConfigModel cfgModel = ((NBConfigurable) driverAdapter).getConfigModel();
|
||||
Optional<String> op_yaml_loc = activityDef.getParams().getOptionalString("yaml", "workload");
|
||||
if (op_yaml_loc.isPresent()) {
|
||||
StmtsDocList workload = StatementsLoader.loadPath(logger, op_yaml_loc.get(), activityDef.getParams(), "activities");
|
||||
cfgModel=cfgModel.add(workload.getConfigModel());
|
||||
}
|
||||
NBConfiguration cfg = cfgModel.apply(activityDef.getParams());
|
||||
((NBConfigurable) driverAdapter).applyConfig(cfg);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user