123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305 |
- /**
- * 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: [
- {hostName: 'host1'}
- ],
- dbHosts: {}
- },
- result: {}
- },
- {
- title: 'Passed host different from hosts in db',
- content: {
- hosts: [
- {hostName: 'host1'}
- ],
- dbHosts: {
- 'host2': {}
- }
- },
- result: {
- 'host2': {}
- }
- },
- {
- title: 'Passed host match host in db',
- content: {
- hosts: [
- {hostName: '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, 'getDBProperty', function (arg) {
- if (arg === 'hosts') return mock.hosts;
- if (arg === 'slaveComponentHosts') return mock.slaveComponentHosts;
- });
- });
- afterEach(function () {
- controller.getDBProperty.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})]);
- controller.saveClients();
- expect(controller.getClientsToInstall.calledWith(
- [Em.Object.create({'isSelected': 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'
- }
- ]);
- expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
- expect(selectedServices).to.eql([
- {
- "serviceId": "S1",
- "displayName": "s1",
- "hosts": [
- "host1"
- ],
- "configGroupsNames": [
- "s1 Default",
- "G1"
- ],
- "configGroups": [
- {
- "ConfigGroup": {
- "tag": "S1",
- "group_name": "G1"
- }
- }
- ],
- "selectedConfigGroup": "s1 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": [
- "s1 Default",
- "G1"
- ],
- "configGroups": [
- {
- "ConfigGroup": {
- "tag": "S1",
- "group_name": "G1"
- }
- }
- ],
- "selectedConfigGroup": "s1 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, 'setCurrentStep', Em.K);
- 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.setCurrentStep.restore();
- 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.setCurrentStep.calledWith('1')).to.be.true;
- 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;
- });
- });
- });
|