12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307 |
- /**
- * 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/step5_controller');
- var modelSetup = require('test/init_model_test');
- require('utils/ajax/ajax');
- var c;
- describe('App.WizardStep5Controller', function () {
- beforeEach(function () {
- c = App.WizardStep5Controller.create();
- sinon.stub(App.router, 'send', Em.K);
- App.router.nextBtnClickInProgress = false;
- });
- afterEach(function () {
- App.router.send.restore();
- App.router.nextBtnClickInProgress = false;
- });
- var controller = App.WizardStep5Controller.create();
- controller.set('content', {});
- controller.set('content', {});
- describe('#sortHosts', function () {
- var tests = Em.A([
- {
- hosts: [
- Em.Object.create({memory: 4, cpu: 1, host_name: 'host1', id: 1}),
- Em.Object.create({memory: 3, cpu: 1, host_name: 'host2', id: 2}),
- Em.Object.create({memory: 2, cpu: 1, host_name: 'host3', id: 3}),
- Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
- ],
- m: 'memory',
- e: [1, 2, 3, 4]
- },
- {
- hosts: [
- Em.Object.create({memory: 1, cpu: 4, host_name: 'host1', id: 1}),
- Em.Object.create({memory: 1, cpu: 3, host_name: 'host2', id: 2}),
- Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 3}),
- Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
- ],
- m: 'cpu',
- e: [1, 2, 3, 4]
- },
- {
- hosts: [
- Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 1}),
- Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 2}),
- Em.Object.create({memory: 1, cpu: 1, host_name: 'host3', id: 3}),
- Em.Object.create({memory: 1, cpu: 1, host_name: 'host1', id: 4})
- ],
- m: 'host_name',
- e: [4, 2, 3, 1]
- },
- {
- hosts: [
- Em.Object.create({memory: 2, cpu: 1, host_name: 'host1', id: 1}),
- Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 2}),
- Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 3}),
- Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 4})
- ],
- m: 'mix',
- e: [1, 2, 4, 3]
- }
- ]);
- tests.forEach(function (test) {
- it(test.m, function () {
- var hosts = Em.copy(test.hosts);
- controller.sortHosts(hosts);
- expect(Em.A(hosts).mapProperty('id')).to.eql(test.e);
- });
- });
- });
- describe('#renderHostInfo', function () {
- var tests = Em.A([
- {
- hosts: {
- h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'INIT'},
- h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'INIT'},
- h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'INIT'},
- h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'INIT'}
- },
- m: 'no one host is REGISTERED',
- e: []
- },
- {
- hosts: {
- h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
- h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
- h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
- h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
- },
- m: 'all hosts are REGISTERED, memory',
- e: ['host1', 'host2', 'host3', 'host4']
- },
- {
- hosts: {
- h1: {memory: 1, cpu: 4, name: 'host1', bootStatus: 'REGISTERED'},
- h2: {memory: 1, cpu: 3, name: 'host2', bootStatus: 'REGISTERED'},
- h3: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'REGISTERED'},
- h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
- },
- m: 'all hosts are REGISTERED, cpu',
- e: ['host1', 'host2', 'host3', 'host4']
- },
- {
- hosts: {
- h1: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
- h2: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
- h3: {memory: 1, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
- h4: {memory: 1, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'}
- },
- m: 'all hosts are REGISTERED, host_name',
- e: ['host1', 'host2', 'host3', 'host4']
- },
- {
- hosts: {
- h1: {memory: 2, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
- h2: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'INIT'},
- h3: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
- h4: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'INIT'}
- },
- m: 'mix',
- e: ['host1', 'host4']
- }
- ]);
- tests.forEach(function (test) {
- it(test.m, function () {
- controller.set('content', {hosts: test.hosts});
- controller.renderHostInfo();
- var r = controller.get('hosts');
- expect(Em.A(r).mapProperty('host_name')).to.eql(test.e);
- });
- });
- });
- describe('#last', function () {
- var tests = Em.A([
- {
- selectedServicesMasters: Em.A([
- {component_name: 'c1', indx: 1},
- {component_name: 'c2', indx: 2},
- {component_name: 'c1', indx: 2}
- ]),
- m: 'Components exists',
- c: 'c1',
- e: 2
- },
- {
- selectedServicesMasters: Em.A([
- {component_name: 'c1', indx: 1},
- {component_name: 'c2', indx: 2},
- {component_name: 'c1', indx: 2}
- ]),
- m: 'Components don\'t exists',
- c: 'c3',
- e: null
- }
- ]);
- tests.forEach(function (test) {
- it(test.m, function () {
- controller.set('selectedServicesMasters', test.selectedServicesMasters);
- if (!Em.isNone(test.e)) {
- expect(controller.last(test.c).indx).to.equal(test.e);
- }
- else {
- expect(Em.isNone(controller.last(test.c))).to.equal(true);
- }
- })
- });
- });
- describe('#remainingHosts', function () {
- it('should show count of hosts without masters', function () {
- c.reopen({masterHostMapping: [
- {}
- ]});
- c.set('hosts', [
- {},
- {},
- {}
- ]);
- expect(c.get('remainingHosts')).to.equal(2);
- });
- });
- describe('#clearStep', function () {
- var tests = Em.A([
- {p: 'hosts'},
- {p: 'selectedServicesMasters'},
- {p: 'servicesMasters'}
- ]);
- tests.forEach(function (test) {
- it('should cleanup ' + test.p, function () {
- c.set(test.p, [Em.Object.create({}), Em.Object.create({})]);
- c.clearStep();
- expect(c.get(test.p).length).to.equal(0);
- });
- });
- });
- describe('#updateComponent', function () {
- var tests = Em.A([
- {
- componentName: 'HBASE_SERVER',
- serviceComponents: [
- Em.Object.create({
- componentName: 'HBASE_SERVER',
- stackService: Em.Object.create({isInstalled: true, serviceName: 'HBASE'})
- })
- ],
- selectedServicesMasters: Em.A([
- Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'}),
- Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
- ]),
- hosts: Em.A([
- Em.Object.create({})
- ]),
- controllerName: 'addServiceController',
- m: 'service is installed',
- e: {
- showAddControl: true,
- showRemoveControl: false
- }
- },
- {
- componentName: 'HBASE_SERVER',
- serviceComponents: [
- Em.Object.create({
- componentName: 'HBASE_SERVER',
- stackService: Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
- })
- ],
- selectedServicesMasters: Em.A([
- Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
- ]),
- hosts: Em.A([
- Em.Object.create({})
- ]),
- controllerName: 'addServiceController',
- m: 'service not installed, but all host already have provided component',
- e: {
- showAddControl: true,
- showRemoveControl: false
- }
- },
- {
- componentName: 'HBASE_SERVER',
- serviceComponents: [
- Em.Object.create({
- componentName: 'HBASE_SERVER',
- stackService: Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
- })
- ],
- selectedServicesMasters: Em.A([
- Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
- ]),
- hosts: Em.A([
- Em.Object.create({}),
- Em.Object.create({})
- ]),
- controllerName: 'reassignMasterController',
- m: 'service not installed, not all host already have provided component, but is reassignMasterController',
- e: {
- showAddControl: false,
- showRemoveControl: false
- }
- }
- ]);
- tests.forEach(function (test) {
- describe(test.m, function () {
- beforeEach(function () {
- sinon.stub(App.StackServiceComponent, 'find', function () {
- return test.serviceComponents;
- });
- c.reopen({
- content: Em.Object.create({
- controllerName: test.controllerName
- }),
- selectedServicesMasters: test.selectedServicesMasters,
- hosts: test.hosts
- });
- c.updateComponent(test.componentName);
- });
- afterEach(function () {
- App.StackServiceComponent.find.restore();
- });
- Em.keys(test.e).forEach(function (k) {
- it(k, function () {
- expect(c.last(test.componentName).get(k)).to.equal(test.e[k]);
- });
- });
- });
- });
- });
- describe('#renderComponents', function () {
- var tests = Em.A([
- {
- masterComponents: Em.A([
- {component_name: 'ZOOKEEPER_SERVER'}
- ]),
- services: Em.A([
- Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
- ]),
- controllerName: 'reassignMasterController',
- m: 'One component',
- isHaEnabled: false,
- component_name: 'ZOOKEEPER_SERVER',
- e: {
- selectedServicesMasters: ['ZOOKEEPER_SERVER'],
- servicesMasters: ['ZOOKEEPER_SERVER'],
- showRemoveControl: [false],
- isInstalled: [false],
- serviceComponentId: [1]
- }
- },
- {
- masterComponents: Em.A([
- {component_name: 'ZOOKEEPER_SERVER'}
- ]),
- services: Em.A([
- Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
- ]),
- controllerName: 'addServiceController',
- m: 'One component, service is not installed',
- component_name: 'ZOOKEEPER_SERVER',
- e: {
- selectedServicesMasters: ['ZOOKEEPER_SERVER'],
- servicesMasters: ['ZOOKEEPER_SERVER'],
- showRemoveControl: [false],
- serviceComponentId: [1]
- }
- },
- {
- masterComponents: Em.A([
- {component_name: 'ZOOKEEPER_SERVER'},
- {component_name: 'ZOOKEEPER_SERVER'}
- ]),
- services: Em.A([
- Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: true})
- ]),
- controllerName: 'addServiceController',
- m: 'Two components, but service is installed',
- component_name: 'ZOOKEEPER_SERVER',
- e: {
- selectedServicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
- servicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
- showRemoveControl: [false, false],
- serviceComponentId: [1, 2]
- }
- }
- ]);
- tests.forEach(function (test) {
- describe(test.m, function () {
- beforeEach(function () {
- sinon.stub(App, 'get').withArgs('isHaEnabled').returns(test.isHaEnabled);
- sinon.stub(App.StackService, 'find', function () {
- return test.services;
- });
- modelSetup.setupStackServiceComponent();
- c.reopen({
- content: Em.Object.create({
- services: test.services,
- controllerName: test.controllerName,
- reassign: {component_name: test.component_name}
- })
- });
- c.renderComponents(test.masterComponents);
- });
- afterEach(function () {
- App.get.restore();
- App.StackService.find.restore();
- modelSetup.cleanStackServiceComponent();
- });
- it('all selectedServicesMasters.component_name are valid', function () {
- expect(c.get('selectedServicesMasters').mapProperty('component_name')).to.eql(test.e.selectedServicesMasters);
- });
- it('all servicesMasters.component_name are valid', function () {
- expect(c.get('servicesMasters').mapProperty('component_name')).to.eql(test.e.servicesMasters);
- });
- it('all showRemoveControl are valid', function () {
- expect(c.get('selectedServicesMasters').mapProperty('showRemoveControl')).to.eql(test.e.showRemoveControl);
- });
- it('all serviceComponentId are valid', function () {
- expect(c.get('selectedServicesMasters').mapProperty('serviceComponentId')).to.eql(test.e.serviceComponentId);
- });
- it('servicesMasters.@each.isInstalled is valid', function () {
- if (c.get('isReasignController')) {
- expect(c.get('servicesMasters').mapProperty('isInstalled')).to.eql(test.e.isInstalled);
- }
- });
- });
- });
- });
- describe('#assignHostToMaster', function () {
- var tests = Em.A([
- {
- componentName: 'c1',
- selectedHost: 'h2',
- serviceComponentId: '1',
- e: {
- indx: 0
- }
- },
- {
- componentName: 'c2',
- selectedHost: 'h3',
- serviceComponentId: '2',
- e: {
- indx: 3
- }
- },
- {
- componentName: 'c3',
- selectedHost: 'h1',
- e: {
- indx: 2
- }
- },
- {
- componentName: 'c2',
- selectedHost: 'h4',
- e: {
- indx: 1
- }
- }
- ]),
- selectedServicesMasters = Em.A([
- Em.Object.create({component_name: 'c1', serviceComponentId: '1', selectedHost: 'h1'}),
- Em.Object.create({component_name: 'c2', serviceComponentId: '1', selectedHost: 'h1'}),
- Em.Object.create({component_name: 'c3', serviceComponentId: '1', selectedHost: 'h3'}),
- Em.Object.create({component_name: 'c2', serviceComponentId: '2', selectedHost: 'h2'})
- ]);
- tests.forEach(function (test) {
- it(test.componentName + ' ' + test.selectedHost + ' ' + test.serviceComponentId, function () {
- c.set('selectedServicesMasters', selectedServicesMasters);
- c.assignHostToMaster(test.componentName, test.selectedHost, test.serviceComponentId);
- expect(c.get('selectedServicesMasters').objectAt(test.e.indx).get('selectedHost')).to.equal(test.selectedHost);
- })
- });
- });
- describe('#removeComponent', function () {
- beforeEach(function () {
- sinon.stub(c, 'getMaxNumberOfMasters', function () {
- return Infinity;
- });
- });
- afterEach(function(){
- c.getMaxNumberOfMasters.restore();
- });
- var tests = Em.A([
- {
- componentName: 'c1',
- serviceComponentId: 1,
- selectedServicesMasters: Em.A([]),
- hosts: [],
- m: 'empty selectedServicesMasters',
- e: false
- },
- {
- componentName: 'ZOOKEPEER_SERVER',
- serviceComponentId: 1,
- selectedServicesMasters: Em.A([
- Em.Object.create({serviceComponentId: 1, component_name: 'HBASE_SERVER'})
- ]),
- hosts: [],
- m: 'no such components',
- e: false
- },
- {
- componentName: 'ZOOKEPEER_SERVER',
- serviceComponentId: 1,
- selectedServicesMasters: Em.A([
- Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER'})
- ]),
- hosts: [],
- m: 'component is only 1',
- e: false
- },
- {
- componentName: 'ZOOKEPEER_SERVER',
- serviceComponentId: 2,
- selectedServicesMasters: Em.A([
- Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
- Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
- ]),
- hosts: [
- {},
- {}
- ],
- m: 'two components, add allowed, remove not allowed',
- e: true,
- showAddControl: true,
- showRemoveControl: false
- },
- {
- componentName: 'ZOOKEPEER_SERVER',
- serviceComponentId: 2,
- selectedServicesMasters: Em.A([
- Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
- Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
- Em.Object.create({serviceComponentId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
- ]),
- hosts: [
- {},
- {},
- {}
- ],
- m: 'three components, add allowed, remove allowed',
- e: true,
- showAddControl: true,
- showRemoveControl: true
- }
- ]);
- tests.forEach(function (test) {
- describe(test.m, function () {
- beforeEach(function () {
- c.set('selectedServicesMasters', JSON.parse(JSON.stringify(test.selectedServicesMasters)));
- c.set('hosts', test.hosts);
- this.result = c.removeComponent(test.componentName, test.serviceComponentId);
- });
- it('removeComponent returns ' + test.e, function () {
- expect(this.result).to.equal(test.e);
- });
- if (test.e) {
- it('showRemoveControl is correct', function () {
- expect(c.get('selectedServicesMasters.lastObject.showRemoveControl')).to.equal(test.showRemoveControl);
- });
- it('showAddControl is correct', function () {
- expect(c.get('selectedServicesMasters.lastObject.showAddControl')).to.equal(test.showAddControl);
- });
- it('componentToRebalance is correct', function () {
- expect(c.get('componentToRebalance')).to.equal(test.componentName);
- });
- it('lastChangedComponent is correct', function () {
- expect(c.get('lastChangedComponent')).to.equal(test.componentName);
- });
- }
- })
- });
- });
- describe('#addComponent', function () {
- beforeEach(function () {
- sinon.stub(c, 'getMaxNumberOfMasters', function () {
- return Infinity;
- });
- });
- afterEach(function(){
- c.getMaxNumberOfMasters.restore();
- });
- var tests = Em.A([
- {
- componentName: 'c1',
- selectedServicesMasters: Em.A([]),
- hosts: [],
- m: 'empty selectedServicesMasters',
- e: false
- },
- {
- componentName: 'ZOOKEPEER_SERVER',
- selectedServicesMasters: Em.A([
- Em.Object.create({serviceComponentId: 1, component_name: 'HBASE_SERVER'})
- ]),
- hosts: [],
- m: 'no such components',
- e: false
- },
- {
- componentName: 'ZOOKEPEER_SERVER',
- selectedServicesMasters: Em.A([
- Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
- Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
- ]),
- hosts: [Em.Object.create({}), Em.Object.create({}), Em.Object.create({})],
- m: 'two components, 3 hosts',
- e: true
- }
- ]);
- tests.forEach(function (test) {
- it(test.m, function () {
- c.set('selectedServicesMasters', test.selectedServicesMasters);
- c.set('hosts', test.hosts);
- expect(c.addComponent(test.componentName)).to.equal(test.e);
- if (test.e) {
- expect(c.get('componentToRebalance')).to.equal(test.componentName);
- expect(c.get('lastChangedComponent')).to.equal(test.componentName);
- }
- });
- });
- });
- describe('#masterHostMapping', function () {
- Em.A([
- {
- selectedServicesMasters: [
- Em.Object.create({selectedHost: 'h1'}),
- Em.Object.create({selectedHost: 'h2'}),
- Em.Object.create({selectedHost: 'h1'})
- ],
- hosts: [
- Em.Object.create({host_name: 'h1', host_info: {}}),
- Em.Object.create({host_name: 'h2', host_info: {}})
- ],
- m: 'Two hosts',
- e: [
- {host_name: 'h1', hostInfo: {}, masterServices: [
- {},
- {}
- ]},
- {host_name: 'h2', hostInfo: {}, masterServices: [
- {}
- ]}
- ]
- },
- {
- selectedServicesMasters: [],
- hosts: [],
- m: 'No hosts',
- e: []
- },
- {
- selectedServicesMasters: [
- Em.Object.create({selectedHost: 'h1'}),
- Em.Object.create({selectedHost: 'h1'})
- ],
- hosts: [
- Em.Object.create({host_name: 'h1', host_info: {}})
- ],
- m: 'One host',
- e: [
- {host_name: 'h1', hostInfo: {}, masterServices: [
- {},
- {}
- ]}
- ]
- }
- ]).forEach(function (test) {
- describe(test.m, function () {
- var result;
- beforeEach(function () {
- c.reopen({
- selectedServicesMasters: test.selectedServicesMasters,
- hosts: test.hosts
- });
- result = c.get('masterHostMapping');
- });
- it('all needed hosts are mapped', function () {
- expect(result.length).to.equal(test.e.length);
- });
- it('all needed hosts have valid data', function () {
- result.forEach(function (r, i) {
- expect(r.get('host_name')).to.equal(test.e[i].host_name);
- expect(r.get('masterServices.length')).to.equal(test.e[i].masterServices.length);
- expect(r.get('hostInfo')).to.be.an.object;
- });
- });
- });
- });
- });
- describe('#anyError', function () {
- Em.A([
- {
- servicesMasters: [
- Em.Object.create({errorMessage: 'some message'}),
- Em.Object.create({errorMessage: ''})
- ],
- generalErrorMessages: [],
- e: true
- },
- {
- servicesMasters: [
- Em.Object.create({errorMessage: ''}),
- Em.Object.create({errorMessage: ''})
- ],
- generalErrorMessages: [],
- e: false
- },
- {
- servicesMasters: [
- Em.Object.create({errorMessage: 'some message'}),
- Em.Object.create({errorMessage: 'some message 2'})
- ],
- generalErrorMessages: ['some message'],
- e: true
- },
- {
- servicesMasters: [
- Em.Object.create({errorMessage: ''}),
- Em.Object.create({errorMessage: ''})
- ],
- generalErrorMessages: ['some message'],
- e: true
- }
- ]).forEach(function (test, i) {
- it('test #' + i.toString(), function () {
- c.setProperties({
- servicesMasters: test.servicesMasters,
- generalErrorMessages: test.generalErrorMessages
- });
- expect(c.get('anyError')).to.equal(test.e);
- });
- });
- });
- describe('#anyWarning', function () {
- Em.A([
- {
- servicesMasters: [
- Em.Object.create({warnMessage: 'some message'}),
- Em.Object.create({warnMessage: ''})
- ],
- generalWarningMessages: [],
- e: true
- },
- {
- servicesMasters: [
- Em.Object.create({warnMessage: ''}),
- Em.Object.create({warnMessage: ''})
- ],
- generalWarningMessages: [],
- e: false
- },
- {
- servicesMasters: [
- Em.Object.create({warnMessage: 'some message'}),
- Em.Object.create({warnMessage: 'some message 2'})
- ],
- generalWarningMessages: ['some message'],
- e: true
- },
- {
- servicesMasters: [
- Em.Object.create({warnMessage: ''}),
- Em.Object.create({warnMessage: ''})
- ],
- generalWarningMessages: ['some message'],
- e: true
- }
- ]).forEach(function (test, i) {
- it('test #' + i.toString(), function () {
- c.setProperties({
- servicesMasters: test.servicesMasters,
- generalWarningMessages: test.generalWarningMessages
- });
- expect(c.get('anyWarning')).to.equal(test.e);
- });
- });
- });
- describe('#clearRecommendations', function () {
- it('should clear content.recommendations', function () {
- c.set('content', {recommendations: {'s': {}}});
- c.clearRecommendations();
- expect(c.get('content.recommendations')).to.be.null;
- });
- });
- describe('#updateIsSubmitDisabled', function () {
- var clearCases = [
- {
- isHostNameValid: true,
- isInitialLayout: true,
- isInitialLayoutResulting: false,
- clearRecommendationsCallCount: 0,
- recommendAndValidateCallCount: 1,
- title: 'initial masters-hosts layout'
- },
- {
- isHostNameValid: true,
- isInitialLayout: false,
- isInitialLayoutResulting: false,
- clearRecommendationsCallCount: 1,
- recommendAndValidateCallCount: 1,
- title: 'master-hosts layout changed'
- },
- {
- isHostNameValid: false,
- isInitialLayout: false,
- isInitialLayoutResulting: false,
- clearRecommendationsCallCount: 0,
- recommendAndValidateCallCount: 0,
- title: 'invalid host name specified'
- }
- ];
- beforeEach(function () {
- c.set('selectedServicesMasters', [
- {isInstalled: false}
- ]);
- sinon.stub(c, 'clearRecommendations', Em.K);
- sinon.stub(c, 'recommendAndValidate', Em.K);
- });
- afterEach(function () {
- c.clearRecommendations.restore();
- c.recommendAndValidate.restore();
- });
- it('shouldn\'t change submitDisabled if thereIsNoMasters returns false', function () {
- c.set('selectedServicesMasters', [
- {isInstalled: true}
- ]);
- c.set('submitDisabled', false);
- c.updateIsSubmitDisabled();
- expect(c.get('submitDisabled')).to.equal(false);
- });
- it('should check servicesMasters.@each.isHostNameValid if useServerValidation is false', function () {
- c.set('useServerValidation', false);
- c.set('servicesMasters', [
- {isHostNameValid: false},
- {isHostNameValid: true}
- ]);
- c.updateIsSubmitDisabled();
- expect(c.get('submitDisabled')).to.equal(true);
- c.set('servicesMasters', [
- {isHostNameValid: true},
- {isHostNameValid: true}
- ]);
- c.updateIsSubmitDisabled();
- expect(c.get('submitDisabled')).to.equal(false);
- });
- clearCases.forEach(function (item) {
- it(item.title, function () {
- c.setProperties({
- isInitialLayout: item.isInitialLayout,
- servicesMasters: [{
- isHostNameValid: item.isHostNameValid
- }]
- });
- expect(c.get('isInitialLayout')).to.equal(item.isInitialLayoutResulting);
- expect(c.clearRecommendations.callCount).to.equal(item.clearRecommendationsCallCount);
- expect(c.recommendAndValidate.callCount).to.equal(item.recommendAndValidateCallCount);
- });
- });
- });
- describe('#isHostNameValid', function () {
- beforeEach(function () {
- c.setProperties({
- hosts: [
- {host_name: 'h1'},
- {host_name: 'h2'},
- {host_name: 'h3'}
- ],
- selectedServicesMasters: [
- {component_name: 'c1', selectedHost: 'h1'},
- {component_name: 'c2', selectedHost: 'h2'},
- {component_name: 'c3', selectedHost: 'h3'},
- {component_name: 'c3', selectedHost: 'h1'}
- ]
- });
- });
- Em.A([
- {
- componentName: 'c1',
- selectedHost: ' ',
- m: 'empty hostName is invalid',
- e: false
- },
- {
- componentName: 'c1',
- selectedHost: 'h4',
- m: 'hostName not exists',
- e: false
- },
- {
- componentName: 'c4',
- selectedHost: 'h3',
- m: 'component not exists on host',
- e: true
- }
- ]).forEach(function (test) {
- it(test.m, function () {
- expect(c.isHostNameValid(test.componentName, test.selectedHost)).to.equal(test.e);
- });
- });
- });
- describe('#createComponentInstallationObject', function () {
- afterEach(function () {
- App.StackServiceComponent.find.restore();
- });
- Em.A([
- {
- fullComponent: Em.Object.create({
- componentName: 'c1',
- serviceName: 's1'
- }),
- hostName: 'h1',
- mastersToMove: ['c1'],
- savedComponent: {
- hostName: 'h2',
- isInstalled: true
- },
- stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
- e: {
- component_name: 'c1',
- display_name: 'C1',
- serviceId: 's1',
- selectedHost: 'h2',
- isInstalled: true,
- isServiceCoHost: false
- }
- },
- {
- fullComponent: Em.Object.create({
- componentName: 'c1',
- serviceName: 's1'
- }),
- hostName: 'h1',
- mastersToMove: [],
- stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: false})],
- e: {
- component_name: 'c1',
- display_name: 'C1',
- serviceId: 's1',
- selectedHost: 'h1',
- isInstalled: false,
- isServiceCoHost: false
- }
- },
- {
- fullComponent: Em.Object.create({
- componentName: 'c1',
- serviceName: 's1'
- }),
- hostName: 'h1',
- mastersToMove: [],
- stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
- e: {
- component_name: 'c1',
- display_name: 'C1',
- serviceId: 's1',
- selectedHost: 'h1',
- isInstalled: false,
- isServiceCoHost: true
- }
- }
- ]).forEach(function (test, i) {
- describe('test #' + i, function () {
- beforeEach(function () {
- sinon.stub(App.StackServiceComponent, 'find', function () {
- return test.stackServiceComponents;
- });
- c.set('mastersToMove', test.mastersToMove);
- c.set('content', {controllerName: test.controllerName});
- });
- it('component-object is valid', function () {
- expect(c.createComponentInstallationObject(test.fullComponent, test.hostName, test.savedComponent)).to.eql(test.e);
- });
- });
- });
- });
- describe('#createComponentInstallationObjects', function () {
- beforeEach(function() {
- sinon.stub(App.StackServiceComponent, 'find', function() {
- return [
- Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
- Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
- Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c4', serviceName: 's2'}),
- Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
- Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
- Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c4', serviceName: 's2'})
- ];
- });
- c.set('content', {
- masterComponentHosts: [],
- services: [
- {serviceName: 's1', isSelected: true, isInstalled: false},
- {serviceName: 's2', isSelected: true, isInstalled: false}
- ],
- recommendations: {
- "blueprint": {
- "host_groups": [
- {
- "name": "host-group-1",
- "components": [ {"name": "c1"}, {"name": "c2"} ]
- },
- {
- "name": "host-group-2",
- "components": [ {"name": "c1"}, {"name": "c2"} ]
- },
- {
- "name": "host-group-3",
- "components": [ {"name": "c1"} ]
- }
- ]
- },
- "blueprint_cluster_binding": {
- "host_groups": [
- {
- "name": "host-group-1",
- "hosts": [ {"fqdn": "h1"} ]
- },
- {
- "name": "host-group-2",
- "hosts": [ {"fqdn": "h2"} ]
- },
- {
- "name": "host-group-3",
- "hosts": [ {"fqdn": "h3"} ]
- }
- ]
- }
- }
- });
- });
- afterEach(function() {
- App.StackServiceComponent.find.restore();
- });
- it('simple map without nothing stored/saved etc', function() {
- var r = c.createComponentInstallationObjects();
- expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1']);
- expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1']);
- expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3']);
- });
- describe('some saved components exist', function() {
- beforeEach(function () {
- c.set('content.controllerName', 'addServiceController');
- c.get('multipleComponents').push('c4');
- c.set('content.masterComponentHosts', [
- {hostName: 'h3', component: 'c4'}
- ]);
- c.get('content.recommendations.blueprint.host_groups')[2].components.push({name: 'c4'});
- });
- it('data contains save components', function () {
- var r = c.createComponentInstallationObjects();
- expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1', 'c4']);
- expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1', 's2']);
- expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3', 'h3']);
- });
- });
- });
- describe('#getCurrentBlueprint', function () {
- beforeEach(function() {
- sinon.stub(c, 'getCurrentSlaveBlueprint', function() {
- return {
- blueprint_cluster_binding: {
- host_groups: []
- },
- blueprint: {
- host_groups: []
- }
- };
- });
- });
- afterEach(function() {
- c.getCurrentSlaveBlueprint.restore();
- });
- it('should map masterHostMapping', function () {
- c.reopen({masterHostMapping: [
- {host_name: 'h1', hostInfo:{}, masterServices: [
- {serviceId: 's1', component_name: 'c1'},
- {serviceId: 's2', component_name: 'c2'}
- ]},
- {host_name: 'h2', hostInfo:{}, masterServices: [
- {serviceId: 's1', component_name: 'c1'},
- {serviceId: 's3', component_name: 'c3'}
- ]}
- ]});
- var r = c.getCurrentBlueprint();
- expect(r).to.eql({"blueprint": {"host_groups": [
- {"name": "host-group-1", "components": [
- {"name": "c1"},
- {"name": "c2"}
- ]},
- {"name": "host-group-2", "components": [
- {"name": "c1"},
- {"name": "c3"}
- ]}
- ]}, "blueprint_cluster_binding": {"host_groups": [
- {"name": "host-group-1", "hosts": [
- {"fqdn": "h1"}
- ]},
- {"name": "host-group-2", "hosts": [
- {"fqdn": "h2"}
- ]}
- ]}}
- );
- });
- });
- describe('#updateValidationsSuccessCallback', function() {
- beforeEach(function() {
- sinon.stub(App.HostComponent, 'find', function() {
- return [];
- });
- });
- afterEach(function() {
- App.HostComponent.find.restore();
- });
- describe('should map messages to generalErrorMessages, generalWarningMessages', function() {
- var data = [
- {
- type: 'host-component',
- 'component-name': 'c1',
- host: 'h1',
- level: 'ERROR',
- message: 'm1'
- },
- {
- type: 'host-component',
- 'component-name': 'c2',
- host: 'h2',
- level: 'WARN',
- message: 'm2'
- },
- {
- type: 'host-component',
- 'component-name': 'c3',
- host: 'h3',
- level: 'ERROR',
- message: 'm3'
- },
- {
- type: 'host-component',
- 'component-name': 'c4',
- host: 'h4',
- level: 'WARN',
- message: 'm4'
- }
- ],
- servicesMasters = [
- Em.Object.create({selectedHost: 'h1', component_name: 'c1'}),
- Em.Object.create({selectedHost: 'h2', component_name: 'c2'})
- ];
- beforeEach(function () {
- c.set('servicesMasters', servicesMasters);
- c.updateValidationsSuccessCallback({resources: [{items: data}]});
- });
- it('submitDisabled is false', function () {
- expect(c.get('submitDisabled')).to.equal(false);
- });
- it('errorMessage for c1 is `m1`', function () {
- expect(c.get('servicesMasters').findProperty('component_name', 'c1').get('errorMessage')).to.equal('m1');
- });
- it('errorMessage for c2 is `m2`', function () {
- expect(c.get('servicesMasters').findProperty('component_name', 'c2').get('warnMessage')).to.equal('m2');
- });
- it('no general errors', function () {
- expect(c.get('generalErrorMessages')).to.be.empty;
- });
- it('no general warnings', function () {
- expect(c.get('generalWarningMessages')).to.be.empty;
- });
- });
- });
- describe('#sortComponentsByServiceName', function () {
- var components = [{
- "component_name": "METRICS_COLLECTOR",
- "serviceId": "AMBARI_METRICS"
- }, {"component_name": "ZOOKEEPER_SERVER", "serviceId": "ZOOKEEPER"}, {
- "component_name": "NAMENODE",
- "serviceId": "HDFS"
- }, {"component_name": "DRPC_SERVER", "serviceId": "STORM"}, {
- "component_name": "APP_TIMELINE_SERVER",
- "serviceId": "YARN"
- }, {"component_name": "RESOURCEMANAGER", "serviceId": "YARN"}, {
- "component_name": "SECONDARY_NAMENODE",
- "serviceId": "HDFS"
- }, {"component_name": "ZOOKEEPER_SERVER", "serviceId": "ZOOKEEPER"}, {
- "component_name": "HISTORYSERVER",
- "serviceId": "MAPREDUCE2"
- }, {"component_name": "NIMBUS", "serviceId": "STORM"}, {"component_name": "STORM_UI_SERVER", "serviceId": "STORM"}];
- it('ZKS should be one after anothert', function () {
- var sorted = c.sortComponentsByServiceName(components);
- expect(sorted.mapProperty('component_name').join('|').contains('ZOOKEEPER_SERVER|ZOOKEEPER_SERVER')).to.be.true;
- });
- });
- describe('#submit',function(){
- it('if Next button is clicked multiple times before the next step renders, it must not be processed',function(){
- c.reopen({isSubmitDisabled:false, submitDisabled:false, useServerValidation:false});
- c.submit();
- expect(App.router.send.calledWith('next')).to.equal(true);
- App.router.send.reset();
- c.submit();
- expect(App.router.send.calledWith('next')).to.equal(false);
- });
- });
- });
|