brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [1/2] brooklyn-server git commit: added highlights to policy endpoint
Date Wed, 13 Sep 2017 08:06:58 GMT
Repository: brooklyn-server
Updated Branches:
  refs/heads/master a26e8f569 -> b9f14e556


added highlights to policy endpoint


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

Branch: refs/heads/master
Commit: 962b777052907b80b93c39dee09dfd976cc87ea9
Parents: 3d650c9
Author: graeme.miller <graeme.miller@cloudsoftcorp.com>
Authored: Thu Sep 7 13:14:42 2017 +0100
Committer: graeme.miller <graeme.miller@cloudsoftcorp.com>
Committed: Mon Sep 11 13:30:30 2017 +0100

----------------------------------------------------------------------
 .../api/mgmt/rebind/mementos/PolicyMemento.java |  3 +
 .../apache/brooklyn/api/objs/EntityAdjunct.java |  3 +
 .../brooklyn/api/objs/HighlightTuple.java       | 81 ++++++++++++++++++++
 .../core/mgmt/rebind/RebindIteration.java       |  1 +
 .../mgmt/rebind/dto/BasicPolicyMemento.java     | 17 +++-
 .../mgmt/rebind/dto/MementosGenerators.java     |  4 +-
 .../core/objs/AbstractEntityAdjunct.java        | 30 ++++++++
 .../core/policy/basic/BasicPolicyTest.java      | 18 +++++
 .../autoscaling/AutoScalerPolicyRebindTest.java | 34 ++++++++
 .../brooklyn/rest/domain/PolicySummary.java     | 15 +++-
 .../rest/transform/PolicyTransformer.java       |  7 +-
 .../rest/resources/PolicyResourceTest.java      | 24 +++++-
 .../testing/mocks/RestMockSimplePolicy.java     |  3 +
 13 files changed, 233 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/mementos/PolicyMemento.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/mementos/PolicyMemento.java
b/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/mementos/PolicyMemento.java
index bfec7af..1c96c8e 100644
--- a/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/mementos/PolicyMemento.java
+++ b/api/src/main/java/org/apache/brooklyn/api/mgmt/rebind/mementos/PolicyMemento.java
@@ -21,6 +21,7 @@ package org.apache.brooklyn.api.mgmt.rebind.mementos;
 import java.util.Map;
 
 import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
+import org.apache.brooklyn.api.objs.HighlightTuple;
 
 /**
  * Represents the state of an policy, so that it can be reconstructed (e.g. after restarting
brooklyn).
@@ -32,4 +33,6 @@ import org.apache.brooklyn.api.mgmt.rebind.RebindSupport;
 public interface PolicyMemento extends Memento {
 
     Map<String, Object> getConfig();
+
+    Map<String, HighlightTuple> getHighlights();
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/api/src/main/java/org/apache/brooklyn/api/objs/EntityAdjunct.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/objs/EntityAdjunct.java b/api/src/main/java/org/apache/brooklyn/api/objs/EntityAdjunct.java
index 674d7f2..7127134 100644
--- a/api/src/main/java/org/apache/brooklyn/api/objs/EntityAdjunct.java
+++ b/api/src/main/java/org/apache/brooklyn/api/objs/EntityAdjunct.java
@@ -18,6 +18,8 @@
  */
 package org.apache.brooklyn.api.objs;
 
+import java.util.Map;
+
 import javax.annotation.Nullable;
 
 /**
@@ -50,4 +52,5 @@ public interface EntityAdjunct extends BrooklynObject {
      */
     @Nullable String getUniqueTag();
 
