You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by lp...@apache.org on 2017/09/05 09:41:02 UTC
[07/50] [abbrv] ambari git commit: AMBARI-21847 Refactor stack
version column view. (atkach)
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/42387818
Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/42387818
Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/42387818
Branch: refs/heads/feature-branch-AMBARI-21307
Commit: 4238781810d8c8236626b204a39353f1f33e8e49
Parents: 418be51
Author: Andrii Tkach <at...@apache.org>
Authored: Tue Aug 29 22:04:57 2017 +0300
Committer: Andrii Tkach <at...@apache.org>
Committed: Wed Aug 30 12:46:50 2017 +0300
----------------------------------------------------------------------
.../stack_upgrade/upgrade_version_box_view.js | 187 ++++++++------
.../upgrade_version_box_view_test.js | 241 +++++++++++++++++++
2 files changed, 354 insertions(+), 74 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ambari/blob/42387818/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 ec3b4c9..84612ab 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
@@ -161,15 +161,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 element = Em.Object.create({
status: status,
- isInstalling: function () {
- return this.get('status') === 'INSTALLING';
- }.property('status'),
+ isInstalling: Em.computed.equal('status', 'INSTALLING'),
buttons: [],
isDisabled: false
});
@@ -182,79 +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.processNotRequiredState(element);
}
- else if ((status === 'INSTALLED' && !this.get('isUpgrading')) ||
- (['INSTALL_FAILED', 'OUT_OF_SYNC'].contains(status))) {
- if (stringUtils.compareVersions(this.get('content.repositoryVersion'), Em.get(currentVersion, 'repository_version')) === 1) {
- 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
- });
- }
- }
- 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', 'glyphicon glyphicon-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', 'glyphicon glyphicon-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') || (!App.isAuthorized('CLUSTER.UPGRADE_DOWNGRADE_STACK'))) {
@@ -282,6 +215,112 @@ 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', 'glyphicon glyphicon-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', 'glyphicon glyphicon-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
+ });
+ }
+ }
+ 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
+ });
+ },
+
+ /**
* check if actions of INSTALLED stack version disabled
* @returns {boolean}
*/
http://git-wip-us.apache.org/repos/asf/ambari/blob/42387818/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 d1c338f..af3e990 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
@@ -1257,4 +1257,245 @@ describe('App.UpgradeVersionBoxView', function () {
});
});
});
+
+ 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": "glyphicon glyphicon-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": "glyphicon glyphicon-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": "glyphicon glyphicon-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": "glyphicon glyphicon-cog",
+ "isLink": true,
+ "text": Em.I18n.t('admin.stackVersions.version.downgrade.running')
+ }));
+ });
+ });
+
+ describe('#processPreUpgradeState', function() {
+ beforeEach(function() {
+ sinon.stub(view, 'isDisabledOnInstalled').returns(false);
+ });
+ afterEach(function() {
+ view.isDisabledOnInstalled.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": "glyphicon glyphicon-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
+ })));
+ });
+ });
+
+ 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('admin.stackVersions.version.installNow'),
+ "action": 'installRepoVersionConfirmation',
+ "isDisabled": false,
+ "isButtonGroup": true
+ })));
+ });
+ });
});