ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From atk...@apache.org
Subject ambari git commit: AMBARI-13799 Label in Express Upgrade Window shows "Downgrade" while doing upgrade after downgrade. (atkach)
Date Tue, 10 Nov 2015 11:14:20 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk d02ec979f -> 7b539281d


AMBARI-13799 Label in Express Upgrade Window shows "Downgrade" while doing upgrade after downgrade.
(atkach)


Project: http://git-wip-us.apache.org/repos/asf/ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/7b539281
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/7b539281
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/7b539281

Branch: refs/heads/trunk
Commit: 7b539281da23aad7a25c0ed25e666c21c4b07518
Parents: d02ec97
Author: Andrii Tkach <atkach@hortonworks.com>
Authored: Tue Nov 10 13:09:53 2015 +0200
Committer: Andrii Tkach <atkach@hortonworks.com>
Committed: Tue Nov 10 13:14:10 2015 +0200

----------------------------------------------------------------------
 .../controllers/global/cluster_controller.js    | 19 +---
 .../main/admin/stack_and_upgrade_controller.js  | 28 ++++++
 .../global/cluster_controller_test.js           | 59 ++++++++++++
 .../admin/stack_and_upgrade_controller_test.js  | 99 +++++++++++++-------
 4 files changed, 152 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/7b539281/ambari-web/app/controllers/global/cluster_controller.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/global/cluster_controller.js b/ambari-web/app/controllers/global/cluster_controller.js
index d36811e..65aa77e 100644
--- a/ambari-web/app/controllers/global/cluster_controller.js
+++ b/ambari-web/app/controllers/global/cluster_controller.js
@@ -295,30 +295,13 @@ App.ClusterController = Em.Controller.extend(App.ReloadPopupMixin, {
       var upgradeController = App.router.get('mainAdminStackAndUpgradeController');
       var lastUpgradeData = data.items.sortProperty('Upgrade.request_id').pop();
       var dbUpgradeState = App.db.get('MainAdminStackAndUpgrade', 'upgradeState');
-      var fromVersion = App.RepositoryVersion.find().findProperty('repositoryVersion', lastUpgradeData.Upgrade.from_version);
 
       if (!Em.isNone(dbUpgradeState)) {
         App.set('upgradeState', dbUpgradeState);
       }
 
       if (lastUpgradeData) {
-        upgradeController.setDBProperties({
-          upgradeId: lastUpgradeData.Upgrade.request_id,
-          isDowngrade: lastUpgradeData.Upgrade.direction === 'DOWNGRADE',
-          upgradeState: lastUpgradeData.Upgrade.request_status,
-          upgradeType: lastUpgradeData.Upgrade.upgrade_type,
-          downgradeAllowed: lastUpgradeData.Upgrade.downgrade_allowed,
-          upgradeTypeDisplayName: fromVersion && fromVersion.get('displayName'),
-          failuresTolerance: Em.Object.create({
-            skipComponentFailures: lastUpgradeData.Upgrade.skip_failures,
-            skipSCFailures: lastUpgradeData.Upgrade.skip_service_check_failures
-          })
-        });
-        upgradeController.loadRepoVersionsToModel().done(function () {
-          upgradeController.setDBProperty('upgradeVersion', App.RepositoryVersion.find().findProperty('repositoryVersion',
lastUpgradeData.Upgrade.to_version).get('displayName'));
-          upgradeController.initDBProperties();
-          upgradeController.loadUpgradeData(true);
-        });
+        upgradeController.restoreLastUpgrade(lastUpgradeData);
       } else {
         upgradeController.initDBProperties();
         upgradeController.loadUpgradeData(true);

http://git-wip-us.apache.org/repos/asf/ambari/blob/7b539281/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 27965dd..fc52678 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
@@ -1400,5 +1400,33 @@ App.MainAdminStackAndUpgradeController = Em.Controller.extend(App.LocalStorage,
         localdb: App.db.data
       });
     });