+    Map<String, HighlightTuple> getHighlights();
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/api/src/main/java/org/apache/brooklyn/api/objs/HighlightTuple.java
----------------------------------------------------------------------
diff --git a/api/src/main/java/org/apache/brooklyn/api/objs/HighlightTuple.java b/api/src/main/java/org/apache/brooklyn/api/objs/HighlightTuple.java
new file mode 100644
index 0000000..d31b317
--- /dev/null
+++ b/api/src/main/java/org/apache/brooklyn/api/objs/HighlightTuple.java
@@ -0,0 +1,81 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.brooklyn.api.objs;
+
+public class HighlightTuple {
+
+    private String description;
+    private long time;
+    private String taskId;
+
+    //required for JSON de-serialisation
+    private HighlightTuple(){
+
+    }
+
+    public HighlightTuple(String description, long time, String taskId) {
+        this.description = description;
+        this.time = time;
+        this.taskId = taskId;
+    }
+
+    public String getDescription() {
+        return description;
+    }
+
+    public void setDescription(String description) {
+        this.description = description;
+    }
+
+    public long getTime() {
+        return time;
+    }
+
+    public void setTime(long time) {
+        this.time = time;
+    }
+
+    public String getTaskId() {
+        return taskId;
+    }
+
+    public void setTaskId(String taskId) {
+        this.taskId = taskId;
+    }
+
+    @Override
+    public boolean equals(Object o) {
+        if (this == o) return true;
+        if (o == null || getClass() != o.getClass()) return false;
+
+        HighlightTuple that = (HighlightTuple) o;
+
+        if (time != that.time) return false;
+        if (description != null ? !description.equals(that.description) : that.description
!= null) return false;
+        return taskId != null ? taskId.equals(that.taskId) : that.taskId == null;
+    }
+
+    @Override
+    public int hashCode() {
+        int result = description != null ? description.hashCode() : 0;
+        result = 31 * result + (int) (time ^ (time >>> 32));
+        result = 31 * result + (taskId != null ? taskId.hashCode() : 0);
+        return result;
+    }
+}

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
index e927e1a..76a4d31 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/RebindIteration.java
@@ -1228,6 +1228,7 @@ public abstract class RebindIteration {
                 policy = policyFactory.constructPolicy(policyClazz);
                 FlagUtils.setFieldsFromFlags(ImmutableMap.of("id", id), policy);
                 ((AbstractPolicy)policy).setManagementContext(managementContext);
+                ((AbstractPolicy)policy).setHighlights(memento.getHighlights());
 
             } else {
                 LOG.warn("Deprecated rebind of policy without no-arg constructor; " +

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BasicPolicyMemento.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BasicPolicyMemento.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BasicPolicyMemento.java
index dfaa616..7a3c442 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BasicPolicyMemento.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/BasicPolicyMemento.java
@@ -22,6 +22,7 @@ import java.io.Serializable;
 import java.util.Map;
 
 import org.apache.brooklyn.api.mgmt.rebind.mementos.PolicyMemento;
+import org.apache.brooklyn.api.objs.HighlightTuple;
 import org.apache.brooklyn.core.config.Sanitizer;
 
 import com.google.common.base.MoreObjects;
@@ -42,15 +43,20 @@ public class BasicPolicyMemento extends AbstractMemento implements PolicyMemento
 
     public static class Builder extends AbstractMemento.Builder<Builder> {
         protected Map<String,Object> config = Maps.newLinkedHashMap();
+        protected Map<String,HighlightTuple> highlights = Maps.newLinkedHashMap();
         
         public Builder from(PolicyMemento other) {
             super.from(other);
             config.putAll(other.getConfig());
+            highlights.putAll(other.getHighlights());
             return this;
         }
         public Builder config(Map<String,?> vals) {
             config.putAll(vals); return this;
         }
+        public Builder highlights(Map<String,HighlightTuple> vals) {
+            highlights.putAll(vals); return this;
+        }
         public PolicyMemento build() {
             return new BasicPolicyMemento(this);
         }
@@ -58,6 +64,7 @@ public class BasicPolicyMemento extends AbstractMemento implements PolicyMemento
     
     private Map<String,Object> config;
     private Map<String, Object> fields;
+    private Map<String, HighlightTuple> highlights;
 
     @SuppressWarnings("unused") // For deserialisation
     private BasicPolicyMemento() {}
@@ -66,6 +73,7 @@ public class BasicPolicyMemento extends AbstractMemento implements PolicyMemento
     protected BasicPolicyMemento(Builder builder) {
         super(builder);
         config = toPersistedMap(builder.config);
+        highlights = toPersistedMap(builder.highlights);
     }
     
     @Deprecated
@@ -84,9 +92,14 @@ public class BasicPolicyMemento extends AbstractMemento implements PolicyMemento
     public Map<String, Object> getConfig() {
         return fromPersistedMap(config);
     }
-    
+
+    @Override
+    public Map<String, HighlightTuple> getHighlights() {
+        return highlights;
+    }
+
     @Override
     protected MoreObjects.ToStringHelper newVerboseStringHelper() {
-        return super.newVerboseStringHelper().add("config", Sanitizer.sanitize(getConfig()));
+        return super.newVerboseStringHelper().add("config", Sanitizer.sanitize(getConfig())).add("highlights",
highlights);
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
index e3969cb..1b0700f 100644
--- a/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
+++ b/core/src/main/java/org/apache/brooklyn/core/mgmt/rebind/dto/MementosGenerators.java
@@ -259,7 +259,9 @@ public class MementosGenerators {
             Object value = configValueToPersistable(entry.getValue(), policy, key.getName());
             builder.config.put(key.getName(), value); 
         }
-        
+
+        builder.highlights(policy.getHighlights());
+
         Map<String, Object> persistableFlags = MutableMap.<String, Object>builder()
                 .putAll(FlagUtils.getFieldsWithFlagsExcludingModifiers(policy, Modifier.STATIC
^ Modifier.TRANSIENT))
                 .remove("id")

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
index df11ed0..2b8d938 100644
--- a/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
+++ b/core/src/main/java/org/apache/brooklyn/core/objs/AbstractEntityAdjunct.java
@@ -23,6 +23,7 @@ import static org.apache.brooklyn.util.JavaGroovyEquivalents.groovyTruth;
 
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
@@ -36,6 +37,7 @@ import org.apache.brooklyn.api.mgmt.SubscriptionHandle;
 import org.apache.brooklyn.api.objs.BrooklynObject;
 import org.apache.brooklyn.api.objs.Configurable;
 import org.apache.brooklyn.api.objs.EntityAdjunct;
+import org.apache.brooklyn.api.objs.HighlightTuple;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.api.sensor.Sensor;
 import org.apache.brooklyn.api.sensor.SensorEventListener;
@@ -109,6 +111,13 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject
imple
     @SetFromFlag(value="uniqueTag")
     protected String uniqueTag;
 
+    private Map<String, HighlightTuple> highlights = new HashMap<>();
+
+    public static String HIGHLIGHT_NAME_LAST_ACTION = "lastAction";
+    public static String HIGHLIGHT_NAME_LAST_CONFIRMATION= "lastConfirmation";
+    public static String HIGHLIGHT_NAME_LAST_VIOLATION= "lastViolation";
+    public static String HIGHLIGHT_NAME_TRIGGERS = "triggers";
+
     public AbstractEntityAdjunct() {
         this(Collections.emptyMap());
     }
@@ -128,6 +137,10 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject
imple
         }
     }
 
+    protected void addHighlight(String name, HighlightTuple tuple) {
+        highlights.put(name, tuple);
+    }
+
     /**
      * @deprecated since 0.7.0; only used for legacy brooklyn types where constructor is
called directly
      */
@@ -549,6 +562,23 @@ public abstract class AbstractEntityAdjunct extends AbstractBrooklynObject
imple
     }
 
     @Override
+    public Map<String, HighlightTuple> getHighlights() {
+        HashMap<String, HighlightTuple> highlightsToReturn = new HashMap<>();
+        highlightsToReturn.putAll(highlights);
+        return highlightsToReturn;
+    }
+
+    /**
+     * Should only be used for rebind
+     * @param highlights
+     */
+    public void setHighlights(Map<String, HighlightTuple> highlights) {
+        if(highlights != null) {
+            this.highlights.putAll(highlights);
+        }
+    }
+
+    @Override
     public String toString() {
         return MoreObjects.toStringHelper(getClass()).omitNullValues()
                 .add("name", name)

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java
b/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java
index 26f3915..4da4188 100644
--- a/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java
+++ b/core/src/test/java/org/apache/brooklyn/core/policy/basic/BasicPolicyTest.java
@@ -23,6 +23,7 @@ import static org.testng.Assert.assertTrue;
 
 import java.util.Map;
 
+import org.apache.brooklyn.api.objs.HighlightTuple;
 import org.apache.brooklyn.api.policy.PolicySpec;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.BasicConfigKey;
@@ -70,6 +71,11 @@ public class BasicPolicyTest extends BrooklynAppUnitTestSupport {
             }
         }
 
+        //make visable for testing
+        @Override
+        protected void addHighlight(String name, HighlightTuple tuple) {
+            super.addHighlight(name, tuple);
+        }
     }
     
     @Test
