Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master 5d60b2c81 -> da6d887f9


Adds PRIVATE_ADDRESSES config to SshMachineLocation

- and same to WinRmMachineLocation


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

Branch: refs/heads/master
Commit: 7b866a9ecf5aa87798c9130ade2e865a35545d88
Parents: 32960be
Author: Aled Sage <[email protected]>
Authored: Fri Jun 26 14:36:18 2015 +0100
Committer: Aled Sage <[email protected]>
Committed: Fri Jun 26 15:33:07 2015 +0100

----------------------------------------------------------------------
 .../location/basic/SshMachineLocation.java      | 11 ++++-
 .../location/basic/WinRmMachineLocation.java    | 11 ++++-
 .../location/basic/SshMachineLocationTest.java  | 10 +++++
 .../basic/WinRmMachineLocationTest.java         | 44 ++++++++++++++++++++
 4 files changed, 73 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7b866a9e/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java 
b/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
index a249305..68f224d 100644
--- a/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/SshMachineLocation.java
@@ -21,6 +21,7 @@ package brooklyn.location.basic;
 import static brooklyn.util.GroovyJavaMethods.truth;
 
 import com.google.common.annotations.Beta;
+
 import groovy.lang.Closure;
 
 import java.io.Closeable;
@@ -114,6 +115,7 @@ import com.google.common.collect.Iterables;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Sets;
 import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
 
 /**
  * Operations on a machine that is accessible via ssh.
@@ -145,6 +147,12 @@ public class SshMachineLocation extends AbstractLocation 
implements MachineLocat
     public static final ConfigKey<Boolean> DETECT_MACHINE_DETAILS = 
ConfigKeys.newBooleanConfigKey("detectMachineDetails",
             "Attempt to detect machine details automatically. Works with 
SSH-accessible Linux instances.", true);
 
+    public static final ConfigKey<Iterable<String>> PRIVATE_ADDRESSES = 
ConfigKeys.newConfigKey(
+            new TypeToken<Iterable<String>>() {},
+            "privateAddresses",
+            "Private addresses of this machine, e.g. those within the private 
network", 
+            null);
+
     @SetFromFlag
     protected String user;
 
@@ -460,7 +468,8 @@ public class SshMachineLocation extends AbstractLocation 
implements MachineLocat
     
     @Override
     public Set<String> getPrivateAddresses() {
-        return ImmutableSet.of();
+        Iterable<String> result = getConfig(PRIVATE_ADDRESSES);
+        return (result == null) ? ImmutableSet.<String>of() : 
ImmutableSet.copyOf(result);
     }
 
     public HostAndPort getSshHostAndPort() {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7b866a9e/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
----------------------------------------------------------------------
diff --git 
a/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java 
b/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
index 36c0360..54ee63a 100644
--- a/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
+++ b/core/src/main/java/brooklyn/location/basic/WinRmMachineLocation.java
@@ -53,7 +53,7 @@ import com.google.common.base.Joiner;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Lists;
-import com.google.common.net.HostAndPort;
+import com.google.common.reflect.TypeToken;
 
 public class WinRmMachineLocation extends AbstractLocation implements 
MachineLocation {
 
@@ -92,6 +92,12 @@ public class WinRmMachineLocation extends AbstractLocation 
implements MachineLoc
             "Max number of times to attempt WinRM operations", 
             10);
 
+    public static final ConfigKey<Iterable<String>> PRIVATE_ADDRESSES = 
ConfigKeys.newConfigKey(
+            new TypeToken<Iterable<String>>() {},
+            "privateAddresses",
+            "Private addresses of this machine, e.g. those within the private 
network", 
+            null);
+
     @Override
     public InetAddress getAddress() {
         return getConfig(ADDRESS);
@@ -128,7 +134,8 @@ public class WinRmMachineLocation extends AbstractLocation 
implements MachineLoc
     
     @Override
     public Set<String> getPrivateAddresses() {
-        return ImmutableSet.of();
+        Iterable<String> result = getConfig(PRIVATE_ADDRESSES);
+        return (result == null) ? ImmutableSet.<String>of() : 
ImmutableSet.copyOf(result);
     }
 
     public WinRmToolResponse executeScript(String script) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7b866a9e/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
----------------------------------------------------------------------
diff --git 
a/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java 
b/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
index 31d48f2..61dc65e 100644
--- a/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
+++ b/core/src/test/java/brooklyn/location/basic/SshMachineLocationTest.java
@@ -122,6 +122,16 @@ public class SshMachineLocationTest {
         assertSame(host2.getMachineDetails(), machineDetails);
     }
     
+    @Test
+    public void testConfigurePrivateAddresses() throws Exception {
+        SshMachineLocation host2 = 
mgmt.getLocationManager().createLocation(LocationSpec.create(SshMachineLocation.class)
+                .configure("address", Networking.getLocalHost())
+                .configure(SshMachineLocation.PRIVATE_ADDRESSES, 
ImmutableList.of("1.2.3.4"))
+                .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, 
true));
+
+        assertEquals(host2.getPrivateAddresses(), ImmutableSet.of("1.2.3.4"));
+    }
+    
     // Wow, this is hard to test (until I accepted creating the entity + 
effector)! Code smell?
     // Need to call getMachineDetails in a DynamicSequentialTask so that the 
"innessential" takes effect,
     // to not fail its caller. But to get one of those outside of an effector 
is non-obvious.

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7b866a9e/software/base/src/test/java/brooklyn/location/basic/WinRmMachineLocationTest.java
----------------------------------------------------------------------
diff --git 
a/software/base/src/test/java/brooklyn/location/basic/WinRmMachineLocationTest.java
 
b/software/base/src/test/java/brooklyn/location/basic/WinRmMachineLocationTest.java
new file mode 100644
index 0000000..de9db6c
--- /dev/null
+++ 
b/software/base/src/test/java/brooklyn/location/basic/WinRmMachineLocationTest.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package brooklyn.location.basic;
+
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.Test;
+
+import brooklyn.entity.BrooklynAppUnitTestSupport;
+import brooklyn.entity.basic.BrooklynConfigKeys;
+import brooklyn.location.LocationSpec;
+import brooklyn.util.net.Networking;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
+
+public class WinRmMachineLocationTest extends BrooklynAppUnitTestSupport {
+
+    @Test
+    public void testConfigurePrivateAddresses() throws Exception {
+        WinRmMachineLocation host = 
mgmt.getLocationManager().createLocation(LocationSpec.create(WinRmMachineLocation.class)
+                .configure("address", Networking.getLocalHost())
+                .configure(WinRmMachineLocation.PRIVATE_ADDRESSES, 
ImmutableList.of("1.2.3.4"))
+                .configure(BrooklynConfigKeys.SKIP_ON_BOX_BASE_DIR_RESOLUTION, 
true));
+
+        assertEquals(host.getPrivateAddresses(), ImmutableSet.of("1.2.3.4"));
+    }
+}

Reply via email to