AMBARI-21497 Conflicts in the ambari config groups. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/b17225df Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b17225df Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b17225df Branch: refs/heads/branch-feature-logsearch-ui Commit: b17225df413ee0f6e562769963df864c69a02821 Parents: 9e91639 Author: Andrii Tkach <atk...@apache.org> Authored: Thu Aug 3 11:35:30 2017 +0300 Committer: Andrii Tkach <atk...@apache.org> Committed: Thu Aug 3 11:35:30 2017 +0300 ---------------------------------------------------------------------- .../app/mixins/common/configs/configs_saver.js | 12 ++++++++++- .../mixins/common/configs/enhanced_configs.js | 13 +++++++++++- .../mixins/common/configs/configs_saver_test.js | 21 ++++++++++++++++++++ .../common/configs/enhanced_configs_test.js | 13 +++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/b17225df/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 4a4163e..dafee79 100644 --- a/ambari-web/app/mixins/common/configs/configs_saver.js +++ b/ambari-web/app/mixins/common/configs/configs_saver.js @@ -135,7 +135,7 @@ App.ConfigsSaverMixin = Em.Mixin.create({ if (configGroup && !configGroup.get('isDefault')) { var overriddenConfigs = this.getConfigsForGroup(configs, configGroup.get('name')); - if (Em.isArray(overriddenConfigs)) { + if (Em.isArray(overriddenConfigs) && this.isOverriddenConfigsModified(overriddenConfigs)) { var successCallback = this.get('content.serviceName') === serviceName ? 'putConfigGroupChangesSuccess' : null; this.saveGroup(overriddenConfigs, configGroup, this.get('serviceConfigVersionNote'), successCallback); } @@ -143,6 +143,16 @@ App.ConfigsSaverMixin = Em.Mixin.create({ }, this); }, + /** + * @param {Array} overriddenConfigs + * @returns {boolean} + */ + isOverriddenConfigsModified: function(overriddenConfigs) { + return overriddenConfigs.some(function(config) { + return config.get('savedValue') !== config.get('value'); + }); + }, + saveConfigsForDefaultGroup: function() { var data = []; this.get('stepConfigs').forEach(function(stepConfig) { http://git-wip-us.apache.org/repos/asf/ambari/blob/b17225df/ambari-web/app/mixins/common/configs/enhanced_configs.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/mixins/common/configs/enhanced_configs.js b/ambari-web/app/mixins/common/configs/enhanced_configs.js index a5af407..f870fc6 100644 --- a/ambari-web/app/mixins/common/configs/enhanced_configs.js +++ b/ambari-web/app/mixins/common/configs/enhanced_configs.js @@ -448,7 +448,7 @@ App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationP var configForGroup = recommendations['config-groups'][0]; this.get('stepConfigs').forEach(function(stepConfig) { var configGroup = this.getGroupForService(stepConfig.get('serviceName')); - if (configGroup) { + if (configGroup && this.isConfigGroupAffected(configForGroup.hosts, configGroup.get('hosts'))) { this.updateOverridesByRecommendations(configForGroup.configurations, stepConfig.get('configs'), changedConfigs, configGroup); this.updateOverridesByRecommendations(configForGroup.dependent_configurations, stepConfig.get('configs'), changedConfigs, configGroup); this.toggleProperty('forceUpdateBoundaries'); @@ -456,6 +456,17 @@ App.EnhancedConfigsMixin = Em.Mixin.create(App.ConfigWithOverrideRecommendationP }, this); }, + + /** + * determine whether hosts of group affected by config modifications + * @param {Array} affectedHosts + * @param {Array} groupHosts + * @returns {boolean} + */ + isConfigGroupAffected: function(affectedHosts, groupHosts) { + return _.intersection(affectedHosts, groupHosts).length > 0; + }, + /** * method to show popup with dependent configs * @method showChangedDependentConfigs http://git-wip-us.apache.org/repos/asf/ambari/blob/b17225df/ambari-web/test/mixins/common/configs/configs_saver_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/mixins/common/configs/configs_saver_test.js b/ambari-web/test/mixins/common/configs/configs_saver_test.js index 7815938..e8e03ea 100644 --- a/ambari-web/test/mixins/common/configs/configs_saver_test.js +++ b/ambari-web/test/mixins/common/configs/configs_saver_test.js @@ -408,12 +408,14 @@ describe('App.ConfigsSaverMixin', function() { this.mockGroup = sinon.stub(mixin, 'getGroupFromModel'); this.mockConfigs = sinon.stub(mixin, 'getConfigsForGroup'); sinon.stub(mixin, 'saveGroup'); + sinon.stub(mixin, 'isOverriddenConfigsModified').returns(true); }); afterEach(function() { this.mockGroup.restore(); this.mockConfigs.restore(); mixin.saveGroup.restore(); + mixin.isOverriddenConfigsModified.restore(); }); it("configGroup is null", function() { @@ -1190,5 +1192,24 @@ describe('App.ConfigsSaverMixin', function() { }); }); + describe('#isOverriddenConfigsModified', function() { + it('no configs modified', function() { + expect(mixin.isOverriddenConfigsModified([ + Em.Object.create({ + savedValue: '1', + value: '1' + }) + ])).to.be.false; + }); + it('one config modified', function() { + expect(mixin.isOverriddenConfigsModified([ + Em.Object.create({ + savedValue: '1', + value: '2' + }) + ])).to.be.true; + }); + }); + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/b17225df/ambari-web/test/mixins/common/configs/enhanced_configs_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/mixins/common/configs/enhanced_configs_test.js b/ambari-web/test/mixins/common/configs/enhanced_configs_test.js index 999ed8c..98f3182 100644 --- a/ambari-web/test/mixins/common/configs/enhanced_configs_test.js +++ b/ambari-web/test/mixins/common/configs/enhanced_configs_test.js @@ -1061,11 +1061,13 @@ describe('App.EnhancedConfigsMixin', function () { this.mock = sinon.stub(mixin, 'getGroupForService'); sinon.stub(mixin, 'updateOverridesByRecommendations'); sinon.stub(mixin, 'toggleProperty'); + sinon.stub(mixin, 'isConfigGroupAffected').returns(true); mixin.set('stepConfigs', [Em.Object.create()]); }); afterEach(function() { this.mock.restore(); + mixin.isConfigGroupAffected.restore(); mixin.updateOverridesByRecommendations.restore(); mixin.toggleProperty.restore(); }); @@ -1077,7 +1079,7 @@ describe('App.EnhancedConfigsMixin', function () { }); it("updateOverridesByRecommendations should be called", function() { - this.mock.returns({}); + this.mock.returns(Em.Object.create()); mixin.saveConfigGroupsRecommendations({'config-groups': [{}]}); expect(mixin.updateOverridesByRecommendations.calledTwice).to.be.true; expect(mixin.toggleProperty.calledWith('forceUpdateBoundaries')).to.be.true; @@ -1456,5 +1458,14 @@ describe('App.EnhancedConfigsMixin', function () { expect(mixin.filterRequiredChanges(recommendations)).to.be.eql(recommendations); }); }); + + describe('#isConfigGroupAffected', function() { + it('groups have no shared hosts', function() { + expect(mixin.isConfigGroupAffected(['host1'], ['host2'])).to.be.false; + }); + it('groups have shared hosts', function() { + expect(mixin.isConfigGroupAffected(['host1'], ['host2', 'host1'])).to.be.true; + }); + }); });