You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by on...@apache.org on 2015/02/25 16:51:16 UTC
ambari git commit: AMBARI-9793. Alert Definition: Thresholds are
empty after edit (onechiporenko)
Repository: ambari
Updated Branches:
refs/heads/branch-2.0.0 c9e901bc2 -> 8ae20f367
AMBARI-9793. Alert Definition: Thresholds are empty after edit (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/8ae20f36
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/8ae20f36
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/8ae20f36
Branch: refs/heads/branch-2.0.0
Commit: 8ae20f3674232be78c26949301f26d561f14c15a
Parents: c9e901b
Author: Oleg Nechiporenko <on...@apache.org>
Authored: Wed Feb 25 16:31:57 2015 +0200
Committer: Oleg Nechiporenko <on...@apache.org>
Committed: Wed Feb 25 17:50:41 2015 +0200
----------------------------------------------------------------------
.../alerts/definition_configs_controller.js | 47 ++++++++-----
ambari-web/app/models/alert_config.js | 72 +++++++++++---------
ambari-web/test/models/alert_config_test.js | 26 +++++++
3 files changed, 96 insertions(+), 49 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/8ae20f36/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/alerts/definition_configs_controller.js b/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
index 4dac378..82844ae 100644
--- a/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
+++ b/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
@@ -87,13 +87,36 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
*/
changeType: function (selectedType) {
if (selectedType === 'alert_type_service') {
- this.get('configs').findProperty('name', 'service').set('isDisabled', false).set('options', this.get('allServices')).set('value', this.get('allServices')[0]);
- this.get('configs').findProperty('name', 'component').set('isDisabled', false).set('value', 'No component');
- this.get('configs').findProperty('name', 'scope').set('isDisabled', false).set('options', this.get('allScopes')).set('value', this.get('allScopes')[0]);
+ this.get('configs').findProperty('name', 'service').setProperties({
+ isDisabled: false,
+ options: this.get('allServices'),
+ value: this.get('allServices')[0]
+ });
+ this.get('configs').findProperty('name', 'component').setProperties({
+ isDisabled: false,
+ value: 'No component'
+ });
+ this.get('configs').findProperty('name', 'scope').setProperties({
+ isDisabled: false,
+ options: this.get('allScopes'),
+ value: this.get('allScopes')[0]
+ });
} else {
- this.get('configs').findProperty('name', 'service').set('isDisabled', true).set('options', ['Ambari']).set('value', 'Ambari');
- this.get('configs').findProperty('name', 'component').set('isDisabled', true).set('options', ['Ambari Agent']).set('value', 'Ambari Agent');
- this.get('configs').findProperty('name', 'scope').set('isDisabled', true).set('options', ['Host']).set('value', 'Host');
+ this.get('configs').findProperty('name', 'service').setProperties({
+ isDisabled: true,
+ options: ['Ambari'],
+ value: 'Ambari'
+ });
+ this.get('configs').findProperty('name', 'component').setProperties({
+ isDisabled: true,
+ options: ['Ambari Agent'],
+ value: 'Ambari Agent'
+ });
+ this.get('configs').findProperty('name', 'scope').setProperties({
+ isDisabled: true,
+ options: ['Host'],
+ value: 'Host'
+ });
}
},
@@ -165,14 +188,12 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
text: isWizard ? '' : this.getThresholdsProperty('ok', 'text'),
value: isWizard ? '' : this.getThresholdsProperty('ok', 'value')
}),
- App.AlertConfigProperties.Thresholds.WarningThreshold.create({
- type: 'PORT',
+ App.AlertConfigProperties.Thresholds.WarningThreshold.create(App.AlertConfigProperties.Thresholds.PositiveMixin, {
valueMetric: 'Seconds',
text: isWizard ? '' : this.getThresholdsProperty('warning', 'text'),
value: isWizard ? '' : this.getThresholdsProperty('warning', 'value')
}),
- App.AlertConfigProperties.Thresholds.CriticalThreshold.create({
- type: 'PORT',
+ App.AlertConfigProperties.Thresholds.CriticalThreshold.create(App.AlertConfigProperties.Thresholds.PositiveMixin, {
valueMetric: 'Seconds',
text: isWizard ? '' : this.getThresholdsProperty('critical', 'text'),
value: isWizard ? '' : this.getThresholdsProperty('critical', 'value')
@@ -212,13 +233,11 @@ 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')
@@ -256,13 +275,11 @@ 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')
@@ -320,13 +337,11 @@ 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: '%'
http://git-wip-us.apache.org/repos/asf/ambari/blob/8ae20f36/ambari-web/app/models/alert_config.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/models/alert_config.js b/ambari-web/app/models/alert_config.js
index 0ba04c6..c76417e 100644
--- a/ambari-web/app/models/alert_config.js
+++ b/ambari-web/app/models/alert_config.js
@@ -17,6 +17,7 @@
*/
var App = require('app');
+var validator = require('utils/validator');
App.AlertConfigProperty = Ember.Object.extend({
@@ -302,7 +303,7 @@ App.AlertConfigProperties = {
apiProperty: [],
init: function () {
- this.valueWasChanged();
+ this.set('displayValue', this.getNewValue());
this._super();
},
@@ -361,7 +362,7 @@ App.AlertConfigProperties = {
valueWasChanged: function () {
var displayValue = this.get('displayValue');
var newDisplayValue = this.getNewValue();
- if (Math.abs(newDisplayValue - displayValue) > 0.000001) {
+ if (newDisplayValue !== displayValue && !(isNaN(newDisplayValue) ||isNaN(displayValue))) {
this.set('displayValue', newDisplayValue);
}
}.observes('value'),
@@ -378,10 +379,23 @@ App.AlertConfigProperties = {
displayValueWasChanged: function () {
var value = this.get('value');
var newValue = this.getNewDisplayValue();
- if (Math.abs(newValue - value) > 0.000001) {
+ if (newValue !== value && !(isNaN(newValue) ||isNaN(value))) {
this.set('value', newValue);
}
- }.observes('displayValue')
+ }.observes('displayValue'),
+
+ /**
+ * Check if <code>displayValue</code> is valid float number
+ * If this value isn't shown (see <code>showInputForValue</code>), result is always true
+ * @return {boolean}
+ */
+ isValid: function () {
+ if (!this.get('showInputForValue')) return true;
+ var value = this.get('displayValue');
+ if (Em.isNone(value)) return false;
+ value = ('' + value).trim();
+ return validator.isValidFloat(value);
+ }.property('displayValue', 'showInputForValue')
}),
@@ -487,21 +501,7 @@ App.AlertConfigProperties.Thresholds = {
ret.push('source.reporting.warning.text');
}
return ret;
- }.property('showInputForValue', 'showInputForText'),
-
- isValid: function () {
- var value = this.get('displayValue');
- if (!value && this.get('type') === 'WEB') return true;
- if (!value) return false;
- value = ('' + value).trim();
- 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')
+ }.property('showInputForValue', 'showInputForText')
}),
@@ -520,21 +520,8 @@ App.AlertConfigProperties.Thresholds = {
ret.push('source.reporting.critical.text');
}
return ret;
- }.property('showInputForValue', 'showInputForText'),
+ }.property('showInputForValue', 'showInputForText')
- isValid: function () {
- var value = this.get('displayValue');
- if (!value && this.get('type') === 'WEB') return true;
- if (!value) return false;
- value = ('' + value).trim();
- 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')
}),
/**
@@ -548,6 +535,7 @@ App.AlertConfigProperties.Thresholds = {
var value = this.get('displayValue');
if (!value) return false;
value = ('' + value).trim();
+ value = parseFloat(value);
return this.get('showInputForValue') ? !isNaN(value) && value > 0 && value <= 100 : true;
}.property('displayValue', 'showInputForValue'),
@@ -569,6 +557,24 @@ App.AlertConfigProperties.Thresholds = {
return (displayValue && !isNaN(displayValue)) ? (Number(displayValue) / 100) + '' : displayValue;
}
+ }),
+
+ /**
+ * Mixin for <code>App.AlertConfigProperties.Threshold</code>
+ * Used to validate values that should be greater than 0
+ * @type {Em.Mixin}
+ */
+ PositiveMixin: Em.Mixin.create({
+
+ isValid: function () {
+ if (!this.get('showInputForValue')) return true;
+ var value = this.get('displayValue');
+ if (!value) return false;
+ value = ('' + value).trim();
+ value = parseFloat(value);
+ return !isNaN(value) && value > 0;
+ }.property('displayValue', 'showInputForValue')
+
})
};
http://git-wip-us.apache.org/repos/asf/ambari/blob/8ae20f36/ambari-web/test/models/alert_config_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/models/alert_config_test.js b/ambari-web/test/models/alert_config_test.js
index 1012a22..933a228 100644
--- a/ambari-web/test/models/alert_config_test.js
+++ b/ambari-web/test/models/alert_config_test.js
@@ -141,6 +141,32 @@ describe('App.AlertConfigProperties', function () {
});
+ describe('#isValid', function () {
+
+ it('should be true if showInputForValue is false', function () {
+ model.set('showInputForValue', false);
+ expect(model.get('isValid')).to.be.true;
+ });
+
+ it('should be false if displayValue is null', function () {
+ model.set('displayValue', null);
+ expect(model.get('isValid')).to.be.false;
+
+ model.set('displayValue', undefined);
+ expect(model.get('isValid')).to.be.false;
+ });
+
+ it('should be true if displayValue is valid float', function () {
+ model.set('displayValue', '123.456');
+ expect(model.get('isValid')).to.be.true;
+
+ model.set('displayValue', '$1234.444');
+ expect(model.get('isValid')).to.be.false;
+ });
+
+
+ });
+
});
describe('App.AlertConfigProperties.Thresholds', function () {