123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471 |
- /**
- * 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/wizard/step10_controller');
- var controller;
- describe('App.WizardStep10Controller', function () {
- beforeEach(function() {
- controller = App.WizardStep10Controller.create();
- controller.set('content', {cluster: {status: 'INSTALL COMPLETE'}});
- });
- afterEach(function() {
- controller.clearStep();
- });
- describe('#clearStep', function() {
- it('should clear clusterInfo', function() {
- controller.get('clusterInfo').pushObject({});
- controller.clearStep();
- expect(controller.get('clusterInfo.length')).to.equal(0);
- });
- });
- describe('#loadStep', function() {
- beforeEach(function() {
- sinon.spy(controller, 'clearStep');
- sinon.stub(controller, 'loadRegisteredHosts', Em.K);
- sinon.stub(controller, 'loadInstalledHosts', Em.K);
- sinon.stub(controller, 'loadInstallTime', Em.K);
- });
- afterEach(function() {
- controller.clearStep.restore();
- controller.loadRegisteredHosts.restore();
- controller.loadInstalledHosts.restore();
- controller.loadInstallTime.restore();
- });
- it('should call clearStep', function() {
- controller.loadStep();
- expect(controller.clearStep.calledOnce).to.equal(true);
- });
- it('should call loadInstalledHosts', function() {
- controller.loadStep();
- expect(controller.loadInstalledHosts.calledOnce).to.equal(true);
- });
- it('should loadInstallTime if not installerController', function() {
- controller.set('content.controllerName', 'addServiceController');
- controller.loadStep();
- expect(controller.loadInstallTime.calledOnce).to.equal(true);
- });
- var testsForLoadInstallTime = Em.A([
- {
- loadMasterComponents: true,
- loadStartedServices: true,
- e: true
- },
- {
- loadMasterComponents: true,
- loadStartedServices: false,
- e: false
- },
- {
- loadMasterComponents: false,
- loadStartedServices: false,
- e: false
- },
- {
- loadMasterComponents: false,
- loadStartedServices: false,
- e: false
- }
- ]);
- testsForLoadInstallTime.forEach(function(test) {
- it('loadMasterComponents: ' + test.loadMasterComponents.toString() + ' loadStartedServices: ' + test.loadStartedServices.toString(), function() {
- controller.set('content.controllerName', 'installerController');
- sinon.stub(controller, 'loadMasterComponents', function() {return test.loadMasterComponents;});
- sinon.stub(controller, 'loadStartedServices', function() {return test.loadStartedServices;});
- controller.loadStep();
- expect(controller.loadInstallTime.called).to.equal(test.e);
- controller.loadMasterComponents.restore();
- controller.loadStartedServices.restore();
- });
- });
- });
- describe('#loadInstalledHosts', function() {
- var tests = Em.A([
- {
- hosts: {
- 'h1': Em.Object.create({status: 'success', tasks: []}),
- 'h2': Em.Object.create({status: 'success', tasks: []}),
- 'h3': Em.Object.create({status: 'success', tasks: []})
- },
- m: 'all success',
- e: Em.A([
- {id: 1, l: 3}
- ])
- },
- {
- hosts: {
- 'h1': Em.Object.create({status: 'warning', tasks: []}),
- 'h2': Em.Object.create({status: 'failed', tasks: []}),
- 'h3': Em.Object.create({status: 'failed', tasks: []})
- },
- m: 'some failed, some warning',
- e: Em.A([
- {id: 2, l: 3}
- ])
- },
- {
- hosts: {
- 'h1': Em.Object.create({status: 'failed', tasks: []}),
- 'h2': Em.Object.create({status: 'success', tasks: []}),
- 'h3': Em.Object.create({status: 'warning', tasks: []})
- },
- m: 'sone failed, some success, some warning',
- e: Em.A([
- {id: 1, l: 1},
- {id: 2, l: 2}
- ])
- }
- ]);
- tests.forEach(function(test) {
- it(test.m, function() {
- controller.set('content.hosts', test.hosts);
- controller.set('clusterInfo', Em.A([Em.Object.create({id: 1, status: []})]));
- controller.loadInstalledHosts();
- test.e.forEach(function(ex) {
- expect(controller.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', ex.id).get('displayStatement').contains(ex.l)).to.equal(true);
- });
- })
- });
- var testsForFailedTasks = Em.A([
- {
- hosts: {
- 'h1': Em.Object.create({
- status: 'failed',
- tasks: [
- {Tasks: {status: 'FAILED'}},
- {Tasks: {status: 'FAILED'}}
- ]
- }),
- 'h2': Em.Object.create({
- status: 'failed',
- tasks: [
- {Tasks: {status: 'FAILED'}}
- ]
- }),
- 'h3': Em.Object.create({status: 'failed', tasks: []})
- },
- m: 'only failed tasks',
- e: Em.A([
- {st: 'failed', l: 3}
- ])
- },
- {
- hosts: {
- 'h1': Em.Object.create({
- status: 'failed',
- tasks: [
- {Tasks: {status: 'TIMEDOUT'}}
- ]
- }),
- 'h2': Em.Object.create({
- status: 'failed',
- tasks: [
- {Tasks: {status: 'TIMEDOUT'}}
- ]
- }),
- 'h3': Em.Object.create({
- status: 'failed',
- tasks: [
- {Tasks: {status: 'TIMEDOUT'}}
- ]
- })
- },
- m: 'only timedout tasks',
- e: Em.A([
- {st: 'timedout', l: 3}
- ])
- },
- {
- hosts: {
- 'h1': Em.Object.create({
- status: 'failed',
- tasks: []
- }),
- 'h2': Em.Object.create({
- status: 'failed',
- tasks: []
- }),
- 'h3': Em.Object.create({
- status: 'failed',
- tasks: [
- {Tasks: {status: 'ABORTED'}},
- {Tasks: {status: 'ABORTED'}},
- {Tasks: {status: 'ABORTED'}}
- ]
- })
- },
- m: 'only aborted tasks',
- e: Em.A([
- {st: 'aborted', l: 3}
- ])
- },
- {
- hosts: {
- 'h1': Em.Object.create({
- status: 'warning',
- tasks: [
- {Tasks: {status: 'FAILED'}},
- {Tasks: {status: 'FAILED'}}
- ]
- }),
- 'h2': Em.Object.create({
- status: 'warning',
- tasks: [
- {Tasks: {status: 'FAILED'}}
- ]
- }),
- 'h3': Em.Object.create({status: 'warning', tasks: []})
- },
- m: 'only failed tasks, warning hosts',
- e: Em.A([
- {st: 'failed', l: 3}
- ])
- },
- {
- hosts: {
- 'h1': Em.Object.create({
- status: 'warning',
- tasks: [
- {Tasks: {status: 'TIMEDOUT'}}
- ]
- }),
- 'h2': Em.Object.create({
- status: 'warning',
- tasks: [
- {Tasks: {status: 'TIMEDOUT'}}
- ]
- }),
- 'h3': Em.Object.create({
- status: 'warning',
- tasks: [
- {Tasks: {status: 'TIMEDOUT'}}
- ]
- })
- },
- m: 'only timedout tasks, warning hosts',
- e: Em.A([
- {st: 'timedout', l: 3}
- ])
- },
- {
- hosts: {
- 'h1': Em.Object.create({
- status: 'warning',
- tasks: []
- }),
- 'h2': Em.Object.create({
- status: 'warning',
- tasks: []
- }),
- 'h3': Em.Object.create({
- status: 'warning',
- tasks: [
- {Tasks: {status: 'ABORTED'}},
- {Tasks: {status: 'ABORTED'}},
- {Tasks: {status: 'ABORTED'}}
- ]
- })
- },
- m: 'only aborted tasks, warning hosts',
- e: Em.A([
- {st: 'aborted', l: 3}
- ])
- }
- ]);
- testsForFailedTasks.forEach(function(test) {
- it(test.m, function() {
- controller.set('content.hosts', test.hosts);
- controller.set('clusterInfo', Em.A([Em.Object.create({id: 1, status: []})]));
- controller.loadInstalledHosts();
- test.e.forEach(function(ex) {
- expect(controller.get('clusterInfo').findProperty('id', 1).get('status').findProperty('id', 2).get('statements').mapProperty('status', ex.st).length).to.equal(ex.l);
- });
- })
- });
- });
- describe('#loadMasterComponent', function() {
- var tests = Em.A([
- {
- component: Em.Object.create({hostName: 'h1'}),
- e: 1
- },
- {
- component: Em.Object.create({}),
- e: 0
- }
- ]);
- tests.forEach(function(test) {
- it(test.component.get('hostName') ? 'Has hosNBame' : 'Doesn\'t have hostName', function() {
- controller.clearStep();
- controller.get('clusterInfo').pushObject(Em.Object.create({id: 2, status: []}));
- controller.loadMasterComponent(test.component);
- expect(controller.get('clusterInfo').findProperty('id', 2).get('status').length).to.equal(test.e);
- })
- });
- });
- describe('#loadStartedServices', function() {
- var tests = Em.A([
- {
- status: 'STARTED',
- e: {
- ids: [3, 4],
- r: true
- }
- },
- {
- status: 'FAILED',
- e: {
- ids: [3],
- r: false
- }
- }
- ]);
- tests.forEach(function(test) {
- it(test.status, function() {
- controller.set('content', {cluster: {status: test.status}});
- var r = controller.loadStartedServices();
- expect(r).to.equal(test.e.r);
- expect(controller.get('clusterInfo').mapProperty('id')).to.eql(test.e.ids);
- });
- });
- });
- describe('#loadInstallTime', function() {
- var tests = Em.A([
- {
- installTime: 123,
- e: [5]
- },
- {
- installTime: null,
- e: []
- }
- ]);
- tests.forEach(function(test) {
- it('Install time' + test.installTime ? ' available' : ' not available', function() {
- controller.set('content', {cluster: {installTime: test.installTime}});
- var r = controller.loadInstallTime();
- expect(controller.get('clusterInfo').mapProperty('id')).to.eql(test.e);
- });
- });
- });
- describe('#calculateInstallTime', function () {
- it('from "9.21" to 9 minutes 12 seconds', function () {
- expect(controller.calculateInstallTime('9.21')).to.eql({minutes: 9, seconds: 12});
- });
- it('from "0" to 0 minutes 0 seconds', function () {
- expect(controller.calculateInstallTime('0')).to.eql({minutes: 0, seconds: 0});
- });
- it('from "10" to 10 minutes 0 seconds', function () {
- expect(controller.calculateInstallTime('10')).to.eql({minutes: 10, seconds: 0});
- });
- it('from "0.5" to 0 minutes 30 seconds', function () {
- expect(controller.calculateInstallTime('0.5')).to.eql({minutes: 0, seconds: 30});
- });
- });
- describe('#loadMasterComponents', function() {
- var components = Em.A(['NAMENODE','SECONDARY_NAMENODE','JOBTRACKER','HISTORYSERVER','RESOURCEMANAGER','HBASE_MASTER','HIVE_SERVER','OOZIE_SERVER','GANGLIA_SERVER','NAGIOS_SERVER']);
- d3.range(1, components.length).forEach(function(i) {
- d3.range(1, i).forEach(function(j) {
- var c = components.slice(0, j);
- it(c.join(', '), function() {
- var m = c.map(function(component){return {component: component, displayName: component, hostName: 'h1'};});
- controller.set('content.masterComponentHosts', m);
- controller.loadMasterComponents();
- expect(controller.get('clusterInfo').findProperty('id', 2).get('status').length).to.equal(m.length);
- });
- });
- });
- });
- describe('#isNagiosRestartRequired', function() {
- Em.A([
- {
- controllerName: 'addServiceController',
- isLoaded: true,
- e: true
- },
- {
- controllerName: 'installerController',
- isLoaded: true,
- e: false
- },
- {
- controllerName: 'addServiceController',
- isLoaded: false,
- e: false
- },
- {
- controllerName: 'installerController',
- isLoaded: false,
- e: false
- }
- ]).forEach(function (test) {
- it(test.controllerName + ' Nagios loaded' + test.isLoaded.toString(), function () {
- controller.set('content.controllerName', test.controllerName);
- sinon.stub(App.Service, 'find', function() {
- return Em.Object.create({
- isLoaded: test.isLoaded
- })
- });
- expect(controller.get('isNagiosRestartRequired')).to.equal(test.e);
- App.Service.find.restore();
- });
- });
- });
- describe('#loadRegisteredHosts', function() {
- it('should add object to clusterInfo', function() {
- var masterComponentHosts = [{hostName: 'h1'}, {hostName: 'h2'}, {hostName: 'h3'}],
- slaveComponentHosts = [{hosts: [{hostName: 'h1'}, {hostName: 'h4'}]}, {hosts: [{hostName: 'h2'}, {hostName: 'h5'}]}],
- hosts = [{hostName: 'h6'}, {hostName: 'h3'}, {hostName: 'h7'}];
- controller.set('content.masterComponentHosts', masterComponentHosts);
- controller.set('content.slaveComponentHosts', slaveComponentHosts);
- controller.set('clusterInfo', []);
- sinon.stub(App.Host, 'find', function() {
- return hosts;
- });
- var obj = controller.loadRegisteredHosts();
- App.Host.find.restore();
- expect(obj.id).to.equal(1);
- expect(obj.color).to.equal('text-info');
- expect(obj.displayStatement).to.equal(Em.I18n.t('installer.step10.hostsSummary').format(7));
- expect(obj.status).to.eql([]);
- expect(controller.get('clusterInfo.firstObject')).to.eql(obj);
- });
- });
- });
|