brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/7] git commit: Refactor location-resolvers
Date Wed, 03 Sep 2014 13:33:56 GMT
Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master c1ab0be58 -> 5b1441584


Refactor location-resolvers

- previously had two newLocationFromString methods, where second
  was only ever called by first. So deleted second method.


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

Branch: refs/heads/master
Commit: 1c7482c00367ec733acd820dc2819c857398fd90
Parents: c1ab0be
Author: Aled Sage <aled.sage@gmail.com>
Authored: Thu Mar 27 13:41:22 2014 +0000
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Wed Sep 3 11:21:04 2014 +0100

----------------------------------------------------------------------
 .../brooklyn/location/basic/ByonLocationResolver.java | 10 ++++------
 .../brooklyn/location/basic/HostLocationResolver.java | 10 ++++------
 .../brooklyn/location/basic/LocalhostResolver.java    | 13 ++++---------
 .../location/basic/NamedLocationResolver.java         |  1 +
 .../location/basic/SingleMachineLocationResolver.java | 10 ++++------
 .../location/jclouds/JcloudsByonLocationResolver.java | 12 +++++-------
 .../brooklyn/location/jclouds/JcloudsResolver.java    | 14 ++++++--------
 7 files changed, 28 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1c7482c0/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java b/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java
index 0ffcb2f..1ba0578 100644
--- a/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java
+++ b/core/src/main/java/brooklyn/location/basic/ByonLocationResolver.java
@@ -78,10 +78,8 @@ public class ByonLocationResolver implements LocationResolver {
     
     @Override
     public FixedListMachineProvisioningLocation<SshMachineLocation> newLocationFromString(Map
locationFlags, String spec, brooklyn.location.LocationRegistry registry) {
-        return newLocationFromString(spec, registry, registry.getProperties(), locationFlags);
-    }
-    
-    protected FixedListMachineProvisioningLocation<SshMachineLocation> newLocationFromString(String
spec, brooklyn.location.LocationRegistry registry, Map properties, Map locationFlags) {
+        Map globalProperties = registry.getProperties();
+
         Matcher matcher = PATTERN.matcher(spec);
         if (!matcher.matches()) {
             throw new IllegalArgumentException("Invalid location '"+spec+"'; must specify
something like byon(hosts=\"addr1,addr2\")");
@@ -144,7 +142,7 @@ public class ByonLocationResolver implements LocationResolver {
             machines.add(machine);
         }
         
-        Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties("byon",
namedLocation, properties);
+        Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties("byon",
namedLocation, globalProperties);
         ConfigBag flags = ConfigBag.newInstance(locationFlags).putIfAbsent(filteredProperties);
 
         flags.putStringKey("machines", machines);
@@ -158,7 +156,7 @@ public class ByonLocationResolver implements LocationResolver {
 
         return managementContext.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class)
                 .configure(flags.getAllConfigRaw())
-                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags,
properties, namedLocation)));
+                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags,
globalProperties, namedLocation)));
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1c7482c0/core/src/main/java/brooklyn/location/basic/HostLocationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/HostLocationResolver.java b/core/src/main/java/brooklyn/location/basic/HostLocationResolver.java
index 71c7073..3744cb9 100644
--- a/core/src/main/java/brooklyn/location/basic/HostLocationResolver.java
+++ b/core/src/main/java/brooklyn/location/basic/HostLocationResolver.java
@@ -47,10 +47,8 @@ public class HostLocationResolver implements LocationResolver {
     @SuppressWarnings("rawtypes")
     @Override
     public Location newLocationFromString(Map locationFlags, String spec, LocationRegistry
registry) {
-        return newLocationFromString(spec, registry, registry.getProperties(), locationFlags);
-    }
-    
-    protected FixedListMachineProvisioningLocation<SshMachineLocation> newLocationFromString(String
spec, brooklyn.location.LocationRegistry registry, Map properties, Map locationFlags) {
+        Map globalProperties = registry.getProperties();
+        
         Matcher matcher = PATTERN.matcher(spec);
         if (!matcher.matches()) {
             throw new IllegalArgumentException("Invalid location '" + spec + "'; must specify
something like host:(\"1.1.1.1\")");
@@ -58,7 +56,7 @@ public class HostLocationResolver implements LocationResolver {
         
         String namedLocation = (String) locationFlags.get("named");
 
-        Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null,
namedLocation, properties);
+        Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null,
namedLocation, globalProperties);
         MutableMap<String, Object> flags = MutableMap.<String, Object>builder().putAll(filteredProperties).putAll(locationFlags).removeAll("named").build();
 
         String args = matcher.group(2);
@@ -70,7 +68,7 @@ public class HostLocationResolver implements LocationResolver {
         return managementContext.getLocationManager().createLocation(LocationSpec.create(SingleMachineProvisioningLocation.class)
                 .configure("location", target)
                 .configure("locationFlags", flags)
-                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags,
properties, namedLocation)));
+                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags,
globalProperties, namedLocation)));
     }
     
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1c7482c0/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java b/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java
index 1cd21f7..de6d530 100644
--- a/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java
+++ b/core/src/main/java/brooklyn/location/basic/LocalhostResolver.java
@@ -20,7 +20,6 @@ package brooklyn.location.basic;
 
 import static com.google.common.base.Preconditions.checkNotNull;
 
