Repository: ambari Updated Branches: refs/heads/trunk efe8ee6a0 -> 82ff8884c
AMBARI-11782. DataNode directories overrides values with "\n" symbol (onechiporenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/82ff8884 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/82ff8884 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/82ff8884 Branch: refs/heads/trunk Commit: 82ff8884c1fd67358c77d1cb41cdf4747903b868 Parents: efe8ee6 Author: Oleg Nechiporenko <[email protected]> Authored: Mon Jun 8 14:56:04 2015 +0300 Committer: Oleg Nechiporenko <[email protected]> Committed: Mon Jun 8 14:59:19 2015 +0300 ---------------------------------------------------------------------- .../configs/objects/service_config_property.js | 24 ++++++++++-- .../objects/service_config_property_test.js | 39 ++++++++++++++++++++ .../widgets/list_config_widget_view_test.js | 1 + 3 files changed, 61 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/82ff8884/ambari-web/app/models/configs/objects/service_config_property.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/configs/objects/service_config_property.js b/ambari-web/app/models/configs/objects/service_config_property.js index f7dcd2d..799c79f 100644 --- a/ambari-web/app/models/configs/objects/service_config_property.js +++ b/ambari-web/app/models/configs/objects/service_config_property.js @@ -475,14 +475,14 @@ App.ServiceConfigProperty = Em.Object.extend({ _validateOverrides: function () { var self = this; var isError = false; - var value = '' + this.get('value'); + var value = this._getValueForCheck(this.get('value')); var isOriginalSCP = this.get('isOriginalSCP'); var supportsFinal = this.get('supportsFinal'); var isFinal = this.get('isFinal'); var parentSCP = this.get('parentSCP'); if (!isOriginalSCP) { if (!Em.isNone(parentSCP)) { - if (value === '' + parentSCP.get('value')) { + if (value === this._getValueForCheck(parentSCP.get('value'))) { if (supportsFinal) { if (isFinal === parentSCP.get('isFinal')) { this.set('errorMessage', Em.I18n.t('config.override.valueEqualToParentConfig')); @@ -499,7 +499,7 @@ App.ServiceConfigProperty = Em.Object.extend({ if (overrides) { overrides.forEach(function (override) { if (self == override) return; - if (value === '' + override.get('value')) { + if (value === self._getValueForCheck(override.get('value'))) { if (supportsFinal) { if (isFinal === parentSCP.get('isFinal')) { self.set('errorMessage', Em.I18n.t('config.override.valueEqualToAnotherOverrideConfig')); @@ -517,6 +517,24 @@ App.ServiceConfigProperty = Em.Object.extend({ } } return isError; + }, + + /** + * Some values should be little bit changed before checking for overrides values + * `directories`-values should be "trimmed" for multiple mew-line symbols + * @param {string} value + * @returns {string} + * @private + */ + _getValueForCheck: function (value) { + value = '' + value; + switch(this.get('displayType')) { + case 'directories': + return value.replace(/(\n\r?)+/g, '\n'); + break; + default: + return value; + } } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/82ff8884/ambari-web/test/models/configs/objects/service_config_property_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/configs/objects/service_config_property_test.js b/ambari-web/test/models/configs/objects/service_config_property_test.js index 08f9cb0..c932d87 100644 --- a/ambari-web/test/models/configs/objects/service_config_property_test.js +++ b/ambari-web/test/models/configs/objects/service_config_property_test.js @@ -568,6 +568,19 @@ describe('App.ServiceConfigProperty', function () { ] }) } + }, + { + m: '`directories`-config with almost equal value', + e: true, + c: { + value: "/hadoop/hdfs/data\n\n", + displayType: 'directories', + supportsFinal: false, + isOriginalSCP: false, + parentSCP: App.ServiceConfigProperty.create({ + value: "/hadoop/hdfs/data\n" + }) + } } ]).forEach(function (test) { it(test.m, function () { @@ -613,4 +626,30 @@ describe('App.ServiceConfigProperty', function () { }); + describe('#_getValueForCheck', function () { + + beforeEach(function () { + serviceConfigProperty.setProperties({ + value: "/hadoop/hdfs/data\n", + displayType: 'directories', + supportsFinal: false, + isOriginalSCP: true, + overrides: [ + Em.Object.create({ + value: "/hadoop/hdfs/data\n\n" + }) + ] + }); + }); + + it('should trim value', function () { + expect(serviceConfigProperty._getValueForCheck(serviceConfigProperty.get('value'))).to.equal('/hadoop/hdfs/data\n'); + }); + + it('should trim value 2', function () { + expect(serviceConfigProperty._getValueForCheck(serviceConfigProperty.get('overrides.0.value'))).to.equal('/hadoop/hdfs/data\n'); + }); + + }); + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/82ff8884/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js b/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js index 63e8f25..3db2dcb 100644 --- a/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js +++ b/ambari-web/test/views/common/configs/widgets/list_config_widget_view_test.js @@ -27,6 +27,7 @@ describe('App.ListConfigWidgetView', function () { initPopover: Em.K, config: Em.Object.create({ _validateOverrides: App.ServiceConfigProperty.prototype._validateOverrides, + _getValueForCheck: App.ServiceConfigProperty.prototype._getValueForCheck, validate: App.ServiceConfigProperty.prototype.validate, name: 'a.b.c', savedValue: '2,1',
