From b3de104bf769d80234f68135feff6e2b7469ad6c Mon Sep 17 00:00:00 2001 From: Aled Sage Date: Wed, 31 Aug 2016 20:33:48 +0100 Subject: [PATCH] Set default minRam to 1gb MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also changes JcloudsLocation’s template building so that if a config key has a default value then that will be used, if there is no explicit value (or empty value) set. --- .../core/location/cloud/CloudLocationConfig.java | 2 +- .../brooklyn/location/jclouds/JcloudsLocation.java | 9 +++++---- .../jclouds/JcloudsHardwareProfilesStubbedLiveTest.java | 5 +++++ 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/apache/brooklyn/core/location/cloud/CloudLocationConfig.java b/core/src/main/java/org/apache/brooklyn/core/location/cloud/CloudLocationConfig.java index f749f64490..77d888f627 100644 --- a/core/src/main/java/org/apache/brooklyn/core/location/cloud/CloudLocationConfig.java +++ b/core/src/main/java/org/apache/brooklyn/core/location/cloud/CloudLocationConfig.java @@ -103,7 +103,7 @@ public interface CloudLocationConfig { "Whether to require 64-bit OS images (true), 32-bit images (false), or either (null)"); public static final ConfigKey MIN_RAM = new BasicConfigKey(Object.class, "minRam", - "Minimum amount of RAM, either as string (4gb) or number of MB (4096), for use in selecting the machine/hardware profile", null); + "Minimum amount of RAM, either as string (4gb) or number of MB (4096), for use in selecting the machine/hardware profile", "1gb"); public static final ConfigKey MIN_CORES = new BasicConfigKey(Integer.class, "minCores", "Minimum number of cores, for use in selecting the machine/hardware profile", null); 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 9ed2672a5f..a1d129360b 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 @@ -1647,10 +1647,11 @@ public Template buildTemplate(ComputeService computeService, ConfigBag config) { // Apply the template builder and options properties for (Map.Entry, 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)); + ConfigKey key = entry.getKey(); + Object val = config.containsKey(key) ? config.get(key) : key.getDefaultValue(); + if (val != null) { + CustomizeTemplateBuilder code = entry.getValue(); + code.apply(templateBuilder, config, val); } } diff --git a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsHardwareProfilesStubbedLiveTest.java b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsHardwareProfilesStubbedLiveTest.java index d899da1ceb..b95c371bc1 100644 --- a/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsHardwareProfilesStubbedLiveTest.java +++ b/locations/jclouds/src/test/java/org/apache/brooklyn/location/jclouds/JcloudsHardwareProfilesStubbedLiveTest.java @@ -63,6 +63,10 @@ protected NodeCreator newNodeCreator() { @Test(groups={"Live", "Live-sanity"}) public void testJcloudsCreateWithHardwareProfiles() throws Exception { + // default minRam is 1gb (but default smallest VM in softlayer is 1024mb so not a particularly useful test!) + obtainMachine(); + assertTrue(template.getHardware().getRam() >= 1000, "template="+template); + obtainMachine(MutableMap.of(JcloudsLocationConfig.MIN_RAM, "4096")); assertTrue(template.getHardware().getRam() >= 4096, "template="+template); @@ -76,4 +80,5 @@ public void testJcloudsCreateWithHardwareProfiles() throws Exception { obtainMachine(MutableMap.of(JcloudsLocationConfig.HARDWARE_ID, hardwareId)); assertEquals(template.getHardware().getId(), hardwareId, "template="+template); } + }