AMBARI-12049. Host can be deleted despite some required masters are present (alexantonenko)
Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/ceaff9f1 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/ceaff9f1 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/ceaff9f1 Branch: refs/heads/trunk Commit: ceaff9f1fc85c2f6335dc5891d3f6668e7b13a2c Parents: 482de8d Author: Alex Antonenko <hiv...@gmail.com> Authored: Sun Jun 21 00:01:54 2015 +0300 Committer: Alex Antonenko <hiv...@gmail.com> Committed: Sun Jun 21 02:57:51 2015 +0300 ---------------------------------------------------------------------- ambari-web/app/controllers/main/host/details.js | 15 ++++++++ .../test/controllers/main/host/details_test.js | 36 ++++++++++++++++++++ 2 files changed, 51 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/ceaff9f1/ambari-web/app/controllers/main/host/details.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/host/details.js b/ambari-web/app/controllers/main/host/details.js index c0678f2..e23c052 100644 --- a/ambari-web/app/controllers/main/host/details.js +++ b/ambari-web/app/controllers/main/host/details.js @@ -1865,6 +1865,21 @@ App.MainHostDetailsController = Em.Controller.extend({ if (!cInstance.get('isDeletable')) { container.nonDeletableComponents.push(cInstance.get('displayName')); } + // if is deletable, but with cardinality 1+ and is the only instance on server + if (cInstance.get('isMaster') && cInstance.get('isDeletable')) { + var displayName = cInstance.get('displayName'), + componentName = cInstance.get('componentName'); + var stackComponentCount = App.StackServiceComponent.find(componentName).get('minToInstall'); + var installedCount = App.StackServiceComponent.find(componentName).get('isMaster') + ? App.HostComponent.find().filterProperty('componentName', componentName).length + : App.SlaveComponent.find().findProperty('componentName', componentName).get('totalCount'); + var isDeleteComponentDisabled = (installedCount <= stackComponentCount) + || ![App.HostComponentStatus.stopped, App.HostComponentStatus.unknown, App.HostComponentStatus.install_failed, App.HostComponentStatus.upgrade_failed, App.HostComponentStatus.init].contains(this.get('workStatus')); + if (isDeleteComponentDisabled) { + if (!container.masterComponents.contains(displayName)) + container.masterComponents.push(displayName); + } + } if (workStatus === App.HostComponentStatus.unknown) { container.unknownComponents.push(cInstance.get('displayName')); } http://git-wip-us.apache.org/repos/asf/ambari/blob/ceaff9f1/ambari-web/test/controllers/main/host/details_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/host/details_test.js b/ambari-web/test/controllers/main/host/details_test.js index 0eb81db..3824a20 100644 --- a/ambari-web/test/controllers/main/host/details_test.js +++ b/ambari-web/test/controllers/main/host/details_test.js @@ -1553,6 +1553,42 @@ describe('App.MainHostDetailsController', function () { expect(controller.getHostComponentsInfo().nonDeletableComponents).to.eql(['ZK1']); App.HostComponent.find.restore(); }); + + + it('content.hostComponents has master deletable with cardinality 1+ and only one installed component', function () { + sinon.stub(App.HostComponent, 'find', function () { + return [ + { + id: 'TASKTRACKER_host1', + componentName: 'TASKTRACKER' + } + ]; + }); + sinon.stub(App.StackServiceComponent, 'find', function (component) { + return Em.Object.create( + { + componentName: 'TASKTRACKER', + minToInstall: 1, + isMaster: true + }); + }); + sinon.stub(App.SlaveComponent, 'find', function () { + return []; + }); + controller.set('content', {hostComponents: [Em.Object.create({ + componentName: 'TASKTRACKER', + workStatus: 'INIT', + isDeletable: true, + isMaster: true, + displayName: 'ZK1' + })]}); + expect(controller.getHostComponentsInfo().masterComponents.contains('ZK1')).to.be.true; + App.HostComponent.find.restore(); + App.StackServiceComponent.find.restore(); + App.SlaveComponent.find.restore(); + }); + + it('content.hostComponents has running component', function () { sinon.stub(App.HostComponent, 'find', function () { return [