+  },
+
+  /**
+   * restore last Upgrade data
+   * @param {object} lastUpgradeData
+   */
+  restoreLastUpgrade: function(lastUpgradeData) {
+    var self = this;
+    var upgradeType = this.get('upgradeMethods').findProperty('type', lastUpgradeData.Upgrade.upgrade_type);
+    var toVersion = App.RepositoryVersion.find().findProperty('repositoryVersion', lastUpgradeData.Upgrade.to_version);
+
+    this.setDBProperties({
+      upgradeId: lastUpgradeData.Upgrade.request_id,
+      isDowngrade: lastUpgradeData.Upgrade.direction === 'DOWNGRADE',
+      upgradeState: lastUpgradeData.Upgrade.request_status,
+      upgradeType: lastUpgradeData.Upgrade.upgrade_type,
+      downgradeAllowed: lastUpgradeData.Upgrade.downgrade_allowed,
+      upgradeTypeDisplayName: upgradeType.get('displayName'),
+      failuresTolerance: Em.Object.create({
+        skipComponentFailures: lastUpgradeData.Upgrade.skip_failures,
+        skipSCFailures: lastUpgradeData.Upgrade.skip_service_check_failures
+      })
+    });
+    this.loadRepoVersionsToModel().done(function () {
+      self.setDBProperty('upgradeVersion', toVersion && toVersion.get('displayName'));
+      self.initDBProperties();
+      self.loadUpgradeData(true);
+    });
   }
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/7b539281/ambari-web/test/controllers/global/cluster_controller_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/controllers/global/cluster_controller_test.js b/ambari-web/test/controllers/global/cluster_controller_test.js
index 2e84fc9..03a874a 100644
--- a/ambari-web/test/controllers/global/cluster_controller_test.js
+++ b/ambari-web/test/controllers/global/cluster_controller_test.js
@@ -398,4 +398,63 @@ describe('App.clusterController', function () {
 
   });
 
+  describe("#restoreUpgradeState()", function() {
+    var data = {upgradeData: {}};
+    var mock = {done: function(callback) {
+      callback(data.upgradeData);
+    }};
+    var upgradeController = Em.Object.create({
+      restoreLastUpgrade: Em.K,
+      initDBProperties: Em.K,
+      loadUpgradeData: Em.K,
+      loadStackVersionsToModel: function(){return {done: Em.K};}
+    });
+
+    beforeEach(function () {
+      sinon.stub(controller, 'getAllUpgrades').returns(mock);
+      sinon.spy(mock, 'done');
+      sinon.stub(App.router, 'get').returns(upgradeController);
+      sinon.stub(App.db, 'get').returns('PENDING');
+      sinon.spy(upgradeController, 'restoreLastUpgrade');
+      sinon.spy(upgradeController, 'initDBProperties');
+      sinon.spy(upgradeController, 'loadUpgradeData');
+      sinon.spy(upgradeController, 'loadStackVersionsToModel');
+    });
+    afterEach(function () {
+      mock.done.restore();
+      controller.getAllUpgrades.restore();
+      App.router.get.restore();
+      App.db.get.restore();
+      upgradeController.restoreLastUpgrade.restore();
+      upgradeController.initDBProperties.restore();
+      upgradeController.loadUpgradeData.restore();
+      upgradeController.loadStackVersionsToModel.restore();
+    });
+    it("has upgrade request", function() {
+      data.upgradeData = {items: [
+        {
+          Upgrade: {
+            request_id: 1
+          }
+        }
+      ]};
+      controller.restoreUpgradeState();
+      expect(controller.getAllUpgrades.calledOnce).to.be.true;
+      expect(App.get('upgradeState')).to.equal('PENDING');
+      expect(upgradeController.restoreLastUpgrade.calledWith(data.upgradeData.items[0])).to.be.true;
+      expect(upgradeController.loadStackVersionsToModel.calledWith(true)).to.be.true;
+      expect(upgradeController.initDBProperties.called).to.be.false;
+      expect(upgradeController.loadUpgradeData.called).to.be.false;
+    });
+    it("does not have upgrade request", function() {
+      data.upgradeData = {items: []};
+      controller.restoreUpgradeState();
+      expect(controller.getAllUpgrades.calledOnce).to.be.true;
+      expect(App.get('upgradeState')).to.equal('PENDING');
+      expect(upgradeController.restoreLastUpgrade.called).to.be.false;
+      expect(upgradeController.loadStackVersionsToModel.calledWith(true)).to.be.true;
+      expect(upgradeController.initDBProperties.calledOnce).to.be.true;
+      expect(upgradeController.loadUpgradeData.calledWith(true)).to.be.true;
+    });
+  });
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/7b539281/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 45c4bd0..a921c74 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
@@ -542,16 +542,6 @@ describe('App.MainAdminStackAndUpgradeController', function() {
           }
         ]
       };
-      controller.upgradeMethods = [
-        Em.Object.create({
-          displayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.RU.title'),
-          type: 'ROLLING'
-        }),
-        Em.Object.create({
-          displayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.EU.title'),
-          type: 'NON_ROLLING'
-        })
-      ];
       controller.upgradeSuccessCallback(data, {}, {label: 'HDP-2.2.1', isDowngrade: true});
       expect(controller.load.calledOnce).to.be.true;
       expect(controller.get('upgradeVersion')).to.equal('HDP-2.2.1');
