ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jonathanhur...@apache.org
Subject ambari git commit: AMBARI-8998 - Alert-instance grouped summary should include summary text (jonathanhurley)
Date Tue, 06 Jan 2015 14:47:00 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 0d601a8d1 -> b3e556f78


AMBARI-8998 - Alert-instance grouped summary should include summary text (jonathanhurley)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b3e556f7
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b3e556f7
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b3e556f7

Branch: refs/heads/trunk
Commit: b3e556f787bf5b466a1258d2934fcda3a9375055
Parents: 0d601a8
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Mon Jan 5 23:05:20 2015 -0500
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Tue Jan 6 09:46:50 2015 -0500

----------------------------------------------------------------------
 .../api/query/render/AlertStateValues.java      |  8 +++
 .../render/AlertSummaryGroupedRenderer.java     | 20 +++++---
 .../internal/AlertResourceProvider.java         |  2 +-
 .../internal/AlertResourceProviderTest.java     | 53 +++++++++++++++++++-
 4 files changed, 73 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b3e556f7/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertStateValues.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertStateValues.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertStateValues.java
index 45fea5d..261aa21 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertStateValues.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertStateValues.java
@@ -18,6 +18,7 @@
 package org.apache.ambari.server.api.query.render;
 
 import org.codehaus.jackson.annotate.JsonProperty;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
 
 /**
  * The {@link AlertStateValues} class holds various information about an alert
@@ -42,4 +43,11 @@ public final class AlertStateValues {
    */
   @JsonProperty(value = "maintenance_count")
   public int MaintenanceCount = 0;
