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-21847 Refactor stack version column view. (atkach)
Date Wed, 30 Aug 2017 09:48:12 GMT
Repository: ambari
Updated Branches:
  refs/heads/branch-2.6 974f7217c -> 39bc724e8


AMBARI-21847 Refactor stack version column view. (atkach)


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

Branch: refs/heads/branch-2.6
Commit: 39bc724e871c0be9bb7daba0564a17ca8ad9e0dc
Parents: 974f721
Author: Andrii Tkach <atkach@apache.org>
Authored: Tue Aug 29 21:40:09 2017 +0300
Committer: Andrii Tkach <atkach@apache.org>
Committed: Wed Aug 30 12:47:58 2017 +0300

----------------------------------------------------------------------
 .../stack_upgrade/upgrade_version_box_view.js   | 195 +++++++++------
 .../upgrade_version_box_view_test.js            | 244 +++++++++++++++++++
 2 files changed, 359 insertions(+), 80 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/39bc724e/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js b/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js
index 4bb06fc..e46a400 100644
--- a/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js
+++ b/ambari-web/app/views/main/admin/stack_upgrade/upgrade_version_box_view.js
@@ -158,19 +158,11 @@ App.UpgradeVersionBoxView = Em.View.extend({
    * TODO remove <code>isUpgrading</code> condition when transition of version
states in API fixed
    */
   stateElement: function () {
-    var currentVersion = this.get('controller.currentVersion');
     var statePropertiesMap = this.get('statePropertiesMap');
-    var requestInProgressRepoId = this.get('controller.requestInProgressRepoId');
     var status = this.get('content.status');
-    var isVersionHigherThanCurrent = stringUtils.compareVersions(
-        this.get('content.repositoryVersion'),
-        Em.get(currentVersion, 'repository_version')
-      ) === 1;
     var element = Em.Object.create({
       status: status,
-      isInstalling: function () {
-        return this.get('status') === 'INSTALLING';
-      }.property('status'),
+      isInstalling: Em.computed.equal('status', 'INSTALLING'),
       buttons: [],
       isDisabled: false
     });
@@ -186,81 +178,16 @@ App.UpgradeVersionBoxView = Em.View.extend({
       element.setProperties(statePropertiesMap[status]);
     }
     else if (status === 'NOT_REQUIRED') {
-      var isDisabledOnInit = this.isDisabledOnInit();
-      requestInProgressRepoId && requestInProgressRepoId == this.get('content.id')
? element.setProperties(statePropertiesMap['LOADING']) : element.setProperties(statePropertiesMap[status]);
-      element.set('isDisabled', isDisabledOnInit);
-      element.set('isButtonGroup', true);
-      element.set('isButton', false);
-      element.get('buttons').pushObject({
-        text: Em.I18n.t('common.discard'),
-        action: 'confirmDiscardRepoVersion',
-        isDisabled: isDisabledOnInit
-      });
-      this.addRemoveIopSelectButton(element, isDisabledOnInit);
+      this.processNotRequiredState(element);
     }
-    else if ((status === 'INSTALLED' && !this.get('isUpgrading')) ||
-             (['INSTALL_FAILED', 'OUT_OF_SYNC'].contains(status))) {
-      if (Em.get(currentVersion, 'stack_name') !== this.get('content.stackVersionType') ||
isVersionHigherThanCurrent) {
-        var isDisabled = this.isDisabledOnInstalled();
-        element.set('isButtonGroup', true);
-        if (status === 'OUT_OF_SYNC') {
-          element.set('text', this.get('isVersionColumnView') ? Em.I18n.t('common.reinstall')
: Em.I18n.t('admin.stackVersions.version.reinstall'));
-          element.set('action', 'installRepoVersionConfirmation');
-          element.get('buttons').pushObject({
-            text: this.get('isVersionColumnView') ? Em.I18n.t('common.upgrade') : Em.I18n.t('admin.stackVersions.version.performUpgrade'),
-            action: 'confirmUpgrade',
-            isDisabled: isDisabled
-          });
-        } else {
-          element.set('text', this.get('isVersionColumnView') ? Em.I18n.t('common.upgrade')
: Em.I18n.t('admin.stackVersions.version.performUpgrade'));
-          element.set('action', 'confirmUpgrade');
-          element.get('buttons').pushObject({
-            text: this.get('isVersionColumnView') ? Em.I18n.t('common.reinstall') : Em.I18n.t('admin.stackVersions.version.reinstall'),
-            action: 'installRepoVersionConfirmation',
-            isDisabled: isDisabled
-          });
-          if (this.get('content.isPatch')) {
-            element.get('buttons').pushObject({
-              text: Em.I18n.t('common.discard'),
-              action: 'confirmDiscardRepoVersion',
-              isDisabled: isDisabled
-            });
-          }
-          this.addRemoveIopSelectButton(element, isDisabled);
-        }
-        element.set('isDisabled', isDisabled);
-      }
-      else {
-        element.setProperties(statePropertiesMap['INSTALLED']);
-      }
+    else if ((status === 'INSTALLED' && !this.get('isUpgrading')) || (['INSTALL_FAILED',
'OUT_OF_SYNC'].contains(status))) {
+      this.processPreUpgradeState(element);
     }
-    else if ((this.get('isUpgrading')) && !isSuspended) {
-      element.set('isLink', true);
-      element.set('action', 'openUpgradeDialog');
-      if (['HOLDING', 'HOLDING_FAILED', 'HOLDING_TIMEDOUT', 'ABORTED'].contains(App.get('upgradeState')))
{
-        element.set('iconClass', 'icon-pause');
-        if (this.get('controller.isDowngrade')) {
-          element.set('text', Em.I18n.t('admin.stackVersions.version.downgrade.pause'));
-        }
-        else {
-          element.set('text', Em.I18n.t('admin.stackVersions.version.upgrade.pause'));
-        }
-      }
-      else {
-        element.set('iconClass', 'icon-cog');
-        if (this.get('controller.isDowngrade')) {
-          element.set('text', Em.I18n.t('admin.stackVersions.version.downgrade.running'));
-        }
-        else {
-          element.set('text', Em.I18n.t('admin.stackVersions.version.upgrade.running'));
-        }
-      }
+    else if (this.get('isUpgrading') && !isSuspended) {
+      this.processUpgradingState(element);
     }
     else if (isSuspended) {
-      element.setProperties(statePropertiesMap['SUSPENDED']);
-      var text = this.get('controller.isDowngrade') ? Em.I18n.t('admin.stackUpgrade.dialog.resume.downgrade')
: Em.I18n.t('admin.stackUpgrade.dialog.resume');
-      element.set('text', this.get('isVersionColumnView') ? Em.I18n.t('common.resume'): text);
-      element.set('isDisabled', this.get('controller.requestInProgress'));
+      this.processSuspendedState(element);
     }
     //For restricted upgrade wizard should be disabled in any state
     if (this.get('controller.isWizardRestricted')) {
@@ -280,6 +207,114 @@ App.UpgradeVersionBoxView = Em.View.extend({
 
   /**
    * @param {Em.Object} element
+   */
+  processSuspendedState: function(element) {
+    element.setProperties(this.get('statePropertiesMap')['SUSPENDED']);
+    var text = this.get('controller.isDowngrade')
+      ? Em.I18n.t('admin.stackUpgrade.dialog.resume.downgrade')
+      : Em.I18n.t('admin.stackUpgrade.dialog.resume');
+    element.set('text', this.get('isVersionColumnView') ? Em.I18n.t('common.resume'): text);
+    element.set('isDisabled', this.get('controller.requestInProgress'));
+  },
+
+  /**
+   * @param {Em.Object} element
+   */
+  processUpgradingState: function(element) {
+    element.set('isLink', true);
+    element.set('action', 'openUpgradeDialog');
+    if (['HOLDING', 'HOLDING_FAILED', 'HOLDING_TIMEDOUT', 'ABORTED'].contains(App.get('upgradeState')))
{
+      element.set('iconClass', 'icon-pause');
+      if (this.get('controller.isDowngrade')) {
+        element.set('text', Em.I18n.t('admin.stackVersions.version.downgrade.pause'));
+      }
+      else {
+        element.set('text', Em.I18n.t('admin.stackVersions.version.upgrade.pause'));
+      }
+    }
+    else {
+      element.set('iconClass', 'icon-cog');
+      if (this.get('controller.isDowngrade')) {
+        element.set('text', Em.I18n.t('admin.stackVersions.version.downgrade.running'));
+      }
+      else {
+        element.set('text', Em.I18n.t('admin.stackVersions.version.upgrade.running'));
+      }
+    }
+  },
+
+  /**
+   * @param {Em.Object} element
+   */
+  processPreUpgradeState: function(element) {
+    var currentVersion = this.get('controller.currentVersion');
+    var status = this.get('content.status');
+    var isVersionHigherThanCurrent = stringUtils.compareVersions(
+        this.get('content.repositoryVersion'),
+        Em.get(currentVersion, 'repository_version')
+      ) === 1;
+
+    if (Em.get(currentVersion, 'stack_name') !== this.get('content.stackVersionType') ||
isVersionHigherThanCurrent) {
+      var isDisabled = this.isDisabledOnInstalled();
+      element.set('isButtonGroup', true);
+      if (status === 'OUT_OF_SYNC') {
+        element.set('text', this.get('isVersionColumnView') ? Em.I18n.t('common.reinstall')
: Em.I18n.t('admin.stackVersions.version.reinstall'));
+        element.set('action', 'installRepoVersionConfirmation');
+        element.get('buttons').pushObject({
+          text: this.get('isVersionColumnView') ? Em.I18n.t('common.upgrade') : Em.I18n.t('admin.stackVersions.version.performUpgrade'),
+          action: 'confirmUpgrade',
+          isDisabled: isDisabled
+        });
+      } else {
+        element.set('text', this.get('isVersionColumnView') ? Em.I18n.t('common.upgrade')
: Em.I18n.t('admin.stackVersions.version.performUpgrade'));
+        element.set('action', 'confirmUpgrade');
+        element.get('buttons').pushObject({
+          text: this.get('isVersionColumnView') ? Em.I18n.t('common.reinstall') : Em.I18n.t('admin.stackVersions.version.reinstall'),
+          action: 'installRepoVersionConfirmation',
+          isDisabled: isDisabled
+        });
+        if (this.get('content.isPatch')) {
+          element.get('buttons').pushObject({
+            text: Em.I18n.t('common.discard'),
+            action: 'confirmDiscardRepoVersion',
+            isDisabled: isDisabled
+          });
+        }
+        this.addRemoveIopSelectButton(element, isDisabled);
+      }
+      element.set('isDisabled', isDisabled);
+    }
+    else {
+      element.setProperties(this.get('statePropertiesMap')['INSTALLED']);
+    }
+  },
+
+  /**
+   * @param {Em.Object} element
+   */
+  processNotRequiredState: function(element) {
+    var isDisabledOnInit = this.isDisabledOnInit();
+    var requestInProgressRepoId = this.get('controller.requestInProgressRepoId');
+    var status = this.get('content.status');
+
+    if (requestInProgressRepoId && requestInProgressRepoId === this.get('content.id'))
{
+      element.setProperties(this.get('statePropertiesMap')['LOADING']);
+    } else {
+      element.setProperties(this.get('statePropertiesMap')[status]);
+    }
+    element.set('isDisabled', isDisabledOnInit);
+    element.set('isButtonGroup', true);
+    element.set('isButton', false);
+    element.get('buttons').pushObject({
+      text: Em.I18n.t('common.discard'),
+      action: 'confirmDiscardRepoVersion',
+      isDisabled: isDisabledOnInit
+    });
+    this.addRemoveIopSelectButton(element, isDisabledOnInit);
+  },
+
+  /**
+   * @param {Em.Object} element
    * @param {boolean} isDisabled
    * @returns {boolean}
    */

http://git-wip-us.apache.org/repos/asf/ambari/blob/39bc724e/ambari-web/test/views/main/admin/stack_upgrade/upgrade_version_box_view_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_version_box_view_test.js
b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_version_box_view_test.js
index da1c9a9..94bd497 100644
--- a/ambari-web/test/views/main/admin/stack_upgrade/upgrade_version_box_view_test.js
+++ b/ambari-web/test/views/main/admin/stack_upgrade/upgrade_version_box_view_test.js
@@ -1217,4 +1217,248 @@ describe('App.UpgradeVersionBoxView', function () {
       expect(element.get('buttons')).to.be.empty;
     });
   });
+
+  describe('#processSuspendedState', function() {
+
+    it('should process suspended state', function() {
+      view.set('controller.requestInProgress', false);
+      var element = Em.Object.create();
+      view.processSuspendedState(element);
+      expect(element).to.be.eql(Em.Object.create({
+        "action": "resumeUpgrade",
+        "isButton": true,
+        "isDisabled": false,
+        "text": Em.I18n.t('admin.stackUpgrade.dialog.resume')
+      }));
+    });
+  });
+
+  describe('#processUpgradingState', function() {
+
+    beforeEach(function() {
+      this.mock = sinon.stub(App, 'get');
+    });
+    afterEach(function() {
+      this.mock.restore();
+    });
+
+    it('downgrade in HOLDING state', function() {
+      this.mock.returns('HOLDING');
+      view.set('controller.isDowngrade', true);
+      var element = Em.Object.create();
+      view.processUpgradingState(element);
+      expect(element).to.be.eql(Em.Object.create({
+        "action": "openUpgradeDialog",
+        "iconClass": "icon-pause",
+        "isLink": true,
+        "text": Em.I18n.t('admin.stackVersions.version.downgrade.pause')
+      }));
+    });
+
+    it('upgrade in HOLDING state', function() {
+      this.mock.returns('HOLDING');
+      view.set('controller.isDowngrade', false);
+      var element = Em.Object.create();
+      view.processUpgradingState(element);
+      expect(element).to.be.eql(Em.Object.create({
+        "action": "openUpgradeDialog",
+        "iconClass": "icon-pause",
+        "isLink": true,
+        "text": Em.I18n.t('admin.stackVersions.version.upgrade.pause')
+      }));
+    });
+
+    it('upgrade in running state', function() {
+      this.mock.returns('UPGRADING');
+      view.set('controller.isDowngrade', false);
+      var element = Em.Object.create();
+      view.processUpgradingState(element);
+      expect(element).to.be.eql(Em.Object.create({
+        "action": "openUpgradeDialog",
+        "iconClass": "icon-cog",
+        "isLink": true,
+        "text": Em.I18n.t('admin.stackVersions.version.upgrade.running')
+      }));
+    });
+
+    it('downgrade in running state', function() {
+      this.mock.returns('UPGRADING');
+      view.set('controller.isDowngrade', true);
+      var element = Em.Object.create();
+      view.processUpgradingState(element);
+      expect(element).to.be.eql(Em.Object.create({
+        "action": "openUpgradeDialog",
+        "iconClass": "icon-cog",
+        "isLink": true,
+        "text": Em.I18n.t('admin.stackVersions.version.downgrade.running')
+      }));
+    });
+  });
+
+  describe('#processPreUpgradeState', function() {
+    beforeEach(function() {
+      sinon.stub(view, 'isDisabledOnInstalled').returns(false);
+      sinon.stub(view, 'addRemoveIopSelectButton');
+    });
+    afterEach(function() {
+      view.isDisabledOnInstalled.restore();
+      view.addRemoveIopSelectButton.restore();
+    });
+
+    it('version lower than current and in INSTALLED state', function() {
+      view.set('controller', Em.Object.create({
+        currentVersion: Em.Object.create({
+          repository_version: '2.0',
+          stack_name: 'HDP'
+        })
+      }));
+      view.set('content', Em.Object.create({
+        status: 'INSTALLED',
+        repositoryVersion: '2.0',
+        stackVersionType: 'HDP'
+      }));
+      var element = Em.Object.create();
+      view.processPreUpgradeState(element);
+      expect(element).to.be.eql(Em.Object.create({
+        "action": null,
+        "iconClass": "icon-ok",
+        "isLink": true,
+        "text": "Installed"
+      }));
+    });
+
+    it('version higher than current and in OUT_OF_SYNC state', function() {
+      view.set('controller', Em.Object.create({
+        currentVersion: Em.Object.create({
+          repository_version: '2.0',
+          stack_name: 'HDP'
+        })
+      }));
+      view.set('content', Em.Object.create({
+        status: 'OUT_OF_SYNC',
+        repositoryVersion: '2.1',
+        stackVersionType: 'HDP'
+      }));
+      var element = Em.Object.create({
+        buttons: []
+      });
+      view.processPreUpgradeState(element);
+      expect(JSON.stringify(element)).to.be.equal(JSON.stringify(Em.Object.create({
+        "buttons": [
+          {
+            "text": Em.I18n.t('admin.stackVersions.version.performUpgrade'),
+            "action": "confirmUpgrade",
+            "isDisabled": false
+          }
+        ],
+        "isButtonGroup": true,
+        "text": Em.I18n.t('admin.stackVersions.version.reinstall'),
+        "action": 'installRepoVersionConfirmation',
+        "isDisabled": false
+      })));
+    });
+
+    it('version higher than current and in INSTALLED state', function() {
+      view.set('controller', Em.Object.create({
+        currentVersion: Em.Object.create({
+          repository_version: '2.0',
+          stack_name: 'HDP'
+        })
+      }));
+      view.set('content', Em.Object.create({
+        status: 'INSTALLED',
+        repositoryVersion: '2.1',
+        stackVersionType: 'HDP',
+        isPatch: true
+      }));
+      var element = Em.Object.create({
+        buttons: []
+      });
+      view.processPreUpgradeState(element);
+      expect(JSON.stringify(element)).to.be.equal(JSON.stringify(Em.Object.create({
+        "buttons": [
+          {
+            "text": Em.I18n.t('admin.stackVersions.version.reinstall'),
+            "action": "installRepoVersionConfirmation",
+            "isDisabled": false
+          },
+          {
+            "text": Em.I18n.t('common.discard'),
+            "action": "confirmDiscardRepoVersion",
+            "isDisabled": false
+          }
+        ],
+        "isButtonGroup": true,
+        "text": Em.I18n.t('admin.stackVersions.version.performUpgrade'),
+        "action": 'confirmUpgrade',
+        "isDisabled": false
+      })));
+      expect(view.addRemoveIopSelectButton.calledOnce).to.be.true;
+    });
+  });
+
+  describe('#processNotRequiredState', function() {
+    beforeEach(function() {
+      sinon.stub(view, 'isDisabledOnInit').returns(false);
+    });
+    afterEach(function() {
+      view.isDisabledOnInit.restore();
+    });
+
+    it('version in LOADING state', function() {
+      view.set('controller', Em.Object.create({
+        requestInProgressRepoId: 1
+      }));
+      view.set('content', Em.Object.create({
+        status: 'NOT_REQUIRED',
+        id: 1
+      }));
+      var element = Em.Object.create({
+        buttons: []
+      });
+      view.processNotRequiredState(element);
+      expect(JSON.stringify(element)).to.be.equal(JSON.stringify(Em.Object.create({
+        "buttons": [
+          {
+            "text": Em.I18n.t('common.discard'),
+            "action": "confirmDiscardRepoVersion",
+            "isDisabled": false
+          }
+        ],
+        "isSpinner": true,
+        "class": "spinner",
+        "isDisabled": false,
+        "isButtonGroup": true,
+        "isButton": false
+      })));
+    });
+
+    it('version in NOT_REQUIRED state', function() {
+      view.set('controller', Em.Object.create({
+        requestInProgressRepoId: 1
+      }));
+      view.set('content', Em.Object.create({
+        status: 'NOT_REQUIRED',
+        id: 2
+      }));
+      var element = Em.Object.create({
+        buttons: []
+      });
+      view.processNotRequiredState(element);
+      expect(JSON.stringify(element)).to.be.equal(JSON.stringify(Em.Object.create({
+        "buttons": [
+          {
+            "text": Em.I18n.t('common.discard'),
+            "action": "confirmDiscardRepoVersion",
+            "isDisabled": false
+          }
+        ],
+        "isButton": false,
+        "text": Em.I18n.t('common.install'),
+        "action": 'installRepoVersionConfirmation',
+        "isDisabled": false,
+        "isButtonGroup": true
+      })));
+    });
+  });
 });


Mime
View raw message