brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [4/9] incubator-brooklyn git commit: convert to single loop, as per review
Date Tue, 28 Apr 2015 09:55:44 GMT
convert to single loop, as per review


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/a8384e3f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/a8384e3f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/a8384e3f

Branch: refs/heads/master
Commit: a8384e3fcc6363d202e1252849a5ab1ed030961d
Parents: b671fb5
Author: Robert Moss <robertgmoss@gmail.com>
Authored: Thu Apr 16 16:19:53 2015 +0100
Committer: Robert Moss <robertgmoss@gmail.com>
Committed: Thu Apr 16 16:19:53 2015 +0100

----------------------------------------------------------------------
 .../entity/basic/SoftwareProcessImpl.java       | 22 ++++++++++----------
 1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/a8384e3f/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
----------------------------------------------------------------------
diff --git a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
index 7fec000..31f2bb0 100644
--- a/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
+++ b/software/base/src/main/java/brooklyn/entity/basic/SoftwareProcessImpl.java
@@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.testng.collections.Sets;
 
 import brooklyn.config.ConfigKey;
 import brooklyn.enricher.basic.AbstractEnricher;
@@ -57,6 +58,7 @@ import brooklyn.util.collections.MutableMap;
 import brooklyn.util.collections.MutableSet;
 import brooklyn.util.config.ConfigBag;
 import brooklyn.util.exceptions.Exceptions;
+import brooklyn.util.flags.TypeCoercions;
 import brooklyn.util.task.DynamicTasks;
 import brooklyn.util.task.Tasks;
 import brooklyn.util.time.CountdownTimer;
@@ -436,22 +438,20 @@ public abstract class SoftwareProcessImpl extends AbstractEntity implements
Soft
      */
     protected Collection<Integer> getRequiredOpenPorts() {
         Set<Integer> ports = MutableSet.of(22);
-        for (ConfigKey k: getEntityType().getConfigKeys()) {
+        Map<ConfigKey<?>, ?> allConfig = config().getBag().getAllConfigAsConfigKeyMap();
+        Set<ConfigKey<?>> configKeys = Sets.newHashSet(allConfig.keySet());
+        configKeys.addAll(getEntityType().getConfigKeys());
+        
+        for (ConfigKey<?> k: configKeys) {
             if (PortRange.class.isAssignableFrom(k.getType())) {
                 PortRange p = (PortRange)getConfig(k);
                 if (p != null && !p.isEmpty()) ports.add(p.iterator().next());
             }   
-        }
-        
-        Map<String, Object> allConfig = config().getBag().getAllConfig();
-        for (String key : allConfig.keySet()) {
-            if(key.matches(".*\\.port")){
-                Object value = allConfig.get(key);
-                if (value instanceof Integer){
-                    ports.add((Integer)value);
-                }
+            if(k.getName().matches(".*\\.port")){
+                Integer value = TypeCoercions.coerce(getConfig(k), Integer.class);
+                if (value !=null)ports.add(value);
             }
-        }         
+        }        
         
         log.debug("getRequiredOpenPorts detected default {} for {}", ports, this);
         return ports;


Mime
View raw message