brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [2/3] brooklyn-server git commit: Address PR comments
Date Mon, 28 Nov 2016 16:46:22 GMT
Address PR comments


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

Branch: refs/heads/master
Commit: 26446b1df3a9ab2b39f05a1a35008d04ed6fef7b
Parents: 2e8e98d
Author: graeme.miller <graeme.miller@cloudsoftcorp.com>
Authored: Mon Nov 28 14:17:17 2016 +0000
Committer: graeme.miller <graeme.miller@cloudsoftcorp.com>
Committed: Mon Nov 28 14:17:17 2016 +0000

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       |  7 +-
 .../location/jclouds/JcloudsLocationConfig.java |  9 +-
 .../jclouds/JcloudsSshMachineLocation.java      |  8 +-
 ...sSshMachineLocationAddressOverwriteTest.java | 95 ++++++++++++++++++++
 ...SshMachineLocationEndpointOverwriteTest.java | 93 -------------------
 5 files changed, 109 insertions(+), 103 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/26446b1d/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
index 4ee4b1b..08ddad9 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
@@ -60,7 +60,6 @@ import org.apache.brooklyn.api.mgmt.AccessController;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
-import org.apache.brooklyn.core.BrooklynVersion;
 import org.apache.brooklyn.core.config.ConfigUtils;
 import org.apache.brooklyn.core.config.Sanitizer;
 import org.apache.brooklyn.core.location.AbstractLocation;
