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 2016/12/19 15:51:10 UTC

[1/4] brooklyn-server git commit: Add/improve jclouds live tests

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 3b4f394fc -> 5f1588ed2


Add/improve jclouds live tests


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

Branch: refs/heads/master
Commit: e0a9d53f3bab07107ced8612337baa20450c8f4a
Parents: 3b4f394
Author: Aled Sage <al...@gmail.com>
Authored: Fri Dec 16 14:02:52 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Dec 19 11:09:05 2016 +0000

----------------------------------------------------------------------
 .../jclouds/AbstractJcloudsLiveTest.java        | 10 ++-
 .../jclouds/JcloudsWinrmingLiveTest.java        | 42 +++++++++--
 .../provider/AwsEc2LocationLiveTest.java        | 11 ++-
 .../jclouds/provider/GceLocationLiveTest.java   | 74 ++++++++++++++++++++
 .../provider/SoftlayerLocationLiveTest.java     | 65 +++++++++++++++++
 5 files changed, 192 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0a9d53f/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
index f2b79d2..706d308 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsLiveTest.java
@@ -22,6 +22,7 @@ import static com.google.common.base.Preconditions.checkNotNull;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 
+import java.net.InetAddress;
 import java.util.List;
 import java.util.Map;
 
@@ -144,7 +145,14 @@ public class AbstractJcloudsLiveTest {
     }
 
     protected void assertWinrmable(WinRmMachineLocation machine) {
-        WinRmToolResponse result = machine.executeCommand(ImmutableList.of("echo mySimpleWinrmCmd"));
+        // Assumes that tests are letting Brooklyn or the cloud auto-generate the password, so ok to log it.
+        // If the assertion fails, we want to know that it had a plausible-looking password etc.
+        WinRmToolResponse result;
+        try {
+            result = machine.executeCommand(ImmutableList.of("echo mySimpleWinrmCmd"));
+        } catch (Exception e) {
+            throw new RuntimeException("Error executing WinRM command on " + machine + " with config " + machine.config().getAllLocalRaw(), e);
+        }
         assertEquals(result.getStatusCode(), 0, "stdout="+result.getStdOut()+"; stderr="+result.getStdErr());
     }
 

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0a9d53f/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsWinrmingLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsWinrmingLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsWinrmingLiveTest.java
index 1c3e63e..df9fefc 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsWinrmingLiveTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsWinrmingLiveTest.java
@@ -18,30 +18,60 @@
  */
 package org.apache.brooklyn.location.jclouds;
 
+import java.util.Map;
+
 import org.apache.brooklyn.util.collections.MutableMap;
 import org.jclouds.compute.domain.OsFamily;
