brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [2/8] git commit: enhance config REST data to provide info so that we get "open REST link" actions, and related cleanup
Date Mon, 27 Oct 2014 14:56:07 GMT
enhance config REST data to provide info so that we get "open REST link" actions, and related
cleanup


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

Branch: refs/heads/master
Commit: 060e3dab5f0cef3a163bac19ac9b9b65e464c911
Parents: 33858e2
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Sun Oct 26 22:32:53 2014 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Mon Oct 27 07:51:41 2014 -0700

----------------------------------------------------------------------
 .../brooklyn/config/render/RendererHints.java   |  8 +----
 .../entity/proxy/AbstractControllerImpl.java    |  4 +--
 .../AbstractNonProvisionedControllerImpl.java   |  2 +-
 .../brooklyn/entity/proxy/LoadBalancer.java     | 18 ++++++----
 .../entity/proxy/LoadBalancerClusterImpl.java   |  2 +-
 .../rest/transform/EntityTransformer.java       | 36 +++++++++++++-------
 .../rest/transform/SensorTransformer.java       | 11 +++---
 7 files changed, 47 insertions(+), 34 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/060e3dab/core/src/main/java/brooklyn/config/render/RendererHints.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/brooklyn/config/render/RendererHints.java b/core/src/main/java/brooklyn/config/render/RendererHints.java
index 2364fd2..8bea13c 100644
--- a/core/src/main/java/brooklyn/config/render/RendererHints.java
+++ b/core/src/main/java/brooklyn/config/render/RendererHints.java
@@ -20,8 +20,6 @@ package brooklyn.config.render;
 
 import groovy.lang.Closure;
 
-import java.net.URI;
-import java.net.URL;
 import java.util.Set;
 
 import org.slf4j.Logger;
@@ -31,10 +29,6 @@ import brooklyn.config.ConfigKey;
 import brooklyn.entity.Entity;
 import brooklyn.event.AttributeSensor;
 import brooklyn.util.GroovyJavaMethods;
-import brooklyn.util.net.UserAndHostAndPort;
-import brooklyn.util.text.StringFunctions;
-import brooklyn.util.time.Duration;
-import brooklyn.util.time.Time;
 
 import com.google.common.annotations.Beta;
 import com.google.common.annotations.VisibleForTesting;
@@ -51,7 +45,6 @@ import com.google.common.collect.LinkedHashMultimap;
 import com.google.common.collect.Multimaps;
 import com.google.common.collect.SetMultimap;
 import com.google.common.collect.Sets;