@@ -3356,9 +3355,9 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation
im
     }
     
     protected String getPrivateHostname(NodeMetadata node, Optional<HostAndPort> sshHostAndPort,
Supplier<? extends LoginCredentials> userCredentials, ConfigBag setup) {
-        Boolean usePublicEndpointAsPrivateEndpoint = (setup != null) ? setup.get(USE_PUBLIC_ENDPOINT_AS_PRIVATE_ENDPOINT)
: false;
-        if(usePublicEndpointAsPrivateEndpoint) {
-            LOG.debug("Overriding private hostname as public hostname because config "+USE_PUBLIC_ENDPOINT_AS_PRIVATE_ENDPOINT+"
is set to true");
+        Boolean useMachinePublicAddressAsPrivateAddress = (setup != null) ? setup.get(USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS)
: false;
+        if(useMachinePublicAddressAsPrivateAddress) {
+            LOG.debug("Overriding private hostname as public hostname because config "+ USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS.getName()+"
is set to true");
             return getPublicHostname(node, sshHostAndPort, userCredentials, setup);
         }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/26446b1d/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java
index e8f4521..68a4644 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocationConfig.java
@@ -293,9 +293,14 @@ public interface JcloudsLocationConfig extends CloudLocationConfig {
     public static final ConfigKey<Map<String,Object>> TEMPLATE_OPTIONS = ConfigKeys.newConfigKey(
             new TypeToken<Map<String, Object>>() {}, "templateOptions", "Additional
jclouds template options");
 
+    /*
+         The purpose of this config is to aid deployment of blueprints to clouds where it
is difficult to get nodes to
+         communicate via private IPs. This config allows a user to overwrite private IPs
as public IPs, thus ensuring
+         that any blueprints they wish to deploy which may use private IPs still work in
these clouds.
+     */
     @Beta
-    public static final ConfigKey<Boolean> USE_PUBLIC_ENDPOINT_AS_PRIVATE_ENDPOINT
= ConfigKeys.newBooleanConfigKey(
-            "usePublicEndpointAsPrivateEndpoint",
+    public static final ConfigKey<Boolean> USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS
= ConfigKeys.newBooleanConfigKey(
+            "useMachinePublicAddressAsPrivateAddress",
             "When true we will use the public IP/Hostname of a JClouds Location as the private
IP/Hostname",
             false);
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/26446b1d/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
index 8f00683..dd096b1 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocation.java
@@ -18,7 +18,7 @@
  */
 package org.apache.brooklyn.location.jclouds;
 
-import static org.apache.brooklyn.location.jclouds.JcloudsLocationConfig.USE_PUBLIC_ENDPOINT_AS_PRIVATE_ENDPOINT;
+import static org.apache.brooklyn.location.jclouds.JcloudsLocationConfig.USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS;
 import static org.apache.brooklyn.util.JavaGroovyEquivalents.groovyTruth;
 
 import java.util.List;
@@ -205,9 +205,9 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements
Jcl
         publicAddresses = node.getPublicAddresses();
         _node = Optional.of(node);
 
-        Boolean usePublicEndpointAsPrivateEndpoint = config().get(USE_PUBLIC_ENDPOINT_AS_PRIVATE_ENDPOINT);
-        if(usePublicEndpointAsPrivateEndpoint) {
-            LOG.debug("Overriding private address ["+node.getPrivateAddresses()+"] as public
address ["+node.getPublicAddresses()+"] as config "+USE_PUBLIC_ENDPOINT_AS_PRIVATE_ENDPOINT+"
is set to true");
+        Boolean useMachinePublicAddressAsPrivateAddress = config().get(USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS);
+        if(useMachinePublicAddressAsPrivateAddress) {
+            LOG.debug("Overriding private address ["+node.getPrivateAddresses()+"] as public
address ["+node.getPublicAddresses()+"] as config "+ USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS
+" is set to true");
             privateAddresses = node.getPublicAddresses();
         } else {
             privateAddresses = node.getPrivateAddresses();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/26446b1d/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationAddressOverwriteTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationAddressOverwriteTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationAddressOverwriteTest.java
new file mode 100644
index 0000000..1ad91bd
--- /dev/null
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationAddressOverwriteTest.java
@@ -0,0 +1,95 @@
+/*
+ * 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 org.apache.brooklyn.location.jclouds;
+
+import static org.testng.Assert.assertEquals;
+
+import java.util.List;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+import org.jclouds.compute.domain.NodeMetadata;
+import org.jclouds.compute.domain.NodeMetadata.Status;
+import org.jclouds.compute.domain.NodeMetadataBuilder;
+import org.jclouds.compute.domain.Template;
+import org.jclouds.domain.LoginCredentials;
+
+import org.apache.brooklyn.core.location.Machines;
+import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.AbstractNodeCreator;
+import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.NodeCreator;
+
+public class JcloudsSshMachineLocationAddressOverwriteTest extends AbstractJcloudsStubbedUnitTest
{
+
+    @SuppressWarnings("unused")
+    private static final Logger log = LoggerFactory.getLogger(JcloudsImageChoiceStubbedLiveTest.class);
+    
+    private List<String> privateAddresses;
+    private List<String> publicAddresses;
+
+    @BeforeMethod(alwaysRun=true)
+    public void setUp() throws Exception {
+        super.setUp();
+        privateAddresses = ImmutableList.of("172.168.10.11");
+        publicAddresses = ImmutableList.of("173.194.32.123");
+        initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of(JcloudsLocationConfig.USE_MACHINE_PUBLIC_ADDRESS_AS_PRIVATE_ADDRESS.getName(),
true));
+    }
+    
+    protected NodeCreator newNodeCreator() {
+        return new AbstractNodeCreator() {
+            @Override protected NodeMetadata newNode(String group, Template template) {
+                NodeMetadata result = new NodeMetadataBuilder()
+                        .id("myid")
+                        .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
+                        .loginPort(22)
+                        .status(Status.RUNNING)
+                        .publicAddresses(publicAddresses)
+                        .privateAddresses(privateAddresses)
+                        .build();
+                return result;
+            }
+        };
+    }
+
+
+    @Test
+    public void testSetPrivateIpToPublicIp() throws Exception {
+        JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.of());
+
+        assertEquals(publicAddresses, machine.getPublicAddresses());
+
+        assertEquals(machine.getPublicAddresses().size(), 1);
+        String publicAddress = machine.getPublicAddresses().iterator().next();
+
+        assertEquals(machine.getPrivateAddress().get(), publicAddress);
+        assertEquals(machine.getSubnetHostname(), machine.getHostname());
+        assertEquals(machine.getSubnetIp(), publicAddress);
+
+        assertEquals(Machines.getSubnetHostname(machine).get(), machine.getHostname());
+        assertEquals(Machines.getSubnetIp(machine).get(), publicAddress);
+        assertEquals(machine.getPrivateAddresses().size(), 1);
+        assertEquals(machine.getPrivateAddresses().iterator().next(), publicAddress);
+
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/26446b1d/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationEndpointOverwriteTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationEndpointOverwriteTest.java
b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationEndpointOverwriteTest.java
deleted file mode 100644
index 3e1812a..0000000
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationEndpointOverwriteTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * 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 org.apache.brooklyn.location.jclouds;
-
-import static org.testng.Assert.assertEquals;
-
-import java.util.List;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Optional;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadata.Status;
-import org.jclouds.compute.domain.NodeMetadataBuilder;
-import org.jclouds.compute.domain.OsFamily;
-import org.jclouds.compute.domain.Template;
-import org.jclouds.domain.LoginCredentials;
-
-import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.AbstractNodeCreator;
-import org.apache.brooklyn.location.jclouds.StubbedComputeServiceRegistry.NodeCreator;
-import org.apache.brooklyn.location.ssh.SshMachineLocation;
-import org.apache.brooklyn.location.winrm.WinRmMachineLocation;
-import org.apache.brooklyn.util.core.internal.ssh.SshTool;
-import org.apache.brooklyn.util.core.internal.winrm.WinRmTool;
-
-public class JcloudsSshMachineLocationEndpointOverwriteTest extends AbstractJcloudsStubbedUnitTest
{
-
-    @SuppressWarnings("unused")
-    private static final Logger log = LoggerFactory.getLogger(JcloudsImageChoiceStubbedLiveTest.class);
-    
-    private List<String> privateAddresses;
-    private List<String> publicAddresses;
-
-    @BeforeMethod(alwaysRun=true)
-    public void setUp() throws Exception {
-        super.setUp();
-        privateAddresses = ImmutableList.of("172.168.10.11");
-        publicAddresses = ImmutableList.of("173.194.32.123");
-        initNodeCreatorAndJcloudsLocation(newNodeCreator(), ImmutableMap.of(JcloudsLocationConfig.USE_PUBLIC_ENDPOINT_AS_PRIVATE_ENDPOINT.getName(),
true));
-    }
-    
-    protected NodeCreator newNodeCreator() {
-        return new AbstractNodeCreator() {
-            @Override protected NodeMetadata newNode(String group, Template template) {
-                NodeMetadata result = new NodeMetadataBuilder()
-                        .id("myid")
-                        .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
-                        .loginPort(22)
-                        .status(Status.RUNNING)
-                        .publicAddresses(publicAddresses)
-                        .privateAddresses(privateAddresses)
-                        .build();
-                return result;
-            }
-        };
-    }
-
-
-    @Test
-    public void testSetPrivateIpToPublicIp() throws Exception {
-        JcloudsSshMachineLocation machine = obtainMachine(ImmutableMap.of());
-
-        assertEquals(machine.getPublicAddresses().size(), 1);
-        String publicAddress = machine.getPublicAddresses().iterator().next();
-
-        assertEquals(machine.getPrivateAddress().get(), publicAddress);
-        assertEquals(machine.getSubnetHostname(), machine.getHostname());
-        assertEquals(machine.getSubnetIp(), publicAddress);
-    }
-}


Mime
View raw message