Explorar o código

AMBARI-15049 Sometimes background operations have incorrect order. (atkach)

Andrii Tkach %!s(int64=9) %!d(string=hai) anos
pai
achega
7f3928bad9

+ 11 - 4
ambari-web/app/controllers/global/background_operations_controller.js

@@ -261,19 +261,26 @@ App.BackgroundOperationsController = Em.Controller.extend({
     this.set('isShowMoreAvailable', countGot >= countIssued);
     this.set('serviceTimestamp', App.dateTimeWithTimeZone());
   },
+
   isShowMoreAvailable: null,
+
   /**
    * remove old requests
    * as API returns 10, or  20 , or 30 ...etc latest request, the requests that absent in response should be removed
    * @param currentRequestIds
    */
   removeOldRequests: function (currentRequestIds) {
-    this.get('services').forEach(function (service, index, services) {
-      if (!currentRequestIds.contains(service.id)) {
-        services.splice(index, 1);
+    var services = this.get('services');
+
+    for (var i = 0, l = services.length; i < l; i++) {
+      if (!currentRequestIds.contains(services[i].id)) {
+        services.splice(i, 1);
+        i--;
+        l--;
       }
-    });
+    }
   },
+
   /**
    * identify whether request is running by task counters
    * @param request

+ 6 - 4
ambari-web/app/utils/host_progress_popup.js

@@ -523,11 +523,13 @@ App.HostPopup = Em.Object.create({
    * @method removeOldServices
    */
   removeOldServices: function (services, currentServicesIds) {
-    services.forEach(function (service, index, services) {
-      if (!currentServicesIds.contains(service.id)) {
-        services.removeAt(index, 1);
+    for (var i = 0, l = services.length; i < l; i++) {
+      if (!currentServicesIds.contains(services[i].id)) {
+        services.splice(i, 1);
+        i--;
+        l--;
       }
-    });
+    }
   },
 
   /**

+ 16 - 0
ambari-web/test/controllers/global/background_operations_test.js

@@ -310,6 +310,22 @@ describe('App.BackgroundOperationsController', function () {
         result: [
           {id: 2}
         ]
+      },
+      {
+        title: 'two old request and two current',
+        content: {
+          currentRequestIds: [3, 4],
+          services: [
+            {id: 1},
+            {id: 2},
+            {id: 3},
+            {id: 4}
+          ]
+        },
+        result: [
+          {id: 3},
+          {id: 4}
+        ]
       }
     ];