mirror of
https://github.com/nosqlbench/nosqlbench.git
synced 2025-01-13 09:22:05 -06:00
move scenario formatting to WorkloadDesc, include description support, alphabetize templates
This commit is contained in:
parent
d120deed79
commit
8a8a1169f1
@ -1,4 +1,7 @@
|
||||
# nb -v run driver=cql yaml=cql-iot tags=phase:schema host=dsehost
|
||||
description: |
|
||||
This workload emulates a time-series data model and access patterns.
|
||||
|
||||
scenarios:
|
||||
default:
|
||||
- run driver=cql tags==phase:schema threads==1 cycles==UNDEF
|
||||
|
@ -108,4 +108,7 @@ public class StmtsDoc implements Tagged, Iterable<StmtsBlock> {
|
||||
return new Scenarios(rawStmtsDoc.getRawScenarios());
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return rawStmtsDoc.getDesc();
|
||||
}
|
||||
}
|
||||
|
@ -89,8 +89,18 @@ public class StmtsDocList implements Iterable<StmtsDoc> {
|
||||
* on the first doc, any `scenarios` defined in different docs will be ignored.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @return the list of named scenarios for the first document in the list.
|
||||
*/
|
||||
public Scenarios getDocScenarios() {
|
||||
return this.getStmtDocs().get(0).getScenarios();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description of the first document in the list.
|
||||
*/
|
||||
public String getDescription() {
|
||||
return this.getStmtDocs().get(0).getDescription();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ import io.nosqlbench.engine.api.templating.StrInterpolator;
|
||||
import io.nosqlbench.nb.api.content.Content;
|
||||
import io.nosqlbench.nb.api.content.NBIO;
|
||||
import io.nosqlbench.nb.api.errors.BasicError;
|
||||
import io.nosqlbench.virtdata.library.basics.core.stathelpers.DiscreteProbabilityBuffer;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -240,77 +241,10 @@ public class NBCLIScenarioParser {
|
||||
}
|
||||
}
|
||||
|
||||
// private static void parseWorkloadYamlCmds(String yamlPath, LinkedList<String> arglist, String scenarioName) {
|
||||
// StmtsDocList stmts = StatementsLoader.load(logger, yamlPath);
|
||||
//
|
||||
// Scenarios scenarios = stmts.getDocScenarios();
|
||||
//
|
||||
// String scenarioName = "default";
|
||||
// if (scenarioName != null) {
|
||||
// scenarioName = scenarioName;
|
||||
// }
|
||||
//
|
||||
// List<String> cmds = scenarios.getNamedScenario(scenarioName);
|
||||
//
|
||||
//
|
||||
// Map<String, String> paramMap = new HashMap<>();
|
||||
// while (arglist.size() > 0 && arglist.peekFirst().contains("=")) {
|
||||
// String arg = arglist.removeFirst();
|
||||
// String oldArg = arg;
|
||||
// arg = Synonyms.canonicalize(arg, logger);
|
||||
//
|
||||
// for (int i = 0; i < cmds.size(); i++) {
|
||||
// String yamlCmd = cmds.get(i);
|
||||
// String[] argArray = arg.split("=");
|
||||
// String argKey = argArray[0];
|
||||
// String argValue = argArray[1];
|
||||
// if (!yamlCmd.contains(argKey)) {
|
||||
// cmds.set(i, yamlCmd + " " + arg);
|
||||
// } else {
|
||||
// paramMap.put(argKey, argValue);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
//
|
||||
// if (cmds == null) {
|
||||
// List<String> names = scenarios.getScenarioNames();
|
||||
// throw new RuntimeException("Unknown scenario name, make sure the scenario name you provide exists in the workload definition (yaml):\n" + String.join(",", names));
|
||||
// }
|
||||
//
|
||||
// for (String cmd : cmds) {
|
||||
// String[] cmdArray = cmd.split(" ");
|
||||
//
|
||||
// for (String parameter : cmdArray) {
|
||||
// if (parameter.contains("=")) {
|
||||
// if (!parameter.contains("TEMPLATE(") && !parameter.contains("<<")) {
|
||||
// String[] paramArray = parameter.split("=");
|
||||
// paramMap.put(paramArray[0], paramArray[1]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// StrSubstitutor sub1 = new StrSubstitutor(paramMap, "<<", ">>", '\\', ",");
|
||||
// StrSubstitutor sub2 = new StrSubstitutor(paramMap, "TEMPLATE(", ")", '\\', ",");
|
||||
//
|
||||
// cmd = sub2.replace(sub1.replace(cmd));
|
||||
//
|
||||
// if (cmd.contains("yaml=") || cmd.contains("workload=")) {
|
||||
// parse(cmd.split(" "));
|
||||
// } else {
|
||||
// parse((cmd + " workload=" + yamlPath).split(" "));
|
||||
// }
|
||||
//
|
||||
// // Is there a better way to do this than regex?
|
||||
//
|
||||
// }
|
||||
// }
|
||||
|
||||
private static Pattern templatePattern = Pattern.compile("TEMPLATE\\((.+?)\\)");
|
||||
private static Pattern innerTemplatePattern = Pattern.compile("TEMPLATE\\((.+?)$");
|
||||
private static Pattern templatePattern2 = Pattern.compile("<<(.+?)>>");
|
||||
|
||||
|
||||
public static List<WorkloadDesc> getWorkloadsWithScenarioScripts(String... includes) {
|
||||
|
||||
List<Content<?>> activities = NBIO.all()
|
||||
@ -334,7 +268,7 @@ public class NBCLIScenarioParser {
|
||||
|
||||
StmtsDocList stmts = StatementsLoader.load(logger, content);
|
||||
|
||||
Map<String, String> templates = new HashMap<>();
|
||||
Map<String, String> templates = new LinkedHashMap<>();
|
||||
try {
|
||||
List<String> lines = Files.readAllLines(yamlPath);
|
||||
for (String line : lines) {
|
||||
@ -352,7 +286,15 @@ public class NBCLIScenarioParser {
|
||||
if (scenarioNames != null && scenarioNames.size() > 0) {
|
||||
String path = yamlPath.toString();
|
||||
path = path.startsWith(FileSystems.getDefault().getSeparator()) ? path.substring(1) : path;
|
||||
workloadDescriptions.add(new WorkloadDesc(path, scenarioNames, templates));
|
||||
LinkedHashMap<String,String> sortedTemplates = new LinkedHashMap<>();
|
||||
ArrayList<String> keyNames = new ArrayList<>(templates.keySet());
|
||||
Collections.sort(keyNames);
|
||||
for (String keyName : keyNames) {
|
||||
sortedTemplates.put(keyName,templates.get(keyName));
|
||||
}
|
||||
|
||||
String description = stmts.getDescription();
|
||||
workloadDescriptions.add(new WorkloadDesc(path, scenarioNames, sortedTemplates, description));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7,20 +7,24 @@ public class WorkloadDesc {
|
||||
private final String yamlPath;
|
||||
private final List<String> scenarioNames;
|
||||
private final Map<String, String> templates;
|
||||
private final String description;
|
||||
|
||||
public WorkloadDesc(String yamlPath, List<String> scenarioNames, Map<String, String> templates) {
|
||||
public WorkloadDesc(String yamlPath,
|
||||
List<String> scenarioNames,
|
||||
Map<String, String> templates,
|
||||
String description) {
|
||||
this.yamlPath = yamlPath;
|
||||
this.scenarioNames = scenarioNames;
|
||||
this.templates = templates;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public String getYamlPath() {
|
||||
return yamlPath;
|
||||
}
|
||||
|
||||
public String getWorkloadName(){
|
||||
public String getWorkloadName() {
|
||||
return getYamlPath().replaceAll("\\.yaml", "");
|
||||
|
||||
}
|
||||
|
||||
public List<String> getScenarioNames() {
|
||||
@ -30,4 +34,53 @@ public class WorkloadDesc {
|
||||
public Map<String, String> getTemplates() {
|
||||
return templates;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return this.description != null ? this.description : "";
|
||||
}
|
||||
|
||||
|
||||
public String toString() {
|
||||
return toString(true);
|
||||
}
|
||||
|
||||
public String toString(boolean includeScenarios) {
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
if (includeScenarios) {
|
||||
sb.append("# workload in ");
|
||||
}
|
||||
sb.append(getYamlPath()).append("\n");
|
||||
|
||||
if (!description.isEmpty()) {
|
||||
sb.append("# description:\n").append(description);
|
||||
if (!description.endsWith("\n")) {
|
||||
sb.append("\n");
|
||||
}
|
||||
}
|
||||
if (includeScenarios) {
|
||||
sb.append(" # scenarios:\n");
|
||||
|
||||
for (String scenario : getScenarioNames()) {
|
||||
sb.append(" nb ")
|
||||
.append(this.getWorkloadName())
|
||||
.append(" ").append(scenario).append("\n");
|
||||
}
|
||||
|
||||
|
||||
if (templates.size() > 0) {
|
||||
sb.append(" # defaults\n");
|
||||
}
|
||||
|
||||
for (Map.Entry<String, String> templateEntry : templates.entrySet()) {
|
||||
sb.append(" ")
|
||||
.append(templateEntry.getKey()).append(" = ").append(templateEntry.getValue())
|
||||
.append("\n");
|
||||
}
|
||||
sb.append("\n");
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -13,31 +13,8 @@ public class NBCLIScenarios {
|
||||
NBCLIScenarioParser.getWorkloadsWithScenarioScripts(includes);
|
||||
|
||||
for (WorkloadDesc workload : workloads) {
|
||||
if (includeScenarios) {
|
||||
System.out.print("# workload in ");
|
||||
}
|
||||
System.out.println(workload.toString(includeScenarios));
|
||||
|
||||
System.out.println(workload.getYamlPath());
|
||||
|
||||
if (includeScenarios) {
|
||||
System.out.println(" # scenarios:");
|
||||
|
||||
List<String> scenarioList = workload.getScenarioNames();
|
||||
String workloadName = workload.getWorkloadName();
|
||||
|
||||
for (String scenario : scenarioList) {
|
||||
System.out.println(" nb " + workloadName + " " + scenario);
|
||||
}
|
||||
|
||||
Map<String, String> templates = workload.getTemplates();
|
||||
if (templates.size() > 0) {
|
||||
System.out.println(" # defaults");
|
||||
for (Map.Entry<String, String> templateEntry : templates.entrySet()) {
|
||||
System.out.println(" " + templateEntry.getKey() + " = " + templateEntry.getValue());
|
||||
}
|
||||
}
|
||||
System.out.println("\n");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user