You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2014/10/28 19:04:34 UTC

[1/2] git commit: Adds JcloudsLocation.SKIP_JCLOUDS_SSHING

Repository: incubator-brooklyn
Updated Branches:
  refs/heads/master f8d2d51e0 -> 7dfb08972


Adds JcloudsLocation.SKIP_JCLOUDS_SSHING

- Config option to do all ssh’ing in brooklyn code, rather than
  configuring the jclouds TemplateOptions to setup the user.
- i.e. have jclouds return the VM, before we then execute the ssh
  commands for user setup/creation.


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

Branch: refs/heads/master
Commit: 4bf3cd2b4e8b279cf5b965bb5efe9efd0ff23b7f
Parents: e994a3a
Author: Aled Sage <al...@gmail.com>
Authored: Thu Oct 23 09:26:03 2014 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Oct 27 11:47:05 2014 +0000

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       | 30 ++++++----
 .../location/jclouds/JcloudsLocationConfig.java | 15 ++++-
 .../jclouds/AbstractJcloudsLiveTest.java        |  3 +
 .../location/jclouds/JcloudsSshingLiveTest.java | 61 ++++++++++++++++++++
 4 files changed, 98 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4bf3cd2b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index 0b8807d..5cccc46 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -544,6 +544,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
         setCreationString(setup);
         boolean waitForSshable = !"false".equalsIgnoreCase(setup.get(WAIT_FOR_SSHABLE));
         boolean usePortForwarding = setup.get(USE_PORT_FORWARDING);
+        boolean skipJcloudsSshing = Boolean.FALSE.equals(setup.get(USE_JCLOUDS_SSH_INIT)) || usePortForwarding;
         JcloudsPortForwarderExtension portForwarder = setup.get(PORT_FORWARDER);
         if (usePortForwarding) checkNotNull(portForwarder, "portForwarder, when use-port-forwarding enabled");
 
@@ -576,7 +577,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
             try {
                 // Setup the template
                 template = buildTemplate(computeService, setup);
-                if (waitForSshable && !usePortForwarding) {
+                if (waitForSshable && !skipJcloudsSshing) {
                     initialCredentials = initTemplateForCreateUser(template, setup);
                 }
 
@@ -615,15 +616,15 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
                         Optional.<Integer>absent(), 
                         Protocol.TCP, 
                         Cidr.UNIVERSAL));
-                
-                if (waitForSshable) {
-                    // once that host:port is definitely reachable, we can create the user
-                    waitForReachable(computeService, node, sshHostAndPortOverride, node.getCredentials(), setup);
-                    initialCredentials = createUser(computeService, node, sshHostAndPortOverride, setup);
-                }
             } else {
                 sshHostAndPortOverride = Optional.absent();
             }
+                
+            if (waitForSshable && skipJcloudsSshing) {
+                // once that host:port is definitely reachable, we can create the user
+                waitForReachable(computeService, node, sshHostAndPortOverride, node.getCredentials(), setup);
+                initialCredentials = createUser(computeService, node, sshHostAndPortOverride, setup);
+            }
             
             // Figure out which login-credentials to use
             LoginCredentials customCredentials = setup.get(CUSTOM_CREDENTIALS);
@@ -632,8 +633,8 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
                 //set userName and other data, from these credentials
                 Object oldUsername = setup.put(USER, customCredentials.getUser());
                 LOG.debug("node {} username {} / {} (customCredentials)", new Object[] { node, customCredentials.getUser(), oldUsername });
-                if (groovyTruth(customCredentials.getPassword())) setup.put(PASSWORD, customCredentials.getPassword());
-                if (groovyTruth(customCredentials.getPrivateKey())) setup.put(PRIVATE_KEY_DATA, customCredentials.getPrivateKey());
+                if (customCredentials.getOptionalPassword().isPresent()) setup.put(PASSWORD, customCredentials.getOptionalPassword().get());
+                if (customCredentials.getOptionalPrivateKey().isPresent()) setup.put(PRIVATE_KEY_DATA, customCredentials.getOptionalPrivateKey().get());
             }
             if (initialCredentials == null) {
                 initialCredentials = extractVmCredentials(setup, node);
@@ -1165,9 +1166,18 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
             if (initialPassword.isPresent()) sshProps.put("password", initialPassword.get());
             if (initialPrivateKey.isPresent()) sshProps.put("privateKeyData", initialPrivateKey.get());
             
+            // TODO Retrying lots of times as workaround for vcloud-director. There the guest customizations
+            // can cause the VM to reboot shortly after it was ssh'able.
             Map<String,Object> execProps = Maps.newLinkedHashMap();
             execProps.put(ShellTool.PROP_RUN_AS_ROOT.getName(), true);
-            
+            execProps.put(SshTool.PROP_SSH_TRIES.getName(), 50);
+            execProps.put(SshTool.PROP_SSH_TRIES_TIMEOUT.getName(), 10*60*1000);
+
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("VM {}: executing user creation/setup via {}@{}:{}; commands: {}", new Object[] {
+                        config.getDescription(), initialUser, address, port, commands});
+            }
+
             SshMachineLocation sshLoc = null;
             try {
                 if (isManaged()) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4bf3cd2b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
index a1ae73f..0346940 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
@@ -37,6 +37,7 @@ import brooklyn.location.cloud.CloudLocationConfig;
 import brooklyn.location.jclouds.networking.JcloudsPortForwarderExtension;
 import brooklyn.util.internal.ssh.SshTool;
 
+import com.google.common.annotations.Beta;
 import com.google.common.base.Function;
 import com.google.common.reflect.TypeToken;
 
@@ -191,9 +192,21 @@ public interface JcloudsLocationConfig extends CloudLocationConfig {
             "generate.hostname", "Use the nodename generated by jclouds", false);
 
     public static final ConfigKey<Boolean> USE_PORT_FORWARDING = ConfigKeys.newBooleanConfigKey(
-            "portforwarding.enabled", "Whether to setup port-forwarding to subsequently access the VM (over the ssh port)", false);
+            "portforwarding.enabled", 
+            "Whether to setup port-forwarding to subsequently access the VM (over the ssh port)",
+            false);
+    
+    @Beta
+    public static final ConfigKey<Boolean> USE_JCLOUDS_SSH_INIT = ConfigKeys.newBooleanConfigKey(
+            "useJcloudsSshInit", 
+            "Whether to use jclouds for initial ssh-based setup (i.e. as part of the 'TemplateOptions'); "
+                    + "if false will use core brooklyn ssh utilities. "
+                    + "This config is beta; its default could be changed and/or the option removed in an upcoming release.", 
+            true);
+    
     public static final ConfigKey<JcloudsPortForwarderExtension> PORT_FORWARDER = ConfigKeys.newConfigKey(
             JcloudsPortForwarderExtension.class, "portforwarding.forwarder", "The port-forwarder to use");
