brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/3] brooklyn-server git commit: Added functionality to overwrite pricate ip/hostname as public ip/hostname
Date Mon, 28 Nov 2016 16:46:21 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master ca0335916 -> b11c87d94


Added functionality to overwrite pricate ip/hostname as public ip/hostname


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

Branch: refs/heads/master
Commit: 2e8e98d5956927adaab887acf7bd9539a556b90b
Parents: 880f842
Author: graeme.miller <graeme.miller@cloudsoftcorp.com>
Authored: Thu Nov 24 14:13:00 2016 +0000
Committer: graeme.miller <graeme.miller@cloudsoftcorp.com>
Committed: Fri Nov 25 16:09:01 2016 +0000

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       |  6 ++
 .../location/jclouds/JcloudsLocationConfig.java |  6 ++
 .../jclouds/JcloudsSshMachineLocation.java      | 10 ++-
 ...SshMachineLocationEndpointOverwriteTest.java | 93 ++++++++++++++++++++
 4 files changed, 114 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2e8e98d5/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 6582b02..4ee4b1b 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
@@ -3356,6 +3356,12 @@ 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");
+            return getPublicHostname(node, sshHostAndPort, userCredentials, setup);
+        }
+
         String provider = (setup != null) ? setup.get(CLOUD_PROVIDER) : null;
         Boolean lookupAwsHostname = (setup != null) ? setup.get(LOOKUP_AWS_HOSTNAME) : null;
         if (provider == null) provider = getProvider();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2e8e98d5/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 3c07f4b..e8f4521 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,6 +293,12 @@ 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");
 
+    @Beta
+    public static final ConfigKey<Boolean> USE_PUBLIC_ENDPOINT_AS_PRIVATE_ENDPOINT
= ConfigKeys.newBooleanConfigKey(
+            "usePublicEndpointAsPrivateEndpoint",
+            "When true we will use the public IP/Hostname of a JClouds Location as the private
IP/Hostname",
+            false);
+
     // TODO
     
 //  "noDefaultSshKeys" - hints that local ssh keys should not be read as defaults

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2e8e98d5/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 3688aa8..8f00683 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,6 +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.util.JavaGroovyEquivalents.groovyTruth;
 
 import java.util.List;
@@ -201,9 +202,16 @@ public class JcloudsSshMachineLocation extends SshMachineLocation implements
Jcl
         config().removeKey("node");
         nodeId = node.getId();
         imageId = node.getImageId();
-        privateAddresses = node.getPrivateAddresses();
         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");
+            privateAddresses = node.getPublicAddresses();
+        } else {
+            privateAddresses = node.getPrivateAddresses();
+        }
     }
 
     protected void setTemplate(Template template) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2e8e98d5/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
new file mode 100644
index 0000000..3e1812a
--- /dev/null
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsSshMachineLocationEndpointOverwriteTest.java
@@ -0,0 +1,93 @@
+/*
+ * 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