AMBARI-19319 Disable auto start before RU/EU and enable during finalization phase. (atkach)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/4fc44e27 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/4fc44e27 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/4fc44e27 Branch: refs/heads/branch-dev-patch-upgrade Commit: 4fc44e277ac396f6967402da767350a4ee2bf47d Parents: 106851b Author: Andrii Tkach <[email protected]> Authored: Tue Jan 3 14:05:34 2017 +0200 Committer: Andrii Tkach <[email protected]> Committed: Tue Jan 3 14:05:34 2017 +0200 ---------------------------------------------------------------------- .../main/admin/stack_and_upgrade_controller.js | 46 +++++- ambari-web/app/messages.js | 2 + .../admin/stack_and_upgrade_controller_test.js | 150 ++++++++++++++++--- 3 files changed, 170 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/4fc44e27/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js b/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js index 59f2a90..93b9f1f 100644 --- a/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js +++ b/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js @@ -1363,11 +1363,44 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage, error: "runPreUpgradeCheckError" }); } else { - this.upgrade(params); + this.showAutoStartDisableModal(params); } }, /** + * + * @param {object} upgradeParams + */ + showAutoStartDisableModal: function(upgradeParams) { + var self = this; + return App.showAlertPopup( + Em.I18n.t('common.warning'), + Em.I18n.t('admin.serviceAutoStart.disabled.popup.body'), + function() { + self.switchServiceAutoStartTo(false); + self.upgrade(upgradeParams); + } + ); + }, + + /** + * + * @param {boolean} state + */ + switchServiceAutoStartTo: function(state) { + var autoStartController = App.router.get('mainAdminServiceAutoStartController'); + return autoStartController.load().done(function() { + var clusterConfigs = autoStartController.get('clusterConfigs'); + if (clusterConfigs && clusterConfigs.recovery_enabled !== String(state)) { + clusterConfigs.recovery_enabled = String(state); + autoStartController.saveClusterConfigs(clusterConfigs); + autoStartController.set('servicesAutoStart', state); + autoStartController.syncStatus(); + } + }); + }, + + /** * success callback of <code>runPreUpgradeCheckSuccess()</code> * if there are some fails - it shows popup else run upgrade * @param data {object} @@ -1377,7 +1410,9 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage, */ runPreUpgradeCheckSuccess: function (data, opt, params) { var self = this; - if (data.items.someProperty('UpgradeChecks.status', 'FAIL') || data.items.someProperty('UpgradeChecks.status', 'WARNING') || data.items.someProperty('UpgradeChecks.status', 'BYPASS')) { + if (data.items.someProperty('UpgradeChecks.status', 'FAIL') || + data.items.someProperty('UpgradeChecks.status', 'WARNING') || + data.items.someProperty('UpgradeChecks.status', 'BYPASS')) { this.set('requestInProgress', false); var hasFails = data.items.someProperty('UpgradeChecks.status', 'FAIL'), header = Em.I18n.t('popup.clusterCheck.Upgrade.header').format(params.label), @@ -1400,11 +1435,11 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage, bypassedFailures: bypassedFailures, noCallbackCondition: hasFails, callback: function () { - self.upgrade(params); + self.showAutoStartDisableModal(params); } }, configs, params.label); } else { - this.upgrade(params); + this.showAutoStartDisableModal(params); } }, @@ -1805,6 +1840,9 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage, * @param status */ setUpgradeItemStatus: function(item, status) { + if (this.get('isFinalizeItem') && status === 'COMPLETED') { + this.switchServiceAutoStartTo(true); + } this.set('requestInProgress', true); return App.ajax.send({ name: 'admin.upgrade.upgradeItem.setState', http://git-wip-us.apache.org/repos/asf/ambari/blob/4fc44e27/ambari-web/app/messages.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/messages.js b/ambari-web/app/messages.js index 6296d55..bba9e84 100644 --- a/ambari-web/app/messages.js +++ b/ambari-web/app/messages.js @@ -3332,6 +3332,8 @@ Em.I18n.translations = { 'Click <b>Save</b> to commit the change or <b>Discard</b> to revert your changes', 'admin.serviceAutoStart.save.popup.transition.title': 'Warning', 'admin.serviceAutoStart.save.popup.transition.body': 'You have unsaved changes', + 'admin.serviceAutoStart.disabled.popup.body': 'During RU/EU auto-start of service components will be disabled.' + + ' Auto-start will be enabled after upgrade is completed.', 'reset.ui.states': 'Reset UI State', 'reset.ui.states.body': 'You should proceed only if the UI is misbehaving (such as incorrect navigation upon login, UI is stuck and won't load, etc.). Are you sure you want to reset the UI state?', http://git-wip-us.apache.org/repos/asf/ambari/blob/4fc44e27/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js b/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js index de2bf3b..3acf1dd 100644 --- a/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js +++ b/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js @@ -502,11 +502,11 @@ describe('App.MainAdminStackAndUpgradeController', function() { ]; beforeEach(function () { sinon.stub(App, 'showClusterCheckPopup', Em.K); - sinon.stub(controller, 'upgrade', Em.K); + sinon.stub(controller, 'showAutoStartDisableModal', Em.K); }); afterEach(function () { App.showClusterCheckPopup.restore(); - controller.upgrade.restore(); + controller.showAutoStartDisableModal.restore(); }); cases.forEach(function (item) { it(item.title, function () { @@ -521,7 +521,7 @@ describe('App.MainAdminStackAndUpgradeController', function() { label: 'name' } ); - expect(controller.upgrade.callCount).to.equal(item.upgradeCalledCount); + expect(controller.showAutoStartDisableModal.callCount).to.equal(item.upgradeCalledCount); expect(App.showClusterCheckPopup.callCount).to.equal(item.showClusterCheckPopupCalledCount); if (item.check.id === 'CONFIG_MERGE') { expect(App.showClusterCheckPopup.firstCall.args[2]).to.eql(item.configs); @@ -1238,31 +1238,57 @@ describe('App.MainAdminStackAndUpgradeController', function() { }); describe("#setUpgradeItemStatus()", function () { - var item; - beforeEach(function () { - item = Em.Object.create({ - request_id: 1, - stage_id: 1, - group_id: 1 - }); - controller.setUpgradeItemStatus(item, 'PENDING'); - this.callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgradeItem.setState')[0]; - }); - it('request-data is valid', function () { - expect(this.callArgs.data).to.be.eql({upgradeId: 1, itemId: 1, groupId: 1, status: 'PENDING'}); - }); - it('request-name is valid', function () { - expect(this.callArgs.name).to.be.equal('admin.upgrade.upgradeItem.setState'); + beforeEach(function() { + sinon.stub(controller, 'switchServiceAutoStartTo'); }); - it('request-sendeer is valid', function () { - expect(this.callArgs.sender).to.be.eql(controller); + afterEach(function() { + controller.switchServiceAutoStartTo.restore(); }); - it('callback is called', function () { - expect(this.callArgs.callback).to.be.called; + + describe('#PENDING status', function() { + var item; + beforeEach(function () { + item = Em.Object.create({ + request_id: 1, + stage_id: 1, + group_id: 1 + }); + controller.setUpgradeItemStatus(item, 'PENDING'); + this.callArgs = testHelpers.findAjaxRequest('name', 'admin.upgrade.upgradeItem.setState')[0]; + }); + + it('request-data is valid', function () { + expect(this.callArgs.data).to.be.eql({upgradeId: 1, itemId: 1, groupId: 1, status: 'PENDING'}); + }); + it('request-name is valid', function () { + expect(this.callArgs.name).to.be.equal('admin.upgrade.upgradeItem.setState'); + }); + it('request-sendeer is valid', function () { + expect(this.callArgs.sender).to.be.eql(controller); + }); + it('callback is called', function () { + expect(this.callArgs.callback).to.be.called; + }); + it('item.status is PENDING', function () { + expect(item.get('status')).to.equal('PENDING'); + }); + it('switchServiceAutoStartTo should not be called', function () { + expect(controller.switchServiceAutoStartTo.called).to.be.false; + }); }); - it('item.status is PENDING', function () { - expect(item.get('status')).to.equal('PENDING'); + + describe('#COMPLETED status', function() { + it('switchServiceAutoStartTo should not be called', function () { + var item = Em.Object.create({ + request_id: 1, + stage_id: 1, + group_id: 1 + }); + controller.set('isFinalizeItem', true); + controller.setUpgradeItemStatus(item, 'COMPLETED'); + expect(controller.switchServiceAutoStartTo.calledOnce).to.be.true; + }); }); }); @@ -3292,4 +3318,80 @@ describe('App.MainAdminStackAndUpgradeController', function() { }); }); + describe('#showAutoStartDisableModal', function() { + + beforeEach(function() { + sinon.spy(App, 'showAlertPopup'); + sinon.stub(controller, 'switchServiceAutoStartTo'); + sinon.stub(controller, 'upgrade'); + }); + + afterEach(function() { + App.showAlertPopup.restore(); + controller.switchServiceAutoStartTo.restore(); + controller.upgrade.restore(); + }); + + it('showAlertPopup should be called', function() { + controller.showAutoStartDisableModal({}); + expect(App.showAlertPopup.calledOnce).to.be.true; + }); + + it('switchServiceAutoStartTo should be called', function() { + var popup = controller.showAutoStartDisableModal({}); + popup.onPrimary(); + expect(controller.switchServiceAutoStartTo.calledWith(false)).to.be.true; + }); + + it('upgrade should be called', function() { + var popup = controller.showAutoStartDisableModal({}); + popup.onPrimary(); + expect(controller.upgrade.calledWith({})).to.be.true; + }); + }); + + describe('#switchServiceAutoStartTo', function() { + var mockController = Em.Object.create({ + load: Em.K, + saveClusterConfigs: Em.K, + syncStatus: Em.K + }); + + beforeEach(function() { + sinon.stub(App.router, 'get').returns(mockController); + sinon.stub(mockController, 'load').returns({ + done: Em.clb + }); + sinon.stub(mockController, 'saveClusterConfigs'); + sinon.stub(mockController, 'syncStatus'); + }); + + afterEach(function() { + App.router.get.restore(); + mockController.load.restore(); + mockController.saveClusterConfigs.restore(); + mockController.syncStatus.restore(); + }); + + it('should not update value on server when state have not been changed', function() { + mockController.set('servicesAutoStart', true); + mockController.set('clusterConfigs', {recovery_enabled: 'true'}); + controller.switchServiceAutoStartTo(true); + expect(mockController.load.calledOnce).to.be.true; + expect(mockController.saveClusterConfigs.called).to.be.false; + expect(mockController.syncStatus.called).to.be.false; + expect(mockController.get('servicesAutoStart')).to.be.true; + }); + + it('should update value on server when state been changed', function() { + mockController.set('servicesAutoStart', true); + mockController.set('clusterConfigs', {recovery_enabled: 'true'}); + controller.switchServiceAutoStartTo(false); + expect(mockController.load.calledOnce).to.be.true; + expect(mockController.saveClusterConfigs.calledWith({recovery_enabled: 'false'})).to.be.true; + expect(mockController.syncStatus.calledOnce).to.be.true; + expect(mockController.get('servicesAutoStart')).to.be.false; + }); + }); + });
