You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ak...@apache.org on 2014/11/21 17:18:34 UTC
ambari git commit: AMBARI-8414. Alerts UI: thresholds property should
be taken from API. (akovalenko)
Repository: ambari
Updated Branches:
refs/heads/trunk 7da19ffd8 -> 2b2accd9c
AMBARI-8414. Alerts UI: thresholds property should be taken from API. (akovalenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/2b2accd9
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/2b2accd9
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/2b2accd9
Branch: refs/heads/trunk
Commit: 2b2accd9ca5b385aec14e5c5025c10d7d2cdc62e
Parents: 7da19ff
Author: Aleksandr Kovalenko <ak...@hortonworks.com>
Authored: Fri Nov 21 18:14:30 2014 +0200
Committer: Aleksandr Kovalenko <ak...@hortonworks.com>
Committed: Fri Nov 21 18:17:43 2014 +0200
----------------------------------------------------------------------
.../alerts/definition_configs_controller.js | 90 ++++++++++++++------
ambari-web/app/models/alert_config.js | 22 +++--
.../definitions_configs_controller_test.js | 74 +++++++++++++++-
3 files changed, 149 insertions(+), 37 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/2b2accd9/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 dc57b09..65846a1 100644
--- a/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
+++ b/ambari-web/app/controllers/main/alerts/definition_configs_controller.js
@@ -51,6 +51,32 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
}.property(),
/**
+ * Compute thresholds from value using <code>content.reporting</code>
+ * @type {Number|Null}
+ */
+ thresholdsFrom: function () {
+ var warning = this.get('content.reporting').findProperty('type', 'warning');
+ if (warning && warning.get('value')) {
+ return warning.get('value');
+ } else {
+ return null;
+ }
+ }.property('content.reporting.@each.value'),
+
+ /**
+ * Compute thresholds to value using <code>content.reporting</code>
+ * @type {Number|Null}
+ */
+ thresholdsTo: function () {
+ var critical = this.get('content.reporting').findProperty('type', 'critical');
+ if (critical && critical.get('value')) {
+ return critical.get('value');
+ } else {
+ return null;
+ }
+ }.property('content.reporting.@each.value'),
+
+ /**
* Change options of "Component", after changing value of "Service" config
*/
onServiceSelect: function () {
@@ -120,9 +146,9 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
value: alertDefinition.get('interval')
}),
App.AlertConfigProperties.Thresholds.create({
- value: alertDefinition.get('thresholds'),
- from: alertDefinition.get('thresholds').split('-')[0],
- to: alertDefinition.get('thresholds').split('-')[1]
+ value: this.get('thresholdsFrom') + '-' + this.get('thresholdsTo'),
+ from: this.get('thresholdsFrom'),
+ to: this.get('thresholdsTo')
}),
App.AlertConfigProperties.URI.create({
value: alertDefinition.get('uri')
@@ -161,9 +187,9 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
value: alertDefinition.get('interval')
}),
App.AlertConfigProperties.Thresholds.create({
- value: alertDefinition.get('thresholds'),
- from: alertDefinition.get('thresholds').split('-')[0],
- to: alertDefinition.get('thresholds').split('-')[1]
+ value: this.get('thresholdsFrom') + '-' + this.get('thresholdsTo'),
+ from: this.get('thresholdsFrom'),
+ to: this.get('thresholdsTo')
}),
App.AlertConfigProperties.URIExtended.create({
value: JSON.stringify({
@@ -212,9 +238,9 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
value: alertDefinition.get('interval')
}),
App.AlertConfigProperties.Thresholds.create({
- value: alertDefinition.get('thresholds'),
- from: alertDefinition.get('thresholds').split('-')[0],
- to: alertDefinition.get('thresholds').split('-')[1]
+ value: this.get('thresholdsFrom') + '-' + this.get('thresholdsTo'),
+ from: this.get('thresholdsFrom'),
+ to: this.get('thresholdsTo')
}),
App.AlertConfigProperties.URIExtended.create({
value: JSON.stringify({
@@ -255,9 +281,9 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
value: alertDefinition.get('interval')
}),
App.AlertConfigProperties.Thresholds.create({
- value: alertDefinition.get('thresholds'),
- from: alertDefinition.get('thresholds').split('-')[0],
- to: alertDefinition.get('thresholds').split('-')[1]
+ value: this.get('thresholdsFrom') + '-' + this.get('thresholdsTo'),
+ from: this.get('thresholdsFrom'),
+ to: this.get('thresholdsTo')
}),
App.AlertConfigProperties.Path.create({
value: alertDefinition.get('location')
@@ -330,24 +356,32 @@ App.MainAlertDefinitionConfigsController = Em.Controller.extend({
getPropertiesToUpdate: function () {
var propertiesToUpdate = {};
this.get('configs').filterProperty('wasChanged').forEach(function (property) {
- if (property.get('apiProperty').contains('source.')) {
- if (!propertiesToUpdate['AlertDefinition/source']) {
- propertiesToUpdate['AlertDefinition/source'] = this.get('content.rawSourceData');
- }
-
- var sourcePath = propertiesToUpdate['AlertDefinition/source'];
- property.get('apiProperty').replace('source.', '').split('.').forEach(function (path, index, array) {
- // check if it is last path
- if (array.length - index === 1) {
- sourcePath[path] = property.get('apiFormattedValue');
- } else {
- sourcePath = sourcePath[path];
+ var apiProperties = property.get('apiProperty');
+ var apiFormattedValues = property.get('apiFormattedValue');
+ if (!Em.isArray(property.get('apiProperty'))) {
+ apiProperties = [property.get('apiProperty')];
+ apiFormattedValues = [property.get('apiFormattedValue')];
+ }
+ apiProperties.forEach(function (apiProperty, i) {
+ if (apiProperty.contains('source.')) {
+ if (!propertiesToUpdate['AlertDefinition/source']) {
+ propertiesToUpdate['AlertDefinition/source'] = this.get('content.rawSourceData');
}
- });
- } else {
- propertiesToUpdate['AlertDefinition/' + property.get('apiProperty')] = property.get('apiFormattedValue');
- }
+ var sourcePath = propertiesToUpdate['AlertDefinition/source'];
+ apiProperty.replace('source.', '').split('.').forEach(function (path, index, array) {
+ // check if it is last path
+ if (array.length - index === 1) {
+ sourcePath[path] = apiFormattedValues[i];
+ } else {
+ sourcePath = sourcePath[path];
+ }
+ });
+
+ } else {
+ propertiesToUpdate['AlertDefinition/' + apiProperty] = apiFormattedValues[i];
+ }
+ }, this);
}, this);
return propertiesToUpdate;
http://git-wip-us.apache.org/repos/asf/ambari/blob/2b2accd9/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 804eec4..4b0a1c4 100644
--- a/ambari-web/app/models/alert_config.js
+++ b/ambari-web/app/models/alert_config.js
@@ -70,8 +70,11 @@ App.AlertConfigProperty = Ember.Object.extend({
classNames: '',
/**
- * name of property related to config
- * @type {String}
+ * name or names of properties related to config
+ * may be either string for one property or array of strings for multiple properties
+ * if this property is array, then <code>apiFormattedValue</code> should also be an array
+ * example: <code>apiProperty[0]</code> relates to <code>apiFormattedValue[0]</code>
+ * @type {String|Array}
*/
apiProperty: '',
@@ -180,8 +183,6 @@ App.AlertConfigProperties = {
from: '',
to: '',
value: '',
- // todo: check value after API will be provided
- apiProperty: 'thresholds',
setFromTo: function () {
this.set('doNotChangeValue', true);
@@ -197,7 +198,18 @@ App.AlertConfigProperties = {
}.observes('from', 'to'),
// flag for providing correct from, to and value recomputing
- doNotChangeValue: false
+ doNotChangeValue: false,
+
+ apiProperty: [
+ 'source.reporting.warning.value',
+ 'source.reporting.critical.value'
+ ],
+ apiFormattedValue: function () {
+ return [
+ +this.get('from'),
+ +this.get('to')
+ ]
+ }.property('from', 'to')
}),
URI: App.AlertConfigProperty.extend({
label: 'URI',
http://git-wip-us.apache.org/repos/asf/ambari/blob/2b2accd9/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js b/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js
index 2c31f4d..0894de6 100644
--- a/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js
+++ b/ambari-web/test/controllers/main/alerts/definitions_configs_controller_test.js
@@ -102,7 +102,20 @@ describe('App.MainAlertDefinitionConfigsController', function () {
scope: 'HOST',
description: 'alertDefinitionDescription',
interval: 60,
- thresholds: '10-20',
+ reporting: [
+ Em.Object.create({
+ type: 'warning',
+ value: 10
+ }),
+ Em.Object.create({
+ type: 'critical',
+ value: 20
+ }),
+ Em.Object.create({
+ type: 'ok',
+ value: 30
+ })
+ ],
uri: 'alertDefinitionUri',
defaultPort: '777'
}));
@@ -134,7 +147,20 @@ describe('App.MainAlertDefinitionConfigsController', function () {
scope: 'HOST',
description: 'alertDefinitionDescription',
interval: 60,
- thresholds: '10-20',
+ reporting: [
+ Em.Object.create({
+ type: 'warning',
+ value: 10
+ }),
+ Em.Object.create({
+ type: 'critical',
+ value: 20
+ }),
+ Em.Object.create({
+ type: 'ok',
+ value: 30
+ })
+ ],
uri: {
"http": "{{mapred-site/mapreduce.jobhistory.webapp.address}}",
"https": "{{mapred-site/mapreduce.jobhistory.webapp.https.address}}",
@@ -180,7 +206,20 @@ describe('App.MainAlertDefinitionConfigsController', function () {
scope: 'HOST',
description: 'alertDefinitionDescription',
interval: 60,
- thresholds: '10-20',
+ reporting: [
+ Em.Object.create({
+ type: 'warning',
+ value: 10
+ }),
+ Em.Object.create({
+ type: 'critical',
+ value: 20
+ }),
+ Em.Object.create({
+ type: 'ok',
+ value: 30
+ })
+ ],
uri: {
"http": "{{mapred-site/mapreduce.jobhistory.webapp.address}}",
"https": "{{mapred-site/mapreduce.jobhistory.webapp.https.address}}",
@@ -216,7 +255,20 @@ describe('App.MainAlertDefinitionConfigsController', function () {
scope: 'HOST',
description: 'alertDefinitionDescription',
interval: 60,
- thresholds: '10-20',
+ reporting: [
+ Em.Object.create({
+ type: 'warning',
+ value: 10
+ }),
+ Em.Object.create({
+ type: 'critical',
+ value: 20
+ }),
+ Em.Object.create({
+ type: 'ok',
+ value: 30
+ })
+ ],
location: 'path to script'
}));
@@ -389,6 +441,20 @@ describe('App.MainAlertDefinitionConfigsController', function () {
}
}
}
+ },
+ {
+ m: 'should correctly multiple apiProperties',
+ configs: [
+ Em.Object.create({
+ wasChanged: true,
+ apiProperty: ['name1', 'name2'],
+ apiFormattedValue: ['value1', 'value2']
+ })
+ ],
+ result: {
+ 'AlertDefinition/name1': 'value1',
+ 'AlertDefinition/name2': 'value2'
+ }
}
];