ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From alexantone...@apache.org
Subject [1/3] ambari git commit: AMBARI-12495. Upgrade status beyond 'Versions' page not being updated (alexantonenko)
Date Wed, 22 Jul 2015 14:02:27 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 81bfa8c67 -> b3fd502c6


AMBARI-12495. Upgrade status beyond 'Versions' page not 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/b3fd502c
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/b3fd502c
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/b3fd502c

Branch: refs/heads/trunk
Commit: b3fd502c6c067ffbbb3bc3a14c1399dcaff574cc
Parents: c3017b9
Author: Alex Antonenko <hiveww@gmail.com>
Authored: Wed Jul 22 16:03:51 2015 +0300
Committer: Alex Antonenko <hiveww@gmail.com>
Committed: Wed Jul 22 17:02:22 2015 +0300

----------------------------------------------------------------------
 .../app/controllers/global/update_controller.js |  12 ++
 .../main/admin/stack_and_upgrade_controller.js  |  12 +-
 .../global/update_controller_test.js            | 144 ++++++++++++++++++-
 .../admin/stack_and_upgrade_controller_test.js  |   3 +-
 4 files changed, 166 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/b3fd502c/ambari-web/app/controllers/global/update_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/update_controller.js b/ambari-web/app/controllers/global/update_controller.js
index cc635d9..bbcd4da 100644
--- a/ambari-web/app/controllers/global/update_controller.js
+++ b/ambari-web/app/controllers/global/update_controller.js
@@ -153,6 +153,7 @@ App.UpdateController = Em.Controller.extend({
       if (!App.get('router.mainAlertInstancesController.isUpdating')) {
         App.updater.run(this, 'updateUnhealthyAlertInstances', 'updateAlertInstances', App.alertInstancesUpdateInterval,
'\/main\/alerts.*');
       }
+      App.updater.run(this, 'updateUpgradeState', 'isWorking', App.bgOperationsUpdateInterval);
     }
   }.observes('isWorking', 'App.router.mainAlertInstancesController.isUpdating'),
 
@@ -554,6 +555,17 @@ App.UpdateController = Em.Controller.extend({
     App.HttpClient.get(App.get('apiPrefix') + '/alert_targets?fields=*', App.alertNotificationMapper,
{
       complete: callback
     });
+  },
+  
+  updateUpgradeState: function (callback) {
+    var currentStateName = App.get('router.currentState.name'),
+      parentStateName = App.get('router.parentState.name'),
+      mainAdminStackAndUpgradeController = App.get('router.mainAdminStackAndUpgradeController');
+    if (!(currentStateName === 'versions' && parentStateName === 'stackAndUpgrade')
&& currentStateName !== 'stackUpgrade' && App.get('upgradeIsNotFinished')
&& !mainAdminStackAndUpgradeController.get('isLoadUpgradeDataPending')) {
+      mainAdminStackAndUpgradeController.loadUpgradeData(true).done(callback);
+    } else {
+      callback();
+    }
   }
 
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3fd502c/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js b/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
index 309ab5e..49a1f85 100644
--- a/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
+++ b/ambari-web/app/controllers/main/admin/stack_and_upgrade_controller.js
@@ -83,6 +83,8 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
    */
   taskDetailsProperties: ['status', 'stdout', 'stderr', 'error_log', 'host_name', 'output_log'],
 
+  isLoadUpgradeDataPending: false,
+
   /**
    * path to the mock json
    * @type {String}
@@ -181,13 +183,15 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
    * @param {boolean} onlyState
    */
   loadUpgradeData: function (onlyState) {
-    var upgradeId = this.get('upgradeId');
-    var deferred = $.Deferred();
+    var upgradeId = this.get('upgradeId'),
+      deferred = $.Deferred(),
+      self = this;
 
     if (Em.isNone(upgradeId)) {
       deferred.resolve();
       console.log('Upgrade in INIT state');
     } else {
+      this.set('isLoadUpgradeDataPending', true);
       App.ajax.send({
         name: (onlyState) ? 'admin.upgrade.state' : 'admin.upgrade.data',
         sender: this,
@@ -195,7 +199,9 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
           id: upgradeId
         },
         success: 'loadUpgradeDataSuccessCallback'
-      }).then(deferred.resolve);
+      }).then(deferred.resolve).complete(function () {
+          self.set('isLoadUpgradeDataPending', false);
+        });
     }
     return deferred.promise();
   },

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3fd502c/ambari-web/test/controllers/global/update_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/global/update_controller_test.js b/ambari-web/test/controllers/global/update_controller_test.js
index 7237bf6..06edcf3 100644
--- a/ambari-web/test/controllers/global/update_controller_test.js
+++ b/ambari-web/test/controllers/global/update_controller_test.js
@@ -62,7 +62,7 @@ describe('App.UpdateController', function () {
 
     it('isWorking = true', function () {
       controller.set('isWorking', true);
-      expect(App.updater.run.callCount).to.equal(10);
+      expect(App.updater.run.callCount).to.equal(11);
     });
   });
 
@@ -263,4 +263,146 @@ describe('App.UpdateController', function () {
       expect(App.hostsMapper.setMetrics.calledWith({})).to.be.true;
     });
   });
