azkaban-memoizeit
Changes
src/java/azkaban/utils/PropsUtils.java 55(+26 -29)
Details
src/java/azkaban/utils/PropsUtils.java 55(+26 -29)
diff --git a/src/java/azkaban/utils/PropsUtils.java b/src/java/azkaban/utils/PropsUtils.java
index e0dac83..fe2bd2c 100644
--- a/src/java/azkaban/utils/PropsUtils.java
+++ b/src/java/azkaban/utils/PropsUtils.java
@@ -24,6 +24,7 @@ import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
+import java.util.StringTokenizer;
import java.util.UUID;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -31,6 +32,7 @@ import java.util.regex.Pattern;
import azkaban.executor.ExecutableFlow;
import azkaban.flow.CommonJobProperties;
+import org.apache.commons.lang.StringUtils;
import org.joda.time.DateTime;
public class PropsUtils {
@@ -147,72 +149,67 @@ public class PropsUtils {
.compile("\\$\\{([a-zA-Z_.0-9]+)\\}");
public static Props resolveProps(Props props) {
- if (props == null) {
- return null;
- }
-
+ if (props == null) return null;
+
Props resolvedProps = new Props();
-
+
LinkedHashSet<String> visitedVariables = new LinkedHashSet<String>();
for (String key : props.getKeySet()) {
String value = props.get(key);
-
+
visitedVariables.add(key);
- String replacedValue = resolveVariableReplacement(value, props,
- visitedVariables);
+ String replacedValue = resolveVariableReplacement(value, props, visitedVariables);
visitedVariables.clear();
-
+
resolvedProps.put(key, replacedValue);
}
-
+
return resolvedProps;
};
-
+
private static String resolveVariableReplacement(String value, Props props, LinkedHashSet<String> visitedVariables) {
StringBuffer buffer = new StringBuffer();
int startIndex = 0;
-
+
Matcher matcher = VARIABLE_PATTERN.matcher(value);
while (matcher.find(startIndex)) {
if (startIndex < matcher.start()) {
// Copy everything up front to the buffer
buffer.append(value.substring(startIndex, matcher.start()));
}
-
+
String subVariable = matcher.group(1);
// Detected a cycle
if (visitedVariables.contains(subVariable)) {
- throw new IllegalArgumentException(String.format(
- "Circular variable substitution found: [%s] -> [%s]",
- StringUtils.join(visitedVariables, "->"),
- subVariable));
- } else {
+ throw new IllegalArgumentException(
+ String.format("Circular variable substitution found: [%s] -> [%s]",
+ StringUtils.join(visitedVariables.toArray(), "->"), subVariable));
+ }
+ else {
// Add substitute variable and recurse.
String replacement = props.get(subVariable);
visitedVariables.add(subVariable);
-
+
if (replacement == null) {
throw new UndefinedPropertyException(
- String.format(
- "Could not find variable substitution for variable(s) [%s]",
- StringUtils.join(visitedVariables, "->")));
+ String.format("Could not find variable substitution for variable(s) [%s]",
+ StringUtils.join(visitedVariables.toArray(), "->")));
}
-
- buffer.append(resolveVariableReplacement(replacement, props,
- visitedVariables));
+
+ buffer.append(resolveVariableReplacement(replacement, props, visitedVariables));
visitedVariables.remove(subVariable);
}
-
+
startIndex = matcher.end();
}
-
+
if (startIndex < value.length()) {
buffer.append(value.substring(startIndex));
}
-
+
return buffer.toString();
}
-
+
public static Props addCommonFlowProperties(final ExecutableFlow flow) {
Props parentProps = new Props();