Repository: ambari Updated Branches: refs/heads/trunk e07d8c931 -> aedb50c0e
AMBARI-11178. List of components which need restart have not refreshed after restart (alexantonenko) Project: http://git-wip-us.apache.org/repos/asf/ambari/repo Commit: http://git-wip-us.apache.org/repos/asf/ambari/commit/c8ac1348 Tree: http://git-wip-us.apache.org/repos/asf/ambari/tree/c8ac1348 Diff: http://git-wip-us.apache.org/repos/asf/ambari/diff/c8ac1348 Branch: refs/heads/trunk Commit: c8ac13489d5c01aacc826b5aa58a560008f3c5d4 Parents: e07d8c9 Author: Alex Antonenko <hiv...@gmail.com> Authored: Fri May 15 20:43:38 2015 +0300 Committer: Alex Antonenko <hiv...@gmail.com> Committed: Fri May 15 20:43:38 2015 +0300 ---------------------------------------------------------------------- ambari-web/app/assets/test/tests.js | 2 + .../controllers/main/service/info/configs.js | 4 +- .../app/templates/main/service/info/configs.hbs | 4 +- .../app/templates/main/service/info/summary.hbs | 4 +- ambari-web/test/controllers/application_test.js | 203 ++++++++++++++ .../test/controllers/login_controller_test.js | 44 ++++ .../main/service/info/config_test.js | 20 +- ambari-web/test/controllers/main_test.js | 264 ++++++++++++++++++- 8 files changed, 532 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ac1348/ambari-web/app/assets/test/tests.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js index eeafa57..64456a9 100644 --- a/ambari-web/app/assets/test/tests.js +++ b/ambari-web/app/assets/test/tests.js @@ -98,7 +98,9 @@ var files = ['test/init_model_test', 'test/controllers/main/admin_test', 'test/controllers/main/views_controller_test', 'test/controllers/installer_test', + 'test/controllers/application_test', 'test/controllers/main_test', + 'test/controllers/login_controller_test', 'test/controllers/wizard_test', 'test/controllers/wizard/slave_component_groups_controller', 'test/controllers/wizard/step0_test', http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ac1348/ambari-web/app/controllers/main/service/info/configs.js ---------------------------------------------------------------------- diff --git a/ambari-web/app/controllers/main/service/info/configs.js b/ambari-web/app/controllers/main/service/info/configs.js index 52e6785..abd7048 100644 --- a/ambari-web/app/controllers/main/service/info/configs.js +++ b/ambari-web/app/controllers/main/service/info/configs.js @@ -1274,7 +1274,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ServerValidatorM * @method showHostsShouldBeRestarted */ showHostsShouldBeRestarted: function (event) { - var restartRequiredHostsAndComponents = event.context; + var restartRequiredHostsAndComponents = event.context.restartRequiredHostsAndComponents; var hosts = []; for (var hostName in restartRequiredHostsAndComponents) { hosts.push(hostName); @@ -1290,7 +1290,7 @@ App.MainServiceInfoConfigsController = Em.Controller.extend(App.ServerValidatorM * @method showComponentsShouldBeRestarted */ showComponentsShouldBeRestarted: function (event) { - var restartRequiredHostsAndComponents = event.context; + var restartRequiredHostsAndComponents = event.context.restartRequiredHostsAndComponents; var hostsComponets = []; var componentsObject = {}; for (var hostName in restartRequiredHostsAndComponents) { http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ac1348/ambari-web/app/templates/main/service/info/configs.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/service/info/configs.hbs b/ambari-web/app/templates/main/service/info/configs.hbs index 030d330..5a60f91 100644 --- a/ambari-web/app/templates/main/service/info/configs.hbs +++ b/ambari-web/app/templates/main/service/info/configs.hbs @@ -23,8 +23,8 @@ <div> <div class="alert alert-warning clearfix"> <i class="icon-refresh"></i> {{t services.service.config.restartService.needToRestart}} <a - href="#" {{action "showComponentsShouldBeRestarted" controller.content.restartRequiredHostsAndComponents target="controller"}}>{{view.componentsCount}} {{pluralize view.componentsCount singular="t:common.component" plural="t:common.components"}}</a> {{t on}} - <a href="#" {{action "showHostsShouldBeRestarted" controller.content.restartRequiredHostsAndComponents target="controller"}}>{{view.hostsCount}} {{pluralize view.hostsCount singular="t:common.host" plural="t:common.hosts"}}</a> + href="#" {{action "showComponentsShouldBeRestarted" controller.content target="controller"}}>{{view.componentsCount}} {{pluralize view.componentsCount singular="t:common.component" plural="t:common.components"}}</a> {{t on}} + <a href="#" {{action "showHostsShouldBeRestarted" controller.content target="controller"}}>{{view.hostsCount}} {{pluralize view.hostsCount singular="t:common.host" plural="t:common.hosts"}}</a> <span class="restart-components pull-right"> </span> <div class="btn-group pull-right"> http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ac1348/ambari-web/app/templates/main/service/info/summary.hbs ---------------------------------------------------------------------- diff --git a/ambari-web/app/templates/main/service/info/summary.hbs b/ambari-web/app/templates/main/service/info/summary.hbs index 740368d..d3b5c06 100644 --- a/ambari-web/app/templates/main/service/info/summary.hbs +++ b/ambari-web/app/templates/main/service/info/summary.hbs @@ -21,8 +21,8 @@ <div id="summary-restart-bar"> <div class="alert alert-warning clearfix"> <i class="icon-refresh"></i> {{{view.needToRestartMessage}}} {{t services.service.config.restartService.needToRestart}} - <a href="#" {{action showComponentsShouldBeRestarted controller.content.restartRequiredHostsAndComponents target="App.router.mainServiceInfoConfigsController"}}>{{view.componentsCount}} {{pluralize view.componentsCount singular="t:common.component" plural="t:common.components"}}</a> {{t on}} - <a href="#" {{action showHostsShouldBeRestarted controller.content.restartRequiredHostsAndComponents target="App.router.mainServiceInfoConfigsController"}}>{{view.hostsCount}} {{pluralize view.hostsCount singular="t:common.host" plural="t:common.hosts"}}</a> + <a href="#" {{action showComponentsShouldBeRestarted controller.content target="App.router.mainServiceInfoConfigsController"}}>{{view.componentsCount}} {{pluralize view.componentsCount singular="t:common.component" plural="t:common.components"}}</a> {{t on}} + <a href="#" {{action showHostsShouldBeRestarted controller.content target="App.router.mainServiceInfoConfigsController"}}>{{view.hostsCount}} {{pluralize view.hostsCount singular="t:common.host" plural="t:common.hosts"}}</a> <span class="restart-components pull-right"> </span> <div class="btn-group pull-right"> http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ac1348/ambari-web/test/controllers/application_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/application_test.js b/ambari-web/test/controllers/application_test.js new file mode 100644 index 0000000..d894038 --- /dev/null +++ b/ambari-web/test/controllers/application_test.js @@ -0,0 +1,203 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +var App = require('app'); +require('models/cluster'); + +describe('App.ApplicationController', function () { + + var installerController = App.ApplicationController.create(); + + describe('#showAboutPopup', function() { + var dataToShowRes = {}; + beforeEach(function () { + sinon.stub(App.ModalPopup, 'show', function(dataToShow){ + dataToShowRes = dataToShow; + }); + }); + afterEach(function () { + App.ModalPopup.show.restore(); + }); + it ('Should send correct data to popup', function() { + installerController.showAboutPopup(); + dataToShowRes = JSON.parse(JSON.stringify(dataToShowRes)); + expect(dataToShowRes).to.eql({ + "header": "About", + "secondary": false + }); + }); + }); + + describe('#clusterName', function() { + beforeEach(function () { + sinon.stub(App.router, 'get').returns('cl1'); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should return cluster name', function() { + expect(installerController.get('clusterName')).to.equal('cl1'); + }); + }); + + describe('#showSettingsPopup', function() { + var dataToShowRes = {}; + + beforeEach(function () { + sinon.stub(App.ModalPopup, 'show', function(dataToShow){ + dataToShowRes = dataToShow; + }); + sinon.stub(App, 'isAccessible').returns(true); + var emulatorClass = function() {}; + emulatorClass.prototype.done = function(func) { + if (func) { + func(); + } + }; + var emulator = new emulatorClass(); + sinon.stub(installerController, 'dataLoading').returns(emulator); + }); + afterEach(function () { + App.isAccessible.restore(); + App.ModalPopup.show.restore(); + installerController.dataLoading.restore(); + }); + it ('Should show settings popup', function() { + installerController.showSettingsPopup(); + dataToShowRes = JSON.parse(JSON.stringify(dataToShowRes)); + expect(dataToShowRes).to.eql({ + "header": "User Settings", + "primary": "Save" + }); + }); + }); + + describe('#startKeepAlivePoller', function() { + it ('Should change run poller state', function() { + installerController.set('isPollerRunning', false); + installerController.startKeepAlivePoller(); + expect(installerController.get('isPollerRunning')).to.be.true; + }); + }); + + describe('#getUserPrefErrorCallback', function() { + it ('Should set currentPrefObject', function() { + installerController.getUserPrefErrorCallback({status: 404}, {}, {}); + expect(installerController.get('currentPrefObject')).to.be.true; + }); + }); + + describe('#getUserPrefSuccessCallback', function() { + it ('Should set currentPrefObject', function() { + installerController.getUserPrefSuccessCallback({status: 200}, {}, {}); + expect(installerController.get('currentPrefObject')).to.be.eql({status: 200}); + }); + }); + + describe('#goToAdminView', function() { + var result; + beforeEach(function () { + sinon.stub(App.router, 'route', function(data) { + result = data; + return false; + }); + }); + afterEach(function () { + App.router.route.restore(); + }); + it ('Should call route once', function() { + installerController.goToAdminView(); + expect(result).to.be.equal('adminView'); + }); + }); + + describe('#dataLoading', function() { + beforeEach(function () { + sinon.stub(installerController, 'getUserPref', function(){ + return { + complete: function(func) { + if (func) { + func(); + } + } + }; + }); + }); + afterEach(function () { + installerController.getUserPref.restore(); + }); + it ('Should change run poller state', function() { + installerController.set('currentPrefObject', {name: 'n1'}); + installerController.dataLoading().then(function(data){ + expect(data).to.be.eql({ + "name": "n1" + }); + }); + }); + }); + + describe('#getStack', function() { + var res; + beforeEach(function () { + sinon.stub(App.ajax, 'send', function(data) { + res = data; + }); + }); + afterEach(function () { + App.ajax.send.restore(); + }); + it ('Should return send value', function() { + var callback = { + 'callback': true + }; + installerController.getStack(callback); + res = JSON.parse(JSON.stringify(res)); + expect(res).to.be.eql({ + "name": "router.login.clusters", + "sender": { + "isPollerRunning": true, + "currentPrefObject": null + }, + "callback": { + "callback": true + } + }); + }); + }); + + describe('#clusterDisplayName', function() { + it ('Should return cluster display name', function() { + installerController.set('clusterName', ''); + expect(installerController.get('clusterDisplayName')).to.equal('mycluster'); + }); + }); + + describe('#isClusterDataLoaded', function() { + beforeEach(function () { + sinon.stub(App.router, 'get').returns('cl1'); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should return true, when data loaded', function() { + expect(installerController.get('isClusterDataLoaded')).to.be.equal('cl1'); + }); + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ac1348/ambari-web/test/controllers/login_controller_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/login_controller_test.js b/ambari-web/test/controllers/login_controller_test.js new file mode 100644 index 0000000..90ba06a --- /dev/null +++ b/ambari-web/test/controllers/login_controller_test.js @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +var App = require('app'); +require('models/cluster'); +require('controllers/wizard'); +require('controllers/installer'); + +describe('App.LoginController', function () { + + var loginController = App.LoginController.create(); + + describe('#postLogin', function() { + it ('Should set error connect', function() { + loginController.postLogin(false, false, false); + expect(loginController.get('errorMessage')).to.be.equal('Unable to connect to Ambari Server. Confirm Ambari Server is running and you can reach Ambari Server from this machine.'); + }); + it ('Should set error login', function() { + loginController.postLogin(true, false, 'User is disabled'); + expect(loginController.get('errorMessage')).to.be.equal('Unable to sign in. Invalid username/password combination.'); + }); + it ('Should set error', function() { + loginController.postLogin(true, false, ''); + expect(loginController.get('errorMessage')).to.be.equal('Unable to sign in. Invalid username/password combination.'); + }); + }); + +}); http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ac1348/ambari-web/test/controllers/main/service/info/config_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main/service/info/config_test.js b/ambari-web/test/controllers/main/service/info/config_test.js index de0e618..7d46d9d 100644 --- a/ambari-web/test/controllers/main/service/info/config_test.js +++ b/ambari-web/test/controllers/main/service/info/config_test.js @@ -199,8 +199,10 @@ describe("App.MainServiceInfoConfigsController", function () { { input: { context: { - 'publicHostName1': ['TaskTracker'], - 'publicHostName2': ['JobTracker', 'TaskTracker'] + restartRequiredHostsAndComponents: { + 'publicHostName1': ['TaskTracker'], + 'publicHostName2': ['JobTracker', 'TaskTracker'] + } } }, components: "2 TaskTrackers, 1 JobTracker", @@ -209,7 +211,9 @@ describe("App.MainServiceInfoConfigsController", function () { { input: { context: { - 'publicHostName1': ['TaskTracker'] + restartRequiredHostsAndComponents: { + 'publicHostName1': ['TaskTracker'] + } } }, components: "1 TaskTracker", @@ -238,8 +242,10 @@ describe("App.MainServiceInfoConfigsController", function () { { input: { context: { - 'publicHostName1': ['TaskTracker'], - 'publicHostName2': ['JobTracker', 'TaskTracker'] + restartRequiredHostsAndComponents: { + 'publicHostName1': ['TaskTracker'], + 'publicHostName2': ['JobTracker', 'TaskTracker'] + } } }, hosts: "publicHostName1, publicHostName2", @@ -248,7 +254,9 @@ describe("App.MainServiceInfoConfigsController", function () { { input: { context: { - 'publicHostName1': ['TaskTracker'] + restartRequiredHostsAndComponents: { + 'publicHostName1': ['TaskTracker'] + } } }, hosts: "publicHostName1", http://git-wip-us.apache.org/repos/asf/ambari/blob/c8ac1348/ambari-web/test/controllers/main_test.js ---------------------------------------------------------------------- diff --git a/ambari-web/test/controllers/main_test.js b/ambari-web/test/controllers/main_test.js index 43ec400..03f8e47 100644 --- a/ambari-web/test/controllers/main_test.js +++ b/ambari-web/test/controllers/main_test.js @@ -19,7 +19,8 @@ var App = require('app'); -describe('App.InstallerController', function () { +describe('App.MainController', function () { + var mainController = App.MainController.create(); describe('#getServerVersionSuccessCallback', function () { @@ -53,7 +54,268 @@ describe('App.InstallerController', function () { expect(App.get('isManagedMySQLForHiveEnabled')).to.equal(item.expected); }); }); + }); + + describe('#isClusterDataLoaded', function() { + beforeEach(function () { + sinon.stub(App.router, 'get').returns(true); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should return true', function() { + expect(mainController.get('isClusterDataLoaded')).to.be.true; + }); + }); + + describe('#clusterDataLoadedPercent', function() { + beforeEach(function () { + sinon.stub(App.router, 'get').returns(16); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should return 16', function() { + expect(mainController.get('clusterDataLoadedPercent')).to.be.equal(16); + }); + }); + + describe('#initialize', function() { + var initialize = false; + beforeEach(function () { + sinon.stub(App.router, 'get').returns({ + loadClusterData: function() { + initialize = true; + } + }); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should return true', function() { + mainController.initialize(); + expect(initialize).to.be.true; + }); + }); + + describe('#dataLoading', function() { + it ('Should resolve promise', function() { + sinon.stub(App.router, 'get').returns(true); + var deffer = mainController.dataLoading(); + App.router.get.restore(); + deffer.then(function(val){ + expect(val).to.be.undefined; + }); + }); + it ('Should resolve promise', function() { + sinon.stub(App.router, 'get').returns(false); + + setTimeout(function() { + mainController.set('isClusterDataLoaded', true); + },150); + + var deffer = mainController.dataLoading(); + App.router.get.restore(); + deffer.then(function(val){ + expect(val).to.be.undefined; + }); + }); + }); + + describe('#checkServerClientVersion', function() { + var initialize = false; + beforeEach(function () { + sinon.stub(mainController, 'getServerVersion').returns({ + done: function(func) { + if (func) { + func(); + } + } + }); + }); + afterEach(function () { + mainController.getServerVersion.restore(); + }); + it ('Should resolve promise', function() { + var deffer = mainController.checkServerClientVersion(); + deffer.then(function(val){ + expect(val).to.be.undefined; + }); + }); + }); + + describe('#getServerVersion', function() { + var res; + beforeEach(function () { + sinon.stub(App.ajax, 'send', function(data) { + res = JSON.parse(JSON.stringify(data)); + }); + }); + afterEach(function () { + App.ajax.send.restore(); + }); + it ('Should send data', function() { + mainController.getServerVersion(); + expect(res).to.be.eql({ + "name": "ambari.service", + "sender": {}, + "data": { + "fields": "?fields=RootServiceComponents/component_version,RootServiceComponents/properties/server.os_family&minimal_response=true" + }, + "success": "getServerVersionSuccessCallback", + "error": "getServerVersionErrorCallback" + }); + }); + }); + + describe('#stopAllService', function() { + beforeEach(function () { + sinon.stub(App.router, 'get').returns({ + stopAllService: function(func) { + if (func) { + func(); + } + } + }); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should call event', function() { + var done = false; + var event = function() { + done = true; + }; + mainController.stopAllService(event); + expect(done).to.be.true; + }); + }); + + describe('#startAllService', function() { + beforeEach(function () { + sinon.stub(App.router, 'get').returns({ + startAllService: function(func) { + if (func) { + func(); + } + } + }); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should call event', function() { + var done = false; + var event = function() { + done = true; + }; + mainController.startAllService(event); + expect(done).to.be.true; + }); + }); + + describe('#isStopAllDisabled', function() { + beforeEach(function () { + sinon.stub(mainController, 'scRequest').returns(true); + }); + afterEach(function () { + mainController.scRequest.restore(); + }); + it ('Should return true', function() { + expect(mainController.get('isStopAllDisabled')).to.be.true; + }); + }); + + describe('#gotoAddService', function() { + var done = false; + beforeEach(function () { + sinon.stub(App.router, 'get').returns({ + gotoAddService: function() { + done = true; + } + }); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should call router', function() { + mainController.gotoAddService(); + expect(done).to.be.true; + }); + }); + describe('#isStartAllDisabled', function() { + beforeEach(function () { + sinon.stub(mainController, 'scRequest').returns(true); + }); + afterEach(function () { + mainController.scRequest.restore(); + }); + it ('Should return true', function() { + expect(mainController.get('isStartAllDisabled')).to.be.true; + }); + }); + + describe('#isAllServicesInstalled', function() { + beforeEach(function () { + sinon.stub(mainController, 'scRequest').returns(true); + }); + afterEach(function () { + mainController.scRequest.restore(); + }); + it ('Should return true', function() { + expect(mainController.get('isAllServicesInstalled')).to.be.true; + }); + }); + + describe('#scRequest', function() { + beforeEach(function () { + sinon.stub(App.router, 'get').returns({ + get: function(request) { + if (request) { + request(); + } + } + }); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should return true', function() { + var done = false; + var event = function() { + done = true; + }; + mainController.scRequest(event); + expect(done).to.be.true; + }); + }); + + describe('#updateTitle', function() { + beforeEach(function () { + sinon.stub(App.router, 'get', function(message){ + if (message == 'clusterController.clusterName') { + return 'c1'; + } else if (message == 'clusterInstallCompleted') { + return true; + } else if (message == 'clusterController') { + return { + get: function() { + return true; + } + }; + } + }); + }); + afterEach(function () { + App.router.get.restore(); + }); + it ('Should update title', function() { + $('body').append('<title id="title-id">text</title>'); + mainController.updateTitle(); + expect($('title').text()).to.be.equal('Ambari - c1'); + $('body').remove('#title-id'); + }); }); });