Repository: ambari Updated Branches: refs/heads/trunk 433286dc6 -> 3c4595e7a
AMBARI-17713. Install packages: status icon and progress percentage aren't being updated (alexantonenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/3c4595e7 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/3c4595e7 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/3c4595e7 Branch: refs/heads/trunk Commit: 3c4595e7a8c2d29b2f661d03fd4bf586ea52a225 Parents: f85e55c Author: Alex Antonenko <[email protected]> Authored: Thu Jul 14 18:12:13 2016 +0300 Committer: Alex Antonenko <[email protected]> Committed: Fri Jul 15 09:00:57 2016 +0300 ---------------------------------------------------------------------- .../progress_popup_controller.js | 27 ++++++++++++++++++-- .../progress_popup_controller_test.js | 26 +++++++++++++++++-- 2 files changed, 49 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/3c4595e7/ambari-web/app/controllers/main/admin/highAvailability/progress_popup_controller.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/admin/highAvailability/progress_popup_controller.js b/ambari-web/app/controllers/main/admin/highAvailability/progress_popup_controller.js index 06dd1cd..7231e5c 100644 --- a/ambari-web/app/controllers/main/admin/highAvailability/progress_popup_controller.js +++ b/ambari-web/app/controllers/main/admin/highAvailability/progress_popup_controller.js @@ -105,7 +105,7 @@ App.HighAvailabilityProgressPopupController = Ember.Controller.extend({ /** * Send AJAX request to get hosts tasks data */ - getHosts: function () { + getHosts: function (successCallback) { var requestIds = this.get('requestIds'); var stageId = this.get('stageId'); var name = 'background_operations.get_by_request'; @@ -115,6 +115,9 @@ App.HighAvailabilityProgressPopupController = Ember.Controller.extend({ stageId = '0'; } } + if (Em.isNone(successCallback)) { + successCallback = 'onGetHostsSuccess'; + } requestIds.forEach(function (requestId) { App.ajax.send({ name: name, @@ -123,10 +126,27 @@ App.HighAvailabilityProgressPopupController = Ember.Controller.extend({ requestId: requestId, stageId: stageId }, - success: 'onGetHostsSuccess' + success: successCallback }) }, this); }, + + doPolling: function () { + var self = this; + this.set('progressController.logs', []); + setTimeout(function () { + self.getHosts('doPollingSuccessCallback'); + }, App.bgOperationsUpdateInterval); + }, + + doPollingSuccessCallback: function (data) { + this.set('hostsData', [data]); + var hostsData = this.get('hostsData'); + this.set('progressController.logs', data.tasks); + if (this.isRequestRunning(hostsData)) { + this.doPolling(); + } + }, /** * Callback for <code>getHosts</code> request @@ -140,6 +160,9 @@ App.HighAvailabilityProgressPopupController = Ember.Controller.extend({ this.calculateHostsData(hostsData); App.HostPopup.initPopup(popupTitle, this); if (this.isRequestRunning(hostsData)) { + if (this.get('progressController.name') === 'mainAdminStackAndUpgradeController') { + this.doPolling(); + } this.addObserver('progressController.logs.length', this, 'getDataFromProgressController'); } } http://git-wip-us.apache.org/repos/asf/ambari/blob/3c4595e7/ambari-web/test/controllers/main/admin/highAvailability/progress_popup_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/admin/highAvailability/progress_popup_controller_test.js b/ambari-web/test/controllers/main/admin/highAvailability/progress_popup_controller_test.js index c7ee374..364d9b0 100644 --- a/ambari-web/test/controllers/main/admin/highAvailability/progress_popup_controller_test.js +++ b/ambari-web/test/controllers/main/admin/highAvailability/progress_popup_controller_test.js @@ -168,18 +168,23 @@ describe('App.HighAvailabilityProgressPopupController', function () { var cases = [ { name: 'background_operations.get_by_request', + success: 'onGetHostsSuccess', title: 'default background operation polling' }, { stageId: 0, name: 'common.request.polling', stageIdPassed: '0', + successCallback: 's', + success: 's', title: 'polling by stage, stageId = 0' }, { stageId: 1, name: 'common.request.polling', stageIdPassed: 1, + successCallback: null, + success: 'onGetHostsSuccess', title: 'polling by stage' } ]; @@ -192,7 +197,7 @@ describe('App.HighAvailabilityProgressPopupController', function () { requestIds: [1, 2], stageId: item.stageId }); - controller.getHosts(); + controller.getHosts(item.successCallback); this.bgArgs = testHelpers.filterAjaxRequests('name', 'background_operations.get_by_request'); this.pollingArgs = testHelpers.filterAjaxRequests('name', 'common.request.polling'); this.args = item.name === 'background_operations.get_by_request' ? this.bgArgs : this.pollingArgs; @@ -218,6 +223,14 @@ describe('App.HighAvailabilityProgressPopupController', function () { expect(this.args[1][0].data.stageId).to.eql(item.stageIdPassed); }); + it('success callback for first request', function () { + expect(this.args[0][0].success).to.equal(item.success); + }); + + it('success callback for second request', function () { + expect(this.args[1][0].success).to.equal(item.success); + }); + }); }); @@ -269,12 +282,16 @@ describe('App.HighAvailabilityProgressPopupController', function () { sinon.stub(App.HostPopup, 'initPopup'); sinon.stub(controller, 'isRequestRunning').returns(true); sinon.stub(controller, 'addObserver'); + sinon.stub(controller, 'doPolling'); sinon.stub(spinner, 'hide'); controller.setProperties({ requestIds: [1], hostsData: [], popupTitle: 'popupTitle', - spinnerPopup: spinner + spinnerPopup: spinner, + progressController: { + name: 'mainAdminStackAndUpgradeController' + } }); controller.onGetHostsSuccess({}); }); @@ -284,6 +301,7 @@ describe('App.HighAvailabilityProgressPopupController', function () { App.HostPopup.initPopup.restore(); controller.isRequestRunning.restore(); controller.addObserver.restore(); + controller.doPolling.restore(); spinner.hide.restore(); }); @@ -302,6 +320,10 @@ describe('App.HighAvailabilityProgressPopupController', function () { it("spinnerPopup.hide should be called", function() { expect(spinner.hide.calledOnce).to.be.true; }); + + it("doPolling should be called", function() { + expect(controller.doPolling.calledOnce).to.be.true; + }); }); describe("#calculateHostsData()", function () {
