Repository: ambari Updated Branches: refs/heads/trunk 0ea54c830 -> a5f81f861
AMBARI-15186 Config saving discards Capacity-scheduler changes. (ababiichuk) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/a5f81f86 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/a5f81f86 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/a5f81f86 Branch: refs/heads/trunk Commit: a5f81f8618a5e0b1b90a8dc2da9c0cf7d36dcff4 Parents: 0ea54c8 Author: ababiichuk <[email protected]> Authored: Fri Feb 26 10:00:08 2016 +0200 Committer: ababiichuk <[email protected]> Committed: Fri Feb 26 11:11:10 2016 +0200 ---------------------------------------------------------------------- ambari-web/app/controllers/wizard.js | 3 + .../app/mixins/common/configs/configs_saver.js | 4 + ambari-web/app/utils/config.js | 47 ++++++++++- ambari-web/app/views/common/controls_view.js | 82 +++++--------------- ambari-web/test/utils/config_test.js | 2 +- 5 files changed, 72 insertions(+), 66 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/a5f81f86/ambari-web/app/controllers/wizard.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/wizard.js b/ambari-web/app/controllers/wizard.js index 654bea5..0f7dbe6 100644 --- a/ambari-web/app/controllers/wizard.js +++ b/ambari-web/app/controllers/wizard.js @@ -889,6 +889,9 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingM var installedServiceNames = stepController.get('installedServiceNames') || []; var installedServiceNamesMap = installedServiceNames.toWickMap(); stepController.get('stepConfigs').forEach(function (_content) { + if (_content.serviceName === 'YARN') { + _content.set('configs', App.config.textareaIntoFileConfigs(_content.get('configs'), 'capacity-scheduler.xml')); + } _content.get('configs').forEach(function (_configProperties) { if (!Em.isNone(_configProperties.get('group'))) { return false; http://git-wip-us.apache.org/repos/asf/ambari/blob/a5f81f86/ambari-web/app/mixins/common/configs/configs_saver.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/common/configs/configs_saver.js b/ambari-web/app/mixins/common/configs/configs_saver.js index 78ce85d..23f69c2 100644 --- a/ambari-web/app/mixins/common/configs/configs_saver.js +++ b/ambari-web/app/mixins/common/configs/configs_saver.js @@ -313,6 +313,10 @@ App.ConfigsSaverMixin = Em.Mixin.create({ */ getServiceConfigToSave: function(serviceName, configs) { + if (serviceName === 'YARN') { + configs = App.config.textareaIntoFileConfigs(configs, 'capacity-scheduler.xml'); + } + //generates list of properties that was changed var modifiedConfigs = this.getModifiedConfigs(configs); var serviceFilenames = Object.keys(App.StackService.find(serviceName).get('configTypes')).map(function (type) { http://git-wip-us.apache.org/repos/asf/ambari/blob/a5f81f86/ambari-web/app/utils/config.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/config.js b/ambari-web/app/utils/config.js index ca1855a..8866612 100644 --- a/ambari-web/app/utils/config.js +++ b/ambari-web/app/utils/config.js @@ -280,7 +280,8 @@ App.config = Em.Object.create({ * @returns {Object} */ createDefaultConfig: function(name, fileName, definedInStack, coreObject) { - var serviceName = this.get('serviceByConfigTypeMap')[fileName] || 'MISC'; + var service = this.get('serviceByConfigTypeMap')[App.config.getConfigTagFromFileName(fileName)]; + var serviceName = service ? service.get('serviceName') : 'MISC'; var tpl = { /** core properties **/ id: this.configId(name, fileName), @@ -626,7 +627,7 @@ App.config = Em.Object.create({ var connectedConfigs = configs.filter(function(config) { return !excludedConfigs.contains(App.config.configId(config.get('name'), config.get('filename'))) && (config.get('filename') === 'capacity-scheduler.xml'); }); - connectedConfigs.setEach('isVisible', false); + var names = connectedConfigs.mapProperty('name'); connectedConfigs.forEach(function (config) { value += config.get('name') + '=' + config.get('value') + '\n'; @@ -652,10 +653,12 @@ App.config = Em.Object.create({ 'recommendedIsFinal': recommendedIsFinal, 'displayName': 'Capacity Scheduler', 'description': 'Capacity Scheduler properties', - 'displayType': 'capacityScheduler', - 'isRequiredByAgent': false + 'displayType': 'capacityScheduler' }); + configs = configs.filter(function(c) { + return !(names.contains(c.get('name')) && (c.get('filename') === 'capacity-scheduler.xml')); + }); configs.push(App.ServiceConfigProperty.create(cs)); return configs; }, @@ -680,6 +683,42 @@ App.config = Em.Object.create({ }, /** + * transform one config with textarea content + * into set of configs of file + * @param configs + * @param filename + * @return {*} + */ + textareaIntoFileConfigs: function (configs, filename) { + var configsTextarea = configs.findProperty('name', 'capacity-scheduler'); + if (configsTextarea && !App.get('testMode')) { + var properties = configsTextarea.get('value').split('\n'); + + properties.forEach(function (_property) { + var name, value; + if (_property) { + _property = _property.split('='); + name = _property[0]; + value = (_property[1]) ? _property[1] : ""; + configs.push(Em.Object.create({ + name: name, + value: value, + savedValue: value, + serviceName: configsTextarea.get('serviceName'), + filename: filename, + isFinal: configsTextarea.get('isFinal'), + isNotDefaultValue: configsTextarea.get('isNotDefaultValue'), + isRequiredByAgent: configsTextarea.get('isRequiredByAgent'), + group: null + })); + } + }); + return configs.without(configsTextarea); + } + return configs; + }, + + /** * trim trailing spaces for all properties. * trim both trailing and leading spaces for host displayType and hive/oozie datebases url. * for directory or directories displayType format string for further using. http://git-wip-us.apache.org/repos/asf/ambari/blob/a5f81f86/ambari-web/app/views/common/controls_view.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/views/common/controls_view.js b/ambari-web/app/views/common/controls_view.js index 2290f58..d355ffe 100644 --- a/ambari-web/app/views/common/controls_view.js +++ b/ambari-web/app/views/common/controls_view.js @@ -299,73 +299,33 @@ App.ServiceConfigTextArea = Ember.TextArea.extend(App.ServiceConfigPopoverSuppor /** * Special config type for Capacity Scheduler */ -App.CapacitySceduler = Ember.TextArea.extend(App.ServiceConfigPopoverSupport, App.ServiceConfigCalculateId, App.SupportsDependentConfigs, { +App.CapacitySceduler = App.ServiceConfigTextArea.extend({ - configs: function() { - return this.get('controller.stepConfigs').findProperty('serviceName', 'YARN').get('configs'); - }.property('controller.stepConfigs'), - - valueBinding: 'serviceConfig.value', - excludedConfigs: function() { - return App.config.getPropertiesFromTheme('YARN'); - }.property(), rows: 16, - classNames: ['directories'], - classNameBindings: ['widthClass'], - widthClass: 'span9', - connectedConfigs: function() { - return this.get('categoryConfigsAll').filter(function(config) { - return !this.get('excludedConfigs').contains(App.config.configId(config.get('name'), config.get('filename'))) - && (config.get('name') !== this.get('serviceConfig.name')) - && (config.get('filename') === 'capacity-scheduler.xml'); - }, this); - }.property('categoryConfigsAll.length'), - - valueObserver: function () { - var self = this, controller = this.get('controller'), - names = []; - delay(function () { - self.get('serviceConfig.value').split('\n').forEach(function (_property) { - if (_property) { - _property = _property.split('='); - var name = _property[0]; - var value = (_property[1]) ? _property[1] : ""; - - names.push(name); - - var cfg = self.get('connectedConfigs').findProperty('name', name); - if (cfg) { - /** update configs **/ - if (cfg.get('value') !== value) { - cfg.set('value', value); - self.sendRequestRorDependentConfigs(cfg, controller); - } - } else { - /** add configs **/ - var newCfg = App.config.getDefaultConfig(name, 'YARN', 'capacity-scheduler', { - 'value': value - }); - self.get('configs').pushObject(App.ServiceConfigProperty.create(newCfg)); - } + /** + * specific property handling for cs + * + * @param {App.ServiceConfigProperty} config + * @param [controller] + * @returns {$.Deferred} + * @override + */ + sendRequestRorDependentConfigs: function(config, controller) { + if (!config.get('isValid') && config.get('isNotDefaultValue')) return $.Deferred().resolve().promise(); + controller = controller || this.get('controller'); + if (controller && ['mainServiceInfoConfigsController','wizardStep7Controller'].contains(controller.get('name'))) { + return controller.loadConfigRecommendations(config.get('value').split('\n').map(function (_property) { + return { + "type": 'capacity-scheduler', + "name": _property.split('=')[0] } - }); + })); + } - /** remove configs **/ - self.get('connectedConfigs').filter(function(c) { - return !names.contains(c.get('name')); - }).forEach(function(c) { - self.get('configs').removeObject(c); - }); - }, 500); - }.observes('serviceConfig.value'), + return $.Deferred().resolve().promise(); + } - /** - * update fina; value for connected configs - */ - isFinalObserver: function () { - this.get('connectedConfigs').setEach('isFinal', this.get('serviceConfig.isFinal')); - }.observes('serviceConfig.isFinal') }); /** http://git-wip-us.apache.org/repos/asf/ambari/blob/a5f81f86/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 e556230..5f233f2 100644 --- a/ambari-web/test/utils/config_test.js +++ b/ambari-web/test/utils/config_test.js @@ -656,7 +656,7 @@ describe('App.config', function () { }); sinon.stub(App.config, 'get', function(param) { if (param === 'serviceByConfigTypeMap') { - return { 'pFileName': 'pServiceName' }; + return { 'pFileName': Em.Object.create({serviceName: 'pServiceName' }) }; } return Em.get(App.config, param); });
