AMBARI-6938 Incorrect behavior of 'Abort operation' button after abort request is sent. (Max Shepel via ababiichuk)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7581b9aa Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7581b9aa Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7581b9aa Branch: refs/heads/branch-alerts-dev Commit: 7581b9aa69b22688db70c99e4bff842a58423fef Parents: 35dbbe9 Author: aBabiichuk <ababiic...@cybervisiontech.com> Authored: Wed Aug 20 14:56:34 2014 +0300 Committer: aBabiichuk <ababiic...@cybervisiontech.com> Committed: Wed Aug 20 14:56:34 2014 +0300 ---------------------------------------------------------------------- .../templates/common/host_progress_popup.hbs | 2 +- ambari-web/app/utils/host_progress_popup.js | 43 +++++------ .../test/utils/host_progress_popup_test.js | 76 ++++++++++++++++---- 3 files changed, 80 insertions(+), 41 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/7581b9aa/ambari-web/app/templates/common/host_progress_popup.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/common/host_progress_popup.hbs b/ambari-web/app/templates/common/host_progress_popup.hbs index d60dd30..a80cd65 100644 --- a/ambari-web/app/templates/common/host_progress_popup.hbs +++ b/ambari-web/app/templates/common/host_progress_popup.hbs @@ -49,7 +49,7 @@ {{servicesInfo.name}} </a> {{#if App.supports.abortRequests}} - {{#if servicesInfo.abortable}} + {{#if servicesInfo.isAbortable}} {{view abortIcon servicesInfoBinding="servicesInfo"}} {{/if}} {{/if}} http://git-wip-us.apache.org/repos/asf/ambari/blob/7581b9aa/ambari-web/app/utils/host_progress_popup.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/utils/host_progress_popup.js b/ambari-web/app/utils/host_progress_popup.js index cc687df..724f131 100644 --- a/ambari-web/app/utils/host_progress_popup.js +++ b/ambari-web/app/utils/host_progress_popup.js @@ -68,19 +68,9 @@ App.HostPopup = Em.Object.create({ */ isPopup: null, - /** - * List of aborted requests - * @type {Array} - */ - abortedRequests: [], - abortIcon: Em.View.extend({ tagName: 'i', - classNames: ['abortable', 'abort-icon', 'icon-remove-circle'], - classNameBindings: ['abortClassName'], - abortClassName: function () { - return this.get('servicesInfo.abortable') ? this.get('servicesInfo.abortClassName') : 'hidden'; - }.property('servicesInfo'), + classNames: ['abort-icon', 'icon-remove-circle'], click: function () { this.get('controller').abortRequest(this.get('servicesInfo')); return false; @@ -107,20 +97,30 @@ App.HostPopup = Em.Object.create({ }), /** + * Determines if background operation can be aborted depending on its status + * @param status + * @returns {boolean} + */ + isAbortableByStatus: function (status) { + var statuses = this.get('statusesStyleMap'); + return !Em.keys(statuses).contains(status) || status == 'IN_PROGRESS'; + }, + + /** * Send request to abort operation */ abortRequest: function (serviceInfo) { var requestName = serviceInfo.get('name'); var self = this; App.showConfirmationPopup(function () { - var requestId = serviceInfo.get('id'); - self.get('abortedRequests').push(requestId); + serviceInfo.set('isAbortable', false); App.ajax.send({ name: 'background_operations.abort_request', sender: self, data: { - requestId: requestId, - requestName: requestName + requestId: serviceInfo.get('id'), + requestName: requestName, + serviceInfo: serviceInfo }, success: 'abortRequestSuccessCallback', error: 'abortRequestErrorCallback' @@ -146,8 +146,7 @@ App.HostPopup = Em.Object.create({ * Method called on unsuccessful sending request to abort operation */ abortRequestErrorCallback: function (xhr, textStatus, error, opt, data) { - var abortedRequests = this.get('controller.abortedRequests'); - this.set('controller.abortedRequests', abortedRequests.without(data.requestId)); + data.serviceInfo.set('isAbortable', this.isAbortableByStatus(data.serviceInfo.status)); App.ajax.defaultErrorHandler(xhr, opt.url, 'PUT', xhr.status); }, /** @@ -359,15 +358,7 @@ App.HostPopup = Em.Object.create({ servicesInfo.insertAt(index, updatedService); } if (App.get('supports.abortRequests')) { - var abortable = !Em.keys(statuses).contains(service.status) || service.status == 'IN_PROGRESS'; - if (!abortable) { - var abortedRequests = this.get('abortedRequests'); - this.set('abortedRequests', abortedRequests.without(id)); - } - updatedService.setProperties({ - abortable: abortable, - abortClassName: 'abort' + id - }); + updatedService.set('isAbortable', this.isAbortableByStatus(service.status)); } }, this); this.removeOldServices(servicesInfo, currentServices); http://git-wip-us.apache.org/repos/asf/ambari/blob/7581b9aa/ambari-web/test/utils/host_progress_popup_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/utils/host_progress_popup_test.js b/ambari-web/test/utils/host_progress_popup_test.js index 1198099..3a8a1c1 100644 --- a/ambari-web/test/utils/host_progress_popup_test.js +++ b/ambari-web/test/utils/host_progress_popup_test.js @@ -231,6 +231,33 @@ describe('App.HostPopup', function () { } ]; + var statusCases = [ + { + status: 'FAILED', + result: false + }, + { + status: 'ABORTED', + result: false + }, + { + status: 'TIMEDOUT', + result: false + }, + { + status: 'IN_PROGRESS', + result: true + }, + { + status: 'COMPLETED', + result: false + }, + { + status: 'PENDING', + result: true + } + ]; + describe('#setSelectCount', function () { var itemsForStatusTest = [ { @@ -334,8 +361,15 @@ describe('App.HostPopup', function () { }); }); + describe('#isAbortableByStatus', function () { + statusCases.forEach(function (item) { + it('should return ' + item.result + ' for ' + item.status, function () { + expect(App.HostPopup.isAbortableByStatus(item.status)).to.equal(item.result); + }); + }); + }); + describe('#abortRequest', function () { - var popup; beforeEach(function () { sinon.stub(App.ajax, 'send', Em.K); sinon.spy(App, 'showConfirmationPopup'); @@ -361,7 +395,8 @@ describe('App.HostPopup', function () { }); it('should open popup', function () { App.HostPopup.abortRequestSuccessCallback(null, null, { - requestName: 'name' + requestName: 'name', + serviceInfo: Em.Object.create() }); expect(App.ModalPopup.show.calledOnce).to.be.true; }); @@ -375,9 +410,12 @@ describe('App.HostPopup', function () { return Em.get(App, k); }); sinon.spy(App.ModalPopup, 'show'); - popup.set('controller', Em.Object.create({ - abortedRequests: [0] - })); + }); + afterEach(function () { + App.ModalPopup.show.restore(); + App.ajax.get.restore(); + }); + it('should open popup', function () { popup.abortRequestErrorCallback({ responseText: { message: 'message' @@ -386,18 +424,28 @@ describe('App.HostPopup', function () { }, 'status', 'error', { url: 'url' }, { - requestId: 0 + requestId: 0, + serviceInfo: Em.Object.create() }); - }); - afterEach(function () { - App.ModalPopup.show.restore(); - App.ajax.get.restore(); - }); - it('should open popup', function () { expect(App.ModalPopup.show.calledOnce).to.be.true; }); - it('should remove current request id from abortedRequests', function () { - expect(App.HostPopup.get('abortedRequests')).to.be.empty; + statusCases.forEach(function (item) { + it('should set serviceInfo.isAbortable to' + item.result + ' if status is ' + item.status, function () { + popup.abortRequestErrorCallback({ + responseText: { + message: 'message' + }, + status: 404 + }, 'status', 'error', { + url: 'url' + }, { + requestId: 0, + serviceInfo: Em.Object.create({ + status: item.status + }) + }); + expect(App.HostPopup.isAbortableByStatus(item.status)).to.equal(item.result); + }); }); });