+
+  describe('#updateUpgradeState()', function () {
+
+    var cases = [
+        {
+          currentStateName: 'versions',
+          parentStateName: 'stackAndUpgrade',
+          upgradeIsNotFinished: true,
+          isLoadUpgradeDataPending: true,
+          loadUpgradeDataCallCount: 0,
+          callbackCallCount: 1,
+          title: 'stack versions page'
+        },
+        {
+          currentStateName: 'stackUpgrade',
+          parentStateName: null,
+          upgradeIsNotFinished: true,
+          isLoadUpgradeDataPending: true,
+          loadUpgradeDataCallCount: 0,
+          callbackCallCount: 1,
+          title: 'upgrade popup open'
+        },
+        {
+          currentStateName: 'versions',
+          parentStateName: null,
+          upgradeIsNotFinished: true,
+          isLoadUpgradeDataPending: false,
+          loadUpgradeDataCallCount: 1,
+          callbackCallCount: 0,
+          title: 'another page with \'versions\' name'
+        },
+        {
+          currentStateName: 'versions',
+          parentStateName: null,
+          upgradeIsNotFinished: false,
+          isLoadUpgradeDataPending: false,
+          loadUpgradeDataCallCount: 0,
+          callbackCallCount: 1,
+          title: 'another page with \'versions\' name, upgrade finished'
+        },
+        {
+          currentStateName: 'versions',
+          parentStateName: null,
+          upgradeIsNotFinished: true,
+          isLoadUpgradeDataPending: true,
+          loadUpgradeDataCallCount: 0,
+          callbackCallCount: 1,
+          title: 'another page with \'versions\' name, another update upgrade request not
completed'
+        },
+        {
+          currentStateName: 'services',
+          parentStateName: 'stackAndUpgrade',
+          upgradeIsNotFinished: true,
+          isLoadUpgradeDataPending: false,
+          loadUpgradeDataCallCount: 1,
+          callbackCallCount: 0,
+          title: 'another page from \'Stack and Versions\' section'
+        },
+        {
+          currentStateName: 'services',
+          parentStateName: 'stackAndUpgrade',
+          upgradeIsNotFinished: false,
+          isLoadUpgradeDataPending: false,
+          loadUpgradeDataCallCount: 0,
+          callbackCallCount: 1,
+          title: 'another page from \'Stack and Versions\' section, upgrade finished'
+        },
+        {
+          currentStateName: 'services',
+          parentStateName: 'stackAndUpgrade',
+          upgradeIsNotFinished: true,
+          isLoadUpgradeDataPending: true,
+          loadUpgradeDataCallCount: 0,
+          callbackCallCount: 1,
+          title: 'another page from \'Stack and Versions\' section, another update upgrade
request not completed'
+        },
+        {
+          currentStateName: 'widgets',
+          parentStateName: 'dashboard',
+          upgradeIsNotFinished: true,
+          isLoadUpgradeDataPending: false,
+          loadUpgradeDataCallCount: 1,
+          callbackCallCount: 0,
+          title: 'not \'Stack and Versions\' section'
+        },
+        {
+          currentStateName: 'widgets',
+          parentStateName: 'dashboard',
+          upgradeIsNotFinished: false,
+          isLoadUpgradeDataPending: false,
+          loadUpgradeDataCallCount: 0,
+          callbackCallCount: 1,
+          title: 'not \'Stack and Versions\' section, upgrade finished'
+        },
+        {
+          currentStateName: 'widgets',
+          parentStateName: 'dashboard',
+          upgradeIsNotFinished: true,
+          isLoadUpgradeDataPending: true,
+          loadUpgradeDataCallCount: 0,
+          callbackCallCount: 1,
+          title: 'not \'Stack and Versions\' section, another update upgrade request not
completed'
+        }
+      ],
+      mock = {
+        callback: Em.K,
+        loadUpgradeData: function () {
+          return {
+            done: Em.K
+          };
+        }
+      },
+      mainAdminStackAndUpgradeController = App.get('router.mainAdminStackAndUpgradeController'),
+      appGetMock;
+
+    beforeEach(function () {
+      sinon.spy(mock, 'callback');
+      sinon.spy(mock, 'loadUpgradeData');
+      appGetMock = sinon.stub(App, 'get');
+    });
+
+    afterEach(function () {
+      mock.callback.restore();
+      mock.loadUpgradeData.restore();
+      App.get.restore();
+      appGetMock.restore();
+    });
+
+    cases.forEach(function (item) {
+      it(item.title, function () {
+        appGetMock.withArgs('router.mainAdminStackAndUpgradeController').returns(Em.Object.create({
+          loadUpgradeData: mock.loadUpgradeData,
+          isLoadUpgradeDataPending: item.isLoadUpgradeDataPending
+        })).withArgs('upgradeIsNotFinished').returns(item.upgradeIsNotFinished);
+        controller.updateUpgradeState(mock.callback);
+        expect(mock.loadUpgradeData.callCount).to.equal(item.loadUpgradeDataCallCount);
+        expect(mock.callback.callCount).to.equal(item.callbackCallCount);
+      });
+    });
+
+  });
+
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/b3fd502c/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js b/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
index a37e115..8fe8364 100644
--- a/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
+++ b/ambari-web/test/controllers/main/admin/stack_and_upgrade_controller_test.js
@@ -113,7 +113,8 @@ describe('App.MainAdminStackAndUpgradeController', function() {
   describe("#loadUpgradeData()", function() {
     beforeEach(function () {
       sinon.stub(App.ajax, 'send').returns({
-        then: Em.K
+        then: Em.K,
+        complete: Em.K
       });
     });
     afterEach(function () {


Mime
View raw message