Browse Source

AMBARI-9818 Rolling Upgrade wizard: redundant update calls. (ababiichuk)

aBabiichuk 10 years ago
parent
commit
f701b9c7be

+ 3 - 2
ambari-web/app/controllers/main/alerts/alert_instances_controller.js

@@ -142,8 +142,9 @@ App.MainAlertInstancesController = Em.Controller.extend({
     var self = this;
     if (this.get('isUpdating')) {
       this.set('updateTimer', setTimeout(function () {
-        self.fetchAlertInstances();
-        self.scheduleUpdate();
+        self.fetchAlertInstances().complete(function() {
+          self.scheduleUpdate();
+        });
       }, App.get('alertInstancesUpdateInterval')));
     }
     else {

+ 22 - 15
ambari-web/app/views/main/admin/stack_upgrade/upgrade_task_view.js

@@ -106,10 +106,11 @@ App.upgradeTaskView = Em.View.extend({
     var self = this;
 
     if (this.get('content.isExpanded') || this.get('outsideView')) {
-      this.getTaskDetails();
-      this.set('timer', setTimeout(function () {
-        self.doPolling();
-      }, App.bgOperationsUpdateInterval));
+      this.getTaskDetails().done(function() {
+        self.set('timer', setTimeout(function () {
+          self.doPolling();
+        }, App.bgOperationsUpdateInterval));
+      });
     } else {
       clearTimeout(this.get('timer'));
     }
@@ -117,19 +118,25 @@ App.upgradeTaskView = Em.View.extend({
 
   /**
    * request task details from server
-   * @return {$.ajax|null}
+   * @return {$.Deferred}
    */
   getTaskDetails: function () {
-    if (Em.isNone(this.get('content'))) return null;
-    return App.ajax.send({
-      name: 'admin.upgrade.task',
-      sender: this,
-      data: {
-        upgradeId: this.get('content.request_id'),
-        taskId: this.get('content.id')
-      },
-      success: 'getTaskDetailsSuccessCallback'
-    });
+    var deferred = $.Deferred();
+
+    if (Em.isNone(this.get('content'))) {
+      deferred.resolve();
+    } else {
+      App.ajax.send({
+        name: 'admin.upgrade.task',
+        sender: this,
+        data: {
+          upgradeId: this.get('content.request_id'),
+          taskId: this.get('content.id')
+        },
+        success: 'getTaskDetailsSuccessCallback'
+      }).then(deferred.resolve);
+    }
+    return deferred.promise();
   },
 
   /**

+ 4 - 3
ambari-web/app/views/main/admin/stack_upgrade/upgrade_wizard_view.js

@@ -217,8 +217,8 @@ App.upgradeWizardView = Em.View.extend({
     if (App.get('clusterName')) {
       this.get('controller').loadUpgradeData().done(function () {
         self.set('isLoaded', true);
+        self.doPolling();
       });
-      this.doPolling();
     }
   }.observes('App.clusterName'),
 
@@ -243,8 +243,9 @@ App.upgradeWizardView = Em.View.extend({
   doPolling: function () {
     var self = this;
     this.set('updateTimer', setTimeout(function () {
-      self.get('controller').loadUpgradeData();
-      self.doPolling();
+      self.get('controller').loadUpgradeData().done(function() {
+        self.doPolling();
+      });
     }, App.bgOperationsUpdateInterval));
   },
 

+ 10 - 3
ambari-web/test/views/main/admin/stack_upgrade/upgrade_task_view_test.js

@@ -66,7 +66,13 @@ describe('App.upgradeTaskView', function () {
 
   describe("#doPolling()", function () {
     beforeEach(function () {
-      sinon.stub(view, 'getTaskDetails', Em.K);
+      sinon.stub(view, 'getTaskDetails', function() {
+        return {
+          done: function (callback) {
+            callback();
+          }
+        }
+      });
       sinon.spy(view, 'doPolling');
       this.clock = sinon.useFakeTimers();
     });
@@ -120,8 +126,9 @@ describe('App.upgradeTaskView', function () {
 
   describe("#getTaskDetails()", function () {
     beforeEach(function () {
-      sinon.stub(App.ajax, 'send', Em.K);
-
+      sinon.stub(App.ajax, 'send').returns({
+        then: Em.K
+      });
     });
     afterEach(function () {
       App.ajax.send.restore();

+ 7 - 1
ambari-web/test/views/main/admin/stack_upgrade/upgrade_wizard_view_test.js

@@ -139,7 +139,13 @@ describe('App.upgradeWizardView', function () {
 
   describe("#doPolling()", function () {
     beforeEach(function () {
-      sinon.stub(view.get('controller'), 'loadUpgradeData', Em.K);
+      sinon.stub(view.get('controller'), 'loadUpgradeData', function () {
+        return {
+          done: function (callback) {
+            callback();
+          }
+        }
+      });
       sinon.spy(view, 'doPolling');
       this.clock = sinon.useFakeTimers();
     });