srdo commented on a change in pull request #3155: STORM-3066: Implement support 
for using list elements in properties in FluxParser
URL: https://github.com/apache/storm/pull/3155#discussion_r339685376
 
 

 ##########
 File path: 
flux/flux-core/src/main/java/org/apache/storm/flux/parser/FluxParser.java
 ##########
 @@ -139,37 +149,49 @@ public static Properties parseProperties(String 
propertiesFile, boolean resource
         return properties;
     }
 
-    private static TopologyDef loadYaml(Yaml yaml, InputStream in, Properties 
properties, boolean envSubstitution) throws IOException {
-        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+    private static TopologyDef loadYaml(Yaml yaml, InputStream in, Properties 
properties, boolean envSubstitution) {
         LOG.info("loading YAML from input stream...");
-        int b = -1;
-        while ((b = in.read()) != -1) {
-            bos.write(b);
-        }
+        StringBuilder bos = new StringBuilder();
+        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
 
-        // TODO substitution implementation is not exactly efficient or kind 
to memory...
-        String str = bos.toString();
-        // properties file substitution
-        if (properties != null) {
-            LOG.info("Performing property substitution.");
-            for (Object key : properties.keySet()) {
-                str = str.replace("${" + key + "}", 
properties.getProperty((String)key));
+        reader.lines().forEach(line -> {
+            Matcher m = propertyPattern.matcher(line);
+            if (m.find()) {
+                String target = "${" + m.group("var") + "}";
+                Optional<String> replacement = 
getPropertyReplacement(properties, m, envSubstitution);
+                replacement.ifPresent(propValue -> 
bos.append(line.replace(target, propValue)));
+                if (!replacement.isPresent()) {
+                    LOG.warn("Could not found replacement for property: " + 
m.group("var"));
 
 Review comment:
   Nit: "Could not find"

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to