+    
     public static final ConfigKey<PortForwardManager> PORT_FORWARDING_MANAGER = BrooklynAccessUtils
             .PORT_FORWARDING_MANAGER;
 

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4bf3cd2b/locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
index 0af5ad5..221df5f 100644
--- a/locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
+++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
@@ -57,6 +57,9 @@ public class AbstractJcloudsLiveTest {
 
     public static final String RACKSPACE_PROVIDER = "rackspace-cloudservers-uk";
     
+    public static final String SOFTLAYER_PROVIDER = "softlayer";
+    public static final String SOFTLAYER_AMS01_REGION_NAME = "ams01";
+    
     protected BrooklynProperties brooklynProperties;
     protected LocalManagementContext managementContext;
     

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4bf3cd2b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsSshingLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsSshingLiveTest.java b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsSshingLiveTest.java
new file mode 100644
index 0000000..bc89fe6
--- /dev/null
+++ b/locations/jclouds/src/test/java/brooklyn/location/jclouds/JcloudsSshingLiveTest.java
@@ -0,0 +1,61 @@
+/*
+ * 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.jclouds;
+
+import static org.testng.Assert.assertEquals;
+
+import org.testng.annotations.Test;
+
+import brooklyn.util.collections.MutableMap;
+
+import com.google.common.collect.ImmutableList;
+
+/**
+ * Tests the initial ssh command execution (e.g. user creation), using jclouds TemplateOptions
+ * and using just brooklyn.
+ */
+public class JcloudsSshingLiveTest extends AbstractJcloudsLiveTest {
+
+    public static final String SOFTLAYER_REGION_NAME = SOFTLAYER_AMS01_REGION_NAME;
+    public static final String SOTLAYER_LOCATION_SPEC = "jclouds:" + SOFTLAYER_PROVIDER + (SOFTLAYER_REGION_NAME == null ? "" : ":" + SOFTLAYER_REGION_NAME);
+    
+    protected JcloudsSshMachineLocation machine;
+    
+    @Test(groups = {"Live"})
+    public void testCreatesUserUsingJcloudsTemplateOptions() throws Exception {
+        runCreatesUser(true);
+    }
+    
+    @Test(groups = {"Live"})
+    public void testCreatesUserWithoutUsingJcloudsTemplateOptions() throws Exception {
+        runCreatesUser(false);
+    }
+    
+    protected void runCreatesUser(boolean useJcloudsSshInit) throws Exception {
+        brooklynProperties.put(BROOKLYN_PROPERTIES_PREFIX+JcloudsLocationConfig.USE_JCLOUDS_SSH_INIT.getName(), Boolean.toString(useJcloudsSshInit));
+        brooklynProperties.put(BROOKLYN_PROPERTIES_PREFIX+JcloudsLocationConfig.USER.getName(), "myname");
+        jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().resolve(SOTLAYER_LOCATION_SPEC);
+        
+        JcloudsSshMachineLocation machine = obtainMachine(MutableMap.<String,Object>builder()
+                .putIfAbsent("inboundPorts", ImmutableList.of(22))
+                .build());
+        assertSshable(machine);
+        assertEquals(machine.getUser(), "myname");
+    }
+}


[2/2] git commit: This closes #268

Posted by al...@apache.org.
This closes #268


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

Branch: refs/heads/master
Commit: 7dfb08972e5c7dfc579a83b5443cbfe4ea914132
Parents: f8d2d51 4bf3cd2
Author: Aled Sage <al...@gmail.com>
Authored: Tue Oct 28 18:04:09 2014 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Tue Oct 28 18:04:09 2014 +0000

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       | 30 ++++++----
 .../location/jclouds/JcloudsLocationConfig.java | 15 ++++-
 .../jclouds/AbstractJcloudsLiveTest.java        |  3 +
 .../location/jclouds/JcloudsSshingLiveTest.java | 61 ++++++++++++++++++++
 4 files changed, 98 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/7dfb0897/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------