brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aleds...@apache.org
Subject [3/5] brooklyn-server git commit: Fixes due to PR comments
Date Wed, 20 Dec 2017 16:13:35 GMT
Fixes due to PR comments


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

Branch: refs/heads/master
Commit: 39e822f9cee1beed03935d6814a19f2c399ac3bd
Parents: 3555b48
Author: graeme.miller <graeme.miller@cloudsoftcorp.com>
Authored: Thu Dec 14 16:47:11 2017 +0000
Committer: graeme.miller <graeme.miller@cloudsoftcorp.com>
Committed: Thu Dec 14 16:47:11 2017 +0000

----------------------------------------------------------------------
 .../stock/aggregator/AggregationJob.java        | 46 +++++++++++++-------
 .../stock/aggregator/DashboardAggregator.java   | 32 +++++++++++++-
 .../stock/aggregator/AggregationJobTest.java    | 20 +++------
 3 files changed, 68 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/39e822f9/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJob.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJob.java
b/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJob.java
index 82b8ee4..641325c 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJob.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJob.java
@@ -31,11 +31,25 @@ import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey;
 
 public final class AggregationJob implements Runnable {
 
-    public static BasicAttributeSensorAndConfigKey<Map<String, String>> DASHBOARD_COST_PER_MONTH
= new BasicAttributeSensorAndConfigKey(Map.class, "dashboard.costPerMonth", "A map of VM ID
to monthly cost. Please note if the same VM ID is reported more than once, only one of the
sensors will be propagated");
-    public static BasicAttributeSensorAndConfigKey<List<Map<String, String>>>
DASHBOARD_HA_PRIMARIES = new BasicAttributeSensorAndConfigKey(List.class, "dashboard.ha.primaries",
"A list of high availability primaries "); //TODO: find out what this is and add a better
description
-    public static BasicAttributeSensorAndConfigKey<List<Map<String, String>>>
DASHBOARD_LICENSES = new BasicAttributeSensorAndConfigKey(List.class, "dashboard.licenses",
"The licences in use for the running entities. This is a list of maps. The map should contain
two keys: product and key");
-    public static BasicAttributeSensorAndConfigKey<Map<String, List<Map<String,
Object>>>> DASHBOARD_LOCATIONS = new BasicAttributeSensorAndConfigKey(Map.class,
"dashboard.locations", "Locations in which the VMs are running. A map where the key is category
of location (e.g. server) and the value is a list of maps containing name/icon/count");
-    public static BasicAttributeSensorAndConfigKey<List<Map<String, String>>>
DASHBOARD_POLICY_HIGHLIGHTS = new BasicAttributeSensorAndConfigKey(List.class, "dashboard.policyHighlights",
"Highlights from policies. List of Masps, where each map should contain text and category");
+    public static BasicAttributeSensorAndConfigKey<Map<String, String>> DASHBOARD_COST_PER_MONTH
= new BasicAttributeSensorAndConfigKey(Map.class,
+            "dashboard.costPerMonth",
+            "A map of VM ID to monthly cost. Please note if the same VM ID is reported more
than once, only one of the sensors will be propagated");
+
+    public static BasicAttributeSensorAndConfigKey<List<Map<String, String>>>
DASHBOARD_HA_PRIMARIES = new BasicAttributeSensorAndConfigKey(List.class,
+            "dashboard.ha.primaries",
+            "A list of high availability primaries "); //TODO: find out what this is and
add a better description
+
+    public static BasicAttributeSensorAndConfigKey<List<Map<String, String>>>
DASHBOARD_LICENSES = new BasicAttributeSensorAndConfigKey(List.class,
+            "dashboard.licenses",
+            "The licences in use for the running entities. This is a list of maps. The map
should contain two keys: product and key");
+
+    public static BasicAttributeSensorAndConfigKey<Map<String, List<Map<String,
Object>>>> DASHBOARD_LOCATIONS = new BasicAttributeSensorAndConfigKey(Map.class,
+            "dashboard.locations",
+            "Locations in which the VMs are running. A map where the key is category of location
(e.g. server) and the value is a list of maps containing name/icon/count");
+
+    public static BasicAttributeSensorAndConfigKey<List<Map<String, String>>>
DASHBOARD_POLICY_HIGHLIGHTS = new BasicAttributeSensorAndConfigKey(List.class,
+            "dashboard.policyHighlights",
+            "Highlights from policies. List of Masps, where each map should contain text
and category");
 
     private final Entity entity;
 
@@ -73,21 +87,21 @@ public final class AggregationJob implements Runnable {
         entity.sensors().set(DASHBOARD_POLICY_HIGHLIGHTS, dashboardPolicyHighlights);
     }
 
-    protected void scanEntity(Entity entity,
+    protected void scanEntity(Entity entityToScan,
                               Map<String, String> costPerMonth,
                               List<Map<String, String>> haPrimaries,
                               List<Map<String, String>> licences,
                               Map<String, List<Map<String, Object>>> locations,
                               List<Map<String, String>> policyHighlights) {
 
-        updateFromConfig(entity, DASHBOARD_HA_PRIMARIES, haPrimaries);
-        updateFromConfig(entity, DASHBOARD_LICENSES, licences);
-        updateFromConfig(entity, DASHBOARD_POLICY_HIGHLIGHTS, policyHighlights);
+        updateFromConfig(entityToScan, DASHBOARD_HA_PRIMARIES, haPrimaries);
+        updateFromConfig(entityToScan, DASHBOARD_LICENSES, licences);
+        updateFromConfig(entityToScan, DASHBOARD_POLICY_HIGHLIGHTS, policyHighlights);
 
         //Cost per month
-        Map<String, String> costPerMonthFromEntity = entity.sensors().get(DASHBOARD_COST_PER_MONTH);
+        Map<String, String> costPerMonthFromEntity = entityToScan.sensors().get(DASHBOARD_COST_PER_MONTH);
         if (costPerMonthFromEntity == null || costPerMonthFromEntity.isEmpty()) {
-            costPerMonthFromEntity = entity.config().get(DASHBOARD_COST_PER_MONTH);
+            costPerMonthFromEntity = entityToScan.config().get(DASHBOARD_COST_PER_MONTH);
         }
 
         if (costPerMonthFromEntity != null) {
@@ -102,9 +116,9 @@ public final class AggregationJob implements Runnable {
         //Further complicating this is that the Map you get back from sensors/config doesn't
conform to the generic expectations.
         //I.E. even if you type this as Map<String, List<Map<String, String>>>
you will still get back an integer from
         //the inner map- hence all the weird casting bellow.
-        Map<String, List<Map<String, Object>>> outerLocationMapFromEntity
= entity.sensors().get(DASHBOARD_LOCATIONS);
+        Map<String, List<Map<String, Object>>> outerLocationMapFromEntity
= entityToScan.sensors().get(DASHBOARD_LOCATIONS);
         if (outerLocationMapFromEntity == null || outerLocationMapFromEntity.isEmpty()) {
-            outerLocationMapFromEntity = entity.config().get(DASHBOARD_LOCATIONS);
+            outerLocationMapFromEntity = entityToScan.config().get(DASHBOARD_LOCATIONS);
         }
 
         if (outerLocationMapFromEntity != null) {
@@ -131,7 +145,7 @@ public final class AggregationJob implements Runnable {
                                 }
                             }
 
-                            //If the entity has a "name" not found in the method param then
add it to the method param
+                            //If the entityToScan has a "name" not found in the method param
then add it to the method param
                             if (!foundInner) {
                                 outerLocationMapFromMethodParam.getValue().add(new HashMap<>(innerMapFromEntity));
                             }
@@ -140,7 +154,7 @@ public final class AggregationJob implements Runnable {
 
                 }
 
-                //If the entity has an entry in the outer map that isn't in the method param,
then add it
+                //If the entityToScan has an entry in the outer map that isn't in the method
param, then add it
                 if (!found) {
                     ArrayList clonedList = new ArrayList();
                     outerLocationMapFromEntityValue.forEach(mapToClone -> {
@@ -153,6 +167,6 @@ public final class AggregationJob implements Runnable {
             });
         }
 
-        entity.getChildren().forEach(childEntity -> scanEntity(childEntity, costPerMonth,
haPrimaries, licences, locations, policyHighlights));
+        entityToScan.getChildren().forEach(childEntity -> scanEntity(childEntity, costPerMonth,
haPrimaries, licences, locations, policyHighlights));
     }
 }

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/39e822f9/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/DashboardAggregator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/DashboardAggregator.java
b/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/DashboardAggregator.java
index 9344d76..f8e9775 100644
--- a/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/DashboardAggregator.java
+++ b/core/src/main/java/org/apache/brooklyn/enricher/stock/aggregator/DashboardAggregator.java
@@ -18,23 +18,48 @@
  */
 package org.apache.brooklyn.enricher.stock.aggregator;
 
+import java.util.Map;
 import java.util.concurrent.Callable;
 
 import org.apache.brooklyn.api.entity.EntityLocal;
 import org.apache.brooklyn.api.mgmt.Task;
 import org.apache.brooklyn.core.enricher.AbstractEnricher;
 import org.apache.brooklyn.core.mgmt.BrooklynTaskTags;
+import org.apache.brooklyn.core.sensor.BasicAttributeSensorAndConfigKey;
 import org.apache.brooklyn.util.core.task.ScheduledTask;
 import org.apache.brooklyn.util.core.task.Tasks;
 import org.apache.brooklyn.util.time.Duration;
 
+/**
+ * The DashboardAggregator is an enricher that combines config/sensor values from the children
of the entity it is attached to.
+ * The combined values are set as sensors on the entity that it is attached to. Preference
is given to the child entities sensors values,
+ * but if none are set, config values are used instead.
+ *
+ * The reason that this exists is to provide high level summary information, that could be
useful to display on a dashboard.
+ * Whilst brooklyn itself has no such dashboard, we can imagine this entity being used in
that fashion.
+ *
+ * Please note, that the DashboardAggregator will aggregate all children of the entity it
is attached to, even intermediate level children.
+ * Therefore, please only ever attach one DashboardAggregator to the top most entity.
+ *
+ * For a detailed list of the config that is combined, please see the AggregationJob class.
+ *
+ */
 public class DashboardAggregator extends AbstractEnricher {
 
+    private ScheduledTask task;
+
+    public static BasicAttributeSensorAndConfigKey<Duration> DASHBOARD_COST_PER_MONTH
= new BasicAttributeSensorAndConfigKey(Duration.class,
+            "dashboard.period",
+            "The amount of time to wait between aggregation jobs",
+            Duration.seconds(1));
+
     @SuppressWarnings("unchecked")
     @Override
     public void setEntity(EntityLocal entity) {
         super.setEntity(entity);
 
+        Duration duration = config().get(DASHBOARD_COST_PER_MONTH);
+
         Callable<Task<?>> taskFactory = () -> Tasks.builder()
                 .dynamic(false)
                 .body(new AggregationJob(entity))
@@ -43,9 +68,14 @@ public class DashboardAggregator extends AbstractEnricher {
                 .description("Retrieves and aggregates sensor values")
                 .build();
 
-        ScheduledTask task = ScheduledTask.builder(taskFactory).period(Duration.seconds(1)).displayName("scheduled:[DashboardAggregator
task]").tagTransient().build();
+        task = ScheduledTask.builder(taskFactory).period(duration).displayName("scheduled:[DashboardAggregator
task]").tagTransient().build();
         this.getManagementContext().getExecutionManager().submit(task);
 
     }
 
+    @Override
+    public void destroy() {
+        super.destroy();
+        task.cancel();
+    }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/39e822f9/core/src/test/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJobTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJobTest.java
b/core/src/test/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJobTest.java
index a286143..fa50c67 100644
--- a/core/src/test/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJobTest.java
+++ b/core/src/test/java/org/apache/brooklyn/enricher/stock/aggregator/AggregationJobTest.java
@@ -36,37 +36,31 @@ import org.testng.annotations.Test;
 
 import org.apache.brooklyn.api.entity.EntitySpec;
 import org.apache.brooklyn.core.mgmt.internal.LocalManagementContext;
+import org.apache.brooklyn.core.test.BrooklynAppUnitTestSupport;
 import org.apache.brooklyn.core.test.entity.LocalManagementContextForTests;
 import org.apache.brooklyn.core.test.entity.TestApplication;
 import org.apache.brooklyn.core.test.entity.TestEntity;
 
-public class AggregationJobTest {
+public class AggregationJobTest extends BrooklynAppUnitTestSupport {
+
 
-    TestApplication testApplication;
     TestEntity parentEntity;
     TestEntity childEntityOne;
     TestEntity childEntityTwo;
 
     AggregationJob aggregationJob;
 
-    LocalManagementContext localManagementContext;
-
     @BeforeMethod
-    public void testSetup() {
-        localManagementContext = LocalManagementContextForTests.newInstance();
-        testApplication = TestApplication.Factory.newManagedInstanceForTests(localManagementContext);
-
-        parentEntity = testApplication.createAndManageChild(EntitySpec.create(TestEntity.class));
+    @Override
+    public void setUp() throws Exception {
+        super.setUp();
+        parentEntity = app.createAndManageChild(EntitySpec.create(TestEntity.class));
         childEntityOne = parentEntity.createAndManageChild(EntitySpec.create(TestEntity.class));
         childEntityTwo = parentEntity.createAndManageChild(EntitySpec.create(TestEntity.class));
 
         aggregationJob = new AggregationJob(parentEntity);
     }
 
-    @AfterMethod
-    public void testTeardown(){
-        localManagementContext.terminate();
-    }
 
     @Test
     public void policyHighlightTest() {


Mime
View raw message