brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [1/6] brooklyn-server git commit: brooklyn.parameter: accept more basic types
Date Thu, 11 Aug 2016 19:38:42 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master 6f148be98 -> b4b48b3fd


brooklyn.parameter: accept more basic types

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

Branch: refs/heads/master
Commit: 611c75f774c484785ee2ab3e30e674ae72a660fd
Parents: bbe8e7a3
Author: Aled Sage <aled.sage@gmail.com>
Authored: Wed Aug 10 21:13:57 2016 +0100
Committer: Aled Sage <aled.sage@gmail.com>
Committed: Thu Aug 11 20:37:25 2016 +0100

----------------------------------------------------------------------
 .../camp/brooklyn/ConfigParametersYamlTest.java | 66 ++++++++++++++++++++
 .../brooklyn/core/objs/BasicSpecParameter.java  |  7 ++-
 2 files changed, 71 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/611c75f7/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
----------------------------------------------------------------------
diff --git a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
index 4f9ead8..f187b6c 100644
--- a/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
+++ b/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/ConfigParametersYamlTest.java
@@ -21,17 +21,22 @@ package org.apache.brooklyn.camp.brooklyn;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertNotNull;
 
+import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.location.PortRange;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 import org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess;
 import org.apache.brooklyn.test.Asserts;
+import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.core.internal.ssh.ExecCmdAsserts;
 import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool;
 import org.apache.brooklyn.util.core.internal.ssh.RecordingSshTool.ExecCmd;
+import org.apache.brooklyn.util.time.Duration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.BeforeMethod;
@@ -332,4 +337,65 @@ public class ConfigParametersYamlTest extends AbstractYamlTest {
         assertEquals(cmd.env.get("KEY_IN_SUPER"), "myDefaultVal", "cmd="+cmd);
         assertEquals(cmd.env.get("KEY_IN_SUB"), "myBoringVal", "cmd="+cmd);
     }
+    
+    @Test
+    public void testConfigParametersTypes() throws Exception {
+        Map<String, Class<?>> keys = ImmutableMap.<String, Class<?>>builder()
+                .put("bool", Boolean.class)
+                .put("boolean", Boolean.class)
+                .put("Boolean", Boolean.class)
+                .put("byte", Byte.class)
+                .put("Byte", Byte.class)
+                .put("char", Character.class)
+                .put("character", Character.class)
+                .put("Character", Character.class)
+                .put("short", Short.class)
+                .put("Short", Short.class)
+                .put("int", Integer.class)
+                .put("integer", Integer.class)
+                .put("Integer", Integer.class)
+                .put("long", Long.class)
+                .put("Long", Long.class)
+                .put("float", Float.class)
+                .put("Float", Float.class)
+                .put("double", Double.class)
+                .put("Double", Double.class)
+                .put("string", String.class)
+                .put("String", String.class)
+                .put("duration", Duration.class)
+                .put("Duration", Duration.class)
+                .put("timestamp", Date.class)
+                .put("Timestamp", Date.class)
+                .put("port", PortRange.class)
+                .put("Port", PortRange.class)
+                .build();
+        
+        List<String> catalogYaml = MutableList.of(
+                "brooklyn.catalog:",
+                "  itemType: entity",
+                "  items:",
+                "  - id: entity-with-keys",
+                "    item:",
+                "      type: "+TestEntity.class.getName(),
+                "      brooklyn.parameters:");
+        for (Map.Entry<String, Class<?>> entry : keys.entrySet()) {
+                catalogYaml.add("      - name: "+entry.getKey()+"_key");
+                catalogYaml.add("        type: "+entry.getKey());
+        }
+        
+        addCatalogItems(catalogYaml);
+        
+        String yaml = Joiner.on("\n").join(
+                "services:",
+                "- type: entity-with-keys");
+        
+        Entity app = createStartWaitAndLogApplication(yaml);
+        TestEntity entity = (TestEntity) Iterables.getOnlyElement(app.getChildren());
+
+        // Check config key is listed
+        for (Map.Entry<String, Class<?>> entry : keys.entrySet()) {
+            String keyName = entry.getKey()+"_key";
+            assertEquals(entity.getEntityType().getConfigKey(keyName).getType(), entry.getValue());
+        }
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/611c75f7/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java b/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
index e525fc6..08d0ad3 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
@@ -185,11 +185,14 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
         private static final String DEFAULT_TYPE = "string";
         private static final Map<String, Class<?>> BUILT_IN_TYPES = ImmutableMap.<String,
Class<?>>builder()
                 .put(DEFAULT_TYPE, String.class)
+                .put("bool", Boolean.class)
                 .put("boolean", Boolean.class)
                 .put("byte", Byte.class)
                 .put("char", Character.class)
+                .put("character", Character.class)
                 .put("short", Short.class)
                 .put("integer", Integer.class)
+                .put("int", Integer.class)
                 .put("long", Long.class)
                 .put("float", Float.class)
                 .put("double", Double.class)
@@ -258,8 +261,8 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
         private static TypeToken inferType(String typeRaw, BrooklynClassLoadingContext loader)
{
             if (typeRaw == null) return TypeToken.of(String.class);
             String type = typeRaw.trim();
-            if (BUILT_IN_TYPES.containsKey(type)) {
-                return TypeToken.of(BUILT_IN_TYPES.get(type));
+            if (BUILT_IN_TYPES.containsKey(type.toLowerCase())) {
+                return TypeToken.of(BUILT_IN_TYPES.get(type.toLowerCase()));
             } else {
                 // Assume it's a Java type
                 Maybe<Class<?>> inputType = loader.tryLoadClass(type);


Mime
View raw message