+import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 
 /**
  * Tests the initial WinRM command execution, for a VM provisioned through jclouds.
  */
 public class JcloudsWinrmingLiveTest extends AbstractJcloudsLiveTest {
 
-    public static final String AWS_EC2_LOCATION_SPEC = "jclouds:" + AWS_EC2_PROVIDER + ":" + AWS_EC2_EUWEST_REGION_NAME;
+    // TODO GCE fails with the default user ("Administrator").
+    //  - https://issues.apache.org/jira/browse/BROOKLYN-415 (worked around with `loginUser: myname`)
+    
+    // TODO Softlayer provisioning fails (therefore not included):
+    //     new Object[] { SOFTLAYER_LOCATION_SPEC, null, ImmutableMap.of(JcloudsLocation.IMAGE_ID.getName(), SOFTLAYER_IMAGE_ID, JcloudsLocation.VM_NAME_MAX_LENGTH.getName(), 15) }
+    //
+    // - https://issues.apache.org/jira/browse/BROOKLYN-414 (worked around with `vmNameMaxLength: 15`)
+    // - https://issues.apache.org/jira/browse/BROOKLYN-413
+    // - https://issues.apache.org/jira/browse/BROOKLYN-411
+
+    public static final String AWS_EC2_LOCATION_SPEC = "jclouds:" + AWS_EC2_PROVIDER + ":" + AWS_EC2_USEAST_REGION_NAME;
     public static final String AWS_EC2_IMAGE_NAME_REGEX = "Windows_Server-2012-R2_RTM-English-64Bit-Base-.*";
 
-    @Test(groups = {"Live"})
-    public void testCreatesWindowsVm() throws Exception {
-        jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged(AWS_EC2_LOCATION_SPEC);
-        
+    public static final String GCE_LOCATION_SPEC = "jclouds:" + GCE_PROVIDER + ":" + GCE_USCENTRAL_REGION_NAME;
+    public static final String GCE_IMAGE_NAME_REGEX = "windows-server-2012-r2-.*";
+
+    public static final String SOFTLAYER_LOCATION_SPEC = "jclouds:" + SOFTLAYER_PROVIDER;
+    public static final String SOFTLAYER_IMAGE_ID = "WIN_2012-STD-R2_64";
+
+    @DataProvider(name = "cloudAndImageNames")
+    public Object[][] cloudAndImageNames() {
+        return new Object[][] {
+                new Object[] { AWS_EC2_LOCATION_SPEC, AWS_EC2_IMAGE_NAME_REGEX, ImmutableMap.of() },
+                new Object[] { GCE_LOCATION_SPEC, GCE_IMAGE_NAME_REGEX, ImmutableMap.of(JcloudsLocation.LOGIN_USER.getName(), "myname") },
+            };
+    }
+
+    @Test(groups = "Live", dataProvider="cloudAndImageNames")
+    public void testCreatesWindowsVm(String locationSpec, String imageNameRegex, Map<String, ?> additionalConfig) throws Exception {
+        jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged(locationSpec);
+
         JcloudsWinRmMachineLocation machine = obtainWinrmMachine(MutableMap.<String,Object>builder()
                 .putIfAbsent("inboundPorts", ImmutableList.of(5986, 5985, 3389))
-                .put(JcloudsLocation.IMAGE_NAME_REGEX.getName(), AWS_EC2_IMAGE_NAME_REGEX)
+                .put(JcloudsLocation.IMAGE_NAME_REGEX.getName(), imageNameRegex)
                 .put(JcloudsLocation.USE_JCLOUDS_SSH_INIT.getName(), false)
                 .put(JcloudsLocation.OS_FAMILY_OVERRIDE.getName(), OsFamily.WINDOWS)
+                .putAll(additionalConfig != null ? additionalConfig : ImmutableMap.<String, Object>of())
                 .build());
         assertWinrmable(machine);
     }
+    
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0a9d53f/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
index 6644645..9ebd2e8 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/AwsEc2LocationLiveTest.java
@@ -21,15 +21,20 @@ package org.apache.brooklyn.location.jclouds.provider;
 import org.testng.annotations.DataProvider;
 import org.testng.annotations.Test;
 
+/**
+ * Tests basic provisioning to aws-ec2.
+ * 
+ * Requires AWS credentials be set up in {@code ~/.brooklyn/brooklyn.properties}.
+ */
 public class AwsEc2LocationLiveTest extends AbstractJcloudsLocationTest {
 
     private static final String PROVIDER = "aws-ec2";
     private static final String EUWEST_REGION_NAME = "eu-west-1";
     private static final String USEAST_REGION_NAME = "us-east-1";
-    private static final String EUWEST_IMAGE_ID = EUWEST_REGION_NAME+"/"+"ami-89def4fd"; // RightImage_CentOS_5.4_i386_v5.5.9_EBS
-    private static final String USEAST_IMAGE_ID = USEAST_REGION_NAME+"/"+"ami-2342a94a"; // RightImage_CentOS_5.4_i386_v5.5.9_EBS
+    private static final String EUWEST_IMAGE_ID = EUWEST_REGION_NAME+"/"+"ami-69841c1e"; // RightImage_CentOS_7.0_x64_v14.2.1_HVM_EBS
+    private static final String USEAST_IMAGE_ID = USEAST_REGION_NAME+"/"+"ami-5492ba3c"; // RightImage_CentOS_7.0_x64_v14.2.1_HVM_EBS
     private static final String IMAGE_OWNER = "411009282317";
-    private static final String IMAGE_PATTERN = "RightImage_CentOS_5.4_i386_v5.5.9_EBS";
+    private static final String IMAGE_PATTERN = "RightImage_CentOS_7.0_x64_v14.2.1.*";
 
     public AwsEc2LocationLiveTest() {
         super(PROVIDER);

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0a9d53f/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/GceLocationLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/GceLocationLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/GceLocationLiveTest.java
new file mode 100644
index 0000000..89906f1
--- /dev/null
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/GceLocationLiveTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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.provider;
+
+import org.apache.brooklyn.api.location.Location;
+import org.apache.brooklyn.api.mgmt.ManagementContext;
+import org.apache.brooklyn.core.internal.BrooklynProperties;
+import org.apache.brooklyn.core.test.entity.TestApplication;
+import org.testng.annotations.DataProvider;
+
+/**
+ * Tests basic provisioning to GCE.
+ * 
+ * Requires AWS credentials be set up in {@code ~/.brooklyn/brooklyn.properties}.
+ */
+public class GceLocationLiveTest extends AbstractJcloudsLocationTest {
+
+    // TODO Would be nice to support short-form of imageId and hardwareId!
+    
+    private static final String PROVIDER = "google-compute-engine";
+    private static final String IMAGE_ID = "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-v20161129";
+    private static final String IMAGE_PATTERN = "centos-6-.*";
+    private static final String REGION_NAME = null;
+    private static final String IMAGE_OWNER = null;
+    
+    protected BrooklynProperties brooklynProperties;
+    protected ManagementContext ctx;
+    
+    protected TestApplication app;
+    protected Location jcloudsLocation;
+    
+    public GceLocationLiveTest() {
+        super(PROVIDER);
+    }
+
+    @Override
+    @DataProvider(name = "fromImageId")
+    public Object[][] cloudAndImageIds() {
+        return new Object[][] {
+                new Object[] { REGION_NAME, IMAGE_ID, IMAGE_OWNER }
+            };
+    }
+
+    // For GCE, use "imageNamePattern" instead
+    @Override
+    @DataProvider(name = "fromImageDescriptionPattern")
+    public Object[][] cloudAndImageDescriptionPatterns() {
+        return new Object[][] {};
+    }
+
+    @Override
+    @DataProvider(name = "fromImageNamePattern")
+    public Object[][] cloudAndImageNamePatterns() {
+        return new Object[][] {
+                new Object[] { REGION_NAME, IMAGE_PATTERN, IMAGE_OWNER }
+            };
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/e0a9d53f/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/SoftlayerLocationLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/SoftlayerLocationLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/SoftlayerLocationLiveTest.java
new file mode 100644
index 0000000..8c6fe3c
--- /dev/null
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/provider/SoftlayerLocationLiveTest.java
@@ -0,0 +1,65 @@
+/*
+ * 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.provider;
+
+import org.testng.annotations.DataProvider;
+
+/**
+ * Tests basic provisioning to Softlayer.
+ * 
+ * Requires AWS credentials be set up in {@code ~/.brooklyn/brooklyn.properties}.
+ */
+public class SoftlayerLocationLiveTest extends AbstractJcloudsLocationTest {
+
+    private static final String PROVIDER = "softlayer";
+    private static final String IMAGE_ID = "CENTOS_6_64"; // Image: {id=CENTOS_6_64, providerId=CENTOS_6_64, os={family=centos, version=6.5, description=CentOS / CentOS / 6.5-64 LAMP for Bare Metal, is64Bit=true}, description=CENTOS_6_64, status=AVAILABLE, loginUser=root}
+    private static final String IMAGE_PATTERN = "CENTOS_6_64.*";
+    private static final String REGION_NAME = null;//FIXME "ams06";
+    private static final String IMAGE_OWNER = null;
+    
+//    public static final int MAX_TAG_LENGTH = 20;
+//    public static final int MAX_VM_NAME_LENGTH = 30;
+
+    public SoftlayerLocationLiveTest() {
+        super(PROVIDER);
+    }
+
+    @Override
+    @DataProvider(name = "fromImageId")
+    public Object[][] cloudAndImageIds() {
+        return new Object[][] {
+                new Object[] { REGION_NAME, IMAGE_ID, IMAGE_OWNER }
+            };
+    }
+
+    @Override
+    @DataProvider(name = "fromImageDescriptionPattern")
+    public Object[][] cloudAndImageDescriptionPatterns() {
+        return new Object[][] {
+                new Object[] { REGION_NAME, IMAGE_PATTERN, IMAGE_OWNER }
+            };
+    }
+
+    // For Softlayer, use "imageDescriptionPattern" instead
+    @Override
+    @DataProvider(name = "fromImageDescriptionPattern")
+    public Object[][] cloudAndImageNamePatterns() {
+        return new Object[][] {};
+    }
+}


[2/4] brooklyn-server git commit: Call BrooklynInitialization.initAll()

Posted by al...@apache.org.
Call BrooklynInitialization.initAll()

Previously, tests like JcloudsWinrmingLiveTest would fail unless
another test had run previously in the suite. Given that this init
is needed by Brooklyn, we should do it in the heart of Brooklyn (i.e.
the ManagementContext) rather than just in AbstractEntity!


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

Branch: refs/heads/master
Commit: 2a4a8a7e61e1df0a017667b63bf05f012a69b872
Parents: e0a9d53
Author: Aled Sage <al...@gmail.com>
Authored: Fri Dec 16 16:12:19 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Dec 19 11:11:35 2016 +0000

----------------------------------------------------------------------
 .../core/mgmt/internal/LocalManagementContext.java        | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/2a4a8a7e/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
index b1bf856..67cd15f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/internal/LocalManagementContext.java
@@ -46,6 +46,7 @@ import org.apache.brooklyn.api.mgmt.TaskAdaptable;
 import org.apache.brooklyn.core.BrooklynFeatureEnablement;
 import org.apache.brooklyn.core.effector.Effectors;
 import org.apache.brooklyn.core.entity.drivers.downloads.BasicDownloadsManager;
+import org.apache.brooklyn.core.internal.BrooklynInitialization;
 import org.apache.brooklyn.core.internal.BrooklynProperties;
 import org.apache.brooklyn.core.internal.BrooklynProperties.Factory.Builder;
 import org.apache.brooklyn.core.internal.storage.DataGridFactory;
@@ -77,6 +78,15 @@ public class LocalManagementContext extends AbstractManagementContext {
     
     private static final Logger log = LoggerFactory.getLogger(LocalManagementContext.class);
 
+    // Any usage of Brooklyn must first create a management context. Therefore do our 
+    // initialisation here.
+    // TODO We could delete our other calls to BrooklynInitialization.initAll(), to rely on
+    // just one (e.g. AbstractEntity should not need to do it; and that is insufficient if a test
+    // just deals with locations but not entities).
+    static {
+        BrooklynInitialization.initAll();
+    }
+    
     private static final Set<LocalManagementContext> INSTANCES = Collections.synchronizedSet(Collections.newSetFromMap(new WeakHashMap<LocalManagementContext, Boolean>()));
     
     private final Builder builder;


[3/4] brooklyn-server git commit: jclouds windows provisioning: pass password to WinRmMachineLocation

Posted by al...@apache.org.
jclouds windows provisioning: pass password to WinRmMachineLocation

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

Branch: refs/heads/master
Commit: 5fa4f3fc03b10c7e325da21963ce58ea3f3f099a
Parents: 2a4a8a7
Author: Aled Sage <al...@gmail.com>
Authored: Fri Dec 16 17:15:16 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Dec 19 11:42:47 2016 +0000

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       | 31 ++++++++++++--------
 1 file changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/5fa4f3fc/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 8a95ca0..8e8d4d3 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
@@ -842,7 +842,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
 
             // Create a JcloudsSshMachineLocation, and register it
             if (windows) {
-                machineLocation = registerWinRmMachineLocation(computeService, node, managementHostAndPort, setup);
+                machineLocation = registerWinRmMachineLocation(computeService, node, Optional.fromNullable(template), userCredentials, managementHostAndPort, setup);
             } else {
                 machineLocation = registerJcloudsSshMachineLocation(computeService, node, Optional.fromNullable(template), userCredentials, managementHostAndPort, setup);
             }
@@ -2387,7 +2387,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
         
 
         if (windows) {
-            return registerWinRmMachineLocation(computeService, node, managementHostAndPort, setup);
+            return registerWinRmMachineLocation(computeService, node, Optional.<Template>absent(), node.getCredentials(), managementHostAndPort, setup);
         } else {
             try {
                 return registerJcloudsSshMachineLocation(computeService, node, Optional.<Template>absent(), node.getCredentials(), managementHostAndPort, setup);
@@ -2519,8 +2519,9 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
         }
     }
 
-    protected JcloudsSshMachineLocation registerJcloudsSshMachineLocation(ComputeService computeService, NodeMetadata node, Optional<Template> template, LoginCredentials credentials,
-                                                                          HostAndPort managementHostAndPort, ConfigBag setup) throws IOException {
+    protected JcloudsSshMachineLocation registerJcloudsSshMachineLocation(ComputeService computeService, NodeMetadata node, 
+            Optional<Template> template, LoginCredentials credentials, HostAndPort managementHostAndPort, ConfigBag setup) 
+            throws IOException {
         JcloudsSshMachineLocation machine = createJcloudsSshMachineLocation(computeService, node, template, credentials, managementHostAndPort, setup);
         registerJcloudsMachineLocation(node.getId(), machine);
         return machine;
@@ -2532,8 +2533,9 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
         vmInstanceIds.put(machine, nodeId);
     }
 
-    protected JcloudsSshMachineLocation createJcloudsSshMachineLocation(ComputeService computeService, NodeMetadata node, Optional<Template> template,
-                                                                        LoginCredentials userCredentials, HostAndPort managementHostAndPort, ConfigBag setup) throws IOException {
+    protected JcloudsSshMachineLocation createJcloudsSshMachineLocation(ComputeService computeService, NodeMetadata node, 
+            Optional<Template> template, LoginCredentials userCredentials, HostAndPort managementHostAndPort, ConfigBag setup) 
+            throws IOException {
         Map<?,?> sshConfig = extractSshConfig(setup, node);
         String nodeAvailabilityZone = extractAvailabilityZone(setup, node);
         String nodeRegion = extractRegion(setup, node);
@@ -2611,14 +2613,15 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
         }
     }
 
-    protected JcloudsWinRmMachineLocation registerWinRmMachineLocation(ComputeService computeService, NodeMetadata node, HostAndPort managementHostAndPort,
-                                                                       ConfigBag setup) {
-        JcloudsWinRmMachineLocation machine = createWinRmMachineLocation(computeService, node, managementHostAndPort, setup);
+    protected JcloudsWinRmMachineLocation registerWinRmMachineLocation(ComputeService computeService, NodeMetadata node, 
+            Optional<Template> template, LoginCredentials credentials, HostAndPort managementHostAndPort, ConfigBag setup) {
+        JcloudsWinRmMachineLocation machine = createWinRmMachineLocation(computeService, node, template, credentials, managementHostAndPort, setup);
         registerJcloudsMachineLocation(node.getId(), machine);
         return machine;
     }
 
-    protected JcloudsWinRmMachineLocation createWinRmMachineLocation(ComputeService computeService, NodeMetadata node, HostAndPort winrmHostAndPort, ConfigBag setup) {
+    protected JcloudsWinRmMachineLocation createWinRmMachineLocation(ComputeService computeService, NodeMetadata node, 
+            Optional<Template> template, LoginCredentials userCredentials, HostAndPort winrmHostAndPort, ConfigBag setup) {
         Map<?,?> winrmConfig = extractWinrmConfig(setup, node);
         String nodeAvailabilityZone = extractAvailabilityZone(setup, node);
         String nodeRegion = extractRegion(setup, node);
@@ -2639,6 +2642,9 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
                     .configure(WinRmMachineLocation.WINRM_CONFIG_PORT, winrmHostAndPort.getPort())
                     .configure("user", getUser(setup))
                     .configure(WinRmMachineLocation.USER, setup.get(USER))
+                    .configure(SshMachineLocation.PASSWORD.getName(), winrmConfig.get(WinRmMachineLocation.PASSWORD.getName()) != null ?
+                            winrmConfig.get(WinRmMachineLocation.PASSWORD.getName()) :
+                            userCredentials.getOptionalPassword().orNull())
                     .configure("node", node)
                     .configureIfNotNull(CLOUD_AVAILABILITY_ZONE_ID, nodeAvailabilityZone)
                     .configureIfNotNull(CLOUD_REGION_ID, nodeRegion)
@@ -2930,9 +2936,10 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
      * Extracts the user that jclouds tells us about (i.e. from the jclouds node).
      */
     protected LoginCredentials extractVmCredentials(ConfigBag setup, NodeMetadata node, LoginCredentials nodeCredentials) {
+        boolean windows = isWindows(node, setup);
         String user = getUser(setup);
         OsCredential localCredentials = LocationConfigUtils.getOsCredential(setup).checkNoErrors();
-
+        
         LOG.debug("Credentials extracted for {}: {}/{} with {}/{}", new Object[] { node,
             user, nodeCredentials.getUser(), localCredentials, nodeCredentials });
 
@@ -2953,7 +2960,7 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
                 return null;
             } else {
                 LoginCredentials.Builder resultBuilder = LoginCredentials.builder().user(user);
-                if (pwd!=null && (Strings.isBlank(pkd) || localCredentials.isUsingPassword()))
+                if (pwd != null && (Strings.isBlank(pkd) || localCredentials.isUsingPassword() || windows))
                     resultBuilder.password(pwd);
                 else // pkd guaranteed non-blank due to above
                     resultBuilder.privateKey(pkd);


[4/4] brooklyn-server git commit: This closes #496

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


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

Branch: refs/heads/master
Commit: 5f1588ed2163e95e4c94c290c610f538716290e1
Parents: 3b4f394 5fa4f3f
Author: Aled Sage <al...@gmail.com>
Authored: Mon Dec 19 15:50:55 2016 +0000
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Dec 19 15:50:55 2016 +0000

----------------------------------------------------------------------
 .../mgmt/internal/LocalManagementContext.java   | 10 +++
 .../location/jclouds/JcloudsLocation.java       | 31 ++++----
 .../jclouds/AbstractJcloudsLiveTest.java        | 10 ++-
 .../jclouds/JcloudsWinrmingLiveTest.java        | 42 +++++++++--
 .../provider/AwsEc2LocationLiveTest.java        | 11 ++-
 .../jclouds/provider/GceLocationLiveTest.java   | 74 ++++++++++++++++++++
 .../provider/SoftlayerLocationLiveTest.java     | 65 +++++++++++++++++
 7 files changed, 221 insertions(+), 22 deletions(-)
----------------------------------------------------------------------