Sfoglia il codice sorgente

AMBARI-8697. Alerts UI: thresholds validation.(xiwang)

Xi Wang 10 anni fa
parent
commit
bf499456c1

+ 16 - 4
ambari-web/app/controllers/main/alerts/definition_configs_controller.js

@@ -171,13 +171,13 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
         value: isWizard ? '' : this.getThresholdsProperty('ok', 'value')
       }),
       App.AlertConfigProperties.Thresholds.WarningThreshold.create({
-        valueMetric: 'sec',
+        valueMetric: 'Sec',
         text: isWizard ? '' : this.getThresholdsProperty('warning', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('warning', 'value')
 
       }),
       App.AlertConfigProperties.Thresholds.CriticalThreshold.create({
-        valueMetric: 'sec',
+        valueMetric: 'Sec',
         text: isWizard ? '' : this.getThresholdsProperty('critical', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('critical', 'value')
       })
@@ -497,12 +497,24 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
     });
   },
 
+  /**
+   * Define whether critical threshold >= critical threshold
+   * @type {Boolean}
+   */
+  hasThresholdsError: function () {
+    var smallValue = Em.get(this.get('configs').findProperty('name', 'warning_threshold'), 'value');
+    var smallValid = Em.get(this.get('configs').findProperty('name', 'warning_threshold'), 'isValid');
+    var largeValue = Em.get(this.get('configs').findProperty('name', 'critical_threshold'), 'value');
+    var largeValid = Em.get(this.get('configs').findProperty('name', 'critical_threshold'), 'isValid');
+    return smallValid && largeValid ? !(smallValue <= largeValue) : false;
+  }.property('configs.@each.value'),
+
   /**
    * Define whether all configs are valid
    * @type {Boolean}
    */
   hasErrors: function () {
-    return this.get('configs').someProperty('isValid', false);
-  }.property('configs.@each.isValid')
+    return this.get('configs').someProperty('isValid', false) || this.get('hasThresholdsError');
+  }.property('configs.@each.isValid', 'hasThresholdsError')
 
 });

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

@@ -903,6 +903,7 @@ Em.I18n.translations = {
   'alerts.definition.details.24-hour': '24-Hour',
   'alerts.definition.details.notification': 'Notification',
   'alerts.definition.details.noAlerts': 'No alert instances to show',
+  'alerts.definition.details.configs.thresholdsErrorMsg': 'Critical threshold should be larger than warning threshold',
 
   'alerts.notifications.addCustomPropertyPopup.header': 'Add Property',
   'alerts.notifications.addCustomPropertyPopup.error.propertyExists': 'Custom Property with current name already exists',

+ 28 - 4
ambari-web/app/models/alert_config.js

@@ -348,7 +348,7 @@ App.AlertConfigProperties = {
       var valueMetric = this.get('valueMetric');
       var displayValue = this.get('displayValue');
       var newDisplayValue = value;
-      if ('%' == valueMetric) {
+      if (value && '%' == valueMetric && !isNaN(value)) {
         newDisplayValue = (Number(value) * 100) + '';
       }
       if (newDisplayValue != displayValue) {
@@ -361,7 +361,7 @@ App.AlertConfigProperties = {
       var valueMetric = this.get('valueMetric');
       var displayValue = this.get('displayValue');
       var newValue = displayValue;
-      if ('%' == valueMetric) {
+      if (displayValue && '%' == valueMetric && !isNaN(displayValue)) {
         newValue = (Number(displayValue) / 100) + '';
       }
       if (newValue != value) {
@@ -461,7 +461,19 @@ App.AlertConfigProperties.Thresholds = {
         ret.push('source.reporting.warning.text');
       }
       return ret;
-    }.property('showInputForValue', 'showInputForText')
+    }.property('showInputForValue', 'showInputForText'),
+    isValid: function () {
+      var value = this.get('value');
+      if (!value) return false;
+      value = ('' + value).trim();
+      if (this.get('showInputForValue') && this.get('valueMetric') == '%') {
+        return !isNaN(value) && value > 0 && value <= 1.0;
+      } else if (this.get('showInputForValue')) {
+        return !isNaN(value) && value > 0;
+      } else {
+        return true;
+      }
+    }.property('value', 'showInputForValue')
   }),
 
   CriticalThreshold: App.AlertConfigProperties.Threshold.extend({
@@ -476,7 +488,19 @@ App.AlertConfigProperties.Thresholds = {
         ret.push('source.reporting.critical.text');
       }
       return ret;
-    }.property('showInputForValue', 'showInputForText')
+    }.property('showInputForValue', 'showInputForText'),
+    isValid: function () {
+      var value = this.get('value');
+      if (!value) return false;
+      value = ('' + value).trim();
+      if (this.get('showInputForValue') && this.get('valueMetric') == '%') {
+        return !isNaN(value) && value > 0 && value <= 1.0;
+      } else if (this.get('showInputForValue')) {
+        return !isNaN(value) && value > 0;
+      } else {
+        return true;
+      }
+    }.property('value', 'showInputForValue')
   })
 
 };

+ 12 - 0
ambari-web/app/styles/alerts.less

@@ -327,6 +327,18 @@
       height: 26px;
     }
   }
+
+  .control-group.error{
+    .alert-text-input input{
+      color: #555555;
+      border-color: #ccc;
+    }
+  }
+  .error-message {
+    color: #b94a48;
+  }
+
+
 }
 
 #host-alerts-table {

+ 5 - 0
ambari-web/app/templates/main/alerts/configs.hbs

@@ -34,4 +34,9 @@
       {{/if}}
     </div>
   {{/each}}
+  {{#if controller.hasThresholdsError}}
+    <div class="error-message controls">
+      {{view.errorMessage}}
+    </div>
+  {{/if}}
 </form>

+ 3 - 1
ambari-web/app/views/main/alerts/definition_configs_view.js

@@ -44,7 +44,9 @@ App.AlertDefinitionConfigsView = Em.View.extend({
     this.set('controller.content', this.get('content'));
     this.get('controller').renderConfigs();
     this._super();
-  }
+  },
+
+  errorMessage: Em.I18n.t('alerts.definition.details.configs.thresholdsErrorMsg')
 
 });