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-15702 - Global Repeat Tolerance Value For Alerts (part3 (jonathanhurley)
Date Tue, 05 Apr 2016 18:37:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 24bb7843c -> 48e418ee6


AMBARI-15702 - Global Repeat Tolerance Value For Alerts (part3 (jonathanhurley)


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

Branch: refs/heads/trunk
Commit: 48e418ee603b3f1cf11bbec9820b829945cd7161
Parents: 24bb784
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Tue Apr 5 14:33:29 2016 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Tue Apr 5 14:33:36 2016 -0400

----------------------------------------------------------------------
 .../listeners/alerts/AlertReceivedListener.java |  2 +-
 .../state/alerts/AlertReceivedListenerTest.java | 70 ++++++++++++++++++++
 2 files changed, 71 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/48e418ee/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
index 71abffd..e56420a 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertReceivedListener.java
@@ -233,7 +233,7 @@ public class AlertReceivedListener {
           // still SOFT, then we transition it to HARD - we also need to fire an
           // event
           AlertFirmness currentFirmness = current.getFirmness();
-          int repeatTolerance = definition.getRepeatTolerance();
+          int repeatTolerance = getRepeatTolerance(definition, clusterName);
           if (currentFirmness == AlertFirmness.SOFT && occurrences >= repeatTolerance)
{
             current.setFirmness(AlertFirmness.HARD);
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/48e418ee/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java
index 302c5fe..28aa19a 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/state/alerts/AlertReceivedListenerTest.java
@@ -19,7 +19,10 @@ package org.apache.ambari.server.state.alerts;
 
 import static org.junit.Assert.assertEquals;
 
+import java.util.Collections;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.UUID;
 
 import org.apache.ambari.server.controller.RootServiceResponseFactory.Components;
@@ -39,6 +42,9 @@ import org.apache.ambari.server.state.AlertFirmness;
 import org.apache.ambari.server.state.AlertState;
 import org.apache.ambari.server.state.Cluster;
 import org.apache.ambari.server.state.Clusters;
+import org.apache.ambari.server.state.Config;
+import org.apache.ambari.server.state.ConfigFactory;
+import org.apache.ambari.server.state.ConfigHelper;
 import org.apache.ambari.server.state.MaintenanceState;
 import org.apache.ambari.server.state.ServiceComponentFactory;
 import org.apache.ambari.server.state.ServiceComponentHostFactory;
@@ -799,4 +805,68 @@ public class AlertReceivedListenerTest {
     assertEquals(1, (long) allCurrent.get(0).getOccurrences());
     assertEquals(AlertFirmness.HARD, allCurrent.get(0).getFirmness());
   }
+
+  /**
+   * Tests that we correctly record alert firmness, using the global value if
+   * the definition does not override it.
+   */
+  @Test
+  @SuppressWarnings("serial")
+  public void testAlertFirmnessUsingGlobalValueHigherThanOverride() throws Exception {
+    ConfigFactory cf = m_injector.getInstance(ConfigFactory.class);
+    Config config = cf.createNew(m_cluster, ConfigHelper.CLUSTER_ENV,
+        new HashMap<String, String>() {
+          {
+            put(ConfigHelper.CLUSTER_ENV_ALERT_REPEAT_TOLERANCE, "3");
+          }
+        }, new HashMap<String, Map<String, String>>());
+
+    config.setTag("version2");
+    config.persist();
+
+    m_cluster.addConfig(config);
+    m_cluster.addDesiredConfig("user", Collections.singleton(config));
+
+    String definitionName = ALERT_DEFINITION + "1";
+    String serviceName = "HDFS";
+    String componentName = "NAMENODE";
+    String text = serviceName + " " + componentName + " is OK";
+
+    Alert alert = new Alert(definitionName, null, serviceName, componentName, HOST1, AlertState.OK);
+    alert.setCluster(m_cluster.getClusterName());
+    alert.setLabel(ALERT_LABEL);
+    alert.setText(text);
+    alert.setTimestamp(1L);
+
+    // fire the alert, and check that the new entry was created
+    AlertReceivedListener listener = m_injector.getInstance(AlertReceivedListener.class);
+    AlertReceivedEvent event = new AlertReceivedEvent(m_cluster.getClusterId(), alert);
+    listener.onAlertEvent(event);
+
+    List<AlertCurrentEntity> allCurrent = m_dao.findCurrent();
+    assertEquals(1, allCurrent.size());
+
+    // check occurrences (should be 1 since it's the first)
+    assertEquals(1, (long) allCurrent.get(0).getOccurrences());
+    assertEquals(AlertFirmness.HARD, allCurrent.get(0).getFirmness());
+
+    // change state to CRITICAL; this should make a SOFT alert since the global
+    // value is 3
+    alert.setState(AlertState.CRITICAL);
+    listener.onAlertEvent(event);
+    allCurrent = m_dao.findCurrent();
+    assertEquals(1, (long) allCurrent.get(0).getOccurrences());
+    assertEquals(AlertFirmness.SOFT, allCurrent.get(0).getFirmness());
+
+    listener.onAlertEvent(event);
+    allCurrent = m_dao.findCurrent();
+    assertEquals(2, (long) allCurrent.get(0).getOccurrences());
+    assertEquals(AlertFirmness.SOFT, allCurrent.get(0).getFirmness());
+
+    // on the 3rd time, we transition to HARD
+    listener.onAlertEvent(event);
+    allCurrent = m_dao.findCurrent();
+    assertEquals(3, (long) allCurrent.get(0).getOccurrences());
+    assertEquals(AlertFirmness.HARD, allCurrent.get(0).getFirmness());
+  }
 }


Mime
View raw message