-import java.io.File;
 import java.util.Collections;
 import java.util.Map;
 import java.util.Set;
@@ -30,14 +29,12 @@ import java.util.regex.Pattern;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import brooklyn.entity.basic.BrooklynConfigKeys;
 import brooklyn.location.Location;
 import brooklyn.location.LocationRegistry;
 import brooklyn.location.LocationResolver;
-import brooklyn.location.LocationSpec;
 import brooklyn.location.LocationResolver.EnableableLocationResolver;
+import brooklyn.location.LocationSpec;
 import brooklyn.management.ManagementContext;
-import brooklyn.util.collections.MutableMap;
 import brooklyn.util.config.ConfigBag;
 import brooklyn.util.guava.Maybe;
 import brooklyn.util.text.KeyValueParser;
@@ -84,10 +81,8 @@ public class LocalhostResolver implements LocationResolver, EnableableLocationRe
     
     @Override
     public Location newLocationFromString(Map locationFlags, String spec, brooklyn.location.LocationRegistry
registry) {
-        return newLocationFromString(spec, registry, registry.getProperties(), locationFlags);
-    }
+        Map globalProperties = registry.getProperties();
     
-    protected Location newLocationFromString(String spec, brooklyn.location.LocationRegistry
registry, Map properties, Map locationFlags) {
         String namedLocation = (String) locationFlags.get(LocationInternal.NAMED_SPEC_NAME.getName());
         
         Matcher matcher = PATTERN.matcher(spec);
@@ -107,7 +102,7 @@ public class LocalhostResolver implements LocationResolver, EnableableLocationRe
             throw new IllegalArgumentException("Invalid location '"+spec+"'; if name supplied
then value must be non-empty");
         }
 
-        Map<String, Object> filteredProperties = new LocalhostPropertiesFromBrooklynProperties().getLocationProperties("localhost",
namedLocation, properties);
+        Map<String, Object> filteredProperties = new LocalhostPropertiesFromBrooklynProperties().getLocationProperties("localhost",
namedLocation, globalProperties);
         // TODO filteredProperties stuff above should not be needed as named location items
will already be passed in
         ConfigBag flags = ConfigBag.newInstance(locationFlags).putIfAbsent(filteredProperties);
         
@@ -118,7 +113,7 @@ public class LocalhostResolver implements LocationResolver, EnableableLocationRe
         
         return managementContext.getLocationManager().createLocation(LocationSpec.create(LocalhostMachineProvisioningLocation.class)
             .configure(flags.getAllConfig())
-            .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags, properties,
namedLocation)));
+            .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags, globalProperties,
namedLocation)));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1c7482c0/core/src/main/java/brooklyn/location/basic/NamedLocationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/NamedLocationResolver.java b/core/src/main/java/brooklyn/location/basic/NamedLocationResolver.java
index 9311b12..93d7a95 100644
--- a/core/src/main/java/brooklyn/location/basic/NamedLocationResolver.java
+++ b/core/src/main/java/brooklyn/location/basic/NamedLocationResolver.java
@@ -64,6 +64,7 @@ public class NamedLocationResolver implements LocationResolver {
         this.managementContext = checkNotNull(managementContext, "managementContext");
     }
     
