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 2017/06/12 16:45:47 UTC

[40/50] [abbrv] ambari git commit: AMBARI-21123 - Part Two: Specify the script directly in alert target for script-based alert dispatchers(Lei Yao via rzang)

AMBARI-21123 - Part Two: Specify the script directly in alert target for script-based alert dispatchers(Lei Yao via rzang)

Change-Id: I56e01562f11f389d36ae87b8caa3841517f04812


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

Branch: refs/heads/branch-feature-AMBARI-12556
Commit: 62f4432cc35e39a8fdd7540e6cfc4f5edbac19cb
Parents: 2bea120
Author: Richard Zang <rz...@apache.org>
Authored: Sun Jun 11 04:25:11 2017 -0700
Committer: Richard Zang <rz...@apache.org>
Committed: Sun Jun 11 04:25:11 2017 -0700

----------------------------------------------------------------------
 .../manage_alert_notifications_controller.js    | 35 ++++++++++++++++--
 ambari-web/app/messages.js                      |  2 ++
 .../main/alerts/create_alert_notification.hbs   | 14 ++++++++
 ambari-web/app/utils/validator.js               |  8 +++++
 ...anage_alert_notifications_controller_test.js | 38 +++++++++++++++++++-
 5 files changed, 93 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/62f4432c/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 df15513..a417a73 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
@@ -154,6 +154,11 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
       value: '',
       defaultValue: ''
     },
+    scriptFileName: {
+      label: Em.I18n.t('alerts.actions.manage_alert_notifications_popup.scriptFileName'),
+      value: '',
+      defaultValue: ''
+    },
     customProperties: Em.A([])
   }),
 
@@ -289,7 +294,8 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     'mail.smtp.host',
     'mail.smtp.port',
     'mail.smtp.starttls.enable',
-    'ambari.dispatch-property.script'
+    'ambari.dispatch-property.script',
+    'ambari.dispatch-property.script.filename'
   ],
 
   validationMap: {
@@ -339,7 +345,12 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
         validator: 'hostsValidation'
       }
     ],
