123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- /**
- * 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('controllers/main/service');
- var mainServiceController;
- describe('App.MainServiceController', function () {
- var tests = Em.A([
- {
- isStartStopAllClicked: true,
- content: Em.A([
- Em.Object.create({
- healthStatus: 'red',
- serviceName: 'HIVE',
- isClientsOnly: false
- }),
- Em.Object.create({
- healthStatus: 'red',
- serviceName: 'HDFS',
- isClientsOnly: false
- }),
- Em.Object.create({
- healthStatus: 'red',
- serviceName: 'TEZ',
- isClientsOnly: true
- })
- ]),
- eStart: true,
- eStop: true,
- mStart: 'mainServiceController StartAll is Disabled 2',
- mStop: 'mainServiceController StopAll is Disabled 2'
- },
- {
- isStartStopAllClicked: false,
- content: Em.A([
- Em.Object.create({
- healthStatus: 'green',
- serviceName: 'HIVE',
- isClientsOnly: false
- }),
- Em.Object.create({
- healthStatus: 'red',
- serviceName: 'HDFS',
- isClientsOnly: false
- }),
- Em.Object.create({
- healthStatus: 'red',
- serviceName: 'TEZ',
- isClientsOnly: true
- })
- ]),
- eStart: false,
- eStop: false,
- mStart: 'mainServiceController StartAll is Enabled 3',
- mStop: 'mainServiceController StopAll is Enabled 3'
- }
- ]);
- beforeEach(function() {
- mainServiceController = App.MainServiceController.create();
- });
- describe('#isStartAllDisabled', function () {
- tests.forEach(function (test) {
- it(test.mStart, function () {
- mainServiceController = App.MainServiceController.create({
- content: test.content,
- isStartStopAllClicked: test.isStartStopAllClicked
- });
- expect(mainServiceController.get('isStartAllDisabled')).to.equals(test.eStart);
- });
- });
- });
- describe('#isStopAllDisabled', function () {
- tests.forEach(function (test) {
- it(test.mStop, function () {
- mainServiceController = App.MainServiceController.create({
- content: test.content,
- isStartStopAllClicked: test.isStartStopAllClicked
- });
- expect(mainServiceController.get('isStopAllDisabled')).to.equals(test.eStop);
- });
- });
- });
- describe('#isStartStopAllClicked', function () {
- beforeEach(function () {
- sinon.stub(App, 'get').withArgs('router.backgroundOperationsController.allOperationsCount').returns(1);
- });
- afterEach(function () {
- App.get.restore();
- });
- it('should be based on BG ops count', function () {
- expect(mainServiceController.get('isStartStopAllClicked')).to.be.true;
- });
- });
- describe('#cluster', function() {
- var tests = Em.A([
- {
- isLoaded: true,
- cluster: [],
- m: 'cluster is loaded',
- e: {name: 'c1'}
- },
- {
- isLoaded: false,
- cluster: [],
- m: 'cluster is not loaded',
- e: null
- }
- ]).forEach(function(test) {
- it(test.m, function() {
- sinon.stub(App.router, 'get', function(k) {
- if ('clusterController.isClusterDataLoaded' === k) return test.isLoaded;
- return Em.get(App.router, k);
- });
- sinon.stub(App.Cluster, 'find', function() {
- return [test.e];
- });
- var c = mainServiceController.get('cluster');
- App.router.get.restore();
- App.Cluster.find.restore();
- expect(c).to.eql(test.e);
- });
- });
- });
- describe('#startAllService', function() {
- beforeEach(function() {
- sinon.stub(mainServiceController, 'allServicesCall', Em.K);
- });
- afterEach(function() {
- mainServiceController.allServicesCall.restore();
- });
- it('target is disabled', function() {
- var event = {target: {className: 'disabled', nodeType: 1}};
- var r = mainServiceController.startAllService(event);
- expect(r).to.be.null;
- });
- it('parent is disabled', function() {
- var event = {target: {parentElement: {className: 'disabled', nodeType: 1}}};
- var r = mainServiceController.startAllService(event);
- expect(r).to.be.null;
- });
- it('nothing disabled', function() {
- var event = {target: {}}, query = 'query';
- mainServiceController.startAllService(event).onPrimary(query);
- expect(mainServiceController.allServicesCall.calledWith('STARTED', query));
- });
- });
- describe('#stopAllService', function() {
- beforeEach(function() {
- sinon.stub(mainServiceController, 'allServicesCall', Em.K);
- });
- afterEach(function() {
- mainServiceController.allServicesCall.restore();
- });
- it('target is disabled', function() {
- var event = {target: {className: 'disabled', nodeType: 1}};
- var r = mainServiceController.stopAllService(event);
- expect(r).to.be.null;
- });
- it('parent is disabled', function() {
- var event = {target: {parentElement: {className: 'disabled', nodeType: 1}}};
- var r = mainServiceController.stopAllService(event);
- expect(r).to.be.null;
- });
- it('nothing disabled', function() {
- var event = {target: {}}, query = 'query';
- mainServiceController.stopAllService(event).onPrimary(query);
- expect(mainServiceController.allServicesCall.calledWith('STARTED', query));
- });
- });
- describe('#startStopAllService', function() {
- var event = { target: document.createElement("BUTTON") };
- beforeEach(function() {
- sinon.stub(mainServiceController, 'allServicesCall', Em.K);
- sinon.spy(Em.I18n, "t");
- });
- afterEach(function() {
- mainServiceController.allServicesCall.restore();
- Em.I18n.t.restore();
- });
- it ("should confirm stop if state is INSTALLED", function() {
- mainServiceController.startStopAllService(event, "INSTALLED");
- expect(Em.I18n.t.calledWith('services.service.stopAll.confirmMsg')).to.be.ok;
- expect(Em.I18n.t.calledWith('services.service.stop.confirmButton')).to.be.ok;
- });
- it ("should check last checkpoint for NN before confirming stop", function() {
- var mainServiceItemController = App.MainServiceItemController.create({});
- sinon.stub(mainServiceItemController, 'checkNnLastCheckpointTime', function() {
- return true;
- });
- sinon.stub(App.router, 'get', function(k) {
- if ('mainServiceItemController' === k) {
- return mainServiceItemController;
- }
- return Em.get(App.router, k);
- });
- sinon.stub(App.Service, 'find', function() {
- return [{
- serviceName: "HDFS",
- workStatus: "STARTED"
- }];
- });
- mainServiceController.startStopAllService(event, "INSTALLED");
- expect(mainServiceItemController.checkNnLastCheckpointTime.calledOnce).to.equal(true);
- mainServiceItemController.checkNnLastCheckpointTime.restore();
- App.router.get.restore();
- App.Service.find.restore();
- });
- it ("should confirm start if state is not INSTALLED", function() {
- mainServiceController.startStopAllService(event, "STARTED");
- expect(Em.I18n.t.calledWith('services.service.startAll.confirmMsg')).to.be.ok;
- expect(Em.I18n.t.calledWith('services.service.start.confirmButton')).to.be.ok;
- });
- });
- describe('#allServicesCall', function() {
- beforeEach(function() {
- sinon.stub($, 'ajax', Em.K);
- sinon.stub(App, 'get', function(k) {
- if ('testMode' === k) return false;
- if ('clusterName' === k) return 'tdk';
- return Em.get(App, k);
- });
- });
- afterEach(function() {
- $.ajax.restore();
- App.get.restore();
- });
- it('should do ajax-request', function() {
- var state = 'STARTED',
- query = 'some query';
- mainServiceController.allServicesCall(state, query);
- var params = $.ajax.args[0][0];
- expect(params.type).to.equal('PUT');
- expect(params.url.contains('/clusters/tdk/services?')).to.be.true;
- var data = JSON.parse(params.data);
- expect(data.Body.ServiceInfo.state).to.equal(state);
- expect(data.RequestInfo.context).to.equal(App.BackgroundOperationsController.CommandContexts.START_ALL_SERVICES);
- });
- });
- describe('#allServicesCallErrorCallback', function() {
- it('should set status to FAIL', function() {
- var params = {query: Em.Object.create({status: ''})};
- mainServiceController.allServicesCallErrorCallback({}, {}, '', {}, params);
- expect(params.query.get('status')).to.equal('FAIL');
- });
- });
- describe('#gotoAddService', function() {
- beforeEach(function() {
- sinon.stub(App.router, 'transitionTo', Em.K);
- });
- afterEach(function() {
- App.router.transitionTo.restore();
- });
- it('should not go to wizard', function() {
- mainServiceController.reopen({isAllServicesInstalled: true});
- mainServiceController.gotoAddService();
- expect(App.router.transitionTo.called).to.be.false;
- });
- it('should go to wizard', function() {
- mainServiceController.reopen({isAllServicesInstalled: false});
- mainServiceController.gotoAddService();
- expect(App.router.transitionTo.calledWith('main.serviceAdd')).to.be.true;
- });
- });
- describe('#isRestartAllRequiredDisabled', function () {
- it('should be false if there is at least one service with isRestartRequired=true', function () {
- mainServiceController.reopen({
- content: [
- {isRestartRequired: false}, {isRestartRequired: false}, {isRestartRequired: true}
- ]
- });
- expect(mainServiceController.get('isRestartAllRequiredDisabled')).to.be.false;
- });
- it('should be true if there is no services with isRestartRequired=true', function () {
- mainServiceController.reopen({
- content: [
- {isRestartRequired: false}, {isRestartRequired: false}, {isRestartRequired: false}
- ]
- });
- expect(mainServiceController.get('isRestartAllRequiredDisabled')).to.be.true;
- });
- });
- describe('#restartAllRequired', function () {
- beforeEach(function () {
- sinon.spy(App, 'showConfirmationPopup');
- sinon.spy(mainServiceController, 'restartHostComponents');
- sinon.stub(App.HostComponent, 'find', function() {
- return [
- Em.Object.create({
- componentName: 'componentName1',
- hostName: 'hostName1',
- service: {
- serviceName: 'serviceName1',
- displayName: 'displayName1'
- },
- staleConfigs: true
- }),
- Em.Object.create({
- componentName: 'componentName2',
- hostName: 'hostName2',
- service: {
- serviceName: 'serviceName2',
- displayName: 'displayName2'
- },
- staleConfigs: true
- }),
- Em.Object.create({
- componentName: 'componentName3',
- hostName: 'hostName3',
- service: {
- serviceName: 'serviceName3',
- displayName: 'displayName3'
- },
- staleConfigs: false
- })
- ];
- });
- });
- afterEach(function () {
- App.HostComponent.find.restore();
- App.showConfirmationPopup.restore();
- mainServiceController.restartHostComponents.restore();
- });
- it('should show confirmation popup with list of services and call restartHostComponents after confirmation', function () {
- var popup = mainServiceController.restartAllRequired();
- popup.onPrimary();
- expect(App.showConfirmationPopup.args[0][1]).to.equal(Em.I18n.t('services.service.refreshAll.confirmMsg').format('displayName1, displayName2'));
- expect(mainServiceController.restartHostComponents.calledWith([
- {
- component_name: 'componentName1',
- service_name: 'serviceName1',
- hosts: 'hostName1'
- },
- {
- component_name: 'componentName2',
- service_name: 'serviceName2',
- hosts: 'hostName2'
- }
- ])).to.be.true;
- });
- });
- describe('#restartHostComponents', function () {
- beforeEach(function () {
- sinon.stub(App.ajax, 'send', Em.K);
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- it('should send ajax request', function () {
- mainServiceController.restartHostComponents();
- expect(App.ajax.send.calledOnce).to.be.true;
- });
- });
- });
|