@@ -106,4 +112,16 @@ public class BasicPolicyTest extends BrooklynAppUnitTestSupport {
         assertEquals(policy.getUniqueTag(), "x");
     }
 
+    @Test
+    public void testHighlights() throws Exception {
+        MyPolicy policy = new MyPolicy();
+
+        HighlightTuple highlight = new HighlightTuple("TEST_DESCRIPTION", 123L, "456");
+        policy.addHighlight("testHighlightName", highlight);
+
+        Map<String, HighlightTuple> highlights = policy.getHighlights();
+
+        assertEquals(1, highlights.size());
+        assertEquals(highlight, highlights.get("testHighlightName"));
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
----------------------------------------------------------------------
diff --git a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
index 07d01ea..10e67e9 100644
--- a/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
+++ b/policy/src/test/java/org/apache/brooklyn/policy/autoscaling/AutoScalerPolicyRebindTest.java
@@ -19,17 +19,22 @@
 package org.apache.brooklyn.policy.autoscaling;
 
 import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
 
+import java.util.HashMap;
 import java.util.Map;
 import java.util.concurrent.TimeUnit;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.api.location.LocationSpec;
+import org.apache.brooklyn.api.objs.HighlightTuple;
+import org.apache.brooklyn.api.policy.Policy;
 import org.apache.brooklyn.api.sensor.AttributeSensor;
 import org.apache.brooklyn.core.entity.EntityAsserts;
 import org.apache.brooklyn.core.entity.EntityInternal;
 import org.apache.brooklyn.core.location.SimulatedLocation;
 import org.apache.brooklyn.core.mgmt.rebind.RebindTestFixtureWithApp;
+import org.apache.brooklyn.core.objs.AbstractEntityAdjunct;
 import org.apache.brooklyn.core.sensor.BasicNotificationSensor;
 import org.apache.brooklyn.core.sensor.Sensors;
 import org.apache.brooklyn.core.test.entity.TestApplication;
@@ -105,6 +110,7 @@ public class AutoScalerPolicyRebindTest extends RebindTestFixtureWithApp
{
         assertEquals(newPolicy.getConfig(AutoScalerPolicy.POOL_OK_SENSOR), POOL_OK_SENSOR);
         assertEquals(newPolicy.getConfig(AutoScalerPolicy.MAX_SIZE_REACHED_SENSOR), MAX_SIZE_REACHED_SENSOR);
         assertEquals(newPolicy.getConfig(AutoScalerPolicy.MAX_REACHED_NOTIFICATION_DELAY),
Duration.of(7, TimeUnit.MILLISECONDS));
+        assertTrue(newPolicy.getHighlights().isEmpty());
     }
     
     @Test
@@ -131,4 +137,32 @@ public class AutoScalerPolicyRebindTest extends RebindTestFixtureWithApp
{
         ((EntityInternal)newCluster).sensors().set(METRIC_SENSOR, 1);
         EntityAsserts.assertGroupSizeEqualsEventually(newCluster, 1);
     }
+
+    @Test
+    public void testAutoScalerHighlightAfterRebind() throws Exception {
+        origCluster.start(ImmutableList.of(origLoc));
+        origCluster.policies().add(AutoScalerPolicy.builder()
+                .name("myname")
+                .metric(METRIC_SENSOR)
+                .entityWithMetric(origCluster)
+                .metricUpperBound(10)
+                .metricLowerBound(100)
+                .minPoolSize(1)
+                .maxPoolSize(3)
+                .buildSpec());
+
+        Map<String, HighlightTuple> highlights = new HashMap<>();
+        highlights.put("testNameTask",  new HighlightTuple("testDescription", 123L, "testTaskId"));
+
+
+        Policy originalPolicy = origCluster.policies().iterator().next();
+        ((AbstractEntityAdjunct)originalPolicy).setHighlights(highlights);
+
+        TestApplication newApp = rebind();
+
+        DynamicCluster newCluster = (DynamicCluster) Iterables.getOnlyElement(newApp.getChildren());
+        AutoScalerPolicy newPolicy = (AutoScalerPolicy) Iterables.getOnlyElement(newCluster.policies());
+
+        assertEquals(originalPolicy.getHighlights(), newPolicy.getHighlights());
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/rest/rest-api/src/main/java/org/apache/brooklyn/rest/domain/PolicySummary.java
----------------------------------------------------------------------
diff --git a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/domain/PolicySummary.java
b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/domain/PolicySummary.java
index a52ef53..ce9c9e0 100644
--- a/rest/rest-api/src/main/java/org/apache/brooklyn/rest/domain/PolicySummary.java
+++ b/rest/rest-api/src/main/java/org/apache/brooklyn/rest/domain/PolicySummary.java
@@ -27,6 +27,8 @@ import com.fasterxml.jackson.annotation.JsonProperty;
 import com.fasterxml.jackson.databind.annotation.JsonSerialize;
 import com.google.common.collect.ImmutableMap;
 
+import org.apache.brooklyn.api.objs.HighlightTuple;
+
 public class PolicySummary implements HasName, HasId, Serializable {
 
     private static final long serialVersionUID = -5086680835225136768L;
@@ -37,18 +39,21 @@ public class PolicySummary implements HasName, HasId, Serializable {
     private final String catalogItemId;
     private final Status state;
     private final Map<String, URI> links;
+    private final Map<String, HighlightTuple> highlights;
 
     public PolicySummary(
             @JsonProperty("id") String id,
             @JsonProperty("name") String name,
             @JsonProperty("catalogItemId") String catalogItemId,
             @JsonProperty("state") Status state,
+            @JsonProperty("highlights") Map<String, HighlightTuple> highlights,
             @JsonProperty("links") Map<String, URI> links) {
         this.id = id;
         this.name = name;
         this.catalogItemId = catalogItemId;
         this.state = state;
         this.links = (links == null) ? ImmutableMap.<String, URI> of() : ImmutableMap.copyOf(links);
+        this.highlights = (highlights == null) ? ImmutableMap.of() : ImmutableMap.copyOf(highlights);
     }
 
     @Override
@@ -73,6 +78,10 @@ public class PolicySummary implements HasName, HasId, Serializable {
         return links;
     }
 
+    public Map<String, HighlightTuple> getHighlights() {
+        return highlights;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;
@@ -82,12 +91,13 @@ public class PolicySummary implements HasName, HasId, Serializable {
                 Objects.equals(name, that.name) &&
                 Objects.equals(catalogItemId, that.catalogItemId) &&
                 state == that.state &&
-                Objects.equals(links, that.links);
+                Objects.equals(highlights, that.highlights) &&
+                Objects.equals(links, that.links) ;
     }
 
     @Override
     public int hashCode() {
-        return Objects.hash(id, name, catalogItemId, state, links);
+        return Objects.hash(id, name, catalogItemId, state, highlights, links);
     }
 
     @Override
@@ -97,6 +107,7 @@ public class PolicySummary implements HasName, HasId, Serializable {
                 ", name='" + name + '\'' +
                 ", catalogItemId='" + catalogItemId + '\'' +
                 ", state=" + state +
+                ", highlights=" + highlights +
                 ", links=" + links +
                 '}';
     }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/PolicyTransformer.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/PolicyTransformer.java
b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/PolicyTransformer.java
index 18e7d57..8dad949 100644
--- a/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/PolicyTransformer.java
+++ b/rest/rest-resources/src/main/java/org/apache/brooklyn/rest/transform/PolicyTransformer.java
@@ -65,7 +65,12 @@ public class PolicyTransformer {
                 .put("entity", entityUri)
                 .build();
 
-        return new PolicySummary(policy.getId(), policy.getDisplayName(), policy.getCatalogItemId(),
ApplicationTransformer.statusFromLifecycle(Policies.getPolicyStatus(policy)), links);
+        return new PolicySummary(   policy.getId(),
+                                    policy.getDisplayName(),
+                                    policy.getCatalogItemId(),
+                                    ApplicationTransformer.statusFromLifecycle(Policies.getPolicyStatus(policy)),
+                                    policy.getHighlights(),
+                                    links);
     }
 
     public static PolicyConfigSummary policyConfigSummary(BrooklynRestResourceUtils utils,
ApplicationSummary application, Entity entity, Policy policy, ConfigKey<?> config, UriBuilder
ub) {

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/PolicyResourceTest.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/PolicyResourceTest.java
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/PolicyResourceTest.java
index 1ba41cc..c555c9c 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/PolicyResourceTest.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/resources/PolicyResourceTest.java
@@ -28,12 +28,12 @@ import java.util.Set;
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.Response;
 
-import org.apache.brooklyn.rest.util.WebResourceUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.testng.annotations.BeforeClass;
 import org.testng.annotations.Test;
 
+import org.apache.brooklyn.api.objs.HighlightTuple;
 import org.apache.brooklyn.rest.domain.ApplicationSpec;
 import org.apache.brooklyn.rest.domain.EntitySpec;
 import org.apache.brooklyn.rest.domain.PolicyConfigSummary;
@@ -45,6 +45,7 @@ import org.apache.brooklyn.rest.testing.mocks.RestMockSimplePolicy;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Sets;
+
 import javax.ws.rs.core.GenericType;
 
 @Test(singleThreaded = true,
@@ -140,4 +141,25 @@ public class PolicyResourceTest extends BrooklynRestResourceTest {
                 .get(String.class);
         assertEquals(configVal, expectedVal);
     }
+
+    @Test
+    public void testHighlights() throws Exception {
+        Set<PolicySummary> policies = client().path(ENDPOINT).get(new GenericType<Set<PolicySummary>>()
{});
+
+        assertEquals(policies.size(), 1);
+        PolicySummary policySummary = policies.iterator().next();
+
+        Map<String, HighlightTuple> highlights = policySummary.getHighlights();
+
+        assertEquals(highlights.size(), 2);
+        HighlightTuple highlightTupleTask = highlights.get("testNameTask");
+        assertEquals(highlightTupleTask.getDescription(), "testDescription");
+        assertEquals(highlightTupleTask.getTime(), 123L);
+        assertEquals(highlightTupleTask.getTaskId(), "testTaskId");
+
+        HighlightTuple highlightTupleNoTask = highlights.get("testNameNoTask");
+        assertEquals(highlightTupleNoTask.getDescription(), "testDescription");
+        assertEquals(highlightTupleNoTask.getTime(), 123L);
+        assertEquals(highlightTupleNoTask.getTaskId(), null);
+    }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/962b7770/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimplePolicy.java
----------------------------------------------------------------------
diff --git a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimplePolicy.java
b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimplePolicy.java
index cdab1ab..9f142c3 100644
--- a/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimplePolicy.java
+++ b/rest/rest-resources/src/test/java/org/apache/brooklyn/rest/testing/mocks/RestMockSimplePolicy.java
@@ -18,6 +18,7 @@
  */
 package org.apache.brooklyn.rest.testing.mocks;
 
+import org.apache.brooklyn.api.objs.HighlightTuple;
 import org.apache.brooklyn.config.ConfigKey;
 import org.apache.brooklyn.core.config.BasicConfigKey;
 import org.apache.brooklyn.core.policy.AbstractPolicy;
@@ -32,6 +33,8 @@ public class RestMockSimplePolicy extends AbstractPolicy {
 
     public RestMockSimplePolicy() {
         super();
+        this.addHighlight("testNameTask",  new HighlightTuple("testDescription", 123L, "testTaskId"));
+        this.addHighlight("testNameNoTask",  new HighlightTuple("testDescription", 123L,
null));
     }
 
     @SetFromFlag("sampleConfig")


Mime
View raw message