-import com.google.common.net.HostAndPort;
 
 /**
  * Registry of hints for displaying items such as sensors, e.g. in the web console.
@@ -173,6 +166,7 @@ public class RendererHints {
             this.postProcessing = postProcessing;
         }
 
+        /** @deprecated since 0.7.0 call {@link #getUrlFromValue(Object)}, parsing the sensor
value yourself */ @Deprecated
         public String getUrl(Entity e, AttributeSensor<T> s) {
             return getUrlFromValue(e.getAttribute(s));
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/060e3dab/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractControllerImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractControllerImpl.java
b/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractControllerImpl.java
index 8bab2fa..bf960f9 100644
--- a/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractControllerImpl.java
+++ b/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractControllerImpl.java
@@ -181,7 +181,7 @@ public abstract class AbstractControllerImpl extends SoftwareProcessImpl
impleme
      * Can pass in the 'serverPool'.
      */
     @Override
-    public void bind(Map flags) {
+    public void bind(Map<?,?> flags) {
         if (flags.containsKey("serverPool")) {
             setConfigEvenIfOwned(SERVER_POOL, (Group) flags.get("serverPool"));
         } 
@@ -292,7 +292,7 @@ public abstract class AbstractControllerImpl extends SoftwareProcessImpl
impleme
     protected void preStart() {
         super.preStart();
 
-        AttributeSensor<?> hostAndPortSensor = getConfig(HOST_AND_PORT_SENSOR);
+        AttributeSensor<String> hostAndPortSensor = getConfig(HOST_AND_PORT_SENSOR);
         Maybe<Object> hostnameSensor = getConfigRaw(HOSTNAME_SENSOR, true);
         Maybe<Object> portSensor = getConfigRaw(PORT_NUMBER_SENSOR, true);
         if (hostAndPortSensor != null) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/060e3dab/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractNonProvisionedControllerImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractNonProvisionedControllerImpl.java
b/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractNonProvisionedControllerImpl.java
index 91d175b..8ce3af5 100644
--- a/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractNonProvisionedControllerImpl.java
+++ b/software/webapp/src/main/java/brooklyn/entity/proxy/AbstractNonProvisionedControllerImpl.java
@@ -84,7 +84,7 @@ public abstract class AbstractNonProvisionedControllerImpl extends AbstractEntit
      * Can pass in the 'serverPool'.
      */
     @Override
-    public void bind(Map flags) {
+    public void bind(Map<?,?> flags) {
         if (flags.containsKey("serverPool")) {
             setConfigEvenIfOwned(SERVER_POOL, (Group) flags.get("serverPool"));
         }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/060e3dab/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancer.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancer.java b/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancer.java
index b130e6f..0502c3f 100644
--- a/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancer.java
+++ b/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancer.java
@@ -64,19 +64,22 @@ public interface LoadBalancer extends Entity, Startable {
             Group.class, "loadbalancer.urlmappings", "Special mapping rules (e.g. for domain/path
matching, rewrite, etc); not supported by all load balancers");
     
     /** sensor for port to forward to on target entities */
+    @SuppressWarnings("serial")
     @SetFromFlag("portNumberSensor")
-    public static final BasicAttributeSensorAndConfigKey<AttributeSensor> PORT_NUMBER_SENSOR
= new BasicAttributeSensorAndConfigKey<AttributeSensor>(
-            AttributeSensor.class, "member.sensor.portNumber", "Port number sensor on members
(defaults to http.port; not supported in all implementations)", Attributes.HTTP_PORT);
+    public static final BasicAttributeSensorAndConfigKey<AttributeSensor<Integer>>
PORT_NUMBER_SENSOR = new BasicAttributeSensorAndConfigKey<AttributeSensor<Integer>>(
+        new TypeToken<AttributeSensor<Integer>>() {}, "member.sensor.portNumber",
"Port number sensor on members (defaults to http.port; not supported in all implementations)",
Attributes.HTTP_PORT);
 
     /** sensor for hostname to forward to on target entities */
+    @SuppressWarnings("serial")
     @SetFromFlag("hostnameSensor")
-    public static final BasicAttributeSensorAndConfigKey<AttributeSensor> HOSTNAME_SENSOR
= new BasicAttributeSensorAndConfigKey<AttributeSensor>(
-            AttributeSensor.class, "member.sensor.hostname", "Hostname/IP sensor on members
(defaults to host.name; not supported in all implementations)", Attributes.HOSTNAME);
+    public static final BasicAttributeSensorAndConfigKey<AttributeSensor<String>>
HOSTNAME_SENSOR = new BasicAttributeSensorAndConfigKey<AttributeSensor<String>>(
+        new TypeToken<AttributeSensor<String>>() {}, "member.sensor.hostname",
"Hostname/IP sensor on members (defaults to host.name; not supported in all implementations)",
Attributes.HOSTNAME);
 
     /** sensor for hostname to forward to on target entities */
+    @SuppressWarnings("serial")
     @SetFromFlag("hostAndPortSensor")
-    public static final BasicAttributeSensorAndConfigKey<AttributeSensor> HOST_AND_PORT_SENSOR
= new BasicAttributeSensorAndConfigKey<AttributeSensor>(
-            AttributeSensor.class, "member.sensor.hostandport", "host:port sensor on members
(invalid to configure this and the portNumber or hostname sensors)", null);
+    public static final BasicAttributeSensorAndConfigKey<AttributeSensor<String>>
HOST_AND_PORT_SENSOR = new BasicAttributeSensorAndConfigKey<AttributeSensor<String>>(
+            new TypeToken<AttributeSensor<String>>() {}, "member.sensor.hostandport",
"host:port sensor on members (invalid to configure this and the portNumber or hostname sensors)",
null);
     
     @SetFromFlag("port")
     /** port where this controller should live */
@@ -92,6 +95,7 @@ public interface LoadBalancer extends Entity, Startable {
     public static final AttributeSensor<URI> MAIN_URI = Attributes.MAIN_URI;
     public static final AttributeSensor<String> ROOT_URL = WebAppService.ROOT_URL;
 
+    @SuppressWarnings("serial")
     public static final AttributeSensor<Map<Entity, String>> SERVER_POOL_TARGETS
= Sensors.newSensor(
             new TypeToken<Map<Entity, String>>() {},
             "proxy.serverpool.targets", 
@@ -111,5 +115,5 @@ public interface LoadBalancer extends Entity, Startable {
      * Opportunity to do late-binding of the cluster that is being controlled. Must be called
before start().
      * Can pass in the 'serverPool'.
      */
-    public void bind(Map flags);
+    public void bind(Map<?,?> flags);
 }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/060e3dab/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancerClusterImpl.java
----------------------------------------------------------------------
diff --git a/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancerClusterImpl.java
b/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancerClusterImpl.java
index bc8f88d..b17049e 100644
--- a/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancerClusterImpl.java
+++ b/software/webapp/src/main/java/brooklyn/entity/proxy/LoadBalancerClusterImpl.java
@@ -66,7 +66,7 @@ public class LoadBalancerClusterImpl extends DynamicClusterImpl implements
LoadB
     }
 
     @Override
-    public void bind(Map flags) {
+    public void bind(Map<?,?> flags) {
         for (Entity member : getMembers()) {
             if (member instanceof LoadBalancer) {
                 ((LoadBalancer)member).bind(flags);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/060e3dab/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
b/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
index 4d8861e..39a0a07 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/transform/EntityTransformer.java
@@ -25,17 +25,21 @@ import java.net.URI;
 import java.util.List;
 import java.util.Map;
 
-import com.google.common.base.Function;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.Lists;
-
 import brooklyn.catalog.CatalogConfig;
 import brooklyn.config.ConfigKey;
+import brooklyn.config.render.RendererHints;
 import brooklyn.entity.Application;
 import brooklyn.entity.Entity;
 import brooklyn.entity.basic.EntityLocal;
 import brooklyn.rest.domain.EntityConfigSummary;
 import brooklyn.rest.domain.EntitySummary;
+import brooklyn.util.collections.MutableMap;
+import brooklyn.util.net.URLParamEncoder;
+
+import com.google.common.base.Function;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
 
 /**
  * @author Adam Lowe
@@ -89,8 +93,8 @@ public class EntityTransformer {
     }
 
     protected static EntityConfigSummary entityConfigSummary(ConfigKey<?> config, String
label, Double priority, Map<String, URI> links) {
-        Map<String, URI> mapOfLinks =  links==null ? null : ImmutableMap.copyOf(links);
-      return new EntityConfigSummary(config, label, priority, mapOfLinks);
+            Map<String, URI> mapOfLinks =  links==null ? null : ImmutableMap.copyOf(links);
+        return new EntityConfigSummary(config, label, priority, mapOfLinks);
     }
     /** generates a representation for a given config key, 
      * with label inferred from annoation in the entity class,
@@ -113,12 +117,20 @@ public class EntityTransformer {
 
         String applicationUri = "/v1/applications/" + entity.getApplicationId();
         String entityUri = applicationUri + "/entities/" + entity.getId();
-        Map<String,URI> links = ImmutableMap.<String, URI>builder()
-                .put("self", URI.create(entityUri + "/config/" + config.getName()))
-                .put("application", URI.create(applicationUri))
-                .put("entity", URI.create(entityUri))
-                .build();
-        return entityConfigSummary(config, label, priority, links);
+        String selfUri = entityUri + "/config/" + URLParamEncoder.encode(config.getName());
+        
+        MutableMap.Builder<String, URI> lb = MutableMap.<String, URI>builder()
+            .put("self", URI.create(selfUri))
+            .put("application", URI.create(applicationUri))
+            .put("entity", URI.create(entityUri))
+            .put("action:json", URI.create(selfUri));
+
+        Iterable<RendererHints.NamedAction> hints = Iterables.filter(RendererHints.getHintsFor(config),
RendererHints.NamedAction.class);
+        for (RendererHints.NamedAction na : hints) {
+            SensorTransformer.addNamedAction(lb, na, entity.getConfig(config), config, entity);
+        }
+    
+        return entityConfigSummary(config, label, priority, lb.build());
     }
 
     public static String applicationUri(Application entity) {

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/060e3dab/usage/rest-server/src/main/java/brooklyn/rest/transform/SensorTransformer.java
----------------------------------------------------------------------
diff --git a/usage/rest-server/src/main/java/brooklyn/rest/transform/SensorTransformer.java
b/usage/rest-server/src/main/java/brooklyn/rest/transform/SensorTransformer.java
index ab9618c..21a4598 100644
--- a/usage/rest-server/src/main/java/brooklyn/rest/transform/SensorTransformer.java
+++ b/usage/rest-server/src/main/java/brooklyn/rest/transform/SensorTransformer.java
@@ -62,19 +62,22 @@ public class SensorTransformer {
         return new SensorSummary(sensor.getName(), sensor.getTypeName(), sensor.getDescription(),
lb.build());
     }
 
-    // TODO should do this with config also (e.g. to show entities or URLs as clickable links);
but we need to set up a ConfigTransformer
-    @SuppressWarnings("unchecked")
     private static <T> void addNamedAction(MutableMap.Builder<String, URI> lb,
RendererHints.NamedAction na , Entity entity, Sensor<T> sensor) {
+        addNamedAction(lb, na, entity.getAttribute( ((AttributeSensor<T>) sensor) ),
sensor, entity);
+    }
+    
+    @SuppressWarnings("unchecked")
+    static <T> void addNamedAction(MutableMap.Builder<String, URI> lb, RendererHints.NamedAction
na, T value, Object context, Entity contextEntity) {
         if (na instanceof RendererHints.NamedActionWithUrl) {
             try {
-                String v = ((RendererHints.NamedActionWithUrl<T>) na).getUrl(entity,
(AttributeSensor<T>) sensor);
+                String v = ((RendererHints.NamedActionWithUrl<T>) na).getUrlFromValue(value);
                 if (Strings.isNonBlank(v)) {
                     String action = na.getActionName().toLowerCase();
                     lb.putIfAbsent("action:"+action, URI.create(v));
                 }
             } catch (Exception e) {
                 Exceptions.propagateIfFatal(e);
-                log.warn("Unable to make use of URL sensor "+sensor+" on "+entity+": "+e,
e);
+                log.warn("Unable to make action "+na+" from "+context+" on "+contextEntity+":
"+e, e);
             }
         }
     }


Mime
View raw message