+    @Override
     @SuppressWarnings({ "rawtypes" })
     public Location newLocationFromString(Map locationFlags, String spec, brooklyn.location.LocationRegistry
registry) {
         String name = spec;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1c7482c0/core/src/main/java/brooklyn/location/basic/SingleMachineLocationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/SingleMachineLocationResolver.java
b/core/src/main/java/brooklyn/location/basic/SingleMachineLocationResolver.java
index 4ae8e8a..6d52b1e 100644
--- a/core/src/main/java/brooklyn/location/basic/SingleMachineLocationResolver.java
+++ b/core/src/main/java/brooklyn/location/basic/SingleMachineLocationResolver.java
@@ -47,10 +47,8 @@ public class SingleMachineLocationResolver implements LocationResolver
{
 
     @Override
     public Location newLocationFromString(Map locationFlags, String spec, brooklyn.location.LocationRegistry
registry) {
-        return newLocationFromString(spec, registry, registry.getProperties(), locationFlags);
-    }
-    
-    protected Location newLocationFromString(String spec, brooklyn.location.LocationRegistry
registry, Map properties, Map locationFlags) {
+        Map globalProperties = registry.getProperties();
+        
         Matcher matcher = PATTERN.matcher(spec);
         if (!matcher.matches()) {
             throw new IllegalArgumentException("Invalid location '" + spec + "'; must specify
something like single(named:foo)");
@@ -60,7 +58,7 @@ public class SingleMachineLocationResolver implements LocationResolver {
         String args = matcher.group(2);
         Map<String,?> locationArgs = KeyValueParser.parseMap(args);
 
-        Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null,
namedLocation, properties);
+        Map<String, Object> filteredProperties = new LocationPropertiesFromBrooklynProperties().getLocationProperties(null,
namedLocation, globalProperties);
         MutableMap<String, Object> flags = MutableMap.<String, Object>builder()
                 .putAll(filteredProperties)
                 .putAll(locationFlags)
@@ -79,7 +77,7 @@ public class SingleMachineLocationResolver implements LocationResolver {
         return managementContext.getLocationManager().createLocation(LocationSpec.create(SingleMachineProvisioningLocation.class)
                 .configure("location", target)
                 .configure("locationFlags", flags)
-                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags,
properties, namedLocation)));
+                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags,
globalProperties, namedLocation)));
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1c7482c0/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java
index 439cd85..aa7d575 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsByonLocationResolver.java
@@ -81,13 +81,11 @@ public class JcloudsByonLocationResolver implements LocationResolver {
         this.managementContext = checkNotNull(managementContext, "managementContext");
     }
     
+    // TODO Remove some duplication from JcloudsResolver; needs more careful review
     @Override
     public FixedListMachineProvisioningLocation<JcloudsSshMachineLocation> newLocationFromString(Map
locationFlags, String spec, brooklyn.location.LocationRegistry registry) {
-        return newLocationFromString(spec, registry, registry.getProperties(), locationFlags);
-    }
-    
-    // TODO Remove some duplication from JcloudsResolver; needs more careful review
-    protected FixedListMachineProvisioningLocation<JcloudsSshMachineLocation> newLocationFromString(String
spec, brooklyn.location.LocationRegistry registry, Map properties, Map locationFlags) {
+        Map globalProperties = registry.getProperties();
+
         Matcher matcher = PATTERN.matcher(spec);
         if (!matcher.matches()) {
             throw new IllegalArgumentException("Invalid location '"+spec+"'; must specify
something like jcloudsByon(provider=\"aws-ec2\",region=\"us-east-1\",hosts=\"i-f2014593,i-d1234567\")");
@@ -132,7 +130,7 @@ public class JcloudsByonLocationResolver implements LocationResolver {
         // But for everything passed in via locationFlags, pass those as-is.
         // TODO Should revisit the locationFlags: where are these actually used? Reason accepting
properties without
         //      full prefix is that the map's context is explicitly this location, rather
than being generic properties.
-        Map allProperties = getAllProperties(registry, properties);
+        Map allProperties = getAllProperties(registry, globalProperties);
         Map jcloudsProperties = new JcloudsPropertiesFromBrooklynProperties().getJcloudsProperties(providerOrApi,
regionName, namedLocation, allProperties);
         jcloudsProperties.putAll(locationFlags);
         
@@ -171,7 +169,7 @@ public class JcloudsByonLocationResolver implements LocationResolver {
         
         return managementContext.getLocationManager().createLocation(LocationSpec.create(FixedListMachineProvisioningLocation.class)
                 .configure(flags.getAllConfig())
-                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags,
properties, namedLocation)));
+                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, locationFlags,
globalProperties, namedLocation)));
     }
     
     private Map getAllProperties(brooklyn.location.LocationRegistry registry, Map<?,?>
properties) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1c7482c0/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsResolver.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsResolver.java
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsResolver.java
index 45a1013..6cfa6a3 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsResolver.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsResolver.java
@@ -83,11 +83,6 @@ public class JcloudsResolver implements LocationResolver {
         this.managementContext = checkNotNull(managementContext, "managementContext");
     }
     
