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 2015/03/26 14:30:02 UTC
ambari git commit: AMBARI-9823 - Alert Notifications Are Not Received
Without Restarting Ambari Server (part2) (jonathanhurley)
Repository: ambari
Updated Branches:
refs/heads/trunk 2c2645767 -> 2ae23688c
AMBARI-9823 - Alert Notifications Are Not Received Without Restarting Ambari Server (part2) (jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2ae23688
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2ae23688
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2ae23688
Branch: refs/heads/trunk
Commit: 2ae23688c6f9d54d2355f173eae89694c77ec697
Parents: 2c26457
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Wed Mar 25 19:36:39 2015 -0400
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Thu Mar 26 09:29:55 2015 -0400
----------------------------------------------------------------------
.../server/orm/entities/AlertGroupEntity.java | 2 +-
.../server/orm/dao/AlertDispatchDAOTest.java | 38 ++++++++++++++++++++
2 files changed, 39 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/2ae23688/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java
index 7d2c6c7..9efb166 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/orm/entities/AlertGroupEntity.java
@@ -82,7 +82,7 @@ public class AlertGroupEntity {
/**
* Unidirectional many-to-many association to {@link AlertTargetEntity}
*/
- @ManyToMany(cascade = CascadeType.MERGE)
+ @ManyToMany(cascade = { CascadeType.MERGE, CascadeType.REFRESH })
@JoinTable(name = "alert_group_target", joinColumns = { @JoinColumn(name = "group_id", nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "target_id", nullable = false) })
private Set<AlertTargetEntity> alertTargets;
http://git-wip-us.apache.org/repos/asf/ambari/blob/2ae23688/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
index a267043..8768ffc 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/orm/dao/AlertDispatchDAOTest.java
@@ -26,6 +26,7 @@ import static org.junit.Assert.assertTrue;
import java.lang.reflect.Field;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@@ -584,6 +585,43 @@ public class AlertDispatchDAOTest {
}
/**
+ * Tests finding groups by a definition ID that they are associatd with in
+ * order to get any targets associated with that group. This exercises the
+ * bi-directional
+ *
+ * @throws Exception
+ */
+ @Test
+ public void testFindTargetsViaGroupsByDefinition() throws Exception {
+ List<AlertDefinitionEntity> definitions = createDefinitions();
+ AlertGroupEntity group = m_helper.createAlertGroup(
+ m_cluster.getClusterId(), null);
+
+ group = m_dao.findGroupById(group.getGroupId());
+ assertNotNull(group);
+
+ AlertDefinitionEntity definition = definitions.get(0);
+ group.addAlertDefinition(definition);
+
+ m_dao.merge(group);
+
+ List<AlertTargetEntity> targets = m_dao.findAllTargets();
+ AlertTargetEntity target = targets.get(0);
+ Set<AlertTargetEntity> setTargets = Collections.singleton(target);
+
+ group.setAlertTargets(setTargets);
+ m_dao.merge(group);
+
+ List<AlertGroupEntity> groups = m_dao.findGroupsByDefinition(definition);
+ assertEquals(2, groups.size());
+
+ group = groups.get(groups.indexOf(group));
+ assertEquals(1, group.getAlertTargets().size());
+ assertEquals(target.getTargetId(),
+ group.getAlertTargets().iterator().next().getTargetId());
+ }
+
+ /**
* @throws Exception
*/
@Test