Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 63CA9200AF5 for ; Thu, 2 Jun 2016 16:10:55 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 6248B160A3F; Thu, 2 Jun 2016 14:10:55 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 8327216098A for ; Thu, 2 Jun 2016 16:10:54 +0200 (CEST) Received: (qmail 30137 invoked by uid 500); 2 Jun 2016 14:10:53 -0000 Mailing-List: contact commits-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list commits@brooklyn.apache.org Received: (qmail 30118 invoked by uid 99); 2 Jun 2016 14:10:53 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 02 Jun 2016 14:10:53 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 69623DFE65; Thu, 2 Jun 2016 14:10:53 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: svet@apache.org To: commits@brooklyn.apache.org Date: Thu, 02 Jun 2016 14:10:53 -0000 Message-Id: <154fd33a202b4fa790e862e0df4efae1@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [1/2] brooklyn-server git commit: JcloudsLocation: handle config null values archived-at: Thu, 02 Jun 2016 14:10:55 -0000 Repository: brooklyn-server Updated Branches: refs/heads/master 817de333e -> 784e18fd1 JcloudsLocation: handle config null values Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/77369283 Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/77369283 Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/77369283 Branch: refs/heads/master Commit: 77369283de7ab69341296a84a67caf1813795038 Parents: 817de33 Author: Aled Sage Authored: Thu Jun 2 12:23:54 2016 +0100 Committer: Aled Sage Committed: Thu Jun 2 12:24:55 2016 +0100 ---------------------------------------------------------------------- .../jclouds/ComputeServiceRegistryImpl.java | 2 +- .../location/jclouds/JcloudsLocation.java | 27 +++++++----- .../JcloudsImageChoiceStubbedLiveTest.java | 45 ++++++++++++++++++++ 3 files changed, 62 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/77369283/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java ---------------------------------------------------------------------- diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java index a4af284..be4e924 100644 --- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java +++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/ComputeServiceRegistryImpl.java @@ -110,7 +110,7 @@ public class ComputeServiceRegistryImpl implements ComputeServiceRegistry, Jclou if (extra.size() > 0) { LOG.warn("Jclouds using deprecated property overrides: "+Sanitizer.sanitize(extra)); } - properties.putAll(extra); + properties.putAll(Maps.filterValues(extra, Predicates.notNull())); String endpoint = conf.get(CloudLocationConfig.CLOUD_ENDPOINT); if (!groovyTruth(endpoint)) endpoint = getDeprecatedProperty(conf, Constants.PROPERTY_ENDPOINT); http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/77369283/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 e30bc0d..71e3b01 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 @@ -1148,15 +1148,11 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im }}) .put(HARDWARE_ID, new CustomizeTemplateBuilder() { public void apply(TemplateBuilder tb, ConfigBag props, Object v) { - if (v != null) { - tb.hardwareId(((CharSequence)v).toString()); - } + tb.hardwareId(((CharSequence)v).toString()); }}) .put(IMAGE_ID, new CustomizeTemplateBuilder() { public void apply(TemplateBuilder tb, ConfigBag props, Object v) { - if (v != null) { - tb.imageId(((CharSequence)v).toString()); - } + tb.imageId(((CharSequence)v).toString()); }}) .put(IMAGE_DESCRIPTION_REGEX, new CustomizeTemplateBuilder() { public void apply(TemplateBuilder tb, ConfigBag props, Object v) { @@ -1412,9 +1408,16 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im Class clazz = options.getClass(); for(final Map.Entry option : optionsMap.entrySet()) { - Maybe result = MethodCoercions.tryFindAndInvokeBestMatchingMethod(options, option.getKey(), option.getValue()); - if(result.isAbsent()) { - LOG.warn("Ignoring request to set template option {} because this is not supported by {}", new Object[] { option.getKey(), clazz.getCanonicalName() }); + if (option.getValue() != null) { + Maybe result = MethodCoercions.tryFindAndInvokeBestMatchingMethod(options, option.getKey(), option.getValue()); + if(result.isAbsent()) { + LOG.warn("Ignoring request to set template option {} because this is not supported by {}", new Object[] { option.getKey(), clazz.getCanonicalName() }); + } + } else { + // jclouds really doesn't like you to pass nulls; don't do it! For us, + // null is the only way to remove an inherited value when the templateOptions + // map is being merged. + LOG.debug("Ignoring request to set template option {} because value is null", new Object[] { option.getKey(), clazz.getCanonicalName() }); } } }}) @@ -1519,8 +1522,9 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im for (Map.Entry, CustomizeTemplateBuilder> entry : SUPPORTED_TEMPLATE_BUILDER_PROPERTIES.entrySet()) { ConfigKey name = entry.getKey(); CustomizeTemplateBuilder code = entry.getValue(); - if (config.containsKey(name)) + if (config.containsKey(name) && config.get(name) != null) { code.apply(templateBuilder, config, config.get(name)); + } } if (templateBuilder instanceof PortableTemplateBuilder) { @@ -1620,8 +1624,9 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im for (Map.Entry, CustomizeTemplateOptions> entry : SUPPORTED_TEMPLATE_OPTIONS_PROPERTIES.entrySet()) { ConfigKey key = entry.getKey(); CustomizeTemplateOptions code = entry.getValue(); - if (config.containsKey(key)) + if (config.containsKey(key) && config.get(key) != null) { code.apply(options, config, config.get(key)); + } } return template; http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/77369283/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 index 0004333..a5d41de 100644 --- 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 @@ -82,4 +82,49 @@ public class JcloudsImageChoiceStubbedLiveTest extends AbstractJcloudsStubbedLiv obtainMachine(MutableMap.of(JcloudsLocationConfig.IMAGE_DESCRIPTION_REGEX, ".*DEBIAN_8_64.*", JcloudsLocationConfig.IMAGE_ID, null)); assertEquals(template.getImage().getId(), "DEBIAN_8_64", "template="+template); } + + @Test(groups={"Live", "Live-sanity"}) + @SuppressWarnings("deprecation") + public void testJcloudsCreateWithNulls() throws Exception { + obtainMachine(MutableMap.builder() + .put(JcloudsLocationConfig.IMAGE_ID, "DEBIAN_8_64") + .put(JcloudsLocationConfig.MIN_RAM, null) + .put(JcloudsLocationConfig.MIN_CORES, null) + .put(JcloudsLocationConfig.MIN_DISK, null) + .put(JcloudsLocationConfig.HARDWARE_ID, null) + .put(JcloudsLocationConfig.OS_64_BIT, null) + .put(JcloudsLocationConfig.OS_FAMILY, null) + .put(JcloudsLocationConfig.IMAGE_DESCRIPTION_REGEX, null) + .put(JcloudsLocationConfig.IMAGE_NAME_REGEX, null) + .put(JcloudsLocationConfig.OS_VERSION_REGEX, null) + .put(JcloudsLocationConfig.SECURITY_GROUPS, null) + .put(JcloudsLocationConfig.INBOUND_PORTS, null) + .put(JcloudsLocationConfig.USER_METADATA_STRING, null) + .put(JcloudsLocationConfig.USER_DATA_UUENCODED, null) + .put(JcloudsLocationConfig.STRING_TAGS, null) + .put(JcloudsLocationConfig.USER_METADATA_MAP, null) + .put(JcloudsLocationConfig.EXTRA_PUBLIC_KEY_DATA_TO_AUTH, null) + .put(JcloudsLocationConfig.RUN_AS_ROOT, null) + .put(JcloudsLocationConfig.LOGIN_USER, null) + .put(JcloudsLocationConfig.LOGIN_USER_PASSWORD, null) + .put(JcloudsLocationConfig.LOGIN_USER_PRIVATE_KEY_FILE, null) + .put(JcloudsLocationConfig.KEY_PAIR, null) + .put(JcloudsLocationConfig.AUTO_GENERATE_KEYPAIRS, null) + .put(JcloudsLocationConfig.AUTO_CREATE_FLOATING_IPS, null) + .put(JcloudsLocationConfig.AUTO_ASSIGN_FLOATING_IP, null) + .put(JcloudsLocationConfig.NETWORK_NAME, null) + .put(JcloudsLocationConfig.DOMAIN_NAME, null) + .put(JcloudsLocationConfig.TEMPLATE_OPTIONS, null) + .build()); + assertEquals(template.getImage().getId(), "DEBIAN_8_64", "template="+template); + } + + @Test(groups={"Live", "Live-sanity"}) + public void testJcloudsCreateWithNullTemplateOptionVal() throws Exception { + obtainMachine(MutableMap.builder() + .put(JcloudsLocationConfig.IMAGE_ID, "DEBIAN_8_64") + .put(JcloudsLocationConfig.TEMPLATE_OPTIONS, MutableMap.of("domainName", null)) + .build()); + assertEquals(template.getImage().getId(), "DEBIAN_8_64", "template="+template); + } }