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-18318 - Agent heartbeat handler would always handle 'UNHEALTHY' state as 'UNKNOWN' (Hemanth Yamijala via jonathanhurley)
Date Thu, 08 Sep 2016 12:25:26 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk c1bfc6dd6 -> c9a0d332e


AMBARI-18318 - Agent heartbeat handler would always handle 'UNHEALTHY' state as 'UNKNOWN'
(Hemanth Yamijala via jonathanhurley)


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

Branch: refs/heads/trunk
Commit: c9a0d332e52d3abf3d8d1996187ae51c00978335
Parents: c1bfc6d
Author: Jonathan Hurley <jhurley@hortonworks.com>
Authored: Thu Sep 8 08:24:48 2016 -0400
Committer: Jonathan Hurley <jhurley@hortonworks.com>
Committed: Thu Sep 8 08:25:15 2016 -0400

----------------------------------------------------------------------
 .../alerts/AgentHeartbeatAlertRunnable.java     |  1 +
 .../alerts/AgentHeartbeatAlertRunnableTest.java | 37 +++++++++++++++++++-
 2 files changed, 37 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/c9a0d332/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java
b/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java
index e520826..41be01e 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnable.java
@@ -111,6 +111,7 @@ public class AgentHeartbeatAlertRunnable extends AlertRunnable {
         case UNHEALTHY:
           alertState = AlertState.CRITICAL;
           alertText = MessageFormat.format(UNHEALTHY_MSG, hostName);
+          break;
         default:
           alertState = AlertState.UNKNOWN;
           alertText = MessageFormat.format(UNKNOWN_MSG, hostName, hostState);

http://git-wip-us.apache.org/repos/asf/ambari/blob/c9a0d332/ambari-server/src/test/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnableTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnableTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnableTest.java
index 377ba30..721db7f 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnableTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/alerts/AgentHeartbeatAlertRunnableTest.java
@@ -179,7 +179,7 @@ public class AgentHeartbeatAlertRunnableTest {
   }
 
   @Test
-  public void testUnhealthyAlert() {
+  public void testLostHeartbeatAlert() {
     EasyMock.reset(m_host);
     expect(m_host.getState()).andReturn(HostState.HEARTBEAT_LOST).atLeastOnce();
     replay(m_host);
@@ -213,6 +213,41 @@ public class AgentHeartbeatAlertRunnableTest {
     verify(m_definition, m_host, m_cluster, m_clusters, m_definitionDao);
   }
 
+  @Test
+  public void testUnhealthyHostAlert() {
+    EasyMock.reset(m_host);
+    expect(m_host.getState()).andReturn(HostState.UNHEALTHY).atLeastOnce();
+    replay(m_host);
+
+    // precondition that no events were fired
+    assertEquals(0,
+        m_listener.getAlertEventReceivedCount(AlertReceivedEvent.class));
+
+    // instantiate and inject mocks
+    AgentHeartbeatAlertRunnable runnable = new AgentHeartbeatAlertRunnable(
+        m_definition.getDefinitionName());
+
+    m_injector.injectMembers(runnable);
+
+    // run the alert
+    runnable.run();
+
+    assertEquals(1,
+        m_listener.getAlertEventReceivedCount(AlertReceivedEvent.class));
+
+    List<AlertEvent> events = m_listener.getAlertEventInstances(AlertReceivedEvent.class);
+    assertEquals(1, events.size());
+
+    AlertReceivedEvent event = (AlertReceivedEvent) events.get(0);
+    Alert alert = event.getAlert();
+    assertEquals("AMBARI", alert.getService());
+    assertEquals("AMBARI_SERVER", alert.getComponent());
+    assertEquals(AlertState.CRITICAL, alert.getState());
+    assertEquals(DEFINITION_NAME, alert.getName());
+
+    verify(m_definition, m_host, m_cluster, m_clusters, m_definitionDao);
+  }
+
   /**
    *
    */


Mime
View raw message