Browse Source

AMBARI-6847. After second canceling of background operation was opened error (Max Shepel via alexantonenko)

Alex Antonenko 10 years ago
parent
commit
1eaf6a9e92

+ 1 - 1
ambari-web/app/templates/common/host_progress_popup.hbs

@@ -46,7 +46,7 @@
                 <div class="operation-name-icon-wrap">
                   <i {{bindAttr class=":service-status servicesInfo.status servicesInfo.icon"}}></i>
                   {{#if App.supports.abortRequests}}
-                    <i {{action abortRequest servicesInfo}} {{translateAttr title="hostPopup.bgop.abortRequest.title"}} class="abort-icon icon-remove-circle hidden"></i>
+                    <i {{action abortRequest servicesInfo}} {{translateAttr title="hostPopup.bgop.abortRequest.title"}} {{bindAttr class="servicesInfo.abortClassName servicesInfo.abortable:abortable :abort-icon :icon-remove-circle :hidden"}}></i>
                   {{/if}}
                   <a href="#">
                     {{servicesInfo.name}}

+ 35 - 7
ambari-web/app/utils/host_progress_popup.js

@@ -67,6 +67,12 @@ App.HostPopup = Em.Object.create({
    */
   isPopup: null,
 
+  /**
+   * List of aborted requests
+   * @type {Array}
+   */
+  abortedRequests: [],
+
   /**
    * Entering point of this component
    * @param {String} serviceName
@@ -264,8 +270,9 @@ App.HostPopup = Em.Object.create({
       this.set("servicesInfo", null);
       this.get("inputData").forEach(function (service) {
         var status = statuses[service.status] || pendingStatus;
+        var id = service.id;
         var newService = Ember.Object.create({
-          id: service.id,
+          id: id,
           displayName: service.displayName,
           progress: service.progress,
           status: App.format.taskStatus(status[0]),
@@ -281,8 +288,19 @@ App.HostPopup = Em.Object.create({
           sourceRequestScheduleId: service.get('sourceRequestScheduleId'),
           contextCommand: service.get('contextCommand')
         });
+        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));
+          }
+          newService.setProperties({
+            abortable: abortable,
+            abortClassName: 'abort' + id
+          });
+        }
         allNewServices.push(newService);
-      });
+      }, this);
       self.set('servicesInfo', allNewServices);
       this.setBackgroundOperationHeader(isServiceListHidden);
     }
@@ -482,10 +500,16 @@ App.HostPopup = Em.Object.create({
         if (App.get('supports.abortRequests')) {
           $(document).on({
             mouseenter: function () {
-              if ($(this).find('.service-status').hasClass(App.format.taskStatus('IN_PROGRESS')) || $(this).find('.service-status').hasClass(App.format.taskStatus('PENDING'))) {
-                App.tooltip($('.abort-icon'));
-                $(this).find('.service-status').addClass('hidden');
-                $(this).find('.abort-icon').removeClass('hidden');
+              var statusIcon = $(this).find('.service-status');
+              var abortIcon = $(this).find('.abort-icon.abortable');
+              if (abortIcon.length > 0) {
+                var id = parseInt(abortIcon.attr('class').split(' ')[0].match(/\d+/)[0]);
+                var abortedRequests = self.get('abortedRequests');
+                if (!(abortedRequests && abortedRequests.contains(id))) {
+                  App.tooltip($('.abort-icon'));
+                  statusIcon.addClass('hidden');
+                  abortIcon.removeClass('hidden');
+                }
               }
             },
             mouseleave: function () {
@@ -1014,6 +1038,8 @@ App.HostPopup = Em.Object.create({
           var requestName = event.context.get('name');
           var self = this;
           App.showConfirmationPopup(function () {
+            var requestId = event.context.get('id');
+            self.get('controller.abortedRequests').push(requestId);
             App.ajax.send({
               name: 'background_operations.abort_request',
               sender: self,
@@ -1038,7 +1064,9 @@ App.HostPopup = Em.Object.create({
         /**
          * Method called on unsuccessful sending request to abort operation
          */
-        abortRequestErrorCallback: function (xhr, textStatus, error, opt) {
+        abortRequestErrorCallback: function (xhr, textStatus, error, opt, data) {
+          var abortedRequests = this.get('controller.abortedRequests');
+          this.set('controller.abortedRequests', abortedRequests.without(data.requestId));
           App.ajax.defaultErrorHandler(xhr, opt.url, 'PUT', xhr.status);
         },
 

+ 19 - 7
ambari-web/test/utils/host_progress_popup_test.js

@@ -373,28 +373,40 @@ describe('App.HostPopup', function () {
   });
 
   describe('#abortRequestErrorCallback', function () {
+    var popup = App.HostPopup.createPopup();
     beforeEach(function () {
       sinon.stub(App.ajax, 'get', function(k) {
         if (k === 'modalPopup') return null;
         return Em.get(App, k);
       });
-      App.HostPopup.createPopup();
       sinon.spy(App.ModalPopup, 'show');
+      sinon.stub(popup, 'get', function(k) {
+        if (k === 'abortedRequests') return [0];
+        return Em.get(popup, k);
+      });
+      popup.get('bodyClass').create().abortRequestErrorCallback({
+        responseText: {
+          message: 'message'
+        },
+        status: 404
+      }, 'status', 'error', {
+        url: 'url'
+      }, {
+        requestId: 0
+      });
     });
     afterEach(function () {
       App.HostPopup.get('isPopup').hide();
       App.ModalPopup.show.restore();
+      popup.get.restore();
       App.ajax.get.restore();
     });
     it('should open popup', function () {
-      App.HostPopup.get('isPopup.bodyClass').create().abortRequestErrorCallback({
-        responseText: {
-          message: 'message'
-        },
-        status: 404
-      }, 'url', 'PUT', 404);
       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;
+    });
   });
 
 });