add_controller_test.js 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/wizard');
  20. require('controllers/main/host/add_controller');
  21. require('models/host_component');
  22. require('models/service');
  23. require('mappers/server_data_mapper');
  24. describe('App.AddHostController', function () {
  25. var controller = App.AddHostController.create({
  26. testDBHosts: null,
  27. getDBProperty: function () {
  28. return this.get('testDBHosts');
  29. },
  30. setDBProperty: function () {
  31. },
  32. loadClients: function () {
  33. }
  34. });
  35. describe('#removeHosts()', function () {
  36. var testCases = [
  37. {
  38. title: 'No hosts, db is empty',
  39. content: {
  40. hosts: [],
  41. dbHosts: {}
  42. },
  43. result: {}
  44. },
  45. {
  46. title: 'Host is passed, db is empty',
  47. content: {
  48. hosts: [
  49. {name: 'host1'}
  50. ],
  51. dbHosts: {}
  52. },
  53. result: {}
  54. },
  55. {
  56. title: 'Passed host different from hosts in db',
  57. content: {
  58. hosts: [
  59. {name: 'host1'}
  60. ],
  61. dbHosts: {
  62. 'host2': {}
  63. }
  64. },
  65. result: {
  66. 'host2': {}
  67. }
  68. },
  69. {
  70. title: 'Passed host match host in db',
  71. content: {
  72. hosts: [
  73. {name: 'host1'}
  74. ],
  75. dbHosts: {
  76. 'host1': {}
  77. }
  78. },
  79. result: {}
  80. }
  81. ];
  82. beforeEach(function () {
  83. sinon.spy(controller, "setDBProperty");
  84. });
  85. afterEach(function () {
  86. controller.setDBProperty.restore();
  87. });
  88. testCases.forEach(function (test) {
  89. it(test.title, function () {
  90. controller.set('testDBHosts', test.content.dbHosts);
  91. controller.removeHosts(test.content.hosts);
  92. expect(controller.setDBProperty.calledWith('hosts', test.result)).to.be.true;
  93. });
  94. });
  95. });
  96. describe('#sortServiceConfigGroups()', function () {
  97. var testCases = [
  98. {
  99. title: 'No selected services',
  100. selectedServices: [
  101. {configGroups: []}
  102. ],
  103. result: [
  104. {configGroups: []}
  105. ]
  106. },
  107. {
  108. title: 'Only one group is present',
  109. selectedServices: [
  110. {configGroups: [
  111. {configGroups: {group_name: 'b'}}
  112. ]}
  113. ],
  114. result: [
  115. {configGroups: [
  116. {configGroups: {group_name: 'b'}}
  117. ]}
  118. ]
  119. },
  120. {
  121. title: 'Reverse order of groups',
  122. selectedServices: [
  123. {configGroups: [
  124. {ConfigGroup: {group_name: 'b2'}},
  125. {ConfigGroup: {group_name: 'a1'}}
  126. ]}
  127. ],
  128. result: [
  129. {configGroups: [
  130. {ConfigGroup: {group_name: 'a1'}},
  131. {ConfigGroup: {group_name: 'b2'}}
  132. ]}
  133. ]
  134. },
  135. {
  136. title: 'Correct order of groups',
  137. selectedServices: [
  138. {configGroups: [
  139. {ConfigGroup: {group_name: 'a1'}},
  140. {ConfigGroup: {group_name: 'b2'}}
  141. ]}
  142. ],
  143. result: [
  144. {configGroups: [
  145. {ConfigGroup: {group_name: 'a1'}},
  146. {ConfigGroup: {group_name: 'b2'}}
  147. ]}
  148. ]
  149. }
  150. ];
  151. testCases.forEach(function (test) {
  152. it(test.title, function () {
  153. controller.sortServiceConfigGroups(test.selectedServices);
  154. expect(test.selectedServices).to.eql(test.result);
  155. });
  156. });
  157. });
  158. describe('#loadServiceConfigGroupsBySlaves()', function () {
  159. var testCases = [
  160. {
  161. title: 'slaveComponentHosts is null',
  162. slaveComponentHosts: null,
  163. result: {
  164. output: false,
  165. selectedServices: []
  166. }
  167. },
  168. {
  169. title: 'slaveComponentHosts is empty',
  170. slaveComponentHosts: [],
  171. result: {
  172. output: false,
  173. selectedServices: []
  174. }
  175. },
  176. {
  177. title: 'Component does not have hosts',
  178. slaveComponentHosts: [
  179. {hosts: []}
  180. ],
  181. result: {
  182. output: true,
  183. selectedServices: []
  184. }
  185. },
  186. {
  187. title: 'Only client component is present',
  188. slaveComponentHosts: [
  189. {
  190. hosts: [
  191. {hostName: 'host1'}
  192. ],
  193. componentName: 'CLIENT'
  194. }
  195. ],
  196. result: {
  197. output: true,
  198. selectedServices: []
  199. }
  200. }
  201. ];
  202. controller.set('content.configGroups', [
  203. {
  204. ConfigGroup: {
  205. tag: 'HDFS',
  206. group_name: 'HDFS test'
  207. }
  208. }
  209. ]);
  210. testCases.forEach(function (test) {
  211. it(test.title, function () {
  212. var selectedServices = [];
  213. controller.set('content.slaveComponentHosts', test.slaveComponentHosts);
  214. expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.equal(test.result.output);
  215. expect(selectedServices).to.eql(test.result.selectedServices);
  216. });
  217. });
  218. });
  219. describe('#loadServiceConfigGroupsByClients()', function () {
  220. var testCases = [
  221. {
  222. title: 'slaveComponentHosts is null',
  223. content: {
  224. slaveComponentHosts: null,
  225. clients: [],
  226. selectedServices: []
  227. },
  228. result: {
  229. output: false,
  230. selectedServices: []
  231. }
  232. },
  233. {
  234. title: 'slaveComponentHosts is empty',
  235. content: {
  236. slaveComponentHosts: [],
  237. clients: [],
  238. selectedServices: []
  239. },
  240. result: {
  241. output: false,
  242. selectedServices: []
  243. }
  244. },
  245. {
  246. title: 'Client does not have hosts',
  247. content: {
  248. slaveComponentHosts: [
  249. {
  250. componentName: 'CLIENT',
  251. hosts: []
  252. }
  253. ],
  254. clients: [],
  255. selectedServices: []
  256. },
  257. result: {
  258. output: false,
  259. selectedServices: []
  260. }
  261. },
  262. {
  263. title: 'Client has hosts, but clients is empty',
  264. content: {
  265. slaveComponentHosts: [
  266. {
  267. componentName: 'CLIENT',
  268. hosts: [
  269. {hostName: 'host1'}
  270. ]
  271. }
  272. ],
  273. clients: [],
  274. selectedServices: []
  275. },
  276. result: {
  277. output: false,
  278. selectedServices: []
  279. }
  280. }
  281. ];
  282. testCases.forEach(function (test) {
  283. it(test.title, function () {
  284. controller.set('content.slaveComponentHosts', test.content.slaveComponentHosts);
  285. controller.set('content.clients', test.content.clients);
  286. expect(controller.loadServiceConfigGroupsByClients(test.content.selectedServices)).to.equal(test.result.output);
  287. expect(test.content.selectedServices).to.eql(test.result.selectedServices);
  288. });
  289. });
  290. });
  291. describe('#installServices()', function () {
  292. beforeEach(function () {
  293. sinon.spy(App.ajax, "send");
  294. });
  295. afterEach(function () {
  296. App.ajax.send.restore();
  297. });
  298. it('No hosts', function () {
  299. controller.set('content.cluster', {name: 'cl'});
  300. controller.set('testDBHosts', {});
  301. expect(controller.installServices()).to.be.false;
  302. expect(App.ajax.send.called).to.be.false;
  303. });
  304. it('Cluster name is empty', function () {
  305. controller.set('content.cluster', {name: ''});
  306. controller.set('testDBHosts', {'host1': {}});
  307. expect(controller.installServices()).to.be.false;
  308. expect(App.ajax.send.called).to.be.false;
  309. });
  310. it('Cluster name is correct and hosts are present', function () {
  311. controller.set('content.cluster', {name: 'cl'});
  312. controller.set('testDBHosts', {'host1': {isInstalled: false}});
  313. expect(controller.installServices()).to.be.true;
  314. expect(App.ajax.send.called).to.be.true;
  315. });
  316. });
  317. describe('#getClientsToInstall', function () {
  318. var services = [
  319. Em.Object.create({
  320. serviceName: 'service1'
  321. }),
  322. Em.Object.create({
  323. serviceName: 'service2'
  324. })
  325. ];
  326. var components = [
  327. Em.Object.create({
  328. componentName: 'comp1',
  329. displayName: 'comp1',
  330. serviceName: 'service1',
  331. isClient: true
  332. }),
  333. Em.Object.create({
  334. componentName: 'comp2',
  335. displayName: 'comp2',
  336. serviceName: 'service1',
  337. isClient: true
  338. }),
  339. Em.Object.create({
  340. componentName: 'comp3',
  341. displayName: 'comp3',
  342. serviceName: 'service2',
  343. isClient: false
  344. }),
  345. Em.Object.create({
  346. componentName: 'comp4',
  347. displayName: 'comp4',
  348. serviceName: 'service3',
  349. isClient: true
  350. })
  351. ];
  352. var clients = [
  353. {
  354. component_name: 'comp1',
  355. display_name: 'comp1',
  356. isInstalled: false
  357. },
  358. {
  359. component_name: 'comp2',
  360. display_name: 'comp2',
  361. isInstalled: false
  362. }
  363. ];
  364. it("generatel list of clients to install", function () {
  365. expect(controller.getClientsToInstall(services, components)).to.eql(clients);
  366. })
  367. });
  368. describe("#setCurrentStep()", function () {
  369. before(function () {
  370. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  371. sinon.stub(App.db, 'setWizardCurrentStep', Em.K);
  372. });
  373. after(function () {
  374. App.clusterStatus.setClusterStatus.restore();
  375. App.db.setWizardCurrentStep.restore();
  376. });
  377. it("call App.clusterStatus.setClusterStatus()", function () {
  378. controller.setCurrentStep();
  379. expect(App.clusterStatus.setClusterStatus.getCall(0).args[0].wizardControllerName).to.be.equal('addHostController');
  380. });
  381. });
  382. describe("#getCluster()", function () {
  383. before(function () {
  384. sinon.stub(App.router, 'getClusterName').returns('c1');
  385. });
  386. after(function () {
  387. App.router.getClusterName.restore();
  388. });
  389. it("", function () {
  390. controller.set('clusterStatusTemplate', {'prop': 'clusterStatusTemplate'});
  391. expect(controller.getCluster()).to.be.eql({
  392. prop: 'clusterStatusTemplate',
  393. name: 'c1'
  394. });
  395. });
  396. });
  397. describe("#loadServices", function () {
  398. var services = {
  399. db: null,
  400. stack: [],
  401. model: []
  402. };
  403. beforeEach(function () {
  404. sinon.stub(controller, 'getDBProperty', function () {
  405. return services.db;
  406. });
  407. sinon.stub(App.StackService, 'find', function () {
  408. return services.stack;
  409. });
  410. sinon.stub(App.Service, 'find', function () {
  411. return services.model;
  412. });
  413. sinon.stub(controller, 'setDBProperty', Em.K);
  414. });
  415. afterEach(function () {
  416. controller.getDBProperty.restore();
  417. App.StackService.find.restore();
  418. App.Service.find.restore();
  419. controller.setDBProperty.restore();
  420. });
  421. it("No services in db, no installed services", function () {
  422. services.stack = [Em.Object.create({
  423. serviceName: 'S1'
  424. })];
  425. controller.loadServices();
  426. expect(controller.setDBProperty.getCall(0).args).to.eql(['services',
  427. {
  428. selectedServices: [],
  429. installedServices: []
  430. }
  431. ]);
  432. expect(controller.get('content.services')).to.eql([
  433. Em.Object.create({
  434. serviceName: 'S1',
  435. isInstalled: false,
  436. isSelected: false
  437. })
  438. ])
  439. });
  440. it("No services in db, installed service present", function () {
  441. services.stack = [
  442. Em.Object.create({
  443. serviceName: 'S1'
  444. }),
  445. Em.Object.create({
  446. serviceName: 'S2'
  447. })
  448. ];
  449. services.model = [
  450. Em.Object.create({
  451. serviceName: 'S1'
  452. })
  453. ];
  454. controller.loadServices();
  455. expect(controller.setDBProperty.getCall(0).args).to.eql(['services',
  456. {
  457. selectedServices: ['S1'],
  458. installedServices: ['S1']
  459. }
  460. ]);
  461. expect(controller.get('content.services')).to.eql([
  462. Em.Object.create({
  463. serviceName: 'S1',
  464. isInstalled: true,
  465. isSelected: true
  466. }),
  467. Em.Object.create({
  468. serviceName: 'S2',
  469. isInstalled: false,
  470. isSelected: false
  471. })
  472. ]);
  473. });
  474. it("DB is empty", function () {
  475. services.stack = [Em.Object.create({
  476. serviceName: 'S1'
  477. })];
  478. services.db = {
  479. selectedServices: [],
  480. installedServices: []
  481. };
  482. controller.loadServices();
  483. expect(controller.setDBProperty.called).to.be.false;
  484. expect(controller.get('content.services')).to.eql([
  485. Em.Object.create({
  486. serviceName: 'S1',
  487. isSelected: false,
  488. isInstalled: false
  489. })
  490. ]);
  491. });
  492. it("DB has selected and installed services", function () {
  493. services.stack = [
  494. Em.Object.create({
  495. serviceName: 'S1'
  496. }),
  497. Em.Object.create({
  498. serviceName: 'S2'
  499. })
  500. ];
  501. services.db = {
  502. selectedServices: ['S1'],
  503. installedServices: ['S2']
  504. };
  505. controller.loadServices();
  506. expect(controller.setDBProperty.called).to.be.false;
  507. expect(controller.get('content.services')).to.eql([
  508. Em.Object.create({
  509. serviceName: 'S1',
  510. isInstalled: false,
  511. isSelected: true
  512. }),
  513. Em.Object.create({
  514. serviceName: 'S2',
  515. isInstalled: true,
  516. isSelected: false
  517. })
  518. ]);
  519. });
  520. });
  521. describe("#loadSlaveComponentHosts()", function () {
  522. var mock = {
  523. hosts: null,
  524. slaveComponentHosts: null
  525. };
  526. beforeEach(function () {
  527. sinon.stub(controller, 'getDBProperty', function (arg) {
  528. if (arg === 'hosts') return mock.hosts;
  529. if (arg === 'slaveComponentHosts') return mock.slaveComponentHosts;
  530. });
  531. });
  532. afterEach(function () {
  533. controller.getDBProperty.restore();
  534. });
  535. it("No slaveComponentHosts in db, null", function () {
  536. controller.loadSlaveComponentHosts();
  537. expect(controller.get('content.slaveComponentHosts')).to.be.empty;
  538. });
  539. it("No slaveComponentHosts in db", function () {
  540. mock.slaveComponentHosts = [];
  541. controller.loadSlaveComponentHosts();
  542. expect(controller.get('content.slaveComponentHosts')).to.be.empty;
  543. });
  544. it("One slaveComponent without hosts", function () {
  545. mock.slaveComponentHosts = [
  546. {hosts: []}
  547. ];
  548. mock.hosts = {};
  549. controller.loadSlaveComponentHosts();
  550. expect(controller.get('content.slaveComponentHosts')).to.be.eql([
  551. {hosts: []}
  552. ]);
  553. });
  554. it("One slaveComponent with host", function () {
  555. mock.slaveComponentHosts = [
  556. {hosts: [
  557. {host_id: 1}
  558. ]}
  559. ];
  560. mock.hosts = {'host1': {id: 1}};
  561. controller.loadSlaveComponentHosts();
  562. expect(controller.get('content.slaveComponentHosts')).to.be.eql([
  563. {hosts: [
  564. {
  565. host_id: 1,
  566. hostName: 'host1'
  567. }
  568. ]}
  569. ]);
  570. });
  571. });
  572. describe("#saveClients()", function () {
  573. before(function () {
  574. sinon.stub(App.StackServiceComponent, 'find').returns('StackServiceComponent');
  575. sinon.stub(controller, 'getClientsToInstall').returns(['client']);
  576. sinon.stub(controller, 'setDBProperty', Em.K);
  577. });
  578. after(function () {
  579. controller.setDBProperty.restore();
  580. App.StackServiceComponent.find.restore();
  581. controller.getClientsToInstall.restore();
  582. });
  583. it("", function () {
  584. controller.set('content.services', [Em.Object.create({'isSelected': true, 'isInstallable': true})]);
  585. controller.saveClients();
  586. expect(controller.getClientsToInstall.calledWith(
  587. [Em.Object.create({'isSelected': true, 'isInstallable': true})],
  588. 'StackServiceComponent'
  589. )).to.be.true;
  590. expect(controller.setDBProperty.calledWith('clientInfo', ['client'])).to.be.true;
  591. expect(controller.get('content.clients')).to.be.eql(['client']);
  592. });
  593. });
  594. describe("#getClientsToInstall()", function () {
  595. var testCases = [
  596. {
  597. title: 'No services',
  598. data: {
  599. services: [],
  600. components: []
  601. },
  602. result: []
  603. },
  604. {
  605. title: 'No components',
  606. data: {
  607. services: [
  608. {}
  609. ],
  610. components: []
  611. },
  612. result: []
  613. },
  614. {
  615. title: 'Component is not client',
  616. data: {
  617. services: [Em.Object.create({serviceName: 'S1'})],
  618. components: [Em.Object.create({serviceName: 'S1'})]
  619. },
  620. result: []
  621. },
  622. {
  623. title: 'Component is not client',
  624. data: {
  625. services: [Em.Object.create({serviceName: 'S1'})],
  626. components: [Em.Object.create({serviceName: 'S1', isClient: false})]
  627. },
  628. result: []
  629. },
  630. {
  631. title: 'Component is client',
  632. data: {
  633. services: [Em.Object.create({serviceName: 'S1'})],
  634. components: [Em.Object.create({
  635. serviceName: 'S1',
  636. isClient: true,
  637. componentName: 'C1',
  638. displayName: 'C1'
  639. })]
  640. },
  641. result: [
  642. {
  643. component_name: 'C1',
  644. display_name: 'C1',
  645. isInstalled: false
  646. }
  647. ]
  648. }
  649. ];
  650. testCases.forEach(function (test) {
  651. it(test.title, function () {
  652. expect(controller.getClientsToInstall(test.data.services, test.data.components)).to.eql(test.result);
  653. });
  654. });
  655. });
  656. describe("#applyConfigGroup()", function () {
  657. beforeEach(function () {
  658. sinon.stub(App.ajax, 'send', Em.K);
  659. });
  660. afterEach(function () {
  661. App.ajax.send.restore();
  662. });
  663. it("No config groups", function () {
  664. controller.set('content.configGroups', []);
  665. controller.applyConfigGroup();
  666. expect(App.ajax.send.called).to.be.false;
  667. });
  668. it("selectedConfigGroup absent", function () {
  669. controller.set('content.configGroups', [
  670. {
  671. configGroups: [],
  672. selectedConfigGroup: ''
  673. }
  674. ]);
  675. controller.applyConfigGroup();
  676. expect(App.ajax.send.called).to.be.false;
  677. });
  678. it("selectedConfigGroup present", function () {
  679. controller.set('content.configGroups', [
  680. {
  681. configGroups: [
  682. {
  683. ConfigGroup: {
  684. id: 1,
  685. group_name: 'G1',
  686. hosts: []
  687. }
  688. }
  689. ],
  690. selectedConfigGroup: 'G1',
  691. hosts: ['host1']
  692. }
  693. ]);
  694. controller.applyConfigGroup();
  695. expect(App.ajax.send.getCall(0).args[0].name).to.equal('config_groups.update_config_group');
  696. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  697. "id": 1,
  698. "configGroup": {
  699. "ConfigGroup": {
  700. "id": 1,
  701. "group_name": "G1",
  702. "hosts": [
  703. {
  704. "host_name": "host1"
  705. }
  706. ]
  707. }
  708. }
  709. });
  710. });
  711. });
  712. describe("#getServiceConfigGroups()", function () {
  713. before(function () {
  714. sinon.stub(controller, 'getDBProperty').withArgs('serviceConfigGroups').returns(['serviceConfigGroup']);
  715. });
  716. after(function () {
  717. controller.getDBProperty.restore();
  718. });
  719. it("", function () {
  720. controller.getServiceConfigGroups();
  721. expect(controller.get('content.configGroups')).to.eql(['serviceConfigGroup']);
  722. });
  723. });
  724. describe("#saveServiceConfigGroups()", function () {
  725. before(function () {
  726. sinon.stub(controller, 'setDBProperty', Em.K);
  727. });
  728. after(function () {
  729. controller.setDBProperty.restore();
  730. });
  731. it("call setDBProperty()", function () {
  732. controller.set('content.configGroups', [
  733. {}
  734. ]);
  735. controller.saveServiceConfigGroups();
  736. expect(controller.setDBProperty.calledWith('serviceConfigGroups', [
  737. {}
  738. ])).to.be.true;
  739. });
  740. });
  741. describe("#loadServiceConfigGroups()", function () {
  742. before(function () {
  743. sinon.stub(controller, 'loadServiceConfigGroupsBySlaves', Em.K);
  744. sinon.stub(controller, 'loadServiceConfigGroupsByClients', Em.K);
  745. sinon.stub(controller, 'sortServiceConfigGroups', Em.K);
  746. });
  747. after(function () {
  748. controller.loadServiceConfigGroupsBySlaves.restore();
  749. controller.loadServiceConfigGroupsByClients.restore();
  750. controller.sortServiceConfigGroups.restore();
  751. });
  752. it("", function () {
  753. controller.loadServiceConfigGroups();
  754. expect(controller.loadServiceConfigGroupsByClients.calledWith([])).to.be.true;
  755. expect(controller.loadServiceConfigGroupsBySlaves.calledWith([])).to.be.true;
  756. expect(controller.sortServiceConfigGroups.calledWith([])).to.be.true;
  757. expect(controller.get('content.configGroups')).to.eql([]);
  758. });
  759. });
  760. describe("#sortServiceConfigGroups", function () {
  761. var testCases = [
  762. {
  763. title: 'sorted',
  764. selectedServices: [
  765. {
  766. configGroups: [
  767. {
  768. ConfigGroup: {
  769. group_name: 'a'
  770. }
  771. },
  772. {
  773. ConfigGroup: {
  774. group_name: 'b'
  775. }
  776. }
  777. ]
  778. }
  779. ],
  780. result: ['a', 'b']
  781. },
  782. {
  783. title: 'not sorted',
  784. selectedServices: [
  785. {
  786. configGroups: [
  787. {
  788. ConfigGroup: {
  789. group_name: 'b'
  790. }
  791. },
  792. {
  793. ConfigGroup: {
  794. group_name: 'a'
  795. }
  796. }
  797. ]
  798. }
  799. ],
  800. result: ['a', 'b']
  801. },
  802. {
  803. title: 'sort equal',
  804. selectedServices: [
  805. {
  806. configGroups: [
  807. {
  808. ConfigGroup: {
  809. group_name: 'a'
  810. }
  811. },
  812. {
  813. ConfigGroup: {
  814. group_name: 'a'
  815. }
  816. }
  817. ]
  818. }
  819. ],
  820. result: ['a', 'a']
  821. }
  822. ];
  823. testCases.forEach(function (test) {
  824. it(test.title, function () {
  825. controller.sortServiceConfigGroups(test.selectedServices);
  826. expect(test.selectedServices[0].configGroups.mapProperty('ConfigGroup.group_name')).to.eql(test.result);
  827. });
  828. });
  829. });
  830. describe("#loadServiceConfigGroupsBySlaves()", function () {
  831. beforeEach(function () {
  832. sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
  833. stackService: Em.Object.create({
  834. serviceName: 'S1',
  835. displayName: 's1'
  836. })
  837. }));
  838. controller.set('content.configGroups', [
  839. {
  840. ConfigGroup: {
  841. tag: 'S1',
  842. group_name: 'G1'
  843. }
  844. }
  845. ]);
  846. });
  847. afterEach(function () {
  848. App.StackServiceComponent.find.restore();
  849. });
  850. it("slaveComponentHosts is empty", function () {
  851. var selectedServices = [];
  852. controller.set('content.slaveComponentHosts', []);
  853. expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.false;
  854. expect(selectedServices).to.be.empty;
  855. });
  856. it("slaveComponentHosts has ho hosts", function () {
  857. var selectedServices = [];
  858. controller.set('content.slaveComponentHosts', [
  859. {hosts: []}
  860. ]);
  861. expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
  862. expect(selectedServices).to.be.empty;
  863. });
  864. it("slaveComponentHosts is CLIENT", function () {
  865. var selectedServices = [];
  866. controller.set('content.slaveComponentHosts', [
  867. {
  868. hosts: [
  869. {hostName: 'host1'}
  870. ],
  871. componentName: 'CLIENT'
  872. }
  873. ]);
  874. expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
  875. expect(selectedServices).to.be.empty;
  876. });
  877. it("slaveComponentHosts is slave", function () {
  878. var selectedServices = [];
  879. controller.set('content.slaveComponentHosts', [
  880. {
  881. hosts: [
  882. {hostName: 'host1'}
  883. ],
  884. componentName: 'C1'
  885. },
  886. {
  887. hosts: [
  888. {hostName: 'host2'}
  889. ],
  890. componentName: 'C2'
  891. }
  892. ]);
  893. expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
  894. expect(selectedServices.toArray()).to.eql([
  895. {
  896. "serviceId": "S1",
  897. "displayName": "s1",
  898. "hosts": [
  899. "host1",
  900. "host2"
  901. ],
  902. "configGroupsNames": [
  903. "s1 Default",
  904. "G1"
  905. ],
  906. "configGroups": [
  907. {
  908. "ConfigGroup": {
  909. "tag": "S1",
  910. "group_name": "G1"
  911. }
  912. }
  913. ],
  914. "selectedConfigGroup": "s1 Default"
  915. }
  916. ]);
  917. });
  918. });
  919. describe("#loadServiceConfigGroupsByClients()", function () {
  920. beforeEach(function () {
  921. sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
  922. stackService: Em.Object.create({
  923. serviceName: 'S1',
  924. displayName: 's1'
  925. })
  926. }));
  927. sinon.stub(controller, 'loadClients', Em.K);
  928. controller.set('content.configGroups', [
  929. {
  930. ConfigGroup: {
  931. tag: 'S1',
  932. group_name: 'G1'
  933. }
  934. }
  935. ]);
  936. });
  937. afterEach(function () {
  938. controller.loadClients.restore();
  939. App.StackServiceComponent.find.restore();
  940. });
  941. it("Clients is null", function () {
  942. var selectedServices = [];
  943. controller.set('content.slaveComponentHosts', null);
  944. controller.set('content.clients', null);
  945. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
  946. expect(selectedServices).to.be.empty;
  947. });
  948. it("No CLIENT component", function () {
  949. var selectedServices = [];
  950. controller.set('content.slaveComponentHosts', []);
  951. controller.set('content.clients', []);
  952. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
  953. expect(selectedServices).to.be.empty;
  954. });
  955. it("Clients is empty", function () {
  956. var selectedServices = [];
  957. controller.set('content.slaveComponentHosts', [
  958. {
  959. componentName: 'CLIENT',
  960. hosts: []
  961. }
  962. ]);
  963. controller.set('content.clients', []);
  964. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
  965. expect(selectedServices).to.be.empty;
  966. });
  967. it("Client component does not have hosts", function () {
  968. var selectedServices = [];
  969. controller.set('content.slaveComponentHosts', [
  970. {
  971. componentName: 'CLIENT',
  972. hosts: []
  973. }
  974. ]);
  975. controller.set('content.clients', [
  976. {}
  977. ]);
  978. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
  979. expect(selectedServices).to.be.empty;
  980. });
  981. it("Client present, selectedServices is empty", function () {
  982. var selectedServices = [];
  983. controller.set('content.slaveComponentHosts', [
  984. {
  985. componentName: 'CLIENT',
  986. hosts: [
  987. {hostName: 'host1'}
  988. ]
  989. }
  990. ]);
  991. controller.set('content.clients', [
  992. {
  993. component_name: 'C1'
  994. }
  995. ]);
  996. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.true;
  997. expect(selectedServices).to.be.eql([
  998. {
  999. "serviceId": "S1",
  1000. "displayName": "s1",
  1001. "hosts": [
  1002. "host1"
  1003. ],
  1004. "configGroupsNames": [
  1005. "s1 Default",
  1006. "G1"
  1007. ],
  1008. "configGroups": [
  1009. {
  1010. "ConfigGroup": {
  1011. "tag": "S1",
  1012. "group_name": "G1"
  1013. }
  1014. }
  1015. ],
  1016. "selectedConfigGroup": "s1 Default"
  1017. }
  1018. ]);
  1019. });
  1020. it("Client present, selectedServices has service", function () {
  1021. var selectedServices = [
  1022. {
  1023. serviceId: 'S1',
  1024. hosts: ['host1', 'host2']
  1025. }
  1026. ];
  1027. controller.set('content.slaveComponentHosts', [
  1028. {
  1029. componentName: 'CLIENT',
  1030. hosts: [
  1031. {hostName: 'host1'}
  1032. ]
  1033. }
  1034. ]);
  1035. controller.set('content.clients', [
  1036. {
  1037. component_name: 'C1'
  1038. }
  1039. ]);
  1040. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.true;
  1041. expect(selectedServices[0].hosts).to.be.eql(["host1", "host2"]);
  1042. });
  1043. });
  1044. describe("#loadServiceConfigProperties()", function () {
  1045. beforeEach(function () {
  1046. this.mock = sinon.stub(App.db, 'get');
  1047. this.mock.withArgs('Installer', 'serviceConfigProperties').returns([1]);
  1048. });
  1049. afterEach(function () {
  1050. this.mock.restore();
  1051. });
  1052. it("serviceConfigProperties is null", function () {
  1053. this.mock.withArgs('AddService', 'serviceConfigProperties').returns(null);
  1054. controller.loadServiceConfigProperties();
  1055. expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
  1056. });
  1057. it("serviceConfigProperties is empty", function () {
  1058. this.mock.withArgs('AddService', 'serviceConfigProperties').returns([]);
  1059. controller.loadServiceConfigProperties();
  1060. expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
  1061. });
  1062. it("serviceConfigProperties has data", function () {
  1063. this.mock.withArgs('AddService', 'serviceConfigProperties').returns([1]);
  1064. controller.loadServiceConfigProperties();
  1065. expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
  1066. });
  1067. });
  1068. describe("#loadAllPriorSteps()", function () {
  1069. var stepsSet = {
  1070. '1': [
  1071. {
  1072. name: 'load',
  1073. args: ['hosts']
  1074. },
  1075. {
  1076. name: 'load',
  1077. args: ['installOptions']
  1078. },
  1079. {
  1080. name: 'load',
  1081. args: ['cluster']
  1082. }
  1083. ],
  1084. '2': [
  1085. {
  1086. name: 'loadServices',
  1087. args: []
  1088. }
  1089. ],
  1090. '3': [
  1091. {
  1092. name: 'loadClients',
  1093. args: []
  1094. },
  1095. {
  1096. name: 'loadServices',
  1097. args: []
  1098. },
  1099. {
  1100. name: 'loadMasterComponentHosts',
  1101. args: []
  1102. },
  1103. {
  1104. name: 'loadSlaveComponentHosts',
  1105. args: []
  1106. },
  1107. {
  1108. name: 'load',
  1109. args: ['hosts']
  1110. }
  1111. ],
  1112. '5': [
  1113. {
  1114. name: 'loadServiceConfigProperties',
  1115. args: []
  1116. },
  1117. {
  1118. name: 'getServiceConfigGroups',
  1119. args: []
  1120. }
  1121. ]
  1122. };
  1123. var testCases = [
  1124. {
  1125. currentStep: '0',
  1126. calledFunctions: []
  1127. },
  1128. {
  1129. currentStep: '1',
  1130. calledFunctions: stepsSet['1']
  1131. },
  1132. {
  1133. currentStep: '2',
  1134. calledFunctions: stepsSet['1'].concat(stepsSet['2'])
  1135. },
  1136. {
  1137. currentStep: '3',
  1138. calledFunctions: stepsSet['3'].concat(stepsSet['2'], stepsSet['1'])
  1139. },
  1140. {
  1141. currentStep: '4',
  1142. calledFunctions: stepsSet['3'].concat(stepsSet['2'], stepsSet['1'])
  1143. },
  1144. {
  1145. currentStep: '5',
  1146. calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
  1147. },
  1148. {
  1149. currentStep: '6',
  1150. calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
  1151. },
  1152. {
  1153. currentStep: '7',
  1154. calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
  1155. },
  1156. {
  1157. currentStep: '8',
  1158. calledFunctions: []
  1159. }
  1160. ];
  1161. var functionsToCall = [
  1162. 'loadServiceConfigProperties',
  1163. 'getServiceConfigGroups',
  1164. 'loadClients',
  1165. 'loadServices',
  1166. 'loadMasterComponentHosts',
  1167. 'loadSlaveComponentHosts',
  1168. 'load'
  1169. ];
  1170. beforeEach(function () {
  1171. this.mock = sinon.stub(controller, 'get');
  1172. sinon.stub(controller, 'loadServiceConfigProperties', Em.K);
  1173. sinon.stub(controller, 'getServiceConfigGroups', Em.K);
  1174. sinon.stub(controller, 'loadClients', Em.K);
  1175. sinon.stub(controller, 'loadServices', Em.K);
  1176. sinon.stub(controller, 'loadMasterComponentHosts', Em.K);
  1177. sinon.stub(controller, 'loadSlaveComponentHosts', Em.K);
  1178. sinon.stub(controller, 'load', Em.K);
  1179. sinon.stub(controller, 'saveClusterStatus', Em.K);
  1180. });
  1181. afterEach(function () {
  1182. this.mock.restore();
  1183. controller.loadServiceConfigProperties.restore();
  1184. controller.getServiceConfigGroups.restore();
  1185. controller.loadClients.restore();
  1186. controller.loadServices.restore();
  1187. controller.loadMasterComponentHosts.restore();
  1188. controller.loadSlaveComponentHosts.restore();
  1189. controller.load.restore();
  1190. controller.saveClusterStatus.restore();
  1191. });
  1192. testCases.forEach(function (test) {
  1193. it("current step - " + test.currentStep, function () {
  1194. this.mock.returns(test.currentStep);
  1195. controller.loadAllPriorSteps();
  1196. functionsToCall.forEach(function (fName) {
  1197. var callStack = test.calledFunctions.filterProperty('name', fName);
  1198. if (callStack.length > 0) {
  1199. callStack.forEach(function (f, index) {
  1200. expect(controller[f.name].getCall(index).args).to.eql(f.args);
  1201. }, this);
  1202. } else {
  1203. expect(controller[fName].called).to.be.false;
  1204. }
  1205. }, this);
  1206. });
  1207. }, this);
  1208. });
  1209. describe("#clearAllSteps()", function () {
  1210. beforeEach(function () {
  1211. sinon.stub(controller, 'clearInstallOptions', Em.K);
  1212. sinon.stub(controller, 'getCluster').returns({});
  1213. });
  1214. afterEach(function () {
  1215. controller.clearInstallOptions.restore();
  1216. controller.getCluster.restore();
  1217. });
  1218. it("", function () {
  1219. controller.clearAllSteps();
  1220. expect(controller.getCluster.calledOnce).to.be.true;
  1221. expect(controller.clearInstallOptions.calledOnce).to.be.true;
  1222. expect(controller.get('content.cluster')).to.eql({});
  1223. });
  1224. });
  1225. describe("#clearStorageData()", function () {
  1226. beforeEach(function () {
  1227. sinon.stub(controller, 'resetDbNamespace', Em.K);
  1228. });
  1229. afterEach(function () {
  1230. controller.resetDbNamespace.restore();
  1231. });
  1232. it("launch resetDbNamespace", function () {
  1233. controller.clearStorageData();
  1234. expect(controller.resetDbNamespace.calledOnce).to.be.true;
  1235. });
  1236. });
  1237. describe("#finish()", function () {
  1238. var mock = {
  1239. updateAll: Em.K,
  1240. getAllHostNames: Em.K
  1241. };
  1242. beforeEach(function () {
  1243. sinon.stub(controller, 'setCurrentStep', Em.K);
  1244. sinon.stub(controller, 'clearAllSteps', Em.K);
  1245. sinon.stub(controller, 'clearStorageData', Em.K);
  1246. sinon.stub(App.updater, 'immediateRun', Em.K);
  1247. sinon.stub(App.router, 'get').returns(mock);
  1248. sinon.spy(mock, 'updateAll');
  1249. sinon.spy(mock, 'getAllHostNames');
  1250. });
  1251. afterEach(function () {
  1252. controller.setCurrentStep.restore();
  1253. controller.clearAllSteps.restore();
  1254. controller.clearStorageData.restore();
  1255. App.updater.immediateRun.restore();
  1256. App.router.get.restore();
  1257. mock.updateAll.restore();
  1258. mock.getAllHostNames.restore();
  1259. });
  1260. it("", function () {
  1261. controller.finish();
  1262. expect(controller.setCurrentStep.calledWith('1')).to.be.true;
  1263. expect(controller.clearAllSteps.calledOnce).to.be.true;
  1264. expect(controller.clearStorageData.calledOnce).to.be.true;
  1265. expect(mock.updateAll.calledOnce).to.be.true;
  1266. expect(App.updater.immediateRun.calledWith('updateHost')).to.be.true;
  1267. expect(mock.getAllHostNames.calledOnce).to.be.true;
  1268. });
  1269. });
  1270. });