12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319 |
- /**
- * 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');
- require('controllers/main/host/add_controller');
- require('models/host_component');
- require('models/service');
- require('mappers/server_data_mapper');
- describe('App.AddHostController', function () {
- var controller = App.AddHostController.create({
- testDBHosts: null,
- getDBProperty: function () {
- return this.get('testDBHosts');
- },
- setDBProperty: function () {
- },
- loadClients: function () {
- }
- });
- describe('#removeHosts()', function () {
- var testCases = [
- {
- title: 'No hosts, db is empty',
- content: {
- hosts: [],
- dbHosts: {}
- },
- result: {}
- },
- {
- title: 'Host is passed, db is empty',
- content: {
- hosts: [
- {name: 'host1'}
- ],
- dbHosts: {}
- },
- result: {}
- },
- {
- title: 'Passed host different from hosts in db',
- content: {
- hosts: [
- {name: 'host1'}
- ],
- dbHosts: {
- 'host2': {}
- }
- },
- result: {
- 'host2': {}
- }
- },
- {
- title: 'Passed host match host in db',
- content: {
- hosts: [
- {name: 'host1'}
- ],
- dbHosts: {
- 'host1': {}
- }
- },
- result: {}
- }
- ];
- beforeEach(function () {
- sinon.spy(controller, "setDBProperty");
- });
- afterEach(function () {
- controller.setDBProperty.restore();
- });
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.set('testDBHosts', test.content.dbHosts);
- controller.removeHosts(test.content.hosts);
- expect(controller.setDBProperty.calledWith('hosts', test.result)).to.be.true;
- });
- });
- });
- describe('#sortServiceConfigGroups()', function () {
- var testCases = [
- {
- title: 'No selected services',
- selectedServices: [
- {configGroups: []}
- ],
- result: [
- {configGroups: []}
- ]
- },
- {
- title: 'Only one group is present',
- selectedServices: [
- {configGroups: [
- {configGroups: {group_name: 'b'}}
- ]}
- ],
- result: [
- {configGroups: [
- {configGroups: {group_name: 'b'}}
- ]}
- ]
- },
- {
- title: 'Reverse order of groups',
- selectedServices: [
- {configGroups: [
- {ConfigGroup: {group_name: 'b2'}},
- {ConfigGroup: {group_name: 'a1'}}
- ]}
- ],
- result: [
- {configGroups: [
- {ConfigGroup: {group_name: 'a1'}},
- {ConfigGroup: {group_name: 'b2'}}
- ]}
- ]
- },
- {
- title: 'Correct order of groups',
- selectedServices: [
- {configGroups: [
- {ConfigGroup: {group_name: 'a1'}},
- {ConfigGroup: {group_name: 'b2'}}
- ]}
- ],
- result: [
- {configGroups: [
- {ConfigGroup: {group_name: 'a1'}},
- {ConfigGroup: {group_name: 'b2'}}
- ]}
- ]
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.sortServiceConfigGroups(test.selectedServices);
- expect(test.selectedServices).to.eql(test.result);
- });
- });
- });
- describe('#loadServiceConfigGroupsBySlaves()', function () {
- var testCases = [
- {
- title: 'slaveComponentHosts is null',
- slaveComponentHosts: null,
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'slaveComponentHosts is empty',
- slaveComponentHosts: [],
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'Component does not have hosts',
- slaveComponentHosts: [
- {hosts: []}
- ],
- result: {
- output: true,
- selectedServices: []
- }
- },
- {
- title: 'Only client component is present',
- slaveComponentHosts: [
- {
- hosts: [
- {hostName: 'host1'}
- ],
- componentName: 'CLIENT'
- }
- ],
- result: {
- output: true,
- selectedServices: []
- }
- }
- ];
- controller.set('content.configGroups', [
- {
- ConfigGroup: {
- tag: 'HDFS',
- group_name: 'HDFS test'
- }
- }
- ]);
- testCases.forEach(function (test) {
- it(test.title, function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', test.slaveComponentHosts);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.equal(test.result.output);
- expect(selectedServices).to.eql(test.result.selectedServices);
- });
- });
- });
- describe('#loadServiceConfigGroupsByClients()', function () {
- var testCases = [
- {
- title: 'slaveComponentHosts is null',
- content: {
- slaveComponentHosts: null,
- clients: [],
- selectedServices: []
- },
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'slaveComponentHosts is empty',
- content: {
- slaveComponentHosts: [],
- clients: [],
- selectedServices: []
- },
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'Client does not have hosts',
- content: {
- slaveComponentHosts: [
- {
- componentName: 'CLIENT',
- hosts: []
- }
- ],
- clients: [],
- selectedServices: []
- },
- result: {
- output: false,
- selectedServices: []
- }
- },
- {
- title: 'Client has hosts, but clients is empty',
- content: {
- slaveComponentHosts: [
- {
- componentName: 'CLIENT',
- hosts: [
- {hostName: 'host1'}
- ]
- }
- ],
- clients: [],
- selectedServices: []
- },
- result: {
- output: false,
- selectedServices: []
- }
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.set('content.slaveComponentHosts', test.content.slaveComponentHosts);
- controller.set('content.clients', test.content.clients);
- expect(controller.loadServiceConfigGroupsByClients(test.content.selectedServices)).to.equal(test.result.output);
- expect(test.content.selectedServices).to.eql(test.result.selectedServices);
- });
- });
- });
- describe('#installServices()', function () {
- beforeEach(function () {
- sinon.spy(App.ajax, "send");
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- it('No hosts', function () {
- controller.set('content.cluster', {name: 'cl'});
- controller.set('testDBHosts', {});
- expect(controller.installServices()).to.be.false;
- expect(App.ajax.send.called).to.be.false;
- });
- it('Cluster name is empty', function () {
- controller.set('content.cluster', {name: ''});
- controller.set('testDBHosts', {'host1': {}});
- expect(controller.installServices()).to.be.false;
- expect(App.ajax.send.called).to.be.false;
- });
- it('Cluster name is correct and hosts are present', function () {
- controller.set('content.cluster', {name: 'cl'});
- controller.set('testDBHosts', {'host1': {isInstalled: false}});
- expect(controller.installServices()).to.be.true;
- expect(App.ajax.send.called).to.be.true;
- });
- });
- describe('#getClientsToInstall', function () {
- var services = [
- Em.Object.create({
- serviceName: 'service1'
- }),
- Em.Object.create({
- serviceName: 'service2'
- })
- ];
- var components = [
- Em.Object.create({
- componentName: 'comp1',
- displayName: 'comp1',
- serviceName: 'service1',
- isClient: true
- }),
- Em.Object.create({
- componentName: 'comp2',
- displayName: 'comp2',
- serviceName: 'service1',
- isClient: true
- }),
- Em.Object.create({
- componentName: 'comp3',
- displayName: 'comp3',
- serviceName: 'service2',
- isClient: false
- }),
- Em.Object.create({
- componentName: 'comp4',
- displayName: 'comp4',
- serviceName: 'service3',
- isClient: true
- })
- ];
- var clients = [
- {
- component_name: 'comp1',
- display_name: 'comp1',
- isInstalled: false
- },
- {
- component_name: 'comp2',
- display_name: 'comp2',
- isInstalled: false
- }
- ];
- it("generatel list of clients to install", function () {
- expect(controller.getClientsToInstall(services, components)).to.eql(clients);
- })
- });
- describe("#setCurrentStep()", function () {
- before(function () {
- sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
- sinon.stub(App.db, 'setWizardCurrentStep', Em.K);
- });
- after(function () {
- App.clusterStatus.setClusterStatus.restore();
- App.db.setWizardCurrentStep.restore();
- });
- it("call App.clusterStatus.setClusterStatus()", function () {
- controller.setCurrentStep();
- expect(App.clusterStatus.setClusterStatus.getCall(0).args[0].wizardControllerName).to.be.equal('addHostController');
- });
- });
- describe("#getCluster()", function () {
- before(function () {
- sinon.stub(App.router, 'getClusterName').returns('c1');
- });
- after(function () {
- App.router.getClusterName.restore();
- });
- it("", function () {
- controller.set('clusterStatusTemplate', {'prop': 'clusterStatusTemplate'});
- expect(controller.getCluster()).to.be.eql({
- prop: 'clusterStatusTemplate',
- name: 'c1'
- });
- });
- });
- describe("#loadServices", function () {
- var services = {
- db: null,
- stack: [],
- model: []
- };
- beforeEach(function () {
- sinon.stub(controller, 'getDBProperty', function () {
- return services.db;
- });
- sinon.stub(App.StackService, 'find', function () {
- return services.stack;
- });
- sinon.stub(App.Service, 'find', function () {
- return services.model;
- });
- sinon.stub(controller, 'setDBProperty', Em.K);
- });
- afterEach(function () {
- controller.getDBProperty.restore();
- App.StackService.find.restore();
- App.Service.find.restore();
- controller.setDBProperty.restore();
- });
- it("No services in db, no installed services", function () {
- services.stack = [Em.Object.create({
- serviceName: 'S1'
- })];
- controller.loadServices();
- expect(controller.setDBProperty.getCall(0).args).to.eql(['services',
- {
- selectedServices: [],
- installedServices: []
- }
- ]);
- expect(controller.get('content.services')).to.eql([
- Em.Object.create({
- serviceName: 'S1',
- isInstalled: false,
- isSelected: false
- })
- ])
- });
- it("No services in db, installed service present", function () {
- services.stack = [
- Em.Object.create({
- serviceName: 'S1'
- }),
- Em.Object.create({
- serviceName: 'S2'
- })
- ];
- services.model = [
- Em.Object.create({
- serviceName: 'S1'
- })
- ];
- controller.loadServices();
- expect(controller.setDBProperty.getCall(0).args).to.eql(['services',
- {
- selectedServices: ['S1'],
- installedServices: ['S1']
- }
- ]);
- expect(controller.get('content.services')).to.eql([
- Em.Object.create({
- serviceName: 'S1',
- isInstalled: true,
- isSelected: true
- }),
- Em.Object.create({
- serviceName: 'S2',
- isInstalled: false,
- isSelected: false
- })
- ]);
- });
- it("DB is empty", function () {
- services.stack = [Em.Object.create({
- serviceName: 'S1'
- })];
- services.db = {
- selectedServices: [],
- installedServices: []
- };
- controller.loadServices();
- expect(controller.setDBProperty.called).to.be.false;
- expect(controller.get('content.services')).to.eql([
- Em.Object.create({
- serviceName: 'S1',
- isSelected: false,
- isInstalled: false
- })
- ]);
- });
- it("DB has selected and installed services", function () {
- services.stack = [
- Em.Object.create({
- serviceName: 'S1'
- }),
- Em.Object.create({
- serviceName: 'S2'
- })
- ];
- services.db = {
- selectedServices: ['S1'],
- installedServices: ['S2']
- };
- controller.loadServices();
- expect(controller.setDBProperty.called).to.be.false;
- expect(controller.get('content.services')).to.eql([
- Em.Object.create({
- serviceName: 'S1',
- isInstalled: false,
- isSelected: true
- }),
- Em.Object.create({
- serviceName: 'S2',
- isInstalled: true,
- isSelected: false
- })
- ]);
- });
- });
- describe("#loadSlaveComponentHosts()", function () {
- var mock = {
- hosts: null,
- slaveComponentHosts: null
- };
- beforeEach(function () {
- sinon.stub(controller, 'getDBProperties', function (propsList) {
- var ret = {};
- propsList.forEach(function(k) {
- ret[k] = mock[k];
- });
- return ret;
- });
- });
- afterEach(function () {
- controller.getDBProperties.restore();
- });
- it("No slaveComponentHosts in db, null", function () {
- controller.loadSlaveComponentHosts();
- expect(controller.get('content.slaveComponentHosts')).to.be.empty;
- });
- it("No slaveComponentHosts in db", function () {
- mock.slaveComponentHosts = [];
- controller.loadSlaveComponentHosts();
- expect(controller.get('content.slaveComponentHosts')).to.be.empty;
- });
- it("One slaveComponent without hosts", function () {
- mock.slaveComponentHosts = [
- {hosts: []}
- ];
- mock.hosts = {};
- controller.loadSlaveComponentHosts();
- expect(controller.get('content.slaveComponentHosts')).to.be.eql([
- {hosts: []}
- ]);
- });
- it("One slaveComponent with host", function () {
- mock.slaveComponentHosts = [
- {hosts: [
- {host_id: 1}
- ]}
- ];
- mock.hosts = {'host1': {id: 1}};
- controller.loadSlaveComponentHosts();
- expect(controller.get('content.slaveComponentHosts')).to.be.eql([
- {hosts: [
- {
- host_id: 1,
- hostName: 'host1'
- }
- ]}
- ]);
- });
- });
- describe("#saveClients()", function () {
- before(function () {
- sinon.stub(App.StackServiceComponent, 'find').returns('StackServiceComponent');
- sinon.stub(controller, 'getClientsToInstall').returns(['client']);
- sinon.stub(controller, 'setDBProperty', Em.K);
- });
- after(function () {
- controller.setDBProperty.restore();
- App.StackServiceComponent.find.restore();
- controller.getClientsToInstall.restore();
- });
- it("", function () {
- controller.set('content.services', [Em.Object.create({'isSelected': true, 'isInstallable': true})]);
- controller.saveClients();
- expect(controller.getClientsToInstall.calledWith(
- [Em.Object.create({'isSelected': true, 'isInstallable': true})],
- 'StackServiceComponent'
- )).to.be.true;
- expect(controller.setDBProperty.calledWith('clientInfo', ['client'])).to.be.true;
- expect(controller.get('content.clients')).to.be.eql(['client']);
- });
- });
- describe("#getClientsToInstall()", function () {
- var testCases = [
- {
- title: 'No services',
- data: {
- services: [],
- components: []
- },
- result: []
- },
- {
- title: 'No components',
- data: {
- services: [
- {}
- ],
- components: []
- },
- result: []
- },
- {
- title: 'Component is not client',
- data: {
- services: [Em.Object.create({serviceName: 'S1'})],
- components: [Em.Object.create({serviceName: 'S1'})]
- },
- result: []
- },
- {
- title: 'Component is not client',
- data: {
- services: [Em.Object.create({serviceName: 'S1'})],
- components: [Em.Object.create({serviceName: 'S1', isClient: false})]
- },
- result: []
- },
- {
- title: 'Component is client',
- data: {
- services: [Em.Object.create({serviceName: 'S1'})],
- components: [Em.Object.create({
- serviceName: 'S1',
- isClient: true,
- componentName: 'C1',
- displayName: 'C1'
- })]
- },
- result: [
- {
- component_name: 'C1',
- display_name: 'C1',
- isInstalled: false
- }
- ]
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- expect(controller.getClientsToInstall(test.data.services, test.data.components)).to.eql(test.result);
- });
- });
- });
- describe("#applyConfigGroup()", function () {
- beforeEach(function () {
- sinon.stub(App.ajax, 'send', Em.K);
- });
- afterEach(function () {
- App.ajax.send.restore();
- });
- it("No config groups", function () {
- controller.set('content.configGroups', []);
- controller.applyConfigGroup();
- expect(App.ajax.send.called).to.be.false;
- });
- it("selectedConfigGroup absent", function () {
- controller.set('content.configGroups', [
- {
- configGroups: [],
- selectedConfigGroup: ''
- }
- ]);
- controller.applyConfigGroup();
- expect(App.ajax.send.called).to.be.false;
- });
- it("selectedConfigGroup present", function () {
- controller.set('content.configGroups', [
- {
- configGroups: [
- {
- ConfigGroup: {
- id: 1,
- group_name: 'G1',
- hosts: []
- }
- }
- ],
- selectedConfigGroup: 'G1',
- hosts: ['host1']
- }
- ]);
- controller.applyConfigGroup();
- expect(App.ajax.send.getCall(0).args[0].name).to.equal('config_groups.update_config_group');
- expect(App.ajax.send.getCall(0).args[0].data).to.eql({
- "id": 1,
- "configGroup": {
- "ConfigGroup": {
- "id": 1,
- "group_name": "G1",
- "hosts": [
- {
- "host_name": "host1"
- }
- ]
- }
- }
- });
- });
- });
- describe("#getServiceConfigGroups()", function () {
- before(function () {
- sinon.stub(controller, 'getDBProperty').withArgs('serviceConfigGroups').returns(['serviceConfigGroup']);
- });
- after(function () {
- controller.getDBProperty.restore();
- });
- it("", function () {
- controller.getServiceConfigGroups();
- expect(controller.get('content.configGroups')).to.eql(['serviceConfigGroup']);
- });
- });
- describe("#saveServiceConfigGroups()", function () {
- before(function () {
- sinon.stub(controller, 'setDBProperty', Em.K);
- });
- after(function () {
- controller.setDBProperty.restore();
- });
- it("call setDBProperty()", function () {
- controller.set('content.configGroups', [
- {}
- ]);
- controller.saveServiceConfigGroups();
- expect(controller.setDBProperty.calledWith('serviceConfigGroups', [
- {}
- ])).to.be.true;
- });
- });
- describe("#loadServiceConfigGroups()", function () {
- before(function () {
- sinon.stub(controller, 'loadServiceConfigGroupsBySlaves', Em.K);
- sinon.stub(controller, 'loadServiceConfigGroupsByClients', Em.K);
- sinon.stub(controller, 'sortServiceConfigGroups', Em.K);
- });
- after(function () {
- controller.loadServiceConfigGroupsBySlaves.restore();
- controller.loadServiceConfigGroupsByClients.restore();
- controller.sortServiceConfigGroups.restore();
- });
- it("", function () {
- controller.loadServiceConfigGroups();
- expect(controller.loadServiceConfigGroupsByClients.calledWith([])).to.be.true;
- expect(controller.loadServiceConfigGroupsBySlaves.calledWith([])).to.be.true;
- expect(controller.sortServiceConfigGroups.calledWith([])).to.be.true;
- expect(controller.get('content.configGroups')).to.eql([]);
- });
- });
- describe("#sortServiceConfigGroups", function () {
- var testCases = [
- {
- title: 'sorted',
- selectedServices: [
- {
- configGroups: [
- {
- ConfigGroup: {
- group_name: 'a'
- }
- },
- {
- ConfigGroup: {
- group_name: 'b'
- }
- }
- ]
- }
- ],
- result: ['a', 'b']
- },
- {
- title: 'not sorted',
- selectedServices: [
- {
- configGroups: [
- {
- ConfigGroup: {
- group_name: 'b'
- }
- },
- {
- ConfigGroup: {
- group_name: 'a'
- }
- }
- ]
- }
- ],
- result: ['a', 'b']
- },
- {
- title: 'sort equal',
- selectedServices: [
- {
- configGroups: [
- {
- ConfigGroup: {
- group_name: 'a'
- }
- },
- {
- ConfigGroup: {
- group_name: 'a'
- }
- }
- ]
- }
- ],
- result: ['a', 'a']
- }
- ];
- testCases.forEach(function (test) {
- it(test.title, function () {
- controller.sortServiceConfigGroups(test.selectedServices);
- expect(test.selectedServices[0].configGroups.mapProperty('ConfigGroup.group_name')).to.eql(test.result);
- });
- });
- });
- describe("#loadServiceConfigGroupsBySlaves()", function () {
- beforeEach(function () {
- sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
- stackService: Em.Object.create({
- serviceName: 'S1',
- displayName: 's1'
- })
- }));
- controller.set('content.configGroups', [
- {
- ConfigGroup: {
- tag: 'S1',
- group_name: 'G1'
- }
- }
- ]);
- });
- afterEach(function () {
- App.StackServiceComponent.find.restore();
- });
- it("slaveComponentHosts is empty", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', []);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("slaveComponentHosts has ho hosts", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {hosts: []}
- ]);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
- expect(selectedServices).to.be.empty;
- });
- it("slaveComponentHosts is CLIENT", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- hosts: [
- {hostName: 'host1'}
- ],
- componentName: 'CLIENT'
- }
- ]);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
- expect(selectedServices).to.be.empty;
- });
- it("slaveComponentHosts is slave", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- hosts: [
- {hostName: 'host1'}
- ],
- componentName: 'C1'
- },
- {
- hosts: [
- {hostName: 'host2'}
- ],
- componentName: 'C2'
- }
- ]);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
- expect(selectedServices.toArray()).to.eql([
- {
- "serviceId": "S1",
- "displayName": "s1",
- "hosts": [
- "host1",
- "host2"
- ],
- "configGroupsNames": [
- "Default",
- "G1"
- ],
- "configGroups": [
- {
- "ConfigGroup": {
- "tag": "S1",
- "group_name": "G1"
- }
- }
- ],
- "selectedConfigGroup": "Default"
- }
- ]);
- });
- });
- describe("#loadServiceConfigGroupsByClients()", function () {
- beforeEach(function () {
- sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
- stackService: Em.Object.create({
- serviceName: 'S1',
- displayName: 's1'
- })
- }));
- sinon.stub(controller, 'loadClients', Em.K);
- controller.set('content.configGroups', [
- {
- ConfigGroup: {
- tag: 'S1',
- group_name: 'G1'
- }
- }
- ]);
- });
- afterEach(function () {
- controller.loadClients.restore();
- App.StackServiceComponent.find.restore();
- });
- it("Clients is null", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', null);
- controller.set('content.clients', null);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("No CLIENT component", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', []);
- controller.set('content.clients', []);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("Clients is empty", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- componentName: 'CLIENT',
- hosts: []
- }
- ]);
- controller.set('content.clients', []);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("Client component does not have hosts", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- componentName: 'CLIENT',
- hosts: []
- }
- ]);
- controller.set('content.clients', [
- {}
- ]);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
- expect(selectedServices).to.be.empty;
- });
- it("Client present, selectedServices is empty", function () {
- var selectedServices = [];
- controller.set('content.slaveComponentHosts', [
- {
- componentName: 'CLIENT',
- hosts: [
- {hostName: 'host1'}
- ]
- }
- ]);
- controller.set('content.clients', [
- {
- component_name: 'C1'
- }
- ]);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.true;
- expect(selectedServices).to.be.eql([
- {
- "serviceId": "S1",
- "displayName": "s1",
- "hosts": [
- "host1"
- ],
- "configGroupsNames": [
- "Default",
- "G1"
- ],
- "configGroups": [
- {
- "ConfigGroup": {
- "tag": "S1",
- "group_name": "G1"
- }
- }
- ],
- "selectedConfigGroup": "Default"
- }
- ]);
- });
- it("Client present, selectedServices has service", function () {
- var selectedServices = [
- {
- serviceId: 'S1',
- hosts: ['host1', 'host2']
- }
- ];
- controller.set('content.slaveComponentHosts', [
- {
- componentName: 'CLIENT',
- hosts: [
- {hostName: 'host1'}
- ]
- }
- ]);
- controller.set('content.clients', [
- {
- component_name: 'C1'
- }
- ]);
- expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.true;
- expect(selectedServices[0].hosts).to.be.eql(["host1", "host2"]);
- });
- });
- describe("#loadServiceConfigProperties()", function () {
- beforeEach(function () {
- this.mock = sinon.stub(App.db, 'get');
- this.mock.withArgs('Installer', 'serviceConfigProperties').returns([1]);
- });
- afterEach(function () {
- this.mock.restore();
- });
- it("serviceConfigProperties is null", function () {
- this.mock.withArgs('AddService', 'serviceConfigProperties').returns(null);
- controller.loadServiceConfigProperties();
- expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
- });
- it("serviceConfigProperties is empty", function () {
- this.mock.withArgs('AddService', 'serviceConfigProperties').returns([]);
- controller.loadServiceConfigProperties();
- expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
- });
- it("serviceConfigProperties has data", function () {
- this.mock.withArgs('AddService', 'serviceConfigProperties').returns([1]);
- controller.loadServiceConfigProperties();
- expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
- });
- });
- describe("#loadAllPriorSteps()", function () {
- var stepsSet = {
- '1': [
- {
- name: 'load',
- args: ['hosts']
- },
- {
- name: 'load',
- args: ['installOptions']
- },
- {
- name: 'load',
- args: ['cluster']
- }
- ],
- '2': [
- {
- name: 'loadServices',
- args: []
- }
- ],
- '3': [
- {
- name: 'loadClients',
- args: []
- },
- {
- name: 'loadServices',
- args: []
- },
- {
- name: 'loadMasterComponentHosts',
- args: []
- },
- {
- name: 'loadSlaveComponentHosts',
- args: []
- },
- {
- name: 'load',
- args: ['hosts']
- }
- ],
- '5': [
- {
- name: 'loadServiceConfigProperties',
- args: []
- },
- {
- name: 'getServiceConfigGroups',
- args: []
- }
- ]
- };
- var testCases = [
- {
- currentStep: '0',
- calledFunctions: []
- },
- {
- currentStep: '1',
- calledFunctions: stepsSet['1']
- },
- {
- currentStep: '2',
- calledFunctions: stepsSet['1'].concat(stepsSet['2'])
- },
- {
- currentStep: '3',
- calledFunctions: stepsSet['3'].concat(stepsSet['2'], stepsSet['1'])
- },
- {
- currentStep: '4',
- calledFunctions: stepsSet['3'].concat(stepsSet['2'], stepsSet['1'])
- },
- {
- currentStep: '5',
- calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
- },
- {
- currentStep: '6',
- calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
- },
- {
- currentStep: '7',
- calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
- },
- {
- currentStep: '8',
- calledFunctions: []
- }
- ];
- var functionsToCall = [
- 'loadServiceConfigProperties',
- 'getServiceConfigGroups',
- 'loadClients',
- 'loadServices',
- 'loadMasterComponentHosts',
- 'loadSlaveComponentHosts',
- 'load'
- ];
- beforeEach(function () {
- this.mock = sinon.stub(controller, 'get');
- sinon.stub(controller, 'loadServiceConfigProperties', Em.K);
- sinon.stub(controller, 'getServiceConfigGroups', Em.K);
- sinon.stub(controller, 'loadClients', Em.K);
- sinon.stub(controller, 'loadServices', Em.K);
- sinon.stub(controller, 'loadMasterComponentHosts', Em.K);
- sinon.stub(controller, 'loadSlaveComponentHosts', Em.K);
- sinon.stub(controller, 'load', Em.K);
- sinon.stub(controller, 'saveClusterStatus', Em.K);
- });
- afterEach(function () {
- this.mock.restore();
- controller.loadServiceConfigProperties.restore();
- controller.getServiceConfigGroups.restore();
- controller.loadClients.restore();
- controller.loadServices.restore();
- controller.loadMasterComponentHosts.restore();
- controller.loadSlaveComponentHosts.restore();
- controller.load.restore();
- controller.saveClusterStatus.restore();
- });
- testCases.forEach(function (test) {
- it("current step - " + test.currentStep, function () {
- this.mock.returns(test.currentStep);
- controller.loadAllPriorSteps();
- functionsToCall.forEach(function (fName) {
- var callStack = test.calledFunctions.filterProperty('name', fName);
- if (callStack.length > 0) {
- callStack.forEach(function (f, index) {
- expect(controller[f.name].getCall(index).args).to.eql(f.args);
- }, this);
- } else {
- expect(controller[fName].called).to.be.false;
- }
- }, this);
- });
- }, this);
- });
- describe("#clearAllSteps()", function () {
- beforeEach(function () {
- sinon.stub(controller, 'clearInstallOptions', Em.K);
- sinon.stub(controller, 'getCluster').returns({});
- });
- afterEach(function () {
- controller.clearInstallOptions.restore();
- controller.getCluster.restore();
- });
- it("", function () {
- controller.clearAllSteps();
- expect(controller.getCluster.calledOnce).to.be.true;
- expect(controller.clearInstallOptions.calledOnce).to.be.true;
- expect(controller.get('content.cluster')).to.eql({});
- });
- });
- describe("#clearStorageData()", function () {
- beforeEach(function () {
- sinon.stub(controller, 'resetDbNamespace', Em.K);
- });
- afterEach(function () {
- controller.resetDbNamespace.restore();
- });
- it("launch resetDbNamespace", function () {
- controller.clearStorageData();
- expect(controller.resetDbNamespace.calledOnce).to.be.true;
- });
- });
- describe("#finish()", function () {
- var mock = {
- updateAll: Em.K,
- getAllHostNames: Em.K
- };
- beforeEach(function () {
- sinon.stub(controller, 'clearAllSteps', Em.K);
- sinon.stub(controller, 'clearStorageData', Em.K);
- sinon.stub(App.updater, 'immediateRun', Em.K);
- sinon.stub(App.router, 'get').returns(mock);
- sinon.spy(mock, 'updateAll');
- sinon.spy(mock, 'getAllHostNames');
- });
- afterEach(function () {
- controller.clearAllSteps.restore();
- controller.clearStorageData.restore();
- App.updater.immediateRun.restore();
- App.router.get.restore();
- mock.updateAll.restore();
- mock.getAllHostNames.restore();
- });
- it("", function () {
- controller.finish();
- expect(controller.clearAllSteps.calledOnce).to.be.true;
- expect(controller.clearStorageData.calledOnce).to.be.true;
- expect(mock.updateAll.calledOnce).to.be.true;
- expect(App.updater.immediateRun.calledWith('updateHost')).to.be.true;
- expect(mock.getAllHostNames.calledOnce).to.be.true;
- });
- });
- });
|