You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by jo...@apache.org on 2016/04/05 19:54:28 UTC
ambari git commit: AMBARI-15430 - alert_group table has service info
after service has been removed (Qin Liu via jonathanhurley)
Repository: ambari
Updated Branches:
refs/heads/trunk a2c6ea46f -> dc088141a
AMBARI-15430 - alert_group table has service info after service has been removed (Qin Liu via jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/dc088141
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/dc088141
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/dc088141
Branch: refs/heads/trunk
Commit: dc088141a40511a0bb51173b594826393da46e69
Parents: a2c6ea4
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Tue Apr 5 13:52:41 2016 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Tue Apr 5 13:52:41 2016 -0400
----------------------------------------------------------------------
.../alerts/AlertServiceStateListener.java | 18 +--
.../apache/ambari/server/events/EventsTest.java | 116 ++++++++++++++++++-
2 files changed, 125 insertions(+), 9 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/dc088141/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java
index 496bb6b..da4cbf5 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/events/listeners/alerts/AlertServiceStateListener.java
@@ -188,16 +188,20 @@ public class AlertServiceStateListener {
for (AlertDefinitionEntity definition : definitions) {
try {
m_definitionDao.remove(definition);
+ } catch (Exception exception) {
+ LOG.error("Unable to remove alert definition {}", definition.getDefinitionName(), exception);
+ }
+ }
- // remove the default group for the service
- AlertGroupEntity group = m_alertDispatchDao.findGroupByName(event.getClusterId(),
- event.getServiceName());
+ // remove the default group for the service
+ AlertGroupEntity group = m_alertDispatchDao.findGroupByName(event.getClusterId(),
+ event.getServiceName());
- if (null != group && group.isDefault()) {
- m_alertDispatchDao.remove(group);
- }
+ if (null != group && group.isDefault()) {
+ try {
+ m_alertDispatchDao.remove(group);
} catch (Exception exception) {
- LOG.error("Unable to remove alert definition {}", definition.getDefinitionName(), exception);
+ LOG.error("Unable to remove default alert group {}", group.getGroupName(), exception);
}
}
} finally {
http://git-wip-us.apache.org/repos/asf/ambari/blob/dc088141/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
index 785f0fb..a3d05a9 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/events/EventsTest.java
@@ -27,7 +27,9 @@ import org.apache.ambari.server.orm.GuiceJpaInitializer;
import org.apache.ambari.server.orm.InMemoryDefaultTestModule;
import org.apache.ambari.server.orm.OrmTestHelper;
import org.apache.ambari.server.orm.dao.AlertDefinitionDAO;
+import org.apache.ambari.server.orm.dao.AlertDispatchDAO;
import org.apache.ambari.server.orm.entities.AlertDefinitionEntity;
+import org.apache.ambari.server.orm.entities.AlertGroupEntity;
import org.apache.ambari.server.state.Cluster;
import org.apache.ambari.server.state.Clusters;
import org.apache.ambari.server.state.Host;
@@ -72,6 +74,7 @@ public class EventsTest {
private MockEventListener m_listener;
private OrmTestHelper m_helper;
private AlertDefinitionDAO m_definitionDao;
+ private AlertDispatchDAO m_alertDispatchDao;
/**
*
@@ -93,6 +96,7 @@ public class EventsTest {
m_componentFactory = m_injector.getInstance(ServiceComponentFactory.class);
m_schFactory = m_injector.getInstance(ServiceComponentHostFactory.class);
m_definitionDao = m_injector.getInstance(AlertDefinitionDAO.class);
+ m_alertDispatchDao = m_injector.getInstance(AlertDispatchDAO.class);
m_clusterName = "foo";
StackId stackId = new StackId("HDP", "2.0.6");
@@ -156,8 +160,8 @@ public class EventsTest {
}
/**
- * Tests that {@link ServiceRemovedEvent}s are fired correctly and alerts are
- * removed.
+ * Tests that {@link ServiceRemovedEvent}s are fired correctly and alerts and
+ * the default alert group are removed.
*
* @throws Exception
*/
@@ -167,6 +171,106 @@ public class EventsTest {
Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
installHdfsService();
+ // get the default group for HDFS
+ AlertGroupEntity group = m_alertDispatchDao.findGroupByName(m_cluster.getClusterId(), "HDFS");
+
+ // verify the default group is there
+ Assert.assertNotNull(group);
+ Assert.assertTrue(group.isDefault());
+
+ // check that there are alert definitions
+ Assert.assertTrue(m_definitionDao.findAll(m_cluster.getClusterId()).size() > 0);
+
+ // get all definitions for HDFS
+ List<AlertDefinitionEntity> hdfsDefinitions = m_definitionDao.findByService(
+ m_cluster.getClusterId(), "HDFS");
+
+ // make sure there are at least 1
+ Assert.assertTrue(hdfsDefinitions.size() > 0);
+
+ AlertDefinitionEntity definition = hdfsDefinitions.get(0);
+
+ // delete HDFS
+ m_cluster.getService("HDFS").delete();
+
+ // verify the event was received
+ Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
+
+ // verify that the definitions were removed
+ hdfsDefinitions = m_definitionDao.findByService(m_cluster.getClusterId(), "HDFS");
+
+ Assert.assertEquals(0, hdfsDefinitions.size());
+
+ // verify that the default group was removed
+ group = m_alertDispatchDao.findGroupByName(m_cluster.getClusterId(), "HDFS");
+
+ Assert.assertNull(group);
+ }
+
+ /**
+ * Tests that {@link ServiceRemovedEvent}s are fired correctly and the default alert group
+ * is removed even though alerts were already removed at the time the event is fired.
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testServiceRemovedEventForDefaultAlertGroup() throws Exception {
+ Class<? extends AmbariEvent> eventClass = ServiceRemovedEvent.class;
+ Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
+ installHdfsService();
+
+ // get the default group for HDFS
+ AlertGroupEntity group = m_alertDispatchDao.findGroupByName(m_cluster.getClusterId(), "HDFS");
+
+ // verify the default group is there
+ Assert.assertNotNull(group);
+ Assert.assertTrue(group.isDefault());
+
+ // get all definitions for HDFS
+ List<AlertDefinitionEntity> hdfsDefinitions = m_definitionDao.findByService(
+ m_cluster.getClusterId(), "HDFS");
+
+ // delete the definitions
+ for (AlertDefinitionEntity definition : hdfsDefinitions) {
+ m_definitionDao.remove(definition);
+ }
+
+ // verify that the definitions were removed
+ hdfsDefinitions = m_definitionDao.findByService(m_cluster.getClusterId(), "HDFS");
+
+ Assert.assertEquals(0, hdfsDefinitions.size());
+
+ // delete HDFS
+ m_cluster.getService("HDFS").delete();
+
+ // verify the event was received
+ Assert.assertTrue(m_listener.isAmbariEventReceived(eventClass));
+
+ // verify that the default group was removed
+ group = m_alertDispatchDao.findGroupByName(m_cluster.getClusterId(), "HDFS");
+
+ Assert.assertNull(group);
+ }
+
+ /**
+ * Tests that {@link ServiceRemovedEvent}s are fired correctly and alerts are removed
+ * even though the default alert group was already removed at the time the event is fired .
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testServiceRemovedEventForAlertDefinitions() throws Exception {
+ Class<? extends AmbariEvent> eventClass = ServiceRemovedEvent.class;
+ Assert.assertFalse(m_listener.isAmbariEventReceived(eventClass));
+ installHdfsService();
+
+ // get the default group for HDFS
+ AlertGroupEntity group = m_alertDispatchDao.findGroupByName(m_cluster.getClusterId(), "HDFS");
+
+ // verify the default group is there
+ Assert.assertNotNull(group);
+ Assert.assertTrue(group.isDefault());
+
// check that there are alert definitions
Assert.assertTrue(m_definitionDao.findAll(m_cluster.getClusterId()).size() > 0);
@@ -179,6 +283,14 @@ public class EventsTest {
AlertDefinitionEntity definition = hdfsDefinitions.get(0);
+ // delete the default alert group
+ m_alertDispatchDao.remove(group);
+
+ // verify that the default group was removed
+ group = m_alertDispatchDao.findGroupByName(m_cluster.getClusterId(), "HDFS");
+
+ Assert.assertNull(group);
+
// delete HDFS
m_cluster.getService("HDFS").delete();