@@ -801,30 +791,14 @@ describe('App.MainAdminStackAndUpgradeController', function() {
       App.showConfirmationFeedBackPopup.restore();
       controller.runPreUpgradeCheck.restore();
       this.mock.restore();
+      controller.get('upgradeMethods').setEach('selected', false);
     });
     it("show confirmation popup", function() {
       var version = Em.Object.create({displayName: 'HDP-2.2'});
       this.mock.returns({
         done: function(callback) {callback([1]);}
       });
-      controller.upgradeMethods = [
-        Em.Object.create({
-          displayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.RU.title'),
-          type: 'ROLLING',
-          icon: "icon-dashboard",
-          description: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.RU.description'),
-          selected: true,
-          allowed: true
-        }),
-        Em.Object.create({
-          displayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.EU.title'),
-          type: 'NON_ROLLING',
-          icon: "icon-bolt",
-          description: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.EU.description'),
-          selected: false,
-          allowed: true
-        })
-      ];
+      controller.get('upgradeMethods')[0].set('selected', true);
       controller.set('isDowngrade', false);
       var popup = controller.upgradeOptions(false, version);
       expect(App.ModalPopup.calledOnce).to.be.true;
@@ -1382,19 +1356,15 @@ describe('App.MainAdminStackAndUpgradeController', function() {
     });
     afterEach(function () {
       controller.runPreUpgradeCheckOnly.restore();
+      controller.get('upgradeMethods').setEach('allowed', true);
     });
     it("no allowed upgrade methods", function () {
-      controller.set('upgradeMethods', [Em.Object.create({
-        allowed: false
-      })]);
+      controller.get('upgradeMethods').setEach('allowed', false);
       controller.runUpgradeMethodChecks();
       expect(controller.runPreUpgradeCheckOnly.called).to.be.false;
     });
     it("Rolling method allowed", function () {
-      controller.set('upgradeMethods', [Em.Object.create({
-        allowed: true,
-        type: 'ROLLING'
-      })]);
+      controller.get('upgradeMethods').setEach('allowed', true);
       controller.runUpgradeMethodChecks(Em.Object.create({
         repositoryVersion: 'v1',
         displayName: 'V1'
@@ -1406,4 +1376,63 @@ describe('App.MainAdminStackAndUpgradeController', function() {
       })).to.be.true;
     });
   });
+
+  describe("#restoreLastUpgrade()", function () {
+    beforeEach(function () {
+      sinon.stub(App.RepositoryVersion, 'find').returns([Em.Object.create({
+        repositoryVersion: '1',
+        displayName: 'HDP-1'
+      })]);
+      sinon.stub(controller, 'setDBProperties');
+      sinon.stub(controller, 'loadRepoVersionsToModel', function () {
+        return {
+          done: function (callback) {
+            callback();
+          }
+        }
+      });
+      sinon.stub(controller, 'setDBProperty');
+      sinon.stub(controller, 'initDBProperties');
+      sinon.stub(controller, 'loadUpgradeData');
+    });
+    afterEach(function () {
+      App.RepositoryVersion.find.restore();
+      controller.setDBProperties.restore();
+      controller.loadRepoVersionsToModel.restore();
+      controller.setDBProperty.restore();
+      controller.initDBProperties.restore();
+      controller.loadUpgradeData.restore();
+    });
+    it("", function () {
+      var data = {
+        Upgrade: {
+          request_id: 1,
+          direction: 'UPGRADE',
+          request_status: 'PENDING',
+          upgrade_type: 'ROLLING',
+          downgrade_allowed: true,
+          skip_failures: true,
+          skip_service_check_failures: true,
+          to_version: '1'
+        }
+      };
+      controller.restoreLastUpgrade(data);
+      expect(controller.setDBProperties.getCall(0).args[0]).to.eql({
+        upgradeId: 1,
+        isDowngrade: false,
+        upgradeState: 'PENDING',
+        upgradeType: "ROLLING",
+        downgradeAllowed: true,
+        upgradeTypeDisplayName: Em.I18n.t('admin.stackVersions.version.upgrade.upgradeOptions.RU.title'),
+        failuresTolerance: Em.Object.create({
+          skipComponentFailures: true,
+          skipSCFailures: true
+        })
+      });
+      expect(controller.loadRepoVersionsToModel.calledOnce).to.be.true;
+      expect(controller.setDBProperty.calledWith('upgradeVersion', 'HDP-1')).to.be.true;
+      expect(controller.initDBProperties.calledOnce).to.be.true;
+      expect(controller.loadUpgradeData.calledWith(true)).to.be.true;
+    });
+  });
 });


Mime
View raw message