You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/04/20 18:29:54 UTC

[1/2] brooklyn-server git commit: BROOKLYN-257: allow nulling imageId in jcloudsLocation.obtain()

Repository: brooklyn-server
Updated Branches:
  refs/heads/master d3cc05026 -> fee7438f9


BROOKLYN-257: allow nulling imageId in jcloudsLocation.obtain()

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

Branch: refs/heads/master
Commit: d5a01b23ec38b7f6e3faba9b7b6ef45257113d55
Parents: d27d6c7
Author: Aled Sage <al...@gmail.com>
Authored: Sat Apr 16 21:19:12 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Sat Apr 16 21:19:12 2016 +0100

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       |  8 +-
 .../jclouds/AbstractJcloudsStubbedLiveTest.java | 12 ++-
 .../JcloudsImageChoiceStubbedLiveTest.java      | 83 ++++++++++++++++++++
 3 files changed, 99 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d5a01b23/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 14c5cfb..814df27 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
@@ -1146,11 +1146,15 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
                     }})
             .put(HARDWARE_ID, new CustomizeTemplateBuilder() {
                     public void apply(TemplateBuilder tb, ConfigBag props, Object v) {
-                        tb.hardwareId(((CharSequence)v).toString());
+                        if (v != null) {
+                            tb.hardwareId(((CharSequence)v).toString());
+                        }
                     }})
             .put(IMAGE_ID, new CustomizeTemplateBuilder() {
                     public void apply(TemplateBuilder tb, ConfigBag props, Object v) {
-                        tb.imageId(((CharSequence)v).toString());
+                        if (v != null) {
+                            tb.imageId(((CharSequence)v).toString());
+                        }
                     }})
             .put(IMAGE_DESCRIPTION_REGEX, new CustomizeTemplateBuilder() {
                     public void apply(TemplateBuilder tb, ConfigBag props, Object v) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d5a01b23/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedLiveTest.java
index 472dbf3..cb2334a 100644
--- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedLiveTest.java
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/AbstractJcloudsStubbedLiveTest.java
@@ -19,6 +19,7 @@
 package org.apache.brooklyn.location.jclouds;
 
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.apache.brooklyn.util.core.config.ConfigBag;
@@ -115,9 +116,16 @@ public abstract class AbstractJcloudsStubbedLiveTest extends AbstractJcloudsLive
         };
         jcloudsLocation = (JcloudsLocation) managementContext.getLocationRegistry().getLocationManaged(
                 LOCATION_SPEC, 
-                ImmutableMap.of(
+                jcloudsLocationConfig(ImmutableMap.<Object, Object>of(
                         JcloudsLocationConfig.COMPUTE_SERVICE_REGISTRY, computeServiceRegistry,
-                        JcloudsLocationConfig.WAIT_FOR_SSHABLE, "false"));
+                        JcloudsLocationConfig.WAIT_FOR_SSHABLE, "false")));
+    }
+    
+    /**
+     * For overriding.
+     */
+    protected Map<Object, Object> jcloudsLocationConfig(Map<Object, Object> defaults) {
+        return defaults;
     }
     
     protected abstract NodeCreator newNodeCreator();

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/d5a01b23/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsImageChoiceStubbedLiveTest.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsImageChoiceStubbedLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsImageChoiceStubbedLiveTest.java
new file mode 100644
index 0000000..4560096
--- /dev/null
+++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsImageChoiceStubbedLiveTest.java
@@ -0,0 +1,83 @@
+/*
+ * 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.Map;
+
+import org.apache.brooklyn.util.collections.MutableMap;
+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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.testng.annotations.Test;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+
+public class JcloudsImageChoiceStubbedLiveTest extends AbstractJcloudsStubbedLiveTest {
+
+    @SuppressWarnings("unused")
+    private static final Logger log = LoggerFactory.getLogger(JcloudsImageChoiceStubbedLiveTest.class);
+    
+    private Template template;
+    
+    @Override
+    protected NodeCreator newNodeCreator() {
+        return new NodeCreator() {
+            @Override protected NodeMetadata newNode(String group, Template template) {
+                JcloudsImageChoiceStubbedLiveTest.this.template = template;
+                
+                NodeMetadata result = new NodeMetadataBuilder()
+                        .id("myid")
+                        .credentials(LoginCredentials.builder().identity("myuser").credential("mypassword").build())
+                        .loginPort(22)
+                        .status(Status.RUNNING)
+                        .publicAddresses(ImmutableList.of("173.194.32.123"))
+                        .privateAddresses(ImmutableList.of("172.168.10.11"))
+                        .build();
+                return result;
+            }
+        };
+    }
+
+    protected Map<Object, Object> jcloudsLocationConfig(Map<Object, Object> defaults) {
+        return ImmutableMap.<Object, Object>builder()
+                .putAll(defaults)
+                .put(JcloudsLocationConfig.IMAGE_ID, "CENTOS_5_64")
+                .build();
+    }
+
+    @Test(groups={"Live", "Live-sanity"})
+    public void testJcloudsCreateWithImageId() throws Exception {
+        obtainMachine(ImmutableMap.of(JcloudsLocationConfig.IMAGE_ID, "DEBIAN_8_64"));
+        assertEquals(template.getImage().getId(), "DEBIAN_8_64", "template="+template);
+    }
+    
+    @Test(groups={"Live", "Live-sanity"})
+    public void testJcloudsCreateWithImageDescriptionRegex() throws Exception {
+        // overrides the imageId specified in jcloudsLocationConfig
+        obtainMachine(MutableMap.of(JcloudsLocationConfig.IMAGE_DESCRIPTION_REGEX, ".*DEBIAN_8_64.*", JcloudsLocationConfig.IMAGE_ID, null));
+        assertEquals(template.getImage().getId(), "DEBIAN_8_64", "template="+template);
+    }
+}


[2/2] brooklyn-server git commit: Closes #115

Posted by sv...@apache.org.
Closes #115

BROOKLYN-257: allow nulling imageId in jcloudsLocation.obtain()

Fixes https://issues.apache.org/jira/browse/BROOKLYN-257.

To fix this, I was tempted to instead change `JcloudsLocation.buildTemplate` so that it ignored all null values, changing the code below:

```
        for (Map.Entry<ConfigKey<?>, CustomizeTemplateBuilder> entry : SUPPORTED_TEMPLATE_BUILDER_PROPERTIES.entrySet()) {
            ConfigKey<?> name = entry.getKey();
            CustomizeTemplateBuilder code = entry.getValue();
            if (config.containsKey(name))
                code.apply(templateBuilder, config, config.get(name));
        }
```

to:

```
        for (Map.Entry<ConfigKey<?>, CustomizeTemplateBuilder> entry : SUPPORTED_TEMPLATE_BUILDER_PROPERTIES.entrySet()) {
            ConfigKey<?> name = entry.getKey();
            CustomizeTemplateBuilder code = entry.getValue();
            if (config.containsKey(name) && config.get(name) != null)
                code.apply(templateBuilder, config, config.get(name));
        }
```

But is that risky? Do we rely for any config keys on `null` meaning something other than "use the jclouds default"?


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

Branch: refs/heads/master
Commit: fee7438f9328dda368ff69b881cc7b30e6a48b50
Parents: d3cc050 d5a01b2
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Wed Apr 20 17:29:40 2016 +0100
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Wed Apr 20 17:29:40 2016 +0100

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       |  8 +-
 .../jclouds/AbstractJcloudsStubbedLiveTest.java | 12 ++-
 .../JcloudsImageChoiceStubbedLiveTest.java      | 83 ++++++++++++++++++++
 3 files changed, 99 insertions(+), 4 deletions(-)
----------------------------------------------------------------------