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:29:30 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.4 21c1d9e3b -> 35d80d695


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/35d80d69
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/35d80d69
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/35d80d69

Branch: refs/heads/branch-2.4
Commit: 35d80d6957a6a7408ed4cc3ba706b7095b0e808a
Parents: 21c1d9e
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:29:20 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/35d80d69/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/35d80d69/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