-    AlertScript:[]
+    AlertScript:[
+     {
+       errorKey: 'scriptFileNameError',
+       validator: 'scriptFileNameValidation',
+     }
+    ]
   },
 
   /**
@@ -435,6 +446,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
     inputFields.set('global.value', selectedAlertNotification.get('global'));
     inputFields.set('allGroups.value', selectedAlertNotification.get('global') ? 'all' : 'custom');
     inputFields.set('scriptDispatchProperty.value', properties['ambari.dispatch-property.script'] || '');
+    inputFields.set('scriptFileName.value', properties['ambari.dispatch-property.script.filename'] || '');
     // not allow to edit global field
     inputFields.set('global.disabled', true);
     inputFields.set('description.value', selectedAlertNotification.get('description'));
@@ -478,6 +490,7 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
           this.smtpUsernameValidation();
           this.smtpPasswordValidation();
           this.retypePasswordValidation();
+          this.scriptFileNameValidation();
         },
 
         isEmailMethodSelected: Em.computed.equal('controller.inputFields.method.value', 'EMAIL'),
@@ -631,7 +644,19 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
           }
         }.observes('controller.inputFields.retypeSMTPPassword.value', 'controller.inputFields.SMTPPassword.value'),
 
-        someErrorExists: Em.computed.or('nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'hostError', 'portError', 'smtpUsernameError', 'smtpPasswordError', 'passwordError'),
+
+        scriptFileNameValidation:function(){
+          var scriptFileNameValue = this.get('controller.inputFields.scriptFileName.value').trim();
+          if(!Em.isBlank(scriptFileNameValue) && !validator.isValidFileName(scriptFileNameValue)){
+             this.set('scriptFileNameError',true);
+             this.set('controller.inputFields.scriptFileName.errorMsg',Em.I18n.t('alerts.actions.manage_alert_notifications_popup.error.scriptFileName.invalid'));
+          }else{
+             this.set('scriptFileNameError',false);
+             this.set('controller.inputFields.scriptFileName.errorMsg',null);
+          }
+        }.observes('controller.inputFields.scriptFileName.value'),
+
+        someErrorExists: Em.computed.or('nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'hostError', 'portError', 'smtpUsernameError', 'smtpPasswordError', 'passwordError','scriptFileNameError'),
 
         setParentErrors: function () {
           this.set('parentView.hasErrors', this.get('someErrorExists'));
@@ -779,6 +804,10 @@ App.ManageAlertNotificationsController = Em.Controller.extend({
       var scriptDispatchProperty = inputFields.get('scriptDispatchProperty.value').trim();
       if( scriptDispatchProperty != '')
           properties['ambari.dispatch-property.script'] = scriptDispatchProperty;
+
+      var scriptFileName = inputFields.get('scriptFileName.value').trim();
+      if( scriptFileName != '')
+          properties['ambari.dispatch-property.script.filename'] = scriptFileName;
     }
     inputFields.get('customProperties').forEach(function (customProperty) {
       properties[customProperty.name] = customProperty.value;

http://git-wip-us.apache.org/repos/asf/ambari/blob/62f4432c/ambari-web/app/messages.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js
index faad84c..4efd75f 100644
--- a/ambari-web/app/messages.js
+++ b/ambari-web/app/messages.js
@@ -2547,6 +2547,8 @@ Em.I18n.translations = {
   'alerts.actions.manage_alert_notifications_popup.error.name.empty': 'Notification name is required',
   'alerts.actions.manage_alert_notifications_popup.error.name.existed': 'Notification name already exists',
   'alerts.actions.manage_alert_notifications_popup.scriptDispatchProperty':'Script Dispatch Property',
+  'alerts.actions.manage_alert_notifications_popup.scriptFileName':'Script Filename',
+  'alerts.actions.manage_alert_notifications_popup.error.scriptFileName.invalid': 'Invalid script filename',
 
   'hosts.host.add':'Add New Hosts',
   'hosts.table.noHosts':'No hosts to display',

http://git-wip-us.apache.org/repos/asf/ambari/blob/62f4432c/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/alerts/create_alert_notification.hbs b/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
index 7ec5b1e..afe00d5 100644
--- a/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
+++ b/ambari-web/app/templates/main/alerts/create_alert_notification.hbs
@@ -317,6 +317,20 @@
 
     {{! alert-notification Alert Script }}
     {{#if view.isAlertScriptMethodSelected}}
+    <div {{bindAttr class=":form-group controller.inputFields.scriptFileName.errorMsg:has-error"}}>
+       <label class="control-label col-md-2">{{controller.inputFields.scriptFileName.label}}</label>
+
+       <div class="col-md-10">
+          {{view Em.TextField valueBinding="controller.inputFields.scriptFileName.value" class="form-control"}}
+       </div>
+
+       {{#if controller.inputFields.scriptFileName.errorMsg}}
+        <div class="col-md-10 col-md-offset-2 help-block validation-block error-msg">
+           {{controller.inputFields.scriptFileName.errorMsg}}
+        </div>
+       {{/if}}
+    </div>
+
     <div class="form-group">
       <label class="control-label col-md-2">{{controller.inputFields.scriptDispatchProperty.label}}</label>
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/62f4432c/ambari-web/app/utils/validator.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/validator.js b/ambari-web/app/utils/validator.js
index c069724..4c7255d 100644
--- a/ambari-web/app/utils/validator.js
+++ b/ambari-web/app/utils/validator.js
@@ -62,6 +62,14 @@ module.exports = {
   },
 
   /**
+   * validate filename
+   */
+  isValidFileName: function(value){
+    var filenameRegex = /^[0-9a-zA-Z_-]+\.[a-zA-Z]+$/;
+    return filenameRegex.test(value);
+  },
+
+  /**
    * defines if config value looks like link to other config
    * @param value
    * @returns {boolean}

http://git-wip-us.apache.org/repos/asf/ambari/blob/62f4432c/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 0d58afa..bbf4b98 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
@@ -90,6 +90,12 @@ function getInputFields() {
     },
     port: {
       value: ''
+    },
+    scriptDispatchProperty:{
+      value: ''
+    },
+    scriptFileName:{
+      value: ''
     }
   });
 }
@@ -339,6 +345,9 @@ describe('App.ManageAlertNotificationsController', function () {
         scriptDispatchProperty:{
           value: ''
         },
+        scriptFileName:{
+          value: ''
+        },
         customProperties: [
           {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
           {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
@@ -407,6 +416,9 @@ describe('App.ManageAlertNotificationsController', function () {
         scriptDispatchProperty:{
           value: ''
         },
+        scriptFileName:{
+          value: ''
+        },
         customProperties: [
           {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
         ]
@@ -504,6 +516,9 @@ describe('App.ManageAlertNotificationsController', function () {
         scriptDispatchProperty:{
           value: ''
         },
+        scriptFileName:{
+          value: ''
+        },
         customProperties: [
           {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
           {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
@@ -568,6 +583,9 @@ describe('App.ManageAlertNotificationsController', function () {
         scriptDispatchProperty:{
           value: ''
         },
+        scriptFileName:{
+          value: ''
+        },
         customProperties: [
           {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
         ]
@@ -664,6 +682,9 @@ describe('App.ManageAlertNotificationsController', function () {
         scriptDispatchProperty:{
           value: ''
         },
+        scriptFileName:{
+          value: ''
+        },
         customProperties: [
           {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
           {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
@@ -726,6 +747,9 @@ describe('App.ManageAlertNotificationsController', function () {
         scriptDispatchProperty:{
           value: ''
         },
+        scriptFileName:{
+          value: ''
+        },
         customProperties: [
           {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
         ]
@@ -744,6 +768,7 @@ describe('App.ManageAlertNotificationsController', function () {
             alertStates: ['OK', 'UNKNOWN'],
             properties: {
               'ambari.dispatch-property.script': "com.mycompany.dispatch.syslog.script",
+              'ambari.dispatch-property.script.filename': 'a.py',
               'customName': 'customValue'
             }
           }));
@@ -815,6 +840,9 @@ describe('App.ManageAlertNotificationsController', function () {
             scriptDispatchProperty: {
               value: ''
             },
+            scriptFileName: {
+              value: ''
+            },
             customProperties: [
               {name: 'customName', value: 'customValue1', defaultValue: 'customValue1'},
               {name: 'customName2', value: 'customValue1', defaultValue: 'customValue1'}
@@ -871,6 +899,9 @@ describe('App.ManageAlertNotificationsController', function () {
             scriptDispatchProperty: {
                value: 'com.mycompany.dispatch.syslog.script'
             },
+            scriptFileName:{
+               value: 'a.py'
+            },
             customProperties: [
               {name: 'customName', value: 'customValue', defaultValue: 'customValue'}
             ]
@@ -929,7 +960,7 @@ describe('App.ManageAlertNotificationsController', function () {
         view = getBodyClass();
       });
 
-      App.TestAliases.testAsComputedOr(getBodyClass(), 'someErrorExists', ['nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'hostError', 'portError', 'smtpUsernameError', 'smtpPasswordError', 'passwordError']);
+      App.TestAliases.testAsComputedOr(getBodyClass(), 'someErrorExists', ['nameError', 'emailToError', 'emailFromError', 'smtpPortError', 'hostError', 'portError', 'smtpUsernameError', 'smtpPasswordError', 'passwordError','scriptFileNameError']);
 
       describe('#selectAllGroups', function () {
 
@@ -1140,6 +1171,11 @@ describe('App.ManageAlertNotificationsController', function () {
               method: 'SNMP',
               errors: ['emailToError', 'emailFromError', 'smtpPortError', 'smtpUsernameError', 'smtpPasswordError', 'passwordError'],
               validators: ['portValidation', 'hostsValidation']
+            },
+            {
+              method: 'ALERT_SCRIPT',
+              errors: ['scriptFileNameError'],
+              validators: ['scriptFileNameValidation']
             }
           ],
           validators = [];