This is an automated email from the ASF dual-hosted git repository. ishanbha pushed a commit to branch trunk in repository https://gitbox.apache.org/repos/asf/ambari.git
The following commit(s) were added to refs/heads/trunk by this push: new dd5c769 [AMBARI-24577] Services should display the Stop button if any of their components are started. dd5c769 is described below commit dd5c769e516b9bd25c6c40db6bef16ca8ee16df7 Author: Ishan Bhatt <ishanbhatt.1...@gmail.com> AuthorDate: Thu Aug 30 15:22:37 2018 -0700 [AMBARI-24577] Services should display the Stop button if any of their components are started. --- ambari-web/app/controllers/main/service/item.js | 21 +++- .../test/controllers/main/service/item_test.js | 107 +++++++++++++++++++-- 2 files changed, 119 insertions(+), 9 deletions(-) diff --git a/ambari-web/app/controllers/main/service/item.js b/ambari-web/app/controllers/main/service/item.js index 55ae995..ea99c54 100644 --- a/ambari-web/app/controllers/main/service/item.js +++ b/ambari-web/app/controllers/main/service/item.js @@ -1176,10 +1176,21 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow return App.MasterComponent.find().toArray().concat(App.SlaveComponent.find().toArray()).filterProperty('service.serviceName', this.get('content.serviceName')); }.property('content.serviceName'), - isStartDisabled: Em.computed.or('isPending', 'content.isStarted'), + isStartDisabled: function () { + let allComponentsStarted = true; + if (this.get('isPending')) return true; + this.get('nonClientServiceComponents').forEach(function (component) { + if (component.get('installedCount') > 0) + allComponentsStarted = false; + }); + return allComponentsStarted && this.get('content.isStarted'); + }.property('content.isStarted', 'isPending'), + isStopDisabled: function () { + let allComponentsStopped = true; if(this.get('isPending')) return true; + if (App.get('isHaEnabled') && this.get('content.serviceName') == 'HDFS' && this.get('content.hostComponents').filterProperty('componentName', 'NAMENODE').someProperty('workStatus', App.HostComponentStatus.started)) { return false; } @@ -1189,7 +1200,13 @@ App.MainServiceItemController = Em.Controller.extend(App.SupportClientConfigsDow if (this.get('content.serviceName') == 'PXF' && App.HostComponent.find().filterProperty('componentName', 'PXF').someProperty('workStatus', App.HostComponentStatus.started)) { return false; } - return !this.get('content.isStarted'); + + this.get('nonClientServiceComponents').forEach(function (component) { + if (component.get('startedCount') > 0) + allComponentsStopped = false; + }); + + return allComponentsStopped && !this.get('content.isStarted'); }.property('content.isStarted','isPending', 'App.isHaEnabled'), isSmokeTestDisabled: function () { diff --git a/ambari-web/test/controllers/main/service/item_test.js b/ambari-web/test/controllers/main/service/item_test.js index 35d31a8..e6abebe 100644 --- a/ambari-web/test/controllers/main/service/item_test.js +++ b/ambari-web/test/controllers/main/service/item_test.js @@ -53,10 +53,6 @@ var stackServiceModel = { describe('App.MainServiceItemController', function () { - App.TestAliases.testAsComputedOr(App.MainServiceItemController.create({ - content: Em.Object.create({serviceName: 'S1'}) - }), 'isStartDisabled', ['isPending', 'content.isStarted']); - describe('#setStartStopState', function () { var tests = [ { @@ -891,12 +887,86 @@ describe('App.MainServiceItemController', function () { }); + describe("#isStartDisabled", function () { + var tests = [ + { + content: { + isStarted: true + }, + nonClientServiceComponents: [ + Em.Object.create({ + installedCount: 0 + }) + ], + isPending: false, + disabled: true, + m: "disabled since service state is started and no component is stopped" + }, + { + content: { + isStarted: true + }, + nonClientServiceComponents: [ + Em.Object.create({ + installedCount: 0 + }), + Em.Object.create({ + installedCount: 2 + }) + ], + isPending: false, + disabled: false, + m: "enabled although service state is started, 2 components are stopped" + }, + { + content: { + isStarted: false + }, + nonClientServiceComponents: [ + Em.Object.create({ + installedCount: 0 + }), + Em.Object.create({ + installedCount: 0 + }) + ], + isPending: false, + disabled: false, + m: "enabled although all components are stopped service state is not started" + }, + { + content: { + isStarted: true + }, + nonClientServiceComponents: [ + Em.Object.create({ + installedCount: 0 + }) + ], + isPending: true, + disabled: true, + m: "disabled since state is pending." + }, + ]; + tests.forEach(function (test) { + it(test.m, function () { + var mainServiceItemController = App.MainServiceItemController.create({content: test.content, isPending: test.isPending, nonClientServiceComponents: test.nonClientServiceComponents}); + expect(mainServiceItemController.get('isStartDisabled')).to.equal(test.disabled); + }); + }); + }); + describe("#isStopDisabled", function () { var tests = [ { content: { isStarted: false }, + nonClientServiceComponents: [ + Em.Object.create({ + startedCount: 0 + }) + ], isPending: true, disabled: true, m: "disabled because of pending" @@ -905,22 +975,45 @@ describe('App.MainServiceItemController', function () { content: { isStarted: true }, + nonClientServiceComponents: [ + Em.Object.create({ + startedCount: 0 + }) + ], + isPending: false, + disabled: false, + m: "enabled because healthStatus is green although no components are started" + }, + { + content: { + isStarted: false + }, + nonClientServiceComponents: [ + Em.Object.create({ + startedCount: 1 + }) + ], isPending: false, disabled: false, - m: "enabled because healthStatus is green and pending is false" + m: "enabled because atleast 1 component is started." }, { content: { isStarted: false }, + nonClientServiceComponents: [ + Em.Object.create({ + startedCount: 0 + }) + ], isPending: false, disabled: true, - m: "disabled because healthStatus is not green" + m: "disabled because healthStatus is not green and no started components" } ]; tests.forEach(function (test) { it(test.m, function () { - var mainServiceItemController = App.MainServiceItemController.create({content: test.content, isPending: test.isPending}); + var mainServiceItemController = App.MainServiceItemController.create({content: test.content, isPending: test.isPending, nonClientServiceComponents: test.nonClientServiceComponents}); expect(mainServiceItemController.get('isStopDisabled')).to.equal(test.disabled); }); });