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/06/02 14:10:53 UTC
[1/2] brooklyn-server git commit: JcloudsLocation: handle config null
values
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 <al...@gmail.com>
Authored: Thu Jun 2 12:23:54 2016 +0100
Committer: Aled Sage <al...@gmail.com>
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<? extends TemplateOptions> clazz = options.getClass();
for(final Map.Entry<String, Object> 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<ConfigKey<?>, 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<ConfigKey<?>, 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);
+ }
}
[2/2] brooklyn-server git commit: Closes #178
Posted by sv...@apache.org.
Closes #178
JcloudsLocation: handle config null values
As discussed in https://github.com/apache/brooklyn-server/pull/115 (for BROOKLYN-286)...
I've confirmed that the live tests in `JcloudsImageChoiceStubbedLiveTest` work for me.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo
Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/784e18fd
Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/784e18fd
Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/784e18fd
Branch: refs/heads/master
Commit: 784e18fd106dd15084052a8ed71015450f13ca3a
Parents: 817de33 7736928
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Thu Jun 2 17:10:43 2016 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Thu Jun 2 17:10:43 2016 +0300
----------------------------------------------------------------------
.../jclouds/ComputeServiceRegistryImpl.java | 2 +-
.../location/jclouds/JcloudsLocation.java | 27 +++++++-----
.../JcloudsImageChoiceStubbedLiveTest.java | 45 ++++++++++++++++++++
3 files changed, 62 insertions(+), 12 deletions(-)
----------------------------------------------------------------------