You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by nc...@apache.org on 2016/02/05 22:56:54 UTC
[39/40] ambari git commit: AMBARI-14766 - Selecting ALL groups does
not work under Manage Alert Notifications (Keta Patel via jonathanhurley)
AMBARI-14766 - Selecting ALL groups does not work under Manage Alert Notifications (Keta Patel via jonathanhurley)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/f57f9b29
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/f57f9b29
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/f57f9b29
Branch: refs/heads/branch-dev-patch-upgrade
Commit: f57f9b2910ad1d888b2bd608e3d8b450154a0a23
Parents: 26ad97b
Author: Jonathan Hurley <jh...@hortonworks.com>
Authored: Fri Feb 5 16:24:12 2016 -0500
Committer: Jonathan Hurley <jh...@hortonworks.com>
Committed: Fri Feb 5 16:24:28 2016 -0500
----------------------------------------------------------------------
.../internal/AlertTargetResourceProvider.java | 12 +-
.../AlertTargetResourceProviderTest.java | 150 ++++++++++++++++++-
.../manage_alert_notifications_controller.js | 7 +
3 files changed, 162 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/f57f9b29/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
index d28987d..992d33f 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProvider.java
@@ -380,7 +380,10 @@ public class AlertTargetResourceProvider extends
String notificationType = (String) requestMap.get(ALERT_TARGET_NOTIFICATION_TYPE);
Collection<String> alertStates = (Collection<String>) requestMap.get(ALERT_TARGET_STATES);
Collection<Long> groupIds = (Collection<Long>) requestMap.get(ALERT_TARGET_GROUPS);
-
+ String isGlobal = (String) requestMap.get(ALERT_TARGET_GLOBAL);
+ if(null != isGlobal){
+ entity.setGlobal(Boolean.parseBoolean(isGlobal));
+ }
if (!StringUtils.isBlank(name)) {
entity.setTargetName(name);
}
@@ -425,6 +428,13 @@ public class AlertTargetResourceProvider extends
}
entity.setAlertGroups(groups);
+ } else if (entity.isGlobal()){
+ Set<AlertGroupEntity> groups = new HashSet<AlertGroupEntity>(s_dao.findAllGroups());
+ for (AlertGroupEntity group : groups) {
+ group.addAlertTarget(entity);
+ s_dao.merge(group);
+ }
+ entity.setAlertGroups(groups);
}
s_dao.merge(entity);
http://git-wip-us.apache.org/repos/asf/ambari/blob/f57f9b29/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java
index f80b6f7..7277b67 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/controller/internal/AlertTargetResourceProviderTest.java
@@ -894,6 +894,126 @@ public class AlertTargetResourceProviderTest {
verify(m_amc, m_dao);
}
+ @Test
+ public void testUpdateAlertTargetsWithCustomGroups() throws Exception{
+ Capture<AlertTargetEntity> entityCapture = new Capture<AlertTargetEntity>();
+ m_dao.create(capture(entityCapture));
+ expectLastCall().times(1);
+
+ AlertTargetEntity target = new AlertTargetEntity();
+ expect(m_dao.findTargetById(ALERT_TARGET_ID)).andReturn(target).once();
+
+ Capture<AlertGroupEntity> groupEntityCapture = new Capture<AlertGroupEntity>();
+
+ //All Groups in the Database with CLuster ID = 1L
+ List<AlertGroupEntity> groups = getMockGroupEntities();
+
+ //List of group ids to be selected in Custom option
+ List<Long> groupIds = Arrays.asList(1L, 2L, 3L);
+
+ expect(m_dao.findGroupsById(EasyMock.eq(groupIds))).andReturn(groups).anyTimes();
+ expect(m_dao.findAllGroups()).andReturn(groups).anyTimes();
+ for(AlertGroupEntity group: groups){
+ expect(m_dao.merge(capture(groupEntityCapture))).andReturn(group).anyTimes();
+ }
+ expect(m_dao.merge(capture(entityCapture))).andReturn(target).anyTimes();
+
+ //start execution with the above Expectation setters
+ replay(m_amc, m_dao);
+
+ SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
+
+ AlertTargetResourceProvider provider = createProvider(m_amc);
+ Map<String, Object> requestProps = getCreationProperties();
+ Request request = PropertyHelper.getCreateRequest(
+ Collections.singleton(requestProps), null);
+ provider.createResources(request);
+
+ requestProps = new HashMap<String, Object>();
+ requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_ID, ALERT_TARGET_ID.toString());
+
+ //selecting CUSTOM option for Groups, 2 group ids selected from the available options
+ requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_GLOBAL, "false");
+ requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_GROUPS, groupIds);
+
+ Predicate predicate = new PredicateBuilder().property(
+ AlertTargetResourceProvider.ALERT_TARGET_ID).equals(
+ ALERT_TARGET_ID.toString()).toPredicate();
+
+ request = PropertyHelper.getUpdateRequest(requestProps, null);
+ provider.updateResources(request, predicate);
+
+ assertTrue(entityCapture.hasCaptured());
+ AlertTargetEntity entity = entityCapture.getValue();
+
+ //verify that only the selected 2 groups were mapped with the target
+ assertEquals(3, entity.getAlertGroups().size());
+
+ //target must not be global for CUSTOM option
+ assertEquals(false,entity.isGlobal());
+
+ verify(m_amc, m_dao);
+ }
+
+ @Test
+ public void testUpdateAlertTargetsWithAllGroups() throws Exception{
+ Capture<AlertTargetEntity> entityCapture = new Capture<AlertTargetEntity>();
+ m_dao.create(capture(entityCapture));
+ expectLastCall().times(1);
+
+ AlertTargetEntity target = new AlertTargetEntity();
+ expect(m_dao.findTargetById(ALERT_TARGET_ID)).andReturn(target).once();
+
+ Capture<AlertGroupEntity> groupEntityCapture = new Capture<AlertGroupEntity>();
+
+ //All Groups in the Database with CLuster ID = 1L
+ List<AlertGroupEntity> groups = getMockGroupEntities();
+
+ //Groups to be selected for ALL option
+ List<Long> groupIds = Arrays.asList(1L, 2L, 3L);
+
+ expect(m_dao.findGroupsById(EasyMock.eq(groupIds))).andReturn(groups).anyTimes();
+ expect(m_dao.findAllGroups()).andReturn(groups).once();
+ for(AlertGroupEntity group: groups){
+ expect(m_dao.merge(capture(groupEntityCapture))).andReturn(group).once();
+ }
+ expect(m_dao.merge(capture(entityCapture))).andReturn(target).anyTimes();
+
+ //start execution with these Expectation setters
+ replay(m_amc, m_dao);
+
+ SecurityContextHolder.getContext().setAuthentication(TestAuthenticationFactory.createAdministrator());
+
+ AlertTargetResourceProvider provider = createProvider(m_amc);
+ Map<String, Object> requestProps = getCreationProperties();
+ Request request = PropertyHelper.getCreateRequest(
+ Collections.singleton(requestProps), null);
+ provider.createResources(request);
+
+ requestProps = new HashMap<String, Object>();
+ requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_ID, ALERT_TARGET_ID.toString());
+
+ //selecting ALL option for Groups
+ requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_GLOBAL, "true");
+
+ Predicate predicate = new PredicateBuilder().property(
+ AlertTargetResourceProvider.ALERT_TARGET_ID).equals(
+ ALERT_TARGET_ID.toString()).toPredicate();
+
+ request = PropertyHelper.getUpdateRequest(requestProps, null);
+ provider.updateResources(request, predicate);
+
+ assertTrue(entityCapture.hasCaptured());
+ AlertTargetEntity entity = entityCapture.getValue();
+
+ //verify that all the groups got mapped with target
+ assertEquals(3, entity.getAlertGroups().size());
+
+ //Target must be global for ALL option
+ assertEquals(true,entity.isGlobal());
+
+ verify(m_amc, m_dao);
+ }
/**
* @param amc
@@ -932,20 +1052,20 @@ public class AlertTargetResourceProviderTest {
private Map<String, Object> getCreationProperties() throws Exception {
Map<String, Object> requestProps = new HashMap<String, Object>();
requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_NAME,
- ALERT_TARGET_NAME);
+ ALERT_TARGET_NAME);
requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_DESCRIPTION,
- ALERT_TARGET_DESC);
+ ALERT_TARGET_DESC);
requestProps.put(
- AlertTargetResourceProvider.ALERT_TARGET_NOTIFICATION_TYPE,
- ALERT_TARGET_TYPE);
+ AlertTargetResourceProvider.ALERT_TARGET_NOTIFICATION_TYPE,
+ ALERT_TARGET_TYPE);
requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES
- + "/foo", "bar");
+ + "/foo", "bar");
requestProps.put(AlertTargetResourceProvider.ALERT_TARGET_PROPERTIES
- + "/foobar", "baz");
+ + "/foobar", "baz");
return requestProps;
}
@@ -976,6 +1096,24 @@ public class AlertTargetResourceProviderTest {
}
/**
+ * @return
+ */
+ @SuppressWarnings({ "rawtypes", "unchecked" })
+ private List<AlertGroupEntity> getMockGroupEntities() throws Exception {
+ AlertGroupEntity group1 = new AlertGroupEntity();
+ AlertGroupEntity group2 = new AlertGroupEntity();
+ AlertGroupEntity group3 = new AlertGroupEntity();
+ group1.setGroupId(1L);
+ group1.setClusterId(1L);
+ group2.setGroupId(2L);
+ group2.setClusterId(1L);
+ group3.setGroupId(3L);
+ group3.setClusterId(1L);
+
+ return Arrays.asList(group1, group2, group3);
+ }
+
+ /**
*
*/
private class MockModule implements Module {
http://git-wip-us.apache.org/repos/asf/ambari/blob/f57f9b29/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
index 38e4e75..79e524e 100644
--- a/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
+++ b/ambari-web/app/controllers/main/alerts/manage_alert_notifications_controller.js
@@ -702,6 +702,13 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
* @method updateAlertNotification
*/
updateAlertNotification: function (apiObject) {
+ if(apiObject!=null){
+ if(apiObject.AlertTarget.global == false){
+ this.get('selectedAlertNotification').set('global',false);
+ } else {
+ this.get('selectedAlertNotification').set('global',true);
+ }
+ }
return App.ajax.send({
name: 'alerts.update_alert_notification',
sender: this,