Browse Source

AMBARI-9479. Alerts: UI should validate threshold values for PORT and METRIC type alerts

Srimanth Gunturi 10 years ago
parent
commit
419e45dc8d

+ 8 - 0
ambari-web/app/controllers/main/alerts/definition_configs_controller.js

@@ -166,11 +166,13 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
         value: isWizard ? '' : this.getThresholdsProperty('ok', 'value')
       }),
       App.AlertConfigProperties.Thresholds.WarningThreshold.create({
+        type: 'PORT',
         valueMetric: 'Seconds',
         text: isWizard ? '' : this.getThresholdsProperty('warning', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('warning', 'value')
       }),
       App.AlertConfigProperties.Thresholds.CriticalThreshold.create({
+        type: 'PORT',
         valueMetric: 'Seconds',
         text: isWizard ? '' : this.getThresholdsProperty('critical', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('critical', 'value')
@@ -210,11 +212,13 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
         value: isWizard ? '' : this.getThresholdsProperty('ok', 'value')
       }),
       App.AlertConfigProperties.Thresholds.WarningThreshold.create({
+        type: 'METRIC',
         valueMetric: units,
         text: isWizard ? '' : this.getThresholdsProperty('warning', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('warning', 'value')
       }),
       App.AlertConfigProperties.Thresholds.CriticalThreshold.create({
+        type: 'METRIC',
         valueMetric: units,
         text: isWizard ? '' : this.getThresholdsProperty('critical', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('critical', 'value')
@@ -252,11 +256,13 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
         value: isWizard ? '' : this.getThresholdsProperty('ok', 'value')
       }),
       App.AlertConfigProperties.Thresholds.WarningThreshold.create({
+        type: 'WEB',
         showInputForValue: false,
         text: isWizard ? '' : this.getThresholdsProperty('warning', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('warning', 'value')
       }),
       App.AlertConfigProperties.Thresholds.CriticalThreshold.create({
+        type: 'WEB',
         showInputForValue: false,
         text: isWizard ? '' : this.getThresholdsProperty('critical', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('critical', 'value')
@@ -314,11 +320,13 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
         value: isWizard ? '' : this.getThresholdsProperty('ok', 'value')
       }),
       App.AlertConfigProperties.Thresholds.WarningThreshold.create(App.AlertConfigProperties.Thresholds.PercentageMixin, {
+        type: 'AGGREGATE',
         text: isWizard ? '' : this.getThresholdsProperty('warning', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('warning', 'value'),
         valueMetric: '%'
       }),
       App.AlertConfigProperties.Thresholds.CriticalThreshold.create(App.AlertConfigProperties.Thresholds.PercentageMixin, {
+        type: 'AGGREGATE',
         text: isWizard ? '' : this.getThresholdsProperty('critical', 'text'),
         value: isWizard ? '' : this.getThresholdsProperty('critical', 'value'),
         valueMetric: '%'

+ 27 - 9
ambari-web/app/models/alert_config.js

@@ -26,6 +26,12 @@ App.AlertConfigProperty = Ember.Object.extend({
    */
   label: '',
 
+  /**
+   * PORT|METRIC|AGGREGATE
+   * @type {String}
+   */
+  type: '',
+
   /**
    * config property value
    * @type {*}
@@ -484,11 +490,17 @@ App.AlertConfigProperties.Thresholds = {
     }.property('showInputForValue', 'showInputForText'),
 
     isValid: function () {
-      var value = this.get('value');
+      var value = this.get('displayValue');
       if (!value) return false;
       value = ('' + value).trim();
-      return this.get('showInputForValue') ? !isNaN(value) && value > 0 : true;
-    }.property('value', 'showInputForValue')
+      if (this.get('type') === 'AGGREGATE') {
+        return this.get('showInputForValue') ? !isNaN(value) && value > 0 && value <= 100 : true;
+      } else if (this.get('type') === 'PORT') {
+        return this.get('showInputForValue') ? !isNaN(value) && value > 0 : true;
+      } else {
+        return this.get('showInputForValue') ? !isNaN(value) : true;
+      }
+    }.property('displayValue', 'showInputForValue')
 
   }),
 
@@ -510,11 +522,17 @@ App.AlertConfigProperties.Thresholds = {
     }.property('showInputForValue', 'showInputForText'),
 
     isValid: function () {
-      var value = this.get('value');
+      var value = this.get('displayValue');
       if (!value) return false;
       value = ('' + value).trim();
-      return this.get('showInputForValue') ? !isNaN(value) && value > 0 : true;
-    }.property('value', 'showInputForValue')
+        if (this.get('type') === 'AGGREGATE') {
+            return this.get('showInputForValue') ? !isNaN(value) && value > 0 && value <= 100 : true;
+        } else if (this.get('type') === 'PORT') {
+            return this.get('showInputForValue') ? !isNaN(value) && value > 0 : true;
+        } else {
+            return this.get('showInputForValue') ? !isNaN(value) : true;
+        }
+    }.property('displayValue', 'showInputForValue')
   }),
 
   /**
@@ -525,11 +543,11 @@ App.AlertConfigProperties.Thresholds = {
   PercentageMixin: Em.Mixin.create({
 
     isValid: function () {
-      var value = this.get('value');
+      var value = this.get('displayValue');
       if (!value) return false;
       value = ('' + value).trim();
-      return this.get('showInputForValue') ? !isNaN(value) && value > 0 && value <= 1.0 : true;
-    }.property('value', 'showInputForValue'),
+      return this.get('showInputForValue') ? !isNaN(value) && value > 0 && value <= 100 : true;
+    }.property('displayValue', 'showInputForValue'),
 
     /**
      * Return <code>value * 100</code>