AMBARI-20683 Reduce size of persisted configurations in wizards. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7d0baec7 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7d0baec7 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7d0baec7 Branch: refs/heads/branch-feature-AMBARI-12556 Commit: 7d0baec7d7ddad29a6955f3af2ff6f020136abcd Parents: 6c0b38e Author: Andrii Tkach <[email protected]> Authored: Wed Apr 5 16:25:23 2017 +0300 Committer: Andrii Tkach <[email protected]> Committed: Wed Apr 5 16:25:23 2017 +0300 ---------------------------------------------------------------------- ambari-web/app/controllers/installer.js | 15 +++-- .../main/admin/kerberos/wizard_controller.js | 18 +++--- .../controllers/main/service/add_controller.js | 43 +++++--------- ambari-web/app/controllers/wizard.js | 61 +++++++++++++++----- ambari-web/app/routes/add_kerberos_routes.js | 22 ++++--- ambari-web/app/routes/add_service_routes.js | 16 +++-- ambari-web/app/routes/installer.js | 25 ++++---- ambari-web/test/controllers/installer_test.js | 17 ------ ambari-web/test/controllers/wizard_test.js | 47 ++++++++++++++- ambari-web/test/init_test.js | 25 ++++++++ 10 files changed, 176 insertions(+), 113 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/app/controllers/installer.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/installer.js b/ambari-web/app/controllers/installer.js index 0946ed8..369e163 100644 --- a/ambari-web/app/controllers/installer.js +++ b/ambari-web/app/controllers/installer.js @@ -1022,14 +1022,13 @@ App.InstallerController = App.WizardController.extend(App.Persist, { callback: function () { var dfd = $.Deferred(); var self = this; - this.loadServiceConfigProperties().always(function() { - self.loadServiceConfigGroups(); - self.loadCurrentHostGroups(); - self.loadRecommendationsConfigs(); - self.loadComponentsFromConfigs(); - self.loadConfigThemes().then(function() { - dfd.resolve(); - }); + this.loadServiceConfigGroups(); + this.loadCurrentHostGroups(); + this.loadRecommendationsConfigs(); + this.loadComponentsFromConfigs(); + this.loadConfigThemes().then(function() { + self.loadServiceConfigProperties(); + dfd.resolve(); }); return dfd.promise(); } http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js b/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js index 93ffcaa..64b2065 100644 --- a/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js +++ b/ambari-web/app/controllers/main/admin/kerberos/wizard_controller.js @@ -280,19 +280,15 @@ App.KerberosWizardController = App.WizardController.extend(App.InstallComponent, ], '2': [ { - type: 'async', + type: 'sync', callback: function () { var self = this; - var dfd = $.Deferred(); - this.loadServiceConfigProperties().always(function() { - if (!self.get('stackConfigsLoaded')) { - App.config.loadConfigsFromStack(['KERBEROS']).complete(function() { - self.set('stackConfigsLoaded', true); - }, self); - } - dfd.resolve(); - }); - return dfd.promise(); + this.loadServiceConfigProperties(); + if (!self.get('stackConfigsLoaded')) { + App.config.loadConfigsFromStack(['KERBEROS']).complete(function() { + self.set('stackConfigsLoaded', true); + }, self); + } } } ], http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/app/controllers/main/service/add_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/add_controller.js b/ambari-web/app/controllers/main/service/add_controller.js index dc8f76c..ee7719c 100644 --- a/ambari-web/app/controllers/main/service/add_controller.js +++ b/ambari-web/app/controllers/main/service/add_controller.js @@ -126,10 +126,9 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, { this.loadKerberosDescriptorConfigs().done(function() { self.loadServiceConfigGroups(); self.loadConfigThemes().then(function() { - self.loadServiceConfigProperties().always(function() { - self.loadCurrentHostGroups(); - dfd.resolve(); - }); + self.loadServiceConfigProperties(); + self.loadCurrentHostGroups(); + dfd.resolve(); }); }); return dfd.promise(); @@ -291,19 +290,14 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, { }, loadServiceConfigProperties: function () { - var self = this; - var dfd = $.Deferred(); - this._super().always(function() { - if (!self.get('content.services')) { - self.loadServices(); - } - if (self.get('currentStep') > 1 && self.get('currentStep') < 6) { - self.set('content.skipConfigStep', self.skipConfigStep()); - self.get('isStepDisabled').findProperty('step', 4).set('value', self.get('content.skipConfigStep')); - } - dfd.resolve(); - }); - return dfd.promise(); + this._super(); + if (!this.get('content.services')) { + this.loadServices(); + } + if (this.get('currentStep') > 1 && this.get('currentStep') < 6) { + this.set('content.skipConfigStep', this.skipConfigStep()); + this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep')); + } }, /** @@ -331,16 +325,11 @@ App.AddServiceController = App.WizardController.extend(App.AddSecurityConfigs, { }, saveServiceConfigProperties: function (stepController) { - var dfd = $.Deferred(); - var self = this; - this._super(stepController).always(function() { - if (self.get('currentStep') > 1 && self.get('currentStep') < 6) { - self.set('content.skipConfigStep', self.skipConfigStep()); - self.get('isStepDisabled').findProperty('step', 4).set('value', self.get('content.skipConfigStep')); - } - dfd.resolve(); - }); - return dfd.promise(); + this._super(stepController); + if (this.get('currentStep') > 1 && this.get('currentStep') < 6) { + this.set('content.skipConfigStep', this.skipConfigStep()); + this.get('isStepDisabled').findProperty('step', 4).set('value', this.get('content.skipConfigStep')); + } }, /** http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/app/controllers/wizard.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/wizard.js b/ambari-web/app/controllers/wizard.js index 49bdac6..c3a54cf 100644 --- a/ambari-web/app/controllers/wizard.js +++ b/ambari-web/app/controllers/wizard.js @@ -21,7 +21,7 @@ var App = require('app'); require('models/host'); -App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingMixin, App.Persist, { +App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingMixin, { isStepDisabled: null, @@ -908,26 +908,45 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingM }, /** - * Load serviceConfigProperties from persist - * @return {$.Deferred} + * Load serviceConfigProperties from localStorage */ loadServiceConfigProperties: function () { - var dfd = $.Deferred(); - var self = this; - this.getDecompressedData('serviceConfigProperties').always(function(data) { - if (data && !data.error) { - self.set('content.serviceConfigProperties', data); - } - dfd.resolve(); - }); - return dfd.promise(); + var stackConfigs = App.configsCollection.getAll(); + var serviceConfigProperties = this.getDBProperty('serviceConfigProperties'); + this.set('content.serviceConfigProperties', this.applyStoredConfigs(stackConfigs, serviceConfigProperties)); + }, + + /** + * + * @param {array} configs + * @param {?array} storedConfigs + * @returns {?array} + */ + applyStoredConfigs: function(configs, storedConfigs) { + if (storedConfigs && storedConfigs.length) { + let result = []; + let configsMap = configs.toMapByProperty('id'); + storedConfigs.forEach(function(stored) { + var config = configsMap[stored.id]; + if (config) { + result.push(Object.assign({}, config, stored, {savedValue: null})); + } else if (stored.isUserProperty) { + result.push(Object.assign({}, stored)); + } + }); + return result; + } + return storedConfigs; }, + /** * Save config properties * @param stepController Step7WizardController */ saveServiceConfigProperties: function (stepController) { var serviceConfigProperties = []; + // properties in db should contain only mutable info to avoid localStorage overflow + var dbConfigProperties = []; var fileNamesToUpdate = this.getDBProperty('fileNamesToUpdate') || []; var installedServiceNames = stepController.get('installedServiceNames') || []; var installedServiceNamesMap = installedServiceNames.toWickMap(); @@ -948,9 +967,19 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingM ); configProperty = App.config.mergeStaticProperties(configProperty, _configProperties, [], ['name', 'filename', 'isUserProperty', 'value']); + var dbConfigProperty = { + id: _configProperties.get('id'), + value: _configProperties.get('value'), + isFinal: _configProperties.get('isFinal') + }; + if (_configProperties.get('isUserProperty') || _configProperties.get('filename') === 'capacity-scheduler.xml') { + dbConfigProperty = configProperty; + } if (this.isExcludedConfig(configProperty)) { configProperty.value = ''; + dbConfigProperty.value = ''; } + dbConfigProperties.push(dbConfigProperty); serviceConfigProperties.push(configProperty); }, this); // check for configs that need to update for installed services @@ -969,8 +998,10 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingM } }, this); this.set('content.serviceConfigProperties', serviceConfigProperties); - this.setDBProperty('fileNamesToUpdate', fileNamesToUpdate); - return this.postCompressedData('serviceConfigProperties', serviceConfigProperties); + this.setDBProperties({ + fileNamesToUpdate: fileNamesToUpdate, + serviceConfigProperties: dbConfigProperties + }); }, isExcludedConfig: function (configProperty) { @@ -1435,7 +1466,7 @@ App.WizardController = Em.Controller.extend(App.LocalStorage, App.ThemesMappingM clearServiceConfigProperties: function() { this.get('content.serviceConfigProperties', null); - return this.postCompressedData('serviceConfigProperties', ''); + return this.setDBProperty('serviceConfigProperties', null); }, saveTasksStatuses: function (tasksStatuses) { http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/app/routes/add_kerberos_routes.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/routes/add_kerberos_routes.js b/ambari-web/app/routes/add_kerberos_routes.js index 3dbf050..50d5595 100644 --- a/ambari-web/app/routes/add_kerberos_routes.js +++ b/ambari-web/app/routes/add_kerberos_routes.js @@ -134,9 +134,8 @@ module.exports = App.WizardRoute.extend({ var kerberosStep1controller = router.get('kerberosWizardStep1Controller'); kerberosWizardController.saveKerberosOption(kerberosStep1controller); - kerberosWizardController.clearServiceConfigProperties().always(function() { - router.transitionTo('step2'); - }); + kerberosWizardController.clearServiceConfigProperties(); + router.transitionTo('step2'); } }), @@ -174,15 +173,14 @@ module.exports = App.WizardRoute.extend({ kerberosWizardStep2Controller.get('stepConfigs')[0].get('configs').findProperty('name', 'manage_krb5_conf').set('value', 'false'); } - kerberosWizardController.saveServiceConfigProperties(kerberosWizardStep2Controller, true).always(function() { - kerberosWizardController.clearTasksData(); - if (kerberosWizardController.get('skipClientInstall')) { - kerberosWizardController.setDBProperty('kerberosDescriptorConfigs', null); - router.transitionTo('step4'); - } else { - router.transitionTo('step3'); - } - }); + kerberosWizardController.saveServiceConfigProperties(kerberosWizardStep2Controller, true); + kerberosWizardController.clearTasksData(); + if (kerberosWizardController.get('skipClientInstall')) { + kerberosWizardController.setDBProperty('kerberosDescriptorConfigs', null); + router.transitionTo('step4'); + } else { + router.transitionTo('step3'); + } } }), http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/app/routes/add_service_routes.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/routes/add_service_routes.js b/ambari-web/app/routes/add_service_routes.js index 773042b..89a4a36 100644 --- a/ambari-web/app/routes/add_service_routes.js +++ b/ambari-web/app/routes/add_service_routes.js @@ -231,12 +231,11 @@ module.exports = App.WizardRoute.extend({ router.get('wizardStep7Controller').clearAllRecommendations(); addServiceController.setDBProperty('serviceConfigGroups', undefined); App.ServiceConfigGroup.find().clear(); - addServiceController.clearServiceConfigProperties().always(function() { - if (App.get('isKerberosEnabled')) { - addServiceController.setDBProperty('kerberosDescriptorConfigs', null); - } - router.transitionTo('step4'); - }); + addServiceController.clearServiceConfigProperties(); + if (App.get('isKerberosEnabled')) { + addServiceController.setDBProperty('kerberosDescriptorConfigs', null); + } + router.transitionTo('step4'); }); }); } @@ -290,9 +289,8 @@ module.exports = App.WizardRoute.extend({ } } addServiceController.saveServiceConfigGroups(wizardStep7Controller, true); - addServiceController.saveServiceConfigProperties(wizardStep7Controller).always(function() { - router.transitionTo('step5'); - }); + addServiceController.saveServiceConfigProperties(wizardStep7Controller); + router.transitionTo('step5'); }); } }), http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/app/routes/installer.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/routes/installer.js b/ambari-web/app/routes/installer.js index 1048e8e..daefa48 100644 --- a/ambari-web/app/routes/installer.js +++ b/ambari-web/app/routes/installer.js @@ -379,10 +379,9 @@ module.exports = Em.Route.extend(App.RouterRedirections, { recommendationsConfigs: null, componentsFromConfigs: [] }); - controller.clearServiceConfigProperties().then(function() { - router.transitionTo('step7'); - console.timeEnd('step6 next'); - }); + controller.clearServiceConfigProperties(); + router.transitionTo('step7'); + console.timeEnd('step6 next'); } }); } @@ -435,15 +434,17 @@ module.exports = Em.Route.extend(App.RouterRedirections, { App.set('router.nextBtnClickInProgress', true); var controller = router.get('installerController'); var wizardStep7Controller = router.get('wizardStep7Controller'); - controller.saveServiceConfigProperties(wizardStep7Controller).always(function() { - controller.saveServiceConfigGroups(wizardStep7Controller); - controller.setDBProperty('recommendationsConfigs', wizardStep7Controller.get('recommendationsConfigs')); - controller.saveComponentsFromConfigs(controller.get('content.componentsFromConfigs')); - controller.setDBProperty('recommendationsHostGroup', wizardStep7Controller.get('content.recommendationsHostGroup')); - controller.setDBProperty('masterComponentHosts', wizardStep7Controller.get('content.masterComponentHosts')); - router.transitionTo('step8'); - console.timeEnd('step7 next'); + controller.saveServiceConfigProperties(wizardStep7Controller); + controller.saveServiceConfigGroups(wizardStep7Controller); + controller.setDBProperty('recommendationsConfigs', wizardStep7Controller.get('recommendationsConfigs')); + controller.saveComponentsFromConfigs(controller.get('content.componentsFromConfigs')); + controller.setDBProperty('recommendationsHostGroup', wizardStep7Controller.get('content.recommendationsHostGroup')); + controller.setDBProperty('masterComponentHosts', wizardStep7Controller.get('content.masterComponentHosts')); + App.clusterStatus.setClusterStatus({ + localdb: App.db.data }); + router.transitionTo('step8'); + console.timeEnd('step7 next'); } } }), http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/test/controllers/installer_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/installer_test.js b/ambari-web/test/controllers/installer_test.js index d936ffc..94af88e 100644 --- a/ambari-web/test/controllers/installer_test.js +++ b/ambari-web/test/controllers/installer_test.js @@ -785,23 +785,6 @@ describe('App.InstallerController', function () { }); }); - describe('#loadServiceConfigProperties', function() { - beforeEach(function () { - sinon.stub(installerController, 'getDecompressedData').returns($.Deferred().resolve({ - value: 2 - }).promise()); - }); - afterEach(function () { - installerController.getDecompressedData.restore(); - }); - it ('Should load service config property', function() { - installerController.loadServiceConfigProperties(); - expect(installerController.get('content.serviceConfigProperties')).to.eql({ - "value": 2 - }); - }); - }); - describe('#saveServices', function() { it ('Should return correct names', function() { var stepController = Em.A([ http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/test/controllers/wizard_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/wizard_test.js b/ambari-web/test/controllers/wizard_test.js index 1a00f24..078f8ae 100644 --- a/ambari-web/test/controllers/wizard_test.js +++ b/ambari-web/test/controllers/wizard_test.js @@ -1055,7 +1055,6 @@ describe('App.WizardController', function () { sinon.stub(c, 'setDBProperty', Em.K); sinon.stub(c, 'setDBProperties', Em.K); sinon.stub(c, 'getDBProperty').withArgs('fileNamesToUpdate').returns([]); - sinon.stub(c, 'postCompressedData', Em.K); sinon.stub(App.config, 'shouldSupportFinal').returns(true); }); @@ -1063,7 +1062,6 @@ describe('App.WizardController', function () { c.setDBProperty.restore(); c.setDBProperties.restore(); c.getDBProperty.restore(); - c.postCompressedData.restore(); App.config.shouldSupportFinal.restore(); }); @@ -1743,4 +1741,49 @@ describe('App.WizardController', function () { }); }); + describe('#applyStoredConfigs', function() { + + it('should return null when storedConfigs null', function() { + expect(c.applyStoredConfigs([], null)).to.be.null; + }); + + it('should merged configs when storedConfigs has items', function() { + var storedConfigs = [ + { + id: 1, + value: 'foo', + isFinal: false + }, + { + id: 2, + value: 'foo2', + isFinal: true, + isUserProperty: true + } + ]; + var configs = [ + { + id: 1, + value: '', + isFinal: true + } + ]; + expect(c.applyStoredConfigs(configs, storedConfigs)).to.be.eql([ + { + id: 1, + value: 'foo', + isFinal: false, + savedValue: null + }, + { + id: 2, + value: 'foo2', + isFinal: true, + isUserProperty: true + } + ]); + }); + }); + + }); http://git-wip-us.apache.org/repos/asf/ambari/blob/7d0baec7/ambari-web/test/init_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/init_test.js b/ambari-web/test/init_test.js index 02188ff..db72744 100644 --- a/ambari-web/test/init_test.js +++ b/ambari-web/test/init_test.js @@ -91,6 +91,31 @@ if (!Array.prototype.includes) { }); } +if (typeof Object.assign != 'function') { + Object.assign = function(target, varArgs) { // .length of function is 2 + 'use strict'; + if (target == null) { // TypeError if undefined or null + throw new TypeError('Cannot convert undefined or null to object'); + } + + var to = Object(target); + + for (var index = 1; index < arguments.length; index++) { + var nextSource = arguments[index]; + + if (nextSource != null) { // Skip over if undefined or null + for (var nextKey in nextSource) { + // Avoid bugs when hasOwnProperty is shadowed + if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) { + to[nextKey] = nextSource[nextKey]; + } + } + } + } + return to; + }; +} + Number.isFinite = Number.isFinite || function(value) { return typeof value === 'number' && isFinite(value); };
