ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From onechipore...@apache.org
Subject ambari git commit: AMBARI-14958. Alerts: Create new Alerts Notification type for SNMP to handle Ambari MIB (onechiporenko)
Date Mon, 08 Feb 2016 16:52:24 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 5cb0fadda -> e139ef57c


AMBARI-14958. Alerts: Create new Alerts Notification type for SNMP to handle Ambari MIB (onechiporenko)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/e139ef57
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/e139ef57
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/e139ef57

Branch: refs/heads/trunk
Commit: e139ef57ce0ec3d705489a36cb2d7cc78f6458c1
Parents: 5cb0fad
Author: Oleg Nechiporenko <onechiporenko@apache.org>
Authored: Mon Feb 8 16:58:17 2016 +0200
Committer: Oleg Nechiporenko <onechiporenko@apache.org>
Committed: Mon Feb 8 18:52:14 2016 +0200

----------------------------------------------------------------------
 .../manage_alert_notifications_controller.js    |  74 +++++++-----
 ...anage_alert_notifications_controller_test.js | 121 +++++++++++--------
 .../views/common/log_file_search_view_test.js   |   3 +-
 3 files changed, 116 insertions(+), 82 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/e139ef57/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 79e524e..244b8f0 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
@@ -61,9 +61,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
       value: '',
       defaultValue: 'custom',
       disabled: false,
