Quick fix for nested Templates that were breaking --list-workloads

This commit is contained in:
Mike Yaacoub 2024-06-30 21:02:23 -04:00
parent 52e9a1a14f
commit eb1adcff5e
5 changed files with 18 additions and 18 deletions

View File

@ -0,0 +1,4 @@
min_version: "5.21.0"
description: |
TBD, similar to find_one_and_delete.yaml

View File

@ -6,4 +6,4 @@ blocks:
list_collection_names:
ops:
op1:
list_collection_names:
list_collection_names: "TEMPLATE(collection1)"

View File

@ -6,4 +6,4 @@ blocks:
list_collections:
ops:
op1:
list_collections:
list_collections: "TEMPLATE(collection1)"

View File

@ -140,7 +140,7 @@ public class RawOpDef extends RawOpFields {
if (v == null) {
throw new OpConfigError("A map key '" + k.toString() + "' with a null value was encountered. This is not" +
" allowed, and may be the result of using an unquoted binding, like {" + k + "}. You can simply wrap this in quotes" +
" like \"{"+ k +"\"} to avoid interpreting this as a JSON map." +
" like \"{"+ k +"}\" to avoid interpreting this as a JSON map." +
(path.size()>0 ? String.join(".",path):""));
} else {
if (v instanceof Map) {

View File

@ -313,7 +313,7 @@ public class NBCLIScenarioPreprocessor {
}
private static final Pattern templatePattern = Pattern.compile("TEMPLATE\\((.+?)\\)");
private static final Pattern innerTemplatePattern = Pattern.compile("TEMPLATE\\((.+?)$");
private static final Pattern innerTemplatePattern = Pattern.compile("TEMPLATE\\((.+?)\\)");
private static final Pattern templatePattern2 = Pattern.compile("<<(.+?)>>");
public static List<WorkloadDesc> filterForScenarios(List<Content<?>> candidates) {
@ -444,22 +444,18 @@ public class NBCLIScenarioPreprocessor {
String match = matcher.group(1);
Matcher innerMatcher = innerTemplatePattern.matcher(match);
String[] matchArray = match.split("[,:]");
if (matchArray.length==1) {
matchArray = new String[]{matchArray[0],""};
}
// if (matchArray.length!=2) {
// throw new BasicError("TEMPLATE form must have two arguments separated by a comma, like 'TEMPLATE(a,b), not '" + match +"'");
// }
//TODO: support recursive matches
if (innerMatcher.find()) {
String[] innerMatch = innerMatcher.group(1).split("[,:]");
//We want the outer name with the inner default value
templates.put(matchArray[0], innerMatch[1]);
} else {
templates.put(matchArray[0], matchArray[1]);
String innerMatch = innerMatcher.group(1);
templates = matchTemplates("TEMPLATE(" + innerMatch + ")", templates);
String resolvedInner = templates.getOrDefault(innerMatch.split("[,:]")[0], "");
match = match.replace("TEMPLATE(" + innerMatch + ")", resolvedInner);
}
String[] matchArray = match.split("[,:]");
if (matchArray.length == 1) {
matchArray = new String[]{matchArray[0], ""};
}
templates.put(matchArray[0], matchArray[1]);
}
matcher = templatePattern2.matcher(line);