brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [02/10] incubator-brooklyn git commit: allow spec parameters to imply sensors as well as config keys; mainly intended for AttributeSensorAndConfigKey -- especially ports.
Date Sat, 30 Jan 2016 03:45:48 GMT
allow spec parameters to imply sensors as well as config keys;
mainly intended for AttributeSensorAndConfigKey -- especially ports.

this means param of type `port` given a range causes a sensor to be published with the actual
value.


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

Branch: refs/heads/master
Commit: 9141c99f4c0f295a3a39b75bf06b42f85650d3f4
Parents: 5e9012b
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Thu Jan 21 13:24:15 2016 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Thu Jan 21 13:25:37 2016 +0000

----------------------------------------------------------------------
 .../apache/brooklyn/api/objs/SpecParameter.java | 16 ++++-
 .../catalog/SpecParameterParsingTest.java       | 18 +++---
 .../brooklyn/core/config/BasicConfigKey.java    | 10 ++-
 .../brooklyn/core/config/ConfigConstraints.java |  3 +-
 .../brooklyn/core/objs/BasicSpecParameter.java  | 68 +++++++++++++++-----
 .../core/objs/proxy/InternalEntityFactory.java  | 14 ++--
 .../sensor/AttributeSensorAndConfigKey.java     |  9 ++-
 .../sensor/PortAttributeSensorAndConfigKey.java |  6 ++
 .../brooklyn/util/core/flags/FlagUtils.java     |  2 +-
 .../objs/BasicSpecParameterFromClassTest.java   |  2 +-
 .../objs/BasicSpecParameterFromListTest.java    | 14 ++--
 .../rest/transform/CatalogTransformer.java      |  8 ++-
 .../rest/transform/EntityTransformer.java       |  2 +-
 13 files changed, 117 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/objs/SpecParameter.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/objs/SpecParameter.java
b/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/objs/SpecParameter.java
index 4e9dc62..fd7047e 100644
--- a/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/objs/SpecParameter.java
+++ b/brooklyn-server/api/src/main/java/org/apache/brooklyn/api/objs/SpecParameter.java
@@ -20,13 +20,23 @@ package org.apache.brooklyn.api.objs;
 
 import java.io.Serializable;
 
+import javax.annotation.Nullable;
+
+import org.apache.brooklyn.api.entity.Entity;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.config.ConfigKey;
 