-      isAll: function () {
-        return this.get('value') == 'all';
-      }.property('value')
+      isAll: Em.computed.equal('value', 'all')
     }),
     method: {
       label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.method'),
@@ -159,7 +157,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
    * used in Type combobox
    * @type {Array}
    */
-  methods: ['EMAIL', 'SNMP'],
+  methods: ['EMAIL', 'SNMP', 'Custom SNMP'],
 
   /**
    * List of available value for Severity Filter
@@ -220,7 +218,8 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     'mail.smtp.from',
     'mail.smtp.host',
     'mail.smtp.port',
-    'mail.smtp.starttls.enable'
+    'mail.smtp.starttls.enable',
+    'ambari.dispatch-property.script'
   ],
 
   validationMap: {
@@ -242,6 +241,16 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
         validator: 'retypePasswordValidation'
       }
     ],
+    'Custom SNMP': [
+      {
+        errorKey: 'portError',
+        validator: 'portValidation'
+      },
+      {
+        errorKey: 'hostError',
+        validator: 'hostsValidation'
+      }
+    ],
     SNMP: [
       {
         errorKey: 'portError',
@@ -322,24 +331,25 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
   fillEditCreateInputs: function (addCopyToName) {
     var inputFields = this.get('inputFields');
     var selectedAlertNotification = this.get('selectedAlertNotification');
+    var props = selectedAlertNotification.get('properties');
     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']
?
-      selectedAlertNotification.get('properties')['ambari.dispatch.recipients'].join(', ')
: '');
-    inputFields.set('SMTPServer.value', selectedAlertNotification.get('properties')['mail.smtp.host']);
-    inputFields.set('SMTPPort.value', selectedAlertNotification.get('properties')['mail.smtp.port']);
-    inputFields.set('SMTPUseAuthentication.value', selectedAlertNotification.get('properties')['mail.smtp.auth']
!== "false");
-    inputFields.set('SMTPUsername.value', selectedAlertNotification.get('properties')['ambari.dispatch.credential.username']);
-    inputFields.set('SMTPPassword.value', selectedAlertNotification.get('properties')['ambari.dispatch.credential.password']);
-    inputFields.set('retypeSMTPPassword.value', selectedAlertNotification.get('properties')['ambari.dispatch.credential.password']);
-    inputFields.set('SMTPSTARTTLS.value', selectedAlertNotification.get('properties')['mail.smtp.starttls.enable']
!== "false");
-    inputFields.set('emailFrom.value', selectedAlertNotification.get('properties')['mail.smtp.from']);
-    inputFields.set('version.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.version']);
-    inputFields.set('OIDs.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.oids.trap']);
-    inputFields.set('community.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.community']);
-    inputFields.set('host.value', selectedAlertNotification.get('properties')['ambari.dispatch.recipients']
?
-      selectedAlertNotification.get('properties')['ambari.dispatch.recipients'].join(', ')
: '');
-    inputFields.set('port.value', selectedAlertNotification.get('properties')['ambari.dispatch.snmp.port']);
+    inputFields.set('email.value', props['ambari.dispatch.recipients'] ?
+      props['ambari.dispatch.recipients'].join(', ') : '');
+    inputFields.set('SMTPServer.value', props['mail.smtp.host']);
+    inputFields.set('SMTPPort.value', props['mail.smtp.port']);
+    inputFields.set('SMTPUseAuthentication.value', props['mail.smtp.auth'] !== "false");
+    inputFields.set('SMTPUsername.value', props['ambari.dispatch.credential.username']);
+    inputFields.set('SMTPPassword.value', props['ambari.dispatch.credential.password']);
+    inputFields.set('retypeSMTPPassword.value', props['ambari.dispatch.credential.password']);
+    inputFields.set('SMTPSTARTTLS.value', props['mail.smtp.starttls.enable'] !== "false");
+    inputFields.set('emailFrom.value', props['mail.smtp.from']);
+    inputFields.set('version.value', props['ambari.dispatch.snmp.version']);
+    inputFields.set('OIDs.value', props['ambari.dispatch.snmp.oids.trap']);
+    inputFields.set('community.value', props['ambari.dispatch.snmp.community']);
+    inputFields.set('host.value', props['ambari.dispatch.recipients'] ?
+      props['ambari.dispatch.recipients'].join(', ') : '');
+    inputFields.set('port.value', props['ambari.dispatch.snmp.port']);
     inputFields.set('severityFilter.value', selectedAlertNotification.get('alertStates'));
     inputFields.set('global.value', selectedAlertNotification.get('global'));
     inputFields.set('allGroups.value', selectedAlertNotification.get('global') ? 'all' :
'custom');
@@ -348,14 +358,13 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     inputFields.set('description.value', selectedAlertNotification.get('description'));
     inputFields.set('method.value', selectedAlertNotification.get('type'));
     inputFields.get('customProperties').clear();
-    var properties = selectedAlertNotification.get('properties');
     var ignoredCustomProperties = this.get('ignoredCustomProperties');
-    Em.keys(properties).forEach(function (k) {
+    Em.keys(props).forEach(function (k) {
       if (ignoredCustomProperties.contains(k)) return;
       inputFields.get('customProperties').pushObject({
         name: k,
-        value: properties[k],
-        defaultValue: properties[k]
+        value: props[k],
+        defaultValue: props[k]
       });
     });
   },
@@ -394,7 +403,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
             validationMap = self.get('validationMap');
           self.get('methods').forEach(function (method) {
             var validations = validationMap[method];
-            if (method == currentMethod) {
+            if (method === currentMethod) {
               validations.mapProperty('validator').forEach(function (key) {
                 this.get(key).call(this);
               }, this);
@@ -418,7 +427,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
             if (!newName) {
               this.set('nameError', true);
               errorMessage = Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.empty');
-            } else if (newName && newName != this.get('currentName') && self.get('alertNotifications').mapProperty('name').contains(newName))
{
+            } else if (newName && newName !== this.get('currentName') &&
self.get('alertNotifications').mapProperty('name').contains(newName)) {
               this.set('nameError', true);
               errorMessage = Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.name.existed');
             } else {
@@ -475,7 +484,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
 
         hostsValidation: function() {
           var inputValue = this.get('controller.inputFields.host.value').trim(),
-            hostError = false;;
+            hostError = false;
           if (!this.get('isEmailMethodSelected')) {
             var array = inputValue.split(',');
             hostError = array.some(function(hostname) {
@@ -531,7 +540,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
          * @method selectAllGroups
          */
         selectAllGroups: function () {
-          if (this.get('controller.inputFields.allGroups.value') == 'custom') {
+          if (this.get('controller.inputFields.allGroups.value') === 'custom') {
             this.set('groupSelect.selection', this.get('groupSelect.content').slice());
           }
         },
@@ -541,7 +550,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
          * @method clearAllGroups
          */
         clearAllGroups: function () {
-          if (this.get('controller.inputFields.allGroups.value') == 'custom') {
+          if (this.get('controller.inputFields.allGroups.value') === 'custom') {
             this.set('groupSelect.selection', []);
           }
         },
@@ -645,6 +654,9 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
       properties['ambari.dispatch.snmp.community'] = inputFields.get('community.value');
       properties['ambari.dispatch.recipients'] = inputFields.get('host.value').replace(/\s/g,
'').split(',');
       properties['ambari.dispatch.snmp.port'] = inputFields.get('port.value');
+      if (inputFields.get('method.value') === 'SNMP') {
+        properties['ambari.dispatch-property.script'] = "org.apache.ambari.contrib.snmp.script";
+      }
     }
     inputFields.get('customProperties').forEach(function (customProperty) {
       properties[customProperty.name] = customProperty.value;
@@ -659,7 +671,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
         properties: properties
       }
     };
-    if (inputFields.get('allGroups.value') == 'custom') {
+    if (inputFields.get('allGroups.value') === 'custom') {
       apiObject.AlertTarget.groups = inputFields.get('groups.value').mapProperty('id');
     }
     return apiObject;

http://git-wip-us.apache.org/repos/asf/ambari/blob/e139ef57/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 19d0c1b..283c0af 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
@@ -699,56 +699,77 @@ describe('App.ManageAlertNotificationsController', function () {
 
   describe("#formatNotificationAPIObject()", function () {
 
-    var inputFields = Em.Object.create({
-      name: {
-        value: 'test_name'
-      },
-      groups: {
-        value: [{id: 1}, {id: 2}, {id: 3}]
-      },
-      allGroups: {
-        value: 'custom'
-      },
-      global: {
-        value: false
-      },
-      method: {
-        value: 'EMAIL'
-      },
-      email: {
-        value: 'test1@test.test, test2@test.test,test3@test.test , test4@test.test'
-      },
-      severityFilter: {
-        value: ['OK', 'CRITICAL']
-      },
-      SMTPServer: {
-        value: 's1'
-      },
-      SMTPPort: {
-        value: '25'
-      },
-      SMTPUseAuthentication: {
-        value: "true"
-      },
-      SMTPUsername: {
-        value: 'user'
-      },
-      SMTPPassword: {
-        value: 'pass'
-      },
-      SMTPSTARTTLS: {
-        value: "true"
-      },
-      emailFrom: {
-        value: 'from'
-      },
-      description: {
-        value: 'test_description'
-      },
-      customProperties: [
-        {name: 'n1', value: 'v1'},
-        {name: 'n2', value: 'v2'}
-      ]
+    var inputFields;
+
+    beforeEach(function () {
+      inputFields = Em.Object.create({
+        name: {
+          value: 'test_name'
+        },
+        groups: {
+          value: [{id: 1}, {id: 2}, {id: 3}]
+        },
+        allGroups: {
+          value: 'custom'
+        },
+        global: {
+          value: false
+        },
+        method: {
+          value: 'EMAIL'
+        },
+        email: {
+          value: 'test1@test.test, test2@test.test,test3@test.test , test4@test.test'
+        },
+        severityFilter: {
+          value: ['OK', 'CRITICAL']
+        },
+        SMTPServer: {
+          value: 's1'
+        },
+        SMTPPort: {
+          value: '25'
+        },
+        SMTPUseAuthentication: {
+          value: "true"
+        },
+        SMTPUsername: {
+          value: 'user'
+        },
+        SMTPPassword: {
+          value: 'pass'
+        },
+        SMTPSTARTTLS: {
+          value: "true"
+        },
+        emailFrom: {
+          value: 'from'
+        },
+        description: {
+          value: 'test_description'
+        },
+        host: {
+          value: ''
+        },
+        customProperties: [
+          {name: 'n1', value: 'v1'},
+          {name: 'n2', value: 'v2'}
+        ]
+      });
+    });
+
+    it('should set property `ambari.dispatch-property.script` for SNMP type', function ()
{
+      Em.set(inputFields, 'method.value', 'SNMP');
+      controller.set('inputFields', inputFields);
+      var result = controller.formatNotificationAPIObject();
+      expect(result.AlertTarget.properties['ambari.dispatch-property.script']).to.be.equal('org.apache.ambari.contrib.snmp.script');
+    });
+
+    it('should not set property `ambari.dispatch-property.script` for EMAIL type', function
() {
+      Em.set(inputFields, 'method.value', 'EMAIL');
+      controller.set('inputFields', inputFields);
+      var result = controller.formatNotificationAPIObject();
+      expect(result.AlertTarget.properties).to.not.have.property('ambari.dispatch-property.script');
     });
 
     it("should create object with properties from inputFields values", function () {

http://git-wip-us.apache.org/repos/asf/ambari/blob/e139ef57/ambari-web/test/views/common/log_file_search_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/common/log_file_search_view_test.js b/ambari-web/test/views/common/log_file_search_view_test.js
index ca208b3..a5f940e 100644
--- a/ambari-web/test/views/common/log_file_search_view_test.js
+++ b/ambari-web/test/views/common/log_file_search_view_test.js
@@ -32,7 +32,8 @@ describe('App.LogFileSearchView', function() {
         isIncluded: !!isIncluded
       });
     };
-    var cases = [
+
+    [
       {
         viewContent: {
           keywordsFilterValue: 'some_keyword'


Mime
View raw message