Prechádzať zdrojové kódy

AMBARI-15603 Exposure of Global Alert Repeat Tolerance Value in Web Client (zhewang)

Zhe (Joe) Wang 9 rokov pred
rodič
commit
780cd60957

+ 97 - 0
ambari-web/app/controllers/main/alerts/alert_definitions_actions_controller.js

@@ -16,6 +16,8 @@
  * limitations under the License.
  */
 
+var validator = require('utils/validator');
+
 App.MainAlertDefinitionActionsController = Em.ArrayController.extend({
 
   name: 'mainAlertDefinitionActionsController',
@@ -42,6 +44,12 @@ App.MainAlertDefinitionActionsController = Em.ArrayController.extend({
       icon: 'icon-envelope-alt',
       action: 'manageNotifications',
       showDivider: false
+    },
+    {
+      title: Em.I18n.t('alerts.actions.manageSettings'),
+      icon: 'icon-cogs',
+      action: 'manageSettings',
+      showDivider: false
     }
   ],
 
@@ -201,6 +209,95 @@ App.MainAlertDefinitionActionsController = Em.ArrayController.extend({
       autoHeight: false
 
     });
+  },
+
+  /**
+   * "Manage Alert Settings" handler
+   * @method manageSettings
+   * @return {App.ModalPopup}
+   */
+  manageSettings: function () {
+    var controller = this;
+    var loadingPopup = App.ModalPopup.show({
+      header: Em.I18n.t('jobs.loadingTasks'),
+      primary: false,
+      secondary: false,
+      bodyClass: Em.View.extend({
+        template: Em.Handlebars.compile('{{view App.SpinnerView}}')
+      })
+    });
+    this.loadClusterConfig().done(function (data) {
+      var tag = [
+        {
+          siteName: 'cluster-env',
+          tagName: data.Clusters.desired_configs['cluster-env'].tag,
+          newTagName: null
+        }
+      ];
+      App.router.get('configurationController').getConfigsByTags(tag).done(function (config) {
+        var configProperties = config[0].properties;
+
+        loadingPopup.hide();
+        return App.ModalPopup.show({
+          classNames: ['fourty-percent-width-modal'],
+          header: Em.I18n.t('alerts.actions.manageSettings'),
+          primary: Em.I18n.t('common.save'),
+          secondary: Em.I18n.t('common.cancel'),
+          inputValue: configProperties.alerts_repeat_tolerance || '1',
+          errorMessage: Em.I18n.t('alerts.actions.editRepeatTolerance.error'),
+          isInvalid: function () {
+            var intValue = Number(this.get('inputValue'));
+            return this.get('inputValue') !== 'DEBUG' && (!validator.isValidInt(intValue) || intValue < 1);
+          }.property('inputValue'),
+          disablePrimary: Em.computed.alias('isInvalid'),
+          onPrimary: function () {
+            if (this.get('isInvalid')) {
+              return;
+            }
+            configProperties.alerts_repeat_tolerance = this.get('inputValue');
+            App.ajax.send({
+              name: 'admin.save_configs',
+              sender: controller,
+              data: {
+                siteName: 'cluster-env',
+                properties: configProperties
+              },
+              error: 'manageSettingsErrorCallback'
+            });
+            this.hide();
+          },
+          bodyClass: Ember.View.extend({
+            templateName: require('templates/common/modal_popups/prompt_popup'),
+            text: Em.I18n.t('alerts.actions.editRepeatTolerance.text'),
+            title: Em.I18n.t('alerts.actions.editRepeatTolerance.title'),
+            description: Em.I18n.t('alerts.actions.editRepeatTolerance.description'),
+            label: Em.I18n.t('alerts.actions.editRepeatTolerance.label')
+          })
+        });
+      });
+    });
+  },
+
+  loadClusterConfig: function () {
+    return App.ajax.send({
+      name: 'config.tags.site',
+      sender: this,
+      data: {
+        site: 'cluster-env'
+      }
+    });
+  },
+
+  manageSettingsErrorCallback: function(data) {
+    var error = Em.I18n.t('alerts.actions.manageSettings.error');
+    if(data && data.responseText){
+      try {
+        var json = $.parseJSON(data.responseText);
+        error += json.message;
+      } catch (err) {
+      }
+    }
+    App.showAlertPopup(Em.I18n.t('alerts.actions.manageSettings.error'), error);
   }
 
 });

+ 9 - 0
ambari-web/app/messages.js

@@ -999,6 +999,15 @@ Em.I18n.translations = {
   'alerts.actions.manageGroups': 'Manage Alert Groups',
   'alerts.actions.manageNotifications': 'Manage Notifications',
   'alerts.actions.manageNotifications.info': 'You can manage notification methods and recipients.',
+  'alerts.actions.editRepeatTolerance.text': 'Manage global setting for alerts',
+  'alerts.actions.editRepeatTolerance.title': 'Alert Check Retries',
+  'alerts.actions.editRepeatTolerance.description': 'Set the amount of alert check retries to perform before dispatching a notification.' +
+    'If during an alert check a state change occurs, Ambari will retry this number of times before dispatching a notification. Increase this number if your environment experiences temporal issues.',
+  'alerts.actions.editRepeatTolerance.label': 'Retries:',
+  'alerts.actions.editRepeatTolerance.error':'Input should be a positive integer.',
+  'alerts.actions.manageSettings': 'Manage Alert Settings',
+  'alerts.actions.manageGlobalRepeatTolerance.tooltip': 'This value will be overriden, if specific repeat tolerance value is set for individual alert.',
+  'alerts.actions.manageSettings.error':'Error during remote command: ',
 
   'alerts.groups.successPopup.header': 'Alert Groups processing results',
   'alerts.groups.successPopup.body.created': 'New Alert Groups',

+ 0 - 3
ambari-web/app/styles/application.less

@@ -5772,9 +5772,6 @@ input[type="radio"].align-checkbox, input[type="checkbox"].align-checkbox {
   form {
     margin-top: 20px;
   }
-  .prompt-input {
-    width: 520px;
-  }
 }
 
 #views {

+ 4 - 0
ambari-web/app/templates/common/modal_popups/prompt_popup.hbs

@@ -19,7 +19,11 @@
   <form>
     <div {{bindAttr class=":control-group view.parentView.isInvalid:error"}}>
       <label class="control-label">{{view.text}}</label>
+      <br>
+      <h4>{{view.title}}</h4>
+      <p>{{view.description}}</p>
       <div class="controls">
+        <strong>{{view.label}}&nbsp;&nbsp;</strong>
         {{view Em.TextField class="prompt-input" valueBinding="view.parentView.inputValue"}}
       </div>
       {{#if view.parentView.isInvalid}}