AMBARI-15736. Service can't be deleted if all component are in state "install failed". (onechiporenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/9c3fe327 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/9c3fe327 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/9c3fe327 Branch: refs/heads/trunk Commit: 9c3fe327d45a384cad8489e3bf65de8a357e0f75 Parents: 8bb0d16 Author: Oleg Nechiporenko <onechipore...@apache.org> Authored: Wed Apr 6 18:11:11 2016 +0300 Committer: Oleg Nechiporenko <onechipore...@apache.org> Committed: Thu Apr 7 13:51:34 2016 +0300 ---------------------------------------------------------------------- ambari-web/app/models/client_component.js | 18 ++++- ambari-web/app/models/service.js | 9 ++- .../test/controllers/wizard/step8_test.js | 3 +- ambari-web/test/models/service_test.js | 77 ++++++++++++++++++++ 4 files changed, 98 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/9c3fe327/ambari-web/app/models/client_component.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/client_component.js b/ambari-web/app/models/client_component.js index 492d5ef..3902227 100644 --- a/ambari-web/app/models/client_component.js +++ b/ambari-web/app/models/client_component.js @@ -34,9 +34,21 @@ App.ClientComponent = DS.Model.extend({ * * @type {boolean} */ - allStopped: function() { - return this.get('installedCount') === this.get('totalCount'); - }.property('installedCount', 'totalCount'), + allStopped: Em.computed.equalProperties('installedCount', 'totalCount'), + + /** + * No stated and no installed component + * + * @type {boolean} + */ + noOneInstalled: Em.computed.and('!installedCount', '!startedCount'), + + /** + * Determines if component may be deleted + * + * @type {boolean} + */ + allowToDelete: Em.computed.or('allStopped', 'noOneInstalled'), summaryLabelClassName:function(){ return 'label_for_'+this.get('componentName').toLowerCase(); http://git-wip-us.apache.org/repos/asf/ambari/blob/9c3fe327/ambari-web/app/models/service.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/models/service.js b/ambari-web/app/models/service.js index 3e25be9..2818b9f 100644 --- a/ambari-web/app/models/service.js +++ b/ambari-web/app/models/service.js @@ -47,10 +47,11 @@ App.Service = DS.Model.extend({ * @type {boolean} */ allowToDelete: function() { - return App.Service.allowUninstallStates.contains(this.get('workStatus')) - && this.get('slaveComponents').everyProperty('allStopped') - && this.get('masterComponents').everyProperty('allStopped'); - }.property('slaveComponents.@each.allStopped', 'masterComponents.@each.allStopped', 'workStatus'), + var workStatus = this.get('workStatus'); + return App.Service.allowUninstallStates.contains(workStatus) + && this.get('slaveComponents').everyProperty('allowToDelete') + && this.get('masterComponents').everyProperty('allowToDelete'); + }.property('slaveComponents.@each.allowToDelete', 'masterComponents.@each.allowToDelete', 'workStatus'), /** * @type {bool} http://git-wip-us.apache.org/repos/asf/ambari/blob/9c3fe327/ambari-web/test/controllers/wizard/step8_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/wizard/step8_test.js b/ambari-web/test/controllers/wizard/step8_test.js index 867d5f8..4974460 100644 --- a/ambari-web/test/controllers/wizard/step8_test.js +++ b/ambari-web/test/controllers/wizard/step8_test.js @@ -20,7 +20,7 @@ var App = require('app'); require('utils/ajax/ajax_queue'); require('controllers/main/service/info/configs'); require('controllers/wizard/step8_controller'); -var installerStep8Controller, configurationController; +var installerStep8Controller; var testHelpers = require('test/helpers'); var configs = Em.A([ @@ -64,7 +64,6 @@ describe('App.WizardStep8Controller', function () { beforeEach(function () { installerStep8Controller = getController(); - configurationController = App.MainServiceInfoConfigsController.create({}); }); App.TestAliases.testAsComputedFilterBy(getController(), 'installedServices', 'content.services', 'isInstalled', true); http://git-wip-us.apache.org/repos/asf/ambari/blob/9c3fe327/ambari-web/test/models/service_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/models/service_test.js b/ambari-web/test/models/service_test.js index 6caf80a..e527e1e 100644 --- a/ambari-web/test/models/service_test.js +++ b/ambari-web/test/models/service_test.js @@ -187,5 +187,82 @@ describe('App.Service', function () { }); }); + describe('#allowToDelete', function () { + + beforeEach(function () { + this.stub = sinon.stub(service, 'get'); + }); + + afterEach(function () { + this.stub.restore(); + }); + + Em.A([ + { + m: 'may be deleted (1)', + slaveComponents: [{allowToDelete: true}], + masterComponents: [{allowToDelete: true}], + workStatus: 'INIT', + e: true + }, + { + m: 'may be deleted (2)', + slaveComponents: [{allowToDelete: true}], + masterComponents: [{allowToDelete: true}], + workStatus: 'INSTALL_FAILED', + e: true + }, + { + m: 'may be deleted (3)', + slaveComponents: [{allowToDelete: true}], + masterComponents: [{allowToDelete: true}], + workStatus: 'INSTALLED', + e: true + }, + { + m: 'may be deleted (4)', + slaveComponents: [{allowToDelete: true}], + masterComponents: [{allowToDelete: true}], + workStatus: 'UNKNOWN', + e: true + }, + { + m: 'deleting is not allowed (1)', + slaveComponents: [{allowToDelete: false}], + masterComponents: [{allowToDelete: true}], + workStatus: 'UNKNOWN', + e: false + }, + { + m: 'deleting is not allowed (2)', + slaveComponents: [{allowToDelete: false}], + masterComponents: [{allowToDelete: false}], + workStatus: 'UNKNOWN', + e: false + }, + { + m: 'deleting is not allowed (3)', + slaveComponents: [{allowToDelete: true}], + masterComponents: [{allowToDelete: false}], + workStatus: 'UNKNOWN', + e: false + }, + { + m: 'deleting is not allowed (4)', + slaveComponents: [{allowToDelete: true}], + masterComponents: [{allowToDelete: true}], + workStatus: 'STARTED', + e: false + } + ]).forEach(function (test) { + it(test.m, function () { + this.stub.withArgs('workStatus').returns(test.workStatus); + this.stub.withArgs('slaveComponents').returns(test.slaveComponents); + this.stub.withArgs('masterComponents').returns(test.masterComponents); + expect(Em.get(service, 'allowToDelete')).to.be.equal(test.e); + }); + }); + + }); });