+/** A wrapper around a {@link ConfigKey} which will be added to an {@link Entity},
+ * providing additional information for rendering in a UI */
 public interface SpecParameter<T> extends Serializable {
     /** Short name, to be used in UI */
     String getLabel();
-    /** Visible by default in UI, not all inputs may be visible at once */
+    /** Whether visible by default in UI, not all inputs may be visible at once */
     boolean isPinned();
-    /** Type information for the input */
-    ConfigKey<T> getType();
+    /** All config key info for this spec parameter;
+     * this is the config key which is added to the defined type */
+    ConfigKey<T> getConfigKey();
+    /** An optional sensor which may also be added to the defined type */
+    @Nullable AttributeSensor<?> getSensor();
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
index fdf5807..869ebc0 100644
--- a/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
+++ b/brooklyn-server/camp/camp-brooklyn/src/test/java/org/apache/brooklyn/camp/brooklyn/catalog/SpecParameterParsingTest.java
@@ -62,20 +62,20 @@ public class SpecParameterParsingTest  extends AbstractYamlTest {
         SpecParameter<?> firstInput = inputs.get(0);
         assertEquals(firstInput.getLabel(), "simple");
         assertEquals(firstInput.isPinned(), true);
-        assertEquals(firstInput.getType().getName(), "simple");
-        assertEquals(firstInput.getType().getTypeToken(), TypeToken.of(String.class));
+        assertEquals(firstInput.getConfigKey().getName(), "simple");
+        assertEquals(firstInput.getConfigKey().getTypeToken(), TypeToken.of(String.class));
         
         SpecParameter<?> secondInput = inputs.get(1);
         assertEquals(secondInput.getLabel(), "explicit_name");
         assertEquals(secondInput.isPinned(), true);
-        assertEquals(secondInput.getType().getName(), "explicit_name");
-        assertEquals(secondInput.getType().getTypeToken(), TypeToken.of(String.class));
+        assertEquals(secondInput.getConfigKey().getName(), "explicit_name");
+        assertEquals(secondInput.getConfigKey().getTypeToken(), TypeToken.of(String.class));
         
         SpecParameter<?> thirdInput = inputs.get(2);
         assertEquals(thirdInput.getLabel(), "third_input");
         assertEquals(thirdInput.isPinned(), true);
-        assertEquals(thirdInput.getType().getName(), "third_input");
-        assertEquals(thirdInput.getType().getTypeToken(), TypeToken.of(Integer.class));
+        assertEquals(thirdInput.getConfigKey().getName(), "third_input");
+        assertEquals(thirdInput.getConfigKey().getTypeToken(), TypeToken.of(Integer.class));
     }
 
     @Test
@@ -99,8 +99,8 @@ public class SpecParameterParsingTest  extends AbstractYamlTest {
         SpecParameter<?> firstInput = inputs.get(0);
         assertEquals(firstInput.getLabel(), "simple");
         assertTrue(firstInput.isPinned());
-        assertEquals(firstInput.getType().getName(), "simple");
-        assertEquals(firstInput.getType().getTypeToken().getRawType().getName(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY);
+        assertEquals(firstInput.getConfigKey().getName(), "simple");
+        assertEquals(firstInput.getConfigKey().getTypeToken().getRawType().getName(), OsgiTestResources.BROOKLYN_TEST_OSGI_ENTITIES_SIMPLE_ENTITY);
     }
 
     @Test
@@ -126,7 +126,7 @@ public class SpecParameterParsingTest  extends AbstractYamlTest {
         SpecParameter<?> input = inputs.get(0);
         assertEquals(input.getLabel(), "more_config");
         assertFalse(input.isPinned());
-        assertEquals(input.getType().getName(), "more_config");
+        assertEquals(input.getConfigKey().getName(), "more_config");
     }
 
     private String add(String... def) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
index 2e59185..f158c2c 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/BasicConfigKey.java
@@ -49,7 +49,6 @@ import com.google.common.reflect.TypeToken;
 
 public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>, Serializable
{
     
-    @SuppressWarnings("unused")
     private static final Logger log = LoggerFactory.getLogger(BasicConfigKey.class);
     private static final long serialVersionUID = -1762014059150215376L;
     
@@ -119,6 +118,13 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>,
Serializab
         public BasicConfigKey<T> build() {
             return new BasicConfigKey<T>(this);
         }
+        
+        public String getName() {
+            return name;
+        }
+        public String getDescription() {
+            return description;
+        }
     }
     
     private String name;
@@ -165,7 +171,7 @@ public class BasicConfigKey<T> implements ConfigKeySelfExtracting<T>,
Serializab
         this.constraint = Predicates.alwaysTrue();
     }
 
-    protected BasicConfigKey(Builder<T> builder) {
+    public BasicConfigKey(Builder<T> builder) {
         this.name = checkNotNull(builder.name, "name");
         this.type = TypeTokens.getRawTypeIfRaw(checkNotNull(builder.type, "type"));
         this.typeToken = TypeTokens.getTypeTokenIfNotRaw(builder.type);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java
b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java
index 1a273f6..c508349 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/config/ConfigConstraints.java
@@ -28,10 +28,9 @@ import org.apache.brooklyn.api.location.Location;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.objs.EntityAdjunct;
 import org.apache.brooklyn.config.ConfigKey;
-import org.apache.brooklyn.core.location.AbstractLocation;
 import org.apache.brooklyn.core.objs.AbstractEntityAdjunct;
-import org.apache.brooklyn.core.objs.BrooklynObjectPredicate;
 import org.apache.brooklyn.core.objs.BrooklynObjectInternal;
+import org.apache.brooklyn.core.objs.BrooklynObjectPredicate;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
index dfbe1c1..2bc2346 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/BasicSpecParameter.java
@@ -36,12 +36,18 @@ import org.apache.brooklyn.api.mgmt.classloading.BrooklynClassLoadingContext;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.objs.BrooklynType;
 import org.apache.brooklyn.api.objs.SpecParameter;
+import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.config.ConfigKey.HasConfigKey;
 import org.apache.brooklyn.core.config.BasicConfigKey;
+import org.apache.brooklyn.core.config.BasicConfigKey.Builder;
+import org.apache.brooklyn.core.sensor.PortAttributeSensorAndConfigKey;
 import org.apache.brooklyn.util.collections.MutableList;
 import org.apache.brooklyn.util.guava.Maybe;
 import org.apache.brooklyn.util.text.StringPredicates;
+import org.apache.brooklyn.util.time.Duration;
 
+import com.google.common.annotations.Beta;
 import com.google.common.base.Function;
 import com.google.common.base.Objects;
 import com.google.common.base.Predicate;
@@ -54,14 +60,26 @@ import com.google.common.reflect.TypeToken;
 public class BasicSpecParameter<T> implements SpecParameter<T>{
     private static final long serialVersionUID = -4728186276307619778L;
 
-    private String label;
-    private boolean pinned;
-    private ConfigKey<T> type;
+    private final String label;
+    
+    /** pinning may become a priority or other more expansive indicator */
+    @Beta
+    private final boolean pinned;
+    
+    private final ConfigKey<T> configKey;
+    private final AttributeSensor<?> sensor;
 
-    public BasicSpecParameter(String label, boolean pinned, ConfigKey<T> type) {
+    @Beta // TBD whether "pinned" stays
+    public BasicSpecParameter(String label, boolean pinned, ConfigKey<T> config) {
+        this(label, pinned, config, null);
+    }
+
+    @Beta // TBD whether "pinned" and "sensor" stay
+    public <SensorType> BasicSpecParameter(String label, boolean pinned, ConfigKey<T>
config, AttributeSensor<SensorType> sensor) {
         this.label = label;
         this.pinned = pinned;
-        this.type = type;
+        this.configKey = config;
+        this.sensor = sensor;
     }
 
     @Override
@@ -73,15 +91,20 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
     public boolean isPinned() {
         return pinned;
     }
+    
+    @Override
+    public ConfigKey<T> getConfigKey() {
+        return configKey;
+    }
 
     @Override
-    public ConfigKey<T> getType() {
-        return type;
+    public AttributeSensor<?> getSensor() {
+        return sensor;
     }
 
     @Override
     public int hashCode() {
-        return Objects.hashCode(label, pinned, type);
+        return Objects.hashCode(label, pinned, configKey);
     }
 
     @Override
@@ -95,7 +118,7 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
         BasicSpecParameter<?> other = (BasicSpecParameter<?>) obj;
         return Objects.equal(label,  other.label) &&
                 pinned == other.pinned &&
-                Objects.equal(type, other.type);
+                Objects.equal(configKey, other.configKey);
     }
 
     @Override
@@ -103,7 +126,7 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
         return Objects.toStringHelper(this)
                 .add("label", label)
                 .add("pinned", pinned)
-                .add("type", type)
+                .add("type", configKey)
                 .toString();
     }
 
@@ -154,6 +177,7 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
                 .put("long", Long.class)
                 .put("float", Float.class)
                 .put("double", Double.class)
+                .put("duration", Duration.class)
                 .put("timestamp", Date.class)
                 .put("port", PortRange.class)
                 .build();
@@ -191,13 +215,23 @@ public class BasicSpecParameter<T> implements SpecParameter<T>{
                 throw new IllegalArgumentException("'name' value missing from input definition
" + obj + " but is required. Check for typos.");
             }
 
-            ConfigKey inputType = BasicConfigKey.builder(inferType(type, loader))
-                    .name(name)
-                    .description(description)
-                    .defaultValue(defaultValue)
-                    .constraint(constraints)
-                    .build();
-            return new BasicSpecParameter(Objects.firstNonNull(label, name), true, inputType);
+            ConfigKey configType;
+            AttributeSensor sensorType = null;
+            
+            TypeToken typeToken = inferType(type, loader);
+            Builder builder = BasicConfigKey.builder(typeToken)
+                .name(name)
+                .description(description)
+                .defaultValue(defaultValue)
+                .constraint(constraints);
+            
+            if (PortRange.class.equals(typeToken.getRawType())) {
+                sensorType = new PortAttributeSensorAndConfigKey(builder);
+                configType = ((HasConfigKey)sensorType).getConfigKey();
+            } else {
+                configType = builder.build();
+            }
+            return new BasicSpecParameter(Objects.firstNonNull(label, name), true, configType,
sensorType);
         }
 
         @SuppressWarnings({ "rawtypes" })

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
index eb4ff10..e55d6d9 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/objs/proxy/InternalEntityFactory.java
@@ -44,6 +44,7 @@ import org.apache.brooklyn.core.config.ConfigConstraints;
 import org.apache.brooklyn.core.entity.AbstractApplication;
 import org.apache.brooklyn.core.entity.AbstractEntity;
 import org.apache.brooklyn.core.entity.Entities;
+import org.apache.brooklyn.core.entity.EntityDynamicType;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
 import org.apache.brooklyn.core.mgmt.internal.ManagementContextInternal;
@@ -248,13 +249,13 @@ public class InternalEntityFactory extends InternalFactory {
             }
             
             entity.tags().addTags(spec.getTags());
-            ((AbstractEntity)entity).configure(getConfigKeysFromSpecParameters(spec));
-            ((AbstractEntity)entity).configure(MutableMap.copyOf(spec.getFlags()));
+            addSpecParameters(spec, ((AbstractEntity)entity).getMutableEntityType());
             
+            ((AbstractEntity)entity).configure(MutableMap.copyOf(spec.getFlags()));
             for (Map.Entry<ConfigKey<?>, Object> entry : spec.getConfig().entrySet())
{
                 entity.config().set((ConfigKey)entry.getKey(), entry.getValue());
             }
-
+            
             Entity parent = spec.getParent();
             if (parent != null) {
                 parent = (parent instanceof AbstractEntity) ? ((AbstractEntity)parent).getProxyIfAvailable()
: parent;
@@ -268,12 +269,11 @@ public class InternalEntityFactory extends InternalFactory {
         }
     }
 
-    private <T extends Entity> List<ConfigKey<?>> getConfigKeysFromSpecParameters(EntitySpec<T>
spec) {
-        List<ConfigKey<?>> configKeys = MutableList.of();
+    private void addSpecParameters(EntitySpec<?> spec, EntityDynamicType edType) {
         for (SpecParameter<?> param : spec.getParameters()) {
-            configKeys.add(param.getType());
+            edType.addConfigKey(param.getConfigKey());
+            if (param.getSensor()!=null) edType.addSensor(param.getSensor());
         }
-        return configKeys;
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/AttributeSensorAndConfigKey.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/AttributeSensorAndConfigKey.java
b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/AttributeSensorAndConfigKey.java
index f76baaa..2a26fa7 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/AttributeSensorAndConfigKey.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/AttributeSensorAndConfigKey.java
@@ -19,11 +19,11 @@
 package org.apache.brooklyn.core.sensor;
 
 import org.apache.brooklyn.api.entity.Entity;
-import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.BasicConfigKey;
+import org.apache.brooklyn.core.config.BasicConfigKey.Builder;
 import org.apache.brooklyn.core.config.ConfigKeys;
 import org.apache.brooklyn.core.entity.AbstractEntity;
 import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
@@ -45,6 +45,7 @@ import com.google.common.reflect.TypeToken;
 */
 public abstract class AttributeSensorAndConfigKey<ConfigType,SensorType> extends BasicAttributeSensor<SensorType>

         implements ConfigKey.HasConfigKey<ConfigType> {
+    
     private static final long serialVersionUID = -3103809215973264600L;
     private static final Logger log = LoggerFactory.getLogger(AttributeSensorAndConfigKey.class);
 
@@ -87,6 +88,10 @@ public abstract class AttributeSensorAndConfigKey<ConfigType,SensorType>
extends
         configKey = ConfigKeys.newConfigKeyWithDefault(orig.configKey, 
                 TypeCoercions.coerce(defaultValue, orig.configKey.getTypeToken()));
     }
+    public AttributeSensorAndConfigKey(Builder<ConfigType> configKeyBuilder, TypeToken<SensorType>
sensorType) {
+        super(sensorType, configKeyBuilder.getName(), configKeyBuilder.getDescription());
+        configKey = new BasicConfigKey<ConfigType>(configKeyBuilder);
+    }
 
     public ConfigKey<ConfigType> getConfigKey() { return configKey; }
     
@@ -106,7 +111,7 @@ public abstract class AttributeSensorAndConfigKey<ConfigType,SensorType>
extends
         SensorType sensorValue = e.getAttribute(this);
         if (sensorValue!=null) return sensorValue;
         
-        ConfigType v = ((EntityLocal)e).getConfig(this);
+        ConfigType v = e.config().get(this);
         try {
             return convertConfigToSensor(v, e);
         } catch (Throwable t) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/PortAttributeSensorAndConfigKey.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/PortAttributeSensorAndConfigKey.java
b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/PortAttributeSensorAndConfigKey.java
index 3de0de6..aa396d2 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/PortAttributeSensorAndConfigKey.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/core/sensor/PortAttributeSensorAndConfigKey.java
@@ -29,6 +29,7 @@ import org.apache.brooklyn.api.location.PortSupplier;
 import org.apache.brooklyn.api.mgmt.ManagementContext;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.config.ConfigKey;
+import org.apache.brooklyn.core.config.BasicConfigKey;
 import org.apache.brooklyn.core.entity.BrooklynConfigKeys;
 import org.apache.brooklyn.core.internal.BrooklynInitialization;
 import org.apache.brooklyn.core.location.Locations;
@@ -40,6 +41,7 @@ import org.slf4j.LoggerFactory;
 import com.google.common.base.Optional;
 import com.google.common.base.Predicates;
 import com.google.common.collect.Iterables;
+import com.google.common.reflect.TypeToken;
 
 /**
  * A {@link Sensor} describing a port on a system,
@@ -68,6 +70,10 @@ public class PortAttributeSensorAndConfigKey extends AttributeSensorAndConfigKey
     public PortAttributeSensorAndConfigKey(PortAttributeSensorAndConfigKey orig, Object defaultValue)
{
         super(orig, TypeCoercions.coerce(defaultValue, PortRange.class));
     }
+    public PortAttributeSensorAndConfigKey(BasicConfigKey.Builder<PortRange> builder)
{
+        super(builder, TypeToken.of(Integer.class));
+    }
+    
     @Override
     protected Integer convertConfigToSensor(PortRange value, Entity entity) {
         if (value==null) return null;

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
b/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
index 85c9537..3bc22e0 100644
--- a/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
+++ b/brooklyn-server/core/src/main/java/org/apache/brooklyn/util/core/flags/FlagUtils.java
@@ -234,7 +234,7 @@ public class FlagUtils {
     public static List<FlagConfigKeyAndValueRecord> findAllParameterConfigKeys(List<SpecParameter<?>>
parameters, ConfigBag input) {
         List<FlagConfigKeyAndValueRecord> output = new ArrayList<FlagUtils.FlagConfigKeyAndValueRecord>();
         for (SpecParameter<?> param : parameters) {
-            FlagConfigKeyAndValueRecord record = getFlagConfigKeyRecord(null, param.getType(),
input);
+            FlagConfigKeyAndValueRecord record = getFlagConfigKeyRecord(null, param.getConfigKey(),
input);
             if (record.isValuePresent())
                 output.add(record);
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromClassTest.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromClassTest.java
b/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromClassTest.java
index 49cb2d6..30745f0 100644
--- a/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromClassTest.java
+++ b/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromClassTest.java
@@ -103,7 +103,7 @@ public class BasicSpecParameterFromClassTest {
     private void assertInput(SpecParameter<?> input, String label, boolean pinned,
ConfigKey<?> type) {
         assertEquals(input.getLabel(), label);
         assertEquals(input.isPinned(), pinned);
-        assertEquals(input.getType(), type);
+        assertEquals(input.getConfigKey(), type);
     }
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java
b/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java
index 9f2eaaf..07ad81a 100644
--- a/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java
+++ b/brooklyn-server/core/src/test/java/org/apache/brooklyn/core/objs/BasicSpecParameterFromListTest.java
@@ -56,7 +56,7 @@ public class BasicSpecParameterFromListTest {
         SpecParameter<?> input = parse(name);
         assertEquals(input.getLabel(), name);
         assertTrue(input.isPinned());
-        ConfigKey<?> type = input.getType();
+        ConfigKey<?> type = input.getConfigKey();
         assertEquals(type.getName(), name);
         assertEquals(type.getTypeToken(), TypeToken.of(String.class));
         assertNull(type.getDefaultValue());
@@ -70,8 +70,8 @@ public class BasicSpecParameterFromListTest {
         String name = "minRam";
         SpecParameter<?> input = parse(ImmutableMap.of("name", name));
         assertEquals(input.getLabel(), name);
-        assertEquals(input.getType().getName(), name);
-        assertEquals(input.getType().getTypeToken(), TypeToken.of(String.class));
+        assertEquals(input.getConfigKey().getName(), name);
+        assertEquals(input.getConfigKey().getTypeToken(), TypeToken.of(String.class));
     }
 
     @Test
@@ -99,7 +99,7 @@ public class BasicSpecParameterFromListTest {
         assertEquals(input.getLabel(), label);
         assertTrue(input.isPinned());
 
-        ConfigKey<?> type = input.getType();
+        ConfigKey<?> type = input.getConfigKey();
         assertEquals(type.getName(), name);
         assertEquals(type.getTypeToken(), TypeToken.of(String.class));
         assertEquals(type.getDefaultValue(), defaultValue);
@@ -123,7 +123,7 @@ public class BasicSpecParameterFromListTest {
         assertEquals(input.getLabel(), name);
         assertTrue(input.isPinned());
 
-        ConfigKey<?> type = input.getType();
+        ConfigKey<?> type = input.getConfigKey();
         assertEquals(type.getName(), name);
         assertEquals(type.getDefaultValue(), defaultValue);
         assertEquals(type.getDescription(), description);
@@ -137,7 +137,7 @@ public class BasicSpecParameterFromListTest {
         SpecParameter<?> input = parse(ImmutableMap.of(
                 "name", name,
                 "constraints", ImmutableList.of(constraint)));
-        ConfigKey<?> type = input.getType();
+        ConfigKey<?> type = input.getConfigKey();
         assertConstraint(type.getConstraint(), StringPredicates.isNonBlank());
     }
 
@@ -153,7 +153,7 @@ public class BasicSpecParameterFromListTest {
         SpecParameter<?> input = parse(ImmutableMap.of(
                 "name", name,
                 "type", BasicSpecParameterFromListTest.class.getName()));
-        assertEquals(input.getType().getTypeToken(), TypeToken.of(BasicSpecParameterFromListTest.class));
+        assertEquals(input.getConfigKey().getTypeToken(), TypeToken.of(BasicSpecParameterFromListTest.class));
     }
 
     @Test(expectedExceptions = IllegalArgumentException.class)

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
b/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
index 74625fd..3c19625 100644
--- a/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
+++ b/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/CatalogTransformer.java
@@ -68,15 +68,17 @@ public class CatalogTransformer {
         Set<EffectorSummary> effectors = Sets.newTreeSet(SummaryComparators.nameComparator());
 
         EntitySpec<?> spec = null;
-
         try {
-            spec = (EntitySpec<?>) b.getCatalog().createSpec((CatalogItem) item);
+            spec = (EntitySpec<?>) b.getCatalog().createSpec(item);
             EntityDynamicType typeMap = BrooklynTypes.getDefinedEntityType(spec.getType());
             EntityType type = typeMap.getSnapshot();
 
             AtomicInteger paramPriorityCnt = new AtomicInteger();
-            for (SpecParameter<?> input: spec.getParameters())
+            for (SpecParameter<?> input: spec.getParameters()) {
                 config.add(EntityTransformer.entityConfigSummary(input, paramPriorityCnt));
+                if (input.getSensor()!=null)
+                    sensors.add(SensorTransformer.sensorSummaryForCatalog(input.getSensor()));
+            }
             for (Sensor<?> x: type.getSensors())
                 sensors.add(SensorTransformer.sensorSummaryForCatalog(x));
             for (Effector<?> x: type.getEffectors())

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/9141c99f/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/EntityTransformer.java
----------------------------------------------------------------------
diff --git a/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/EntityTransformer.java
b/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/EntityTransformer.java
index 2d9f8a0..f5079b9 100644
--- a/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/EntityTransformer.java
+++ b/brooklyn-server/rest/rest-server/src/main/java/org/apache/brooklyn/rest/transform/EntityTransformer.java
@@ -159,7 +159,7 @@ public class EntityTransformer {
         // which results in correctly ordered items on the wire (as a list). Clients which
use the java bindings
         // though will push the items in an unordered set - so give them means to recover
the correct order.
         Double priority = input.isPinned() ? Double.valueOf(paramPriorityCnt.incrementAndGet())
: null;
-        return entityConfigSummary(input.getType(), input.getLabel(), priority, null);
+        return entityConfigSummary(input.getConfigKey(), input.getLabel(), priority, null);
     }
 
 }


Mime
View raw message