Repository: ambari Updated Branches: refs/heads/trunk 623929f58 -> 9077a9d30
AMBARI-10754 Final buttons are not present for Custom core-site properties. (ababiichk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9077a9d3 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9077a9d3 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9077a9d3 Branch: refs/heads/trunk Commit: 9077a9d3044302860d543907e23542c25603f79f Parents: 623929f Author: aBabiichuk <[email protected]> Authored: Mon Apr 27 11:50:08 2015 +0300 Committer: aBabiichuk <[email protected]> Committed: Mon Apr 27 11:50:08 2015 +0300 ---------------------------------------------------------------------- ambari-web/app/utils/config.js | 21 ++++++- .../configs/service_configs_by_category_view.js | 11 +--- ambari-web/test/utils/config_test.js | 59 ++++++++++++++++++++ 3 files changed, 80 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/9077a9d3/ambari-web/app/utils/config.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js index 54a4609..874c7e9 100644 --- a/ambari-web/app/utils/config.js +++ b/ambari-web/app/utils/config.js @@ -332,7 +332,7 @@ App.config = Em.Object.create({ showLabel: true, serviceName: serviceName, belongsToService: [], - supportsFinal: advancedConfig ? Em.get(advancedConfig, 'supportsFinal') : false + supportsFinal: advancedConfig ? Em.get(advancedConfig, 'supportsFinal') : this.shouldSupportFinal(serviceName, _tag.siteName) }); @@ -1552,6 +1552,25 @@ App.config = Em.Object.create({ */ saveConfigsToModel: function (data) { App.stackConfigPropertiesMapper.map(data); + }, + + /** + * Check if config filename supports final attribute + * @param serviceName + * @param filename + * @returns {boolean} + */ + shouldSupportFinal: function (serviceName, filename) { + if (!serviceName || serviceName == 'MISC' || !filename) { + return false; + } else { + var stackService = App.StackService.find().findProperty('serviceName', serviceName); + var supportsFinal = this.getConfigTypesInfoFromService(stackService).supportsFinal; + var matchingConfigType = supportsFinal.find(function (configType) { + return filename.startsWith(configType); + }); + return !!matchingConfigType; + } } }); http://git-wip-us.apache.org/repos/asf/ambari/blob/9077a9d3/ambari-web/app/views/common/configs/service_configs_by_category_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/configs/service_configs_by_category_view.js b/ambari-web/app/views/common/configs/service_configs_by_category_view.js index 1187a4d..d9fb8f2 100644 --- a/ambari-web/app/views/common/configs/service_configs_by_category_view.js +++ b/ambari-web/app/views/common/configs/service_configs_by_category_view.js @@ -378,16 +378,7 @@ App.ServiceConfigsByCategoryView = Em.View.extend(App.UserPref, App.ConfigOverri var configsOfFile = service.get('configs').filterProperty('filename', siteFileName); var siteFileProperties = App.config.get('configMapping').all().filterProperty('filename', siteFileName); - function shouldSupportFinal(filename) { - var stackService = App.StackService.find().findProperty('serviceName', serviceName); - var supportsFinal = App.config.getConfigTypesInfoFromService(stackService).supportsFinal; - var matchingConfigType = supportsFinal.find(function (configType) { - return filename.startsWith(configType); - }); - return !!matchingConfigType; - } - - var supportsFinal = (serviceName == 'MISC') ? false: (siteFileName ? shouldSupportFinal(siteFileName) : false); + var supportsFinal = App.config.shouldSupportFinal(serviceName, siteFileName); function isDuplicatedConfigKey(name) { return siteFileProperties.findProperty('name', name) || configsOfFile.findProperty('name', name); http://git-wip-us.apache.org/repos/asf/ambari/blob/9077a9d3/ambari-web/test/utils/config_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/config_test.js b/ambari-web/test/utils/config_test.js index bd97b1c..bbfdc6b 100644 --- a/ambari-web/test/utils/config_test.js +++ b/ambari-web/test/utils/config_test.js @@ -632,6 +632,9 @@ describe('App.config', function () { before(function() { sinon.stub(App.config, 'parseValue', function(value) {return value}); + sinon.stub(App.config, 'getConfigTypesInfoFromService').returns({ + supportsFinal: ['hdfs-site'] + }); setups.setupStackVersion(this, 'HDP-2.2'); loadServiceModelsData(['HDFS', 'STORM']); App.config.loadAdvancedConfigSuccess(modelSetup.advancedConfigs, { url: '/serviceName/configurations'}, { @@ -655,6 +658,7 @@ describe('App.config', function () { after(function() { App.config.parseValue.restore(); + App.config.getConfigTypesInfoFromService.restore(); setups.restoreStackVersion(this); removeServiceModelData(['HDFS', 'STORM']); }); @@ -1216,4 +1220,59 @@ describe('App.config', function () { }); + describe('#shouldSupportFinal', function () { + + var cases = [ + { + shouldSupportFinal: false, + title: 'no service name specified' + }, + { + serviceName: 's0', + shouldSupportFinal: false, + title: 'no filename specified' + }, + { + serviceName: 'MISC', + shouldSupportFinal: false, + title: 'MISC' + }, + { + serviceName: 's0', + filename: 's0-site', + shouldSupportFinal: true, + title: 'final attribute supported' + }, + { + serviceName: 's0', + filename: 's0-env', + shouldSupportFinal: false, + title: 'final attribute not supported' + } + ]; + + beforeEach(function () { + sinon.stub(App.StackService, 'find').returns([ + { + serviceName: 's0' + } + ]); + sinon.stub(App.config, 'getConfigTypesInfoFromService').returns({ + supportsFinal: ['s0-site'] + }); + }); + + afterEach(function () { + App.StackService.find.restore(); + App.config.getConfigTypesInfoFromService.restore(); + }); + + cases.forEach(function (item) { + it(item.title, function () { + expect(App.config.shouldSupportFinal(item.serviceName, item.filename)).to.equal(item.shouldSupportFinal); + }); + }); + + }); + });
