brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sjcorb...@apache.org
Subject [4/6] incubator-brooklyn git commit: ByonLocationResolver handles non-lowercase values for osFamily
Date Mon, 24 Aug 2015 08:53:52 GMT
ByonLocationResolver handles non-lowercase values for osFamily


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

Branch: refs/heads/master
Commit: c3e027b80826427d04e3b726bf9f71f24fc46103
Parents: d6f2f38
Author: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Authored: Tue Aug 18 18:19:21 2015 +0100
Committer: Sam Corbett <sam.corbett@cloudsoftcorp.com>
Committed: Fri Aug 21 10:16:43 2015 +0100

----------------------------------------------------------------------
 .../brooklyn/core/location/BasicLocationRegistry.java |  2 +-
 .../brooklyn/location/byon/ByonLocationResolver.java  |  9 +++++++--
 .../location/byon/ByonLocationResolverTest.java       | 14 ++++++++++----
 3 files changed, 18 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c3e027b8/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
index f8b7c73..573da76 100644
--- a/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
+++ b/core/src/main/java/org/apache/brooklyn/core/location/BasicLocationRegistry.java
@@ -334,7 +334,7 @@ public class BasicLocationRegistry implements LocationRegistry {
                 try {
                     return Maybe.of(resolver.newLocationFromString(locationFlags, spec, this));
                 } catch (RuntimeException e) {
-                    return Maybe.absent(Suppliers.ofInstance(e));
+                     return Maybe.absent(Suppliers.ofInstance(e));
                 }
             }
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c3e027b8/core/src/main/java/org/apache/brooklyn/location/byon/ByonLocationResolver.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/location/byon/ByonLocationResolver.java
b/core/src/main/java/org/apache/brooklyn/location/byon/ByonLocationResolver.java
index 2705f65..bef0046 100644
--- a/core/src/main/java/org/apache/brooklyn/location/byon/ByonLocationResolver.java
+++ b/core/src/main/java/org/apache/brooklyn/location/byon/ByonLocationResolver.java
@@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkArgument;
 
 import java.net.InetAddress;
 import java.util.List;
+import java.util.Locale;
 import java.util.Map;
 
 import org.apache.brooklyn.api.location.Location;
@@ -98,7 +99,7 @@ public class ByonLocationResolver extends AbstractLocationResolver {
         config.remove("hosts");
         String user = (String) config.getStringKey("user");
         Integer port = (Integer) TypeCoercions.coerce(config.getStringKey("port"), Integer.class);
-        Class<? extends MachineLocation> locationClass = OS_TO_MACHINE_LOCATION_TYPE.get(config.get(OS_FAMILY));
+        Class<? extends MachineLocation> locationClass = getLocationClass(config.get(OS_FAMILY));
 
         MutableMap<String, Object> defaultProps = MutableMap.of();
         defaultProps.addIfNotNull("user", user);
@@ -199,12 +200,16 @@ public class ByonLocationResolver extends AbstractLocationResolver {
         
         Class<? extends MachineLocation> locationClassHere = locationClass;
         if (osfamily != null) {
-            locationClassHere = OS_TO_MACHINE_LOCATION_TYPE.get(osfamily);
+            locationClassHere = getLocationClass(osfamily);
         }
 
         return LocationSpec.create(locationClassHere).configure(machineConfig);
     }
 
+    private Class<? extends MachineLocation> getLocationClass(String osFamily) {
+        return osFamily == null ? null : OS_TO_MACHINE_LOCATION_TYPE.get(osFamily.toLowerCase(Locale.ENGLISH));
+    }
+
     protected LocationSpec<? extends MachineLocation> parseMachine(String val, Class<?
extends MachineLocation> locationClass, Map<String, ?> defaults, String specForErrMsg)
{
         Map<String, Object> machineConfig = Maps.newLinkedHashMap();
         

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/c3e027b8/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java
b/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java
index 8e4e71a..51120e0 100644
--- a/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java
+++ b/core/src/test/java/org/apache/brooklyn/location/byon/ByonLocationResolverTest.java
@@ -56,6 +56,7 @@ import org.slf4j.LoggerFactory;
 import org.testng.Assert;
 import org.testng.annotations.AfterMethod;
 import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 import com.google.common.base.Function;
@@ -332,14 +333,19 @@ public class ByonLocationResolverTest {
         Assert.assertEquals("1.1.1.1", location1.getAddress().getHostAddress());
     }
 
-    @Test
-    public void testWindowsMachines() throws Exception {
+    @DataProvider(name = "windowsOsFamilies")
+    public Object[][] getWindowsOsFamilies() {
+        return new Object[][]{{"windows"}, {"WINDOWS"}, {"wInDoWs"}};
+    }
+
+    @Test(dataProvider = "windowsOsFamilies")
+    public void testWindowsMachines(String osFamily) throws Exception {
         brooklynProperties.put("brooklyn.location.byon.user", "myuser");
         brooklynProperties.put("brooklyn.location.byon.password", "mypassword");
         String spec = "byon";
         Map<String, ?> flags = ImmutableMap.of(
                 "hosts", ImmutableList.of("1.1.1.1", "2.2.2.2"),
-                "osfamily", "windows"
+                "osfamily", osFamily
         );
         MachineProvisioningLocation<MachineLocation> provisioner = resolve(spec, flags);
         WinRmMachineLocation location = (WinRmMachineLocation) provisioner.obtain(ImmutableMap.of());
@@ -350,7 +356,7 @@ public class ByonLocationResolverTest {
     }
 
     @Test
-    public void testNoneWindowsMachines() throws Exception {
+    public void testNonWindowsMachines() throws Exception {
         String spec = "byon";
         Map<String, ?> flags = ImmutableMap.of(
                 "hosts", ImmutableList.of("1.1.1.1", "2.2.2.2"),


Mime
View raw message