+
+  /**
+   * The most recently received text from any instance of the alert.
+   */
+  @JsonProperty(value = "latest_text")
+  @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL)
+  public String AlertText = null;
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3e556f7/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertSummaryGroupedRenderer.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertSummaryGroupedRenderer.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertSummaryGroupedRenderer.java
index 3903335..b5c08f9 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertSummaryGroupedRenderer.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/query/render/AlertSummaryGroupedRenderer.java
@@ -53,12 +53,14 @@ import org.codehaus.jackson.annotate.JsonProperty;
  *         "CRITICAL": {
  *           "count": 1,
  *           "maintenance_count" : 1,
- *           "original_timestamp": 1415372992337
+ *           "original_timestamp": 1415372992337,
+ *           "latest_text" : "TCP Connection Failure"
  *         },
  *         "OK": {
  *           "count": 1,
  *           "maintenance_count" : 0,
- *           "original_timestamp": 1415372992337
+ *           "original_timestamp": 1415372992337,
+ *           "latest_text" : "TCP OK"
  *         },
  *         "UNKNOWN": {
  *           "count": 0,
@@ -134,6 +136,7 @@ public class AlertSummaryGroupedRenderer extends AlertSummaryRenderer
{
       AlertState state = (AlertState) resource.getPropertyValue(AlertResourceProvider.ALERT_STATE);
       Long originalTimestampObject = (Long) resource.getPropertyValue(AlertResourceProvider.ALERT_ORIGINAL_TIMESTAMP);
       MaintenanceState maintenanceState = (MaintenanceState) resource.getPropertyValue(AlertResourceProvider.ALERT_MAINTENANCE_STATE);
+      String alertText = (String) resource.getPropertyValue(AlertResourceProvider.ALERT_TEXT);
 
       // NPE sanity
       if (null == state) {
@@ -192,9 +195,11 @@ public class AlertSummaryGroupedRenderer extends AlertSummaryRenderer
{
         alertStateValues.Count++;
       }
 
-      // track the most recent timestamp if state change
+      // check to see if this alerts time is sooner; if so, keep track of it
+      // and of its text
       if (originalTimestamp > alertStateValues.Timestamp) {
         alertStateValues.Timestamp = originalTimestamp;
+        alertStateValues.AlertText = alertText;
       }
     }
 
@@ -230,6 +235,7 @@ public class AlertSummaryGroupedRenderer extends AlertSummaryRenderer
{
     properties.add(AlertResourceProvider.ALERT_ID);
     properties.add(AlertResourceProvider.ALERT_DEFINITION_NAME);
     properties.add(AlertResourceProvider.ALERT_MAINTENANCE_STATE);
+    properties.add(AlertResourceProvider.ALERT_TEXT);
   }
 
   /**
@@ -237,14 +243,14 @@ public class AlertSummaryGroupedRenderer extends AlertSummaryRenderer
{
    * track of each alert definition's summary information as the result set is
    * being iterated over.
    */
-  private final static class AlertDefinitionSummary {
+  public final static class AlertDefinitionSummary {
     @JsonProperty(value = "definition_id")
-    private long Id;
+    public long Id;
 
     @JsonProperty(value = "definition_name")
-    private String Name;
+    public String Name;
 
     @JsonProperty(value = "summary")
-    private final AlertStateSummary State = new AlertStateSummary();
+    public final AlertStateSummary State = new AlertStateSummary();
   }
 }

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3e556f7/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
index c9c0870..3c11379 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertResourceProvider.java
@@ -55,12 +55,12 @@ public class AlertResourceProvider extends ReadOnlyResourceProvider {
   public static final String ALERT_MAINTENANCE_STATE = "Alert/maintenance_state";
   public static final String ALERT_DEFINITION_ID = "Alert/definition_id";
   public static final String ALERT_DEFINITION_NAME = "Alert/definition_name";
+  public static final String ALERT_TEXT = "Alert/text";
 
   protected static final String ALERT_CLUSTER_NAME = "Alert/cluster_name";
   protected static final String ALERT_LATEST_TIMESTAMP = "Alert/latest_timestamp";
   protected static final String ALERT_INSTANCE = "Alert/instance";
   protected static final String ALERT_LABEL = "Alert/label";
-  protected static final String ALERT_TEXT = "Alert/text";
   protected static final String ALERT_COMPONENT = "Alert/component_name";
   protected static final String ALERT_HOST = "Alert/host_name";
   protected static final String ALERT_SERVICE = "Alert/service_name";

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3e556f7/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
index 130e774..ed543f9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertResourceProviderTest.java
@@ -39,6 +39,7 @@ import javax.persistence.EntityManager;
 
 import org.apache.ambari.server.api.query.render.AlertStateSummary;
 import org.apache.ambari.server.api.query.render.AlertSummaryGroupedRenderer;
+import org.apache.ambari.server.api.query.render.AlertSummaryGroupedRenderer.AlertDefinitionSummary;
 import org.apache.ambari.server.api.query.render.AlertSummaryRenderer;
 import org.apache.ambari.server.api.services.Result;
 import org.apache.ambari.server.api.services.ResultImpl;
@@ -270,7 +271,8 @@ public class AlertResourceProviderTest {
     Request request = PropertyHelper.getReadRequest(
         AlertResourceProvider.ALERT_ID, AlertResourceProvider.ALERT_DEFINITION_NAME,
         AlertResourceProvider.ALERT_LABEL, AlertResourceProvider.ALERT_STATE,
-        AlertResourceProvider.ALERT_ORIGINAL_TIMESTAMP);
+        AlertResourceProvider.ALERT_ORIGINAL_TIMESTAMP,
+        AlertResourceProvider.ALERT_TEXT);
 
     Predicate predicate = new PredicateBuilder().property(
         AlertResourceProvider.ALERT_CLUSTER_NAME).equals("c1").toPredicate();
@@ -297,8 +299,54 @@ public class AlertResourceProviderTest {
     TreeNode<Resource> summaryResources = summaryResultTree.getChild("alerts_summary_grouped");
 
     Resource summaryResource = summaryResources.getObject();
-    List<Object> summaryList = (List<Object>) summaryResource.getPropertyValue("alerts_summary_grouped");
+    List<AlertDefinitionSummary> summaryList = (List<AlertDefinitionSummary>)
summaryResource.getPropertyValue("alerts_summary_grouped");
     Assert.assertEquals(4, summaryList.size());
+
+    AlertDefinitionSummary nnSummary = null;
+    AlertDefinitionSummary rmSummary = null;
+    AlertDefinitionSummary hiveSummary = null;
+    AlertDefinitionSummary flumeSummary = null;
+
+    for (AlertDefinitionSummary summary : summaryList) {
+      if (summary.Name.equals("hdfs_namenode")) {
+        nnSummary = summary;
+      } else if (summary.Name.equals("yarn_resourcemanager")) {
+        rmSummary = summary;
+      } else if (summary.Name.equals("hive_server")) {
+        hiveSummary = summary;
+      } else if (summary.Name.equals("flume_handler")) {
+        flumeSummary = summary;
+      }
+    }
+
+    Assert.assertNotNull(nnSummary);
+    Assert.assertNotNull(rmSummary);
+    Assert.assertNotNull(hiveSummary);
+    Assert.assertNotNull(flumeSummary);
+
+    Assert.assertEquals(10, nnSummary.State.Ok.Count);
+    Assert.assertEquals(ALERT_VALUE_TEXT, nnSummary.State.Ok.AlertText);
+    Assert.assertEquals(0, nnSummary.State.Warning.Count);
+    Assert.assertEquals(0, nnSummary.State.Critical.Count);
+    Assert.assertEquals(0, nnSummary.State.Unknown.Count);
+
+    Assert.assertEquals(0, rmSummary.State.Ok.Count);
+    Assert.assertEquals(2, rmSummary.State.Warning.Count);
+    Assert.assertEquals(ALERT_VALUE_TEXT, rmSummary.State.Warning.AlertText);
+    Assert.assertEquals(0, rmSummary.State.Critical.Count);
+    Assert.assertEquals(0, rmSummary.State.Unknown.Count);
+
+    Assert.assertEquals(0, hiveSummary.State.Ok.Count);
+    Assert.assertEquals(0, hiveSummary.State.Warning.Count);
+    Assert.assertEquals(1, hiveSummary.State.Critical.Count);
+    Assert.assertEquals(ALERT_VALUE_TEXT, hiveSummary.State.Critical.AlertText);
+    Assert.assertEquals(0, hiveSummary.State.Unknown.Count);
+
+    Assert.assertEquals(0, flumeSummary.State.Ok.Count);
+    Assert.assertEquals(0, flumeSummary.State.Warning.Count);
+    Assert.assertEquals(0, flumeSummary.State.Critical.Count);
+    Assert.assertEquals(3, flumeSummary.State.Unknown.Count);
+    Assert.assertEquals(ALERT_VALUE_TEXT, flumeSummary.State.Unknown.AlertText);
   }
 
   /**
@@ -439,6 +487,7 @@ public class AlertResourceProviderTest {
       current.setAlertId(alertId.getAndIncrement());
       current.setOriginalTimestamp(timestamp.getAndAdd(10000));
       current.setLatestTimestamp(timestamp.getAndAdd(10000));
+      current.setLatestText(ALERT_VALUE_TEXT);
 
       AlertHistoryEntity history = new AlertHistoryEntity();
       history.setAlertId(alertId.getAndIncrement());


Mime
View raw message