-    @Override
-    public JcloudsLocation newLocationFromString(Map locationFlags, String spec, brooklyn.location.LocationRegistry
registry) {
-        return newLocationFromString(spec, registry, registry.getProperties(), locationFlags);
-    }
-
     protected static class JcloudsSpecParser {
         String providerOrApi;
         String parameter;
@@ -152,8 +147,11 @@ public class JcloudsResolver implements LocationResolver {
         }
     }
     
+    @Override
     @SuppressWarnings("unchecked")
-    protected JcloudsLocation newLocationFromString(String spec, brooklyn.location.LocationRegistry
registry, Map properties, Map locationFlags) {
+    public JcloudsLocation newLocationFromString(Map locationFlags, String spec, brooklyn.location.LocationRegistry
registry) {
+        Map globalProperties = registry.getProperties();
+
         JcloudsSpecParser details = JcloudsSpecParser.parse(spec, false);
         String namedLocation = (String) locationFlags.get(LocationInternal.NAMED_SPEC_NAME.getName());
 
@@ -173,7 +171,7 @@ public class JcloudsResolver implements LocationResolver {
         // But for everything passed in via locationFlags, pass those as-is.
         // TODO Should revisit the locationFlags: where are these actually used? Reason accepting
properties without
         //      full prefix is that the map's context is explicitly this location, rather
than being generic properties.
-        Map allProperties = getAllProperties(registry, properties);
+        Map allProperties = getAllProperties(registry, globalProperties);
         String regionOrEndpoint = details.parameter;
         if (regionOrEndpoint==null && isProvider) regionOrEndpoint = (String)locationFlags.get(LocationConfigKeys.CLOUD_REGION_ID.getName());
         Map jcloudsProperties = new JcloudsPropertiesFromBrooklynProperties().getJcloudsProperties(providerOrApi,
regionOrEndpoint, namedLocation, allProperties);
@@ -193,7 +191,7 @@ public class JcloudsResolver implements LocationResolver {
         }
         
         return managementContext.getLocationManager().createLocation(LocationSpec.create(JcloudsLocation.class)
-                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, jcloudsProperties,
properties, namedLocation))
+                .configure(LocationConfigUtils.finalAndOriginalSpecs(spec, jcloudsProperties,
globalProperties, namedLocation))
                 .configure(jcloudsProperties) );
     }
 


Mime
View raw message