Skip to content

Commit

Permalink
issue #907 resolution
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kurilov committed Jan 10, 2017
1 parent 62a19f1 commit aaa4773
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 18 deletions.
4 changes: 2 additions & 2 deletions config/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"fsAccess" : false,
"headers" : {
"Connection" : "Keep-Alive",
"User-Agent" : "mongoose/3.0.3"
"User-Agent" : "mongoose/3.0.4"
},
"namespace" : null,
"versioning" : false
Expand Down Expand Up @@ -182,5 +182,5 @@
"node": false
}
},
"version" : "3.0.3"
"version" : "3.0.4"
}
9 changes: 7 additions & 2 deletions run/src/main/java/com/emc/mongoose/run/scenario/ForJob.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,19 +191,20 @@ protected void loadSubTree(final Map<String, Object> subTree)
}

final Object nodeConfig = subTree.get(KEY_NODE_CONFIG);
if(nodeConfig != null) {
/*if(nodeConfig != null) {
if(nodeConfig instanceof Map) {
localConfig.apply((Map<String, Object>) nodeConfig);
} else {
throw new ScenarioParseException(
"Invalid config node type: \"" + nodeConfig.getClass() + "\""
);
}
}
}*/

final Object jobTreeList = subTree.get(KEY_NODE_JOBS);
final String replacePattern = Character.toString(REPLACE_MARKER_CHAR) + FORMAT_CHARS[0] +
replaceMarkerName + FORMAT_CHARS[1];
Map<String, Object> nextNodeConfig;
try {
if(jobTreeList != null) {
if(jobTreeList instanceof List) {
Expand All @@ -213,6 +214,10 @@ protected void loadSubTree(final Map<String, Object> subTree)
childJobConfig = ConfigParser.replace(
localConfig, replacePattern, nextValue
);
nextNodeConfig = ConfigParser.replace(
(Map<String, Object>) nodeConfig, replacePattern, nextValue
);
childJobConfig.apply(nextNodeConfig);
append(
new BasicTaskJob(
() -> LOG.info(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringJoiner;
import java.util.regex.Pattern;

import static com.emc.mongoose.common.Constants.DIR_CONFIG;
Expand Down Expand Up @@ -42,18 +45,10 @@ public static Config replace(
final String rp = Pattern.quote(replacePattern);
if(newValue == null) {
newConfigText = configText.replaceAll("\"" + rp + "\"", "null");
} else if(newValue instanceof Boolean) {
} else if(newValue instanceof Boolean || newValue instanceof Number) {
newConfigText = configText
.replaceAll("\"" + rp + "\"", newValue.toString())
.replaceAll(rp, newValue.toString());
} else if(newValue instanceof Long) {
newConfigText = configText
.replaceAll("\"" + rp + "\"", newValue.toString())
.replaceAll(rp, newValue.toString());
} else if(newValue instanceof Double) {
newConfigText = configText
.replaceAll("\"" + rp+ "\"", newValue.toString())
.replaceAll(rp, newValue.toString());
} else if(newValue instanceof List) {
final List<Object> newValues = (List<Object>) newValue;
final List<String> newStrValues = new ArrayList<>();
Expand All @@ -63,11 +58,7 @@ public static Config replace(
nextValue = newValues.get(i);
if(nextValue == null) {
newStrValues.add("null");
} else if(nextValue instanceof Boolean) {
newStrValues.add(nextValue.toString());
} else if(nextValue instanceof Long) {
newStrValues.add(nextValue.toString());
} else if(nextValue instanceof Double) {
} else if(nextValue instanceof Boolean || nextValue instanceof Number) {
newStrValues.add(nextValue.toString());
} else if(nextValue instanceof String) {
newStrValues.add("\"" + nextValue + "\"");
Expand All @@ -91,4 +82,45 @@ public static Config replace(
throw new OmgDoesNotPerformException(e);
}
}

public static Map<String, Object> replace(
final Map<String, Object> config, final String replacePattern, final Object newValue
) throws OmgLookAtMyConsoleException {
final Map<String, Object> newConfig = new HashMap<>();
final String rp = Pattern.quote(replacePattern);
Object v;
String valueStr;
for(final String k : config.keySet()) {
v = config.get(k);
if(v instanceof String) {
valueStr = (String) v;
if(valueStr.equals("\"" + replacePattern + "\"")) {
v = newValue;
} else {
if(newValue == null) {
v = valueStr.replaceAll(rp, "");
} else if(
newValue instanceof Boolean || newValue instanceof Number ||
newValue instanceof String
) {
v = valueStr.replaceAll(rp, newValue.toString());
} else if(newValue instanceof List) {
final StringJoiner sj = new StringJoiner(",");
for(final Object newValueElement : (List) newValue) {
sj.add(newValueElement == null ? "" : newValueElement.toString());
}
v = valueStr.replaceAll(rp, sj.toString());
} else {
throw new OmgLookAtMyConsoleException(
"Unexpected replacement value type: " + newValue.getClass().getName()
);
}
}
} else if(v instanceof Map) {
v = replace((Map<String, Object>) v, replacePattern, newValue);
}
newConfig.put(k, v);
}
return newConfig;
}
}

0 comments on commit aaa4773

Please sign in to comment.