Repository: ambari Updated Branches: refs/heads/branch-2.5 4f8934d68 -> a76c5c8b2
AMBARI-19252. Incorrect Method types displayed in the description of created Alert notification. (Vivek Subramanian via yusaku) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a76c5c8b Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a76c5c8b Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a76c5c8b Branch: refs/heads/branch-2.5 Commit: a76c5c8b2ce19b8d46805b12baf22d64c45d0f6e Parents: 4f8934d Author: Yusaku Sako <yus...@hortonworks.com> Authored: Wed Dec 28 10:06:45 2016 -0800 Committer: Yusaku Sako <yus...@hortonworks.com> Committed: Wed Dec 28 10:06:45 2016 -0800 ---------------------------------------------------------------------- .../manage_alert_notifications_controller.js | 34 +++-- .../alerts/manage_alert_notifications_popup.hbs | 2 +- .../alerts/manage_alert_notifications_view.js | 4 + ...anage_alert_notifications_controller_test.js | 153 ++++++++++++++++++- 4 files changed, 180 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a76c5c8b/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 369a053..84cf6ca 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 @@ -392,6 +392,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ fillEditCreateInputs: function (addCopyToName) { var inputFields = this.get('inputFields'); var selectedAlertNotification = this.get('selectedAlertNotification'); + var methodValue = this.getNotificationTypeText(selectedAlertNotification.get('type')); inputFields.set('name.value', (addCopyToName ? 'Copy of ' : '') + selectedAlertNotification.get('name')); inputFields.set('groups.value', selectedAlertNotification.get('groups').toArray()); inputFields.set('email.value', selectedAlertNotification.get('properties')['ambari.dispatch.recipients'] ? @@ -416,7 +417,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ // not allow to edit global field inputFields.set('global.disabled', true); inputFields.set('description.value', selectedAlertNotification.get('description')); - inputFields.set('method.value', selectedAlertNotification.get('type')); + inputFields.set('method.value', methodValue); inputFields.get('customProperties').clear(); var properties = selectedAlertNotification.get('properties'); var ignoredCustomProperties = this.get('ignoredCustomProperties'); @@ -768,21 +769,12 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ inputFields.get('customProperties').forEach(function (customProperty) { properties[customProperty.name] = customProperty.value; }); - var getNotificationType = function() { - var methodValue = inputFields.get('method.value'); - if(methodValue == "Custom SNMP") { - methodValue = "SNMP"; - } else if(methodValue == "SNMP") { - methodValue = "AMBARI_SNMP" - } - return methodValue; - }; var apiObject = { AlertTarget: { name: inputFields.get('name.value'), description: inputFields.get('description.value'), global: inputFields.get('allGroups.value') === 'all', - notification_type: getNotificationType(), + notification_type: this.getNotificationType(inputFields.get('method.value')), alert_states: inputFields.get('severityFilter.value'), properties: properties } @@ -793,6 +785,26 @@ App.ManageAlertNotificationsController = Em.Controller.extend({ return apiObject; }, + getNotificationType: function(text) { + var notificationType = text; + if(notificationType == "Custom SNMP") { + notificationType = "SNMP"; + } else if(notificationType == "SNMP") { + notificationType = "AMBARI_SNMP"; + } + return notificationType; + }, + + getNotificationTypeText: function(notificationType) { + var notificationTypeText = notificationType; + if(notificationType == "SNMP") { + notificationTypeText = "Custom SNMP"; + } else if(notificationType == "AMBARI_SNMP") { + notificationTypeText = "SNMP"; + } + return notificationTypeText; + }, + /** * Send request to server to create Alert Notification * @param {object} apiObject (@see formatNotificationAPIObject) http://git-wip-us.apache.org/repos/asf/ambari/blob/a76c5c8b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs index 19f9ca3..854d768 100644 --- a/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs +++ b/ambari-web/app/templates/main/alerts/manage_alert_notifications_popup.hbs @@ -88,7 +88,7 @@ </div> <div class="row-fluid notification-method"> <div class="span3 input-label">{{t alerts.actions.manage_alert_notifications_popup.method}}</div> - <div class="span9 input-value">{{selectedAlertNotification.type}}</div> + <div class="span9 input-value">{{view.selectedAlertNotificationTypeText}}</div> </div> {{#if view.showEmailDetails}} <div class="row-fluid notification-email"> http://git-wip-us.apache.org/repos/asf/ambari/blob/a76c5c8b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js index 53bbfc5..75912b7 100644 --- a/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js +++ b/ambari-web/app/views/main/alerts/manage_alert_notifications_view.js @@ -82,6 +82,10 @@ App.ManageAlertNotificationsView = Em.View.extend({ return this.get('controller.selectedAlertNotification.alertStates').join(', '); }.property('controller.selectedAlertNotification.alertStates'), + selectedAlertNotificationTypeText: function() { + return this.get('controller').getNotificationTypeText(this.get('controller.selectedAlertNotification.type')) + }.property('controller.selectedAlertNotification', 'controller.isLoaded'), + /** * Prevent user select more than 1 alert notification * @method onAlertNotificationSelect http://git-wip-us.apache.org/repos/asf/ambari/blob/a76c5c8b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js index a0a4ce4..9bb85dc 100644 --- a/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js +++ b/ambari-web/test/controllers/main/alerts/manage_alert_notifications_controller_test.js @@ -514,7 +514,7 @@ describe('App.ManageAlertNotificationsController', function () { value: 'all' }, method: { - value: 'SNMP' + value: 'Custom SNMP' }, email: { value: 'c6401.ambari.apache.org, c6402.ambari.apache.org' @@ -557,6 +557,157 @@ describe('App.ManageAlertNotificationsController', function () { ] })); + }); + + it("should map properties from selectedAlertNotification to inputFields (ambari.dispatch.recipients ignored) - AMBARI_SNMP", function () { + + controller.set('selectedAlertNotification', Em.Object.create({ + name: 'AMBARI_SNMP_name', + global: true, + description: 'test_description', + groups: ['test1', 'test2'], + type: 'AMBARI_SNMP', + alertStates: ['OK', 'UNKNOWN'], + properties: { + 'ambari.dispatch.recipients': [ + 'c6401.ambari.apache.org', + 'c6402.ambari.apache.org' + ], + 'customName': 'customValue', + 'ambari.dispatch.snmp.version': 'SNMPv1', + 'ambari.dispatch.snmp.community': 'public', + 'ambari.dispatch.snmp.port': 161 + + } + })); + + controller.set('inputFields', Em.Object.create({ + name: { + value: '' + }, + groups: { + value: [] + }, + global: { + value: false + }, + allGroups: { + value: false + }, + method: { + value: '' + }, + email: { + value: '' + }, + severityFilter: { + value: [] + }, + description: { + value: '' + }, + SMTPServer: { + value: '' + }, + SMTPPort: { + value: '' + }, + SMTPUseAuthentication: { + value: '' + }, + SMTPUsername: { + value: '' + }, + SMTPPassword: { + value: '' + }, + retypeSMTPPassword: { + value: '' + }, + SMTPSTARTTLS: { + value: '' + }, + emailFrom: { + value: '' + }, + version: { + value: '' + }, + OIDs: { + value: '' + }, + community: { + value: '' + }, + host: { + value: '' + }, + port: { + value: '' + }, + customProperties: [ + {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'}, + {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'} + ] + })); + + controller.fillEditCreateInputs(); + + expect(JSON.stringify(controller.get('inputFields'))).to.equal(JSON.stringify({ + name: { + value: 'AMBARI_SNMP_name' + }, + groups: { + value: ['test1', 'test2'] + }, + global: { + value: true, + disabled: true + }, + allGroups: { + value: 'all' + }, + method: { + value: 'SNMP' + }, + email: { + value: 'c6401.ambari.apache.org, c6402.ambari.apache.org' + }, + severityFilter: { + value: ['OK', 'UNKNOWN'] + }, + description: { + value: 'test_description' + }, + SMTPServer: {}, + SMTPPort: {}, + SMTPUseAuthentication: { + value: true + }, + SMTPUsername: {}, + SMTPPassword: {}, + retypeSMTPPassword: {}, + SMTPSTARTTLS: { + value: true + }, + emailFrom: {}, + version: { + value:'SNMPv1' + }, + OIDs: {}, + community: { + value: 'public' + }, + host: { + value: 'c6401.ambari.apache.org, c6402.ambari.apache.org' + }, + port: { + value: 161 + }, + customProperties: [ + {name: 'customName', value: 'customValue', defaultValue: 'customValue'} + ] + })); }) });