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. {hostName: 'host1'}
  50. ],
  51. dbHosts: {}
  52. },
  53. result: {}
  54. },
  55. {
  56. title: 'Passed host different from hosts in db',
  57. content: {
  58. hosts: [
  59. {hostName: '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. {hostName: '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("#getInstallOptions()", function () {
  398. it("", function () {
  399. controller.set('installOptionsTemplate', {'prop': 'installOptionsTemplate'});
  400. expect(controller.getInstallOptions()).to.be.eql({
  401. prop: 'installOptionsTemplate'
  402. });
  403. });
  404. });
  405. describe("#loadServices", function () {
  406. var services = {
  407. db: null,
  408. stack: [],
  409. model: []
  410. };
  411. beforeEach(function () {
  412. sinon.stub(controller, 'getDBProperty', function () {
  413. return services.db;
  414. });
  415. sinon.stub(App.StackService, 'find', function () {
  416. return services.stack;
  417. });
  418. sinon.stub(App.Service, 'find', function () {
  419. return services.model;
  420. });
  421. sinon.stub(controller, 'setDBProperty', Em.K);
  422. });
  423. afterEach(function () {
  424. controller.getDBProperty.restore();
  425. App.StackService.find.restore();
  426. App.Service.find.restore();
  427. controller.setDBProperty.restore();
  428. });
  429. it("No services in db, no installed services", function () {
  430. services.stack = [Em.Object.create({
  431. serviceName: 'S1'
  432. })];
  433. controller.loadServices();
  434. expect(controller.setDBProperty.getCall(0).args).to.eql(['services',
  435. {
  436. selectedServices: [],
  437. installedServices: []
  438. }
  439. ]);
  440. expect(controller.get('content.services')).to.eql([
  441. Em.Object.create({
  442. serviceName: 'S1',
  443. isInstalled: false,
  444. isSelected: false
  445. })
  446. ])
  447. });
  448. it("No services in db, installed service present", function () {
  449. services.stack = [
  450. Em.Object.create({
  451. serviceName: 'S1'
  452. }),
  453. Em.Object.create({
  454. serviceName: 'S2'
  455. })
  456. ];
  457. services.model = [
  458. Em.Object.create({
  459. serviceName: 'S1'
  460. })
  461. ];
  462. controller.loadServices();
  463. expect(controller.setDBProperty.getCall(0).args).to.eql(['services',
  464. {
  465. selectedServices: ['S1'],
  466. installedServices: ['S1']
  467. }
  468. ]);
  469. expect(controller.get('content.services')).to.eql([
  470. Em.Object.create({
  471. serviceName: 'S1',
  472. isInstalled: true,
  473. isSelected: true
  474. }),
  475. Em.Object.create({
  476. serviceName: 'S2',
  477. isInstalled: false,
  478. isSelected: false
  479. })
  480. ]);
  481. });
  482. it("DB is empty", function () {
  483. services.stack = [Em.Object.create({
  484. serviceName: 'S1'
  485. })];
  486. services.db = {
  487. selectedServices: [],
  488. installedServices: []
  489. };
  490. controller.loadServices();
  491. expect(controller.setDBProperty.called).to.be.false;
  492. expect(controller.get('content.services')).to.eql([
  493. Em.Object.create({
  494. serviceName: 'S1',
  495. isSelected: false,
  496. isInstalled: false
  497. })
  498. ]);
  499. });
  500. it("DB has selected and installed services", function () {
  501. services.stack = [
  502. Em.Object.create({
  503. serviceName: 'S1'
  504. }),
  505. Em.Object.create({
  506. serviceName: 'S2'
  507. })
  508. ];
  509. services.db = {
  510. selectedServices: ['S1'],
  511. installedServices: ['S2']
  512. };
  513. controller.loadServices();
  514. expect(controller.setDBProperty.called).to.be.false;
  515. expect(controller.get('content.services')).to.eql([
  516. Em.Object.create({
  517. serviceName: 'S1',
  518. isInstalled: false,
  519. isSelected: true
  520. }),
  521. Em.Object.create({
  522. serviceName: 'S2',
  523. isInstalled: true,
  524. isSelected: false
  525. })
  526. ]);
  527. });
  528. });
  529. describe("#loadSlaveComponentHosts()", function () {
  530. var mock = {
  531. hosts: null,
  532. slaveComponentHosts: null
  533. };
  534. beforeEach(function () {
  535. sinon.stub(controller, 'getDBProperty', function (arg) {
  536. if (arg === 'hosts') return mock.hosts;
  537. if (arg === 'slaveComponentHosts') return mock.slaveComponentHosts;
  538. });
  539. });
  540. afterEach(function () {
  541. controller.getDBProperty.restore();
  542. });
  543. it("No slaveComponentHosts in db, null", function () {
  544. controller.loadSlaveComponentHosts();
  545. expect(controller.get('content.slaveComponentHosts')).to.be.empty;
  546. });
  547. it("No slaveComponentHosts in db", function () {
  548. mock.slaveComponentHosts = [];
  549. controller.loadSlaveComponentHosts();
  550. expect(controller.get('content.slaveComponentHosts')).to.be.empty;
  551. });
  552. it("One slaveComponent without hosts", function () {
  553. mock.slaveComponentHosts = [
  554. {hosts: []}
  555. ];
  556. mock.hosts = {};
  557. controller.loadSlaveComponentHosts();
  558. expect(controller.get('content.slaveComponentHosts')).to.be.eql([
  559. {hosts: []}
  560. ]);
  561. });
  562. it("One slaveComponent with host", function () {
  563. mock.slaveComponentHosts = [
  564. {hosts: [
  565. {host_id: 1}
  566. ]}
  567. ];
  568. mock.hosts = {'host1': {id: 1}};
  569. controller.loadSlaveComponentHosts();
  570. expect(controller.get('content.slaveComponentHosts')).to.be.eql([
  571. {hosts: [
  572. {
  573. host_id: 1,
  574. hostName: 'host1'
  575. }
  576. ]}
  577. ]);
  578. });
  579. });
  580. describe("#saveClients()", function () {
  581. before(function () {
  582. sinon.stub(App.StackServiceComponent, 'find').returns('StackServiceComponent');
  583. sinon.stub(controller, 'getClientsToInstall').returns(['client']);
  584. sinon.stub(controller, 'setDBProperty', Em.K);
  585. });
  586. after(function () {
  587. controller.setDBProperty.restore();
  588. App.StackServiceComponent.find.restore();
  589. controller.getClientsToInstall.restore();
  590. });
  591. it("", function () {
  592. controller.set('content.services', [Em.Object.create({'isSelected': true})]);
  593. controller.saveClients();
  594. expect(controller.getClientsToInstall.calledWith(
  595. [Em.Object.create({'isSelected': true})],
  596. 'StackServiceComponent'
  597. )).to.be.true;
  598. expect(controller.setDBProperty.calledWith('clientInfo', ['client'])).to.be.true;
  599. expect(controller.get('content.clients')).to.be.eql(['client']);
  600. });
  601. });
  602. describe("#getClientsToInstall()", function () {
  603. var testCases = [
  604. {
  605. title: 'No services',
  606. data: {
  607. services: [],
  608. components: []
  609. },
  610. result: []
  611. },
  612. {
  613. title: 'No components',
  614. data: {
  615. services: [
  616. {}
  617. ],
  618. components: []
  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'})]
  627. },
  628. result: []
  629. },
  630. {
  631. title: 'Component is not client',
  632. data: {
  633. services: [Em.Object.create({serviceName: 'S1'})],
  634. components: [Em.Object.create({serviceName: 'S1', isClient: false})]
  635. },
  636. result: []
  637. },
  638. {
  639. title: 'Component is client',
  640. data: {
  641. services: [Em.Object.create({serviceName: 'S1'})],
  642. components: [Em.Object.create({
  643. serviceName: 'S1',
  644. isClient: true,
  645. componentName: 'C1',
  646. displayName: 'C1'
  647. })]
  648. },
  649. result: [
  650. {
  651. component_name: 'C1',
  652. display_name: 'C1',
  653. isInstalled: false
  654. }
  655. ]
  656. }
  657. ];
  658. testCases.forEach(function (test) {
  659. it(test.title, function () {
  660. expect(controller.getClientsToInstall(test.data.services, test.data.components)).to.eql(test.result);
  661. });
  662. });
  663. });
  664. describe("#applyConfigGroup()", function () {
  665. beforeEach(function () {
  666. sinon.stub(App.ajax, 'send', Em.K);
  667. });
  668. afterEach(function () {
  669. App.ajax.send.restore();
  670. });
  671. it("No config groups", function () {
  672. controller.set('content.configGroups', []);
  673. controller.applyConfigGroup();
  674. expect(App.ajax.send.called).to.be.false;
  675. });
  676. it("selectedConfigGroup absent", function () {
  677. controller.set('content.configGroups', [
  678. {
  679. configGroups: [],
  680. selectedConfigGroup: ''
  681. }
  682. ]);
  683. controller.applyConfigGroup();
  684. expect(App.ajax.send.called).to.be.false;
  685. });
  686. it("selectedConfigGroup present", function () {
  687. controller.set('content.configGroups', [
  688. {
  689. configGroups: [
  690. {
  691. ConfigGroup: {
  692. id: 1,
  693. group_name: 'G1',
  694. hosts: []
  695. }
  696. }
  697. ],
  698. selectedConfigGroup: 'G1',
  699. hosts: ['host1']
  700. }
  701. ]);
  702. controller.applyConfigGroup();
  703. expect(App.ajax.send.getCall(0).args[0].name).to.equal('config_groups.update_config_group');
  704. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  705. "id": 1,
  706. "configGroup": {
  707. "ConfigGroup": {
  708. "id": 1,
  709. "group_name": "G1",
  710. "hosts": [
  711. {
  712. "host_name": "host1"
  713. }
  714. ]
  715. }
  716. }
  717. });
  718. });
  719. });
  720. describe("#getServiceConfigGroups()", function () {
  721. before(function () {
  722. sinon.stub(controller, 'getDBProperty').withArgs('serviceConfigGroups').returns(['serviceConfigGroup']);
  723. });
  724. after(function () {
  725. controller.getDBProperty.restore();
  726. });
  727. it("", function () {
  728. controller.getServiceConfigGroups();
  729. expect(controller.get('content.configGroups')).to.eql(['serviceConfigGroup']);
  730. });
  731. });
  732. describe("#saveServiceConfigGroups()", function () {
  733. before(function () {
  734. sinon.stub(controller, 'setDBProperty', Em.K);
  735. });
  736. after(function () {
  737. controller.setDBProperty.restore();
  738. });
  739. it("call setDBProperty()", function () {
  740. controller.set('content.configGroups', [
  741. {}
  742. ]);
  743. controller.saveServiceConfigGroups();
  744. expect(controller.setDBProperty.calledWith('serviceConfigGroups', [
  745. {}
  746. ])).to.be.true;
  747. });
  748. });
  749. describe("#loadServiceConfigGroups()", function () {
  750. before(function () {
  751. sinon.stub(controller, 'loadServiceConfigGroupsBySlaves', Em.K);
  752. sinon.stub(controller, 'loadServiceConfigGroupsByClients', Em.K);
  753. sinon.stub(controller, 'sortServiceConfigGroups', Em.K);
  754. });
  755. after(function () {
  756. controller.loadServiceConfigGroupsBySlaves.restore();
  757. controller.loadServiceConfigGroupsByClients.restore();
  758. controller.sortServiceConfigGroups.restore();
  759. });
  760. it("", function () {
  761. controller.loadServiceConfigGroups();
  762. expect(controller.loadServiceConfigGroupsByClients.calledWith([])).to.be.true;
  763. expect(controller.loadServiceConfigGroupsBySlaves.calledWith([])).to.be.true;
  764. expect(controller.sortServiceConfigGroups.calledWith([])).to.be.true;
  765. expect(controller.get('content.configGroups')).to.eql([]);
  766. });
  767. });
  768. describe("#sortServiceConfigGroups", function () {
  769. var testCases = [
  770. {
  771. title: 'sorted',
  772. selectedServices: [
  773. {
  774. configGroups: [
  775. {
  776. ConfigGroup: {
  777. group_name: 'a'
  778. }
  779. },
  780. {
  781. ConfigGroup: {
  782. group_name: 'b'
  783. }
  784. }
  785. ]
  786. }
  787. ],
  788. result: ['a', 'b']
  789. },
  790. {
  791. title: 'not sorted',
  792. selectedServices: [
  793. {
  794. configGroups: [
  795. {
  796. ConfigGroup: {
  797. group_name: 'b'
  798. }
  799. },
  800. {
  801. ConfigGroup: {
  802. group_name: 'a'
  803. }
  804. }
  805. ]
  806. }
  807. ],
  808. result: ['a', 'b']
  809. },
  810. {
  811. title: 'sort equal',
  812. selectedServices: [
  813. {
  814. configGroups: [
  815. {
  816. ConfigGroup: {
  817. group_name: 'a'
  818. }
  819. },
  820. {
  821. ConfigGroup: {
  822. group_name: 'a'
  823. }
  824. }
  825. ]
  826. }
  827. ],
  828. result: ['a', 'a']
  829. }
  830. ];
  831. testCases.forEach(function (test) {
  832. it(test.title, function () {
  833. controller.sortServiceConfigGroups(test.selectedServices);
  834. expect(test.selectedServices[0].configGroups.mapProperty('ConfigGroup.group_name')).to.eql(test.result);
  835. });
  836. });
  837. });
  838. describe("#loadServiceConfigGroupsBySlaves()", function () {
  839. beforeEach(function () {
  840. sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
  841. stackService: Em.Object.create({
  842. serviceName: 'S1',
  843. displayName: 's1'
  844. })
  845. }));
  846. controller.set('content.configGroups', [
  847. {
  848. ConfigGroup: {
  849. tag: 'S1',
  850. group_name: 'G1'
  851. }
  852. }
  853. ]);
  854. });
  855. afterEach(function () {
  856. App.StackServiceComponent.find.restore();
  857. });
  858. it("slaveComponentHosts is empty", function () {
  859. var selectedServices = [];
  860. controller.set('content.slaveComponentHosts', []);
  861. expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.false;
  862. expect(selectedServices).to.be.empty;
  863. });
  864. it("slaveComponentHosts has ho hosts", function () {
  865. var selectedServices = [];
  866. controller.set('content.slaveComponentHosts', [
  867. {hosts: []}
  868. ]);
  869. expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
  870. expect(selectedServices).to.be.empty;
  871. });
  872. it("slaveComponentHosts is CLIENT", function () {
  873. var selectedServices = [];
  874. controller.set('content.slaveComponentHosts', [
  875. {
  876. hosts: [
  877. {hostName: 'host1'}
  878. ],
  879. componentName: 'CLIENT'
  880. }
  881. ]);
  882. expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
  883. expect(selectedServices).to.be.empty;
  884. });
  885. it("slaveComponentHosts is slave", function () {
  886. var selectedServices = [];
  887. controller.set('content.slaveComponentHosts', [
  888. {
  889. hosts: [
  890. {hostName: 'host1'}
  891. ],
  892. componentName: 'C1'
  893. }
  894. ]);
  895. expect(controller.loadServiceConfigGroupsBySlaves(selectedServices)).to.be.true;
  896. expect(selectedServices).to.eql([
  897. {
  898. "serviceId": "S1",
  899. "displayName": "s1",
  900. "hosts": [
  901. "host1"
  902. ],
  903. "configGroupsNames": [
  904. "s1 Default",
  905. "G1"
  906. ],
  907. "configGroups": [
  908. {
  909. "ConfigGroup": {
  910. "tag": "S1",
  911. "group_name": "G1"
  912. }
  913. }
  914. ],
  915. "selectedConfigGroup": "s1 Default"
  916. }
  917. ]);
  918. });
  919. });
  920. describe("#loadServiceConfigGroupsByClients()", function () {
  921. beforeEach(function () {
  922. sinon.stub(App.StackServiceComponent, 'find').returns(Em.Object.create({
  923. stackService: Em.Object.create({
  924. serviceName: 'S1',
  925. displayName: 's1'
  926. })
  927. }));
  928. sinon.stub(controller, 'loadClients', Em.K);
  929. controller.set('content.configGroups', [
  930. {
  931. ConfigGroup: {
  932. tag: 'S1',
  933. group_name: 'G1'
  934. }
  935. }
  936. ]);
  937. });
  938. afterEach(function () {
  939. controller.loadClients.restore();
  940. App.StackServiceComponent.find.restore();
  941. });
  942. it("Clients is null", function () {
  943. var selectedServices = [];
  944. controller.set('content.slaveComponentHosts', null);
  945. controller.set('content.clients', null);
  946. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
  947. expect(selectedServices).to.be.empty;
  948. });
  949. it("No CLIENT component", function () {
  950. var selectedServices = [];
  951. controller.set('content.slaveComponentHosts', []);
  952. controller.set('content.clients', []);
  953. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
  954. expect(selectedServices).to.be.empty;
  955. });
  956. it("Clients is empty", function () {
  957. var selectedServices = [];
  958. controller.set('content.slaveComponentHosts', [
  959. {
  960. componentName: 'CLIENT',
  961. hosts: []
  962. }
  963. ]);
  964. controller.set('content.clients', []);
  965. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
  966. expect(selectedServices).to.be.empty;
  967. });
  968. it("Client component does not have hosts", function () {
  969. var selectedServices = [];
  970. controller.set('content.slaveComponentHosts', [
  971. {
  972. componentName: 'CLIENT',
  973. hosts: []
  974. }
  975. ]);
  976. controller.set('content.clients', [
  977. {}
  978. ]);
  979. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.false;
  980. expect(selectedServices).to.be.empty;
  981. });
  982. it("Client present, selectedServices is empty", function () {
  983. var selectedServices = [];
  984. controller.set('content.slaveComponentHosts', [
  985. {
  986. componentName: 'CLIENT',
  987. hosts: [
  988. {hostName: 'host1'}
  989. ]
  990. }
  991. ]);
  992. controller.set('content.clients', [
  993. {
  994. component_name: 'C1'
  995. }
  996. ]);
  997. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.true;
  998. expect(selectedServices).to.be.eql([
  999. {
  1000. "serviceId": "S1",
  1001. "displayName": "s1",
  1002. "hosts": [
  1003. "host1"
  1004. ],
  1005. "configGroupsNames": [
  1006. "s1 Default",
  1007. "G1"
  1008. ],
  1009. "configGroups": [
  1010. {
  1011. "ConfigGroup": {
  1012. "tag": "S1",
  1013. "group_name": "G1"
  1014. }
  1015. }
  1016. ],
  1017. "selectedConfigGroup": "s1 Default"
  1018. }
  1019. ]);
  1020. });
  1021. it("Client present, selectedServices has service", function () {
  1022. var selectedServices = [
  1023. {
  1024. serviceId: 'S1',
  1025. hosts: ['host1', 'host2']
  1026. }
  1027. ];
  1028. controller.set('content.slaveComponentHosts', [
  1029. {
  1030. componentName: 'CLIENT',
  1031. hosts: [
  1032. {hostName: 'host1'}
  1033. ]
  1034. }
  1035. ]);
  1036. controller.set('content.clients', [
  1037. {
  1038. component_name: 'C1'
  1039. }
  1040. ]);
  1041. expect(controller.loadServiceConfigGroupsByClients(selectedServices)).to.be.true;
  1042. expect(selectedServices[0].hosts).to.be.eql(["host1", "host2"]);
  1043. });
  1044. });
  1045. describe("#loadServiceConfigProperties()", function () {
  1046. beforeEach(function () {
  1047. this.mock = sinon.stub(App.db, 'get');
  1048. this.mock.withArgs('Installer', 'serviceConfigProperties').returns([1]);
  1049. });
  1050. afterEach(function () {
  1051. this.mock.restore();
  1052. });
  1053. it("serviceConfigProperties is null", function () {
  1054. this.mock.withArgs('AddService', 'serviceConfigProperties').returns(null);
  1055. controller.loadServiceConfigProperties();
  1056. expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
  1057. });
  1058. it("serviceConfigProperties is empty", function () {
  1059. this.mock.withArgs('AddService', 'serviceConfigProperties').returns([]);
  1060. controller.loadServiceConfigProperties();
  1061. expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
  1062. });
  1063. it("serviceConfigProperties has data", function () {
  1064. this.mock.withArgs('AddService', 'serviceConfigProperties').returns([1]);
  1065. controller.loadServiceConfigProperties();
  1066. expect(controller.get('content.serviceConfigProperties')).to.eql([1]);
  1067. });
  1068. });
  1069. describe("#loadAllPriorSteps()", function () {
  1070. var stepsSet = {
  1071. '1': [
  1072. {
  1073. name: 'load',
  1074. args: ['hosts']
  1075. },
  1076. {
  1077. name: 'load',
  1078. args: ['installOptions']
  1079. },
  1080. {
  1081. name: 'load',
  1082. args: ['cluster']
  1083. }
  1084. ],
  1085. '2': [
  1086. {
  1087. name: 'loadServices',
  1088. args: []
  1089. }
  1090. ],
  1091. '3': [
  1092. {
  1093. name: 'loadClients',
  1094. args: []
  1095. },
  1096. {
  1097. name: 'loadServices',
  1098. args: []
  1099. },
  1100. {
  1101. name: 'loadMasterComponentHosts',
  1102. args: []
  1103. },
  1104. {
  1105. name: 'loadSlaveComponentHosts',
  1106. args: []
  1107. },
  1108. {
  1109. name: 'load',
  1110. args: ['hosts']
  1111. }
  1112. ],
  1113. '5': [
  1114. {
  1115. name: 'loadServiceConfigProperties',
  1116. args: []
  1117. },
  1118. {
  1119. name: 'getServiceConfigGroups',
  1120. args: []
  1121. }
  1122. ]
  1123. };
  1124. var testCases = [
  1125. {
  1126. currentStep: '0',
  1127. calledFunctions: []
  1128. },
  1129. {
  1130. currentStep: '1',
  1131. calledFunctions: stepsSet['1']
  1132. },
  1133. {
  1134. currentStep: '2',
  1135. calledFunctions: stepsSet['1'].concat(stepsSet['2'])
  1136. },
  1137. {
  1138. currentStep: '3',
  1139. calledFunctions: stepsSet['3'].concat(stepsSet['2'], stepsSet['1'])
  1140. },
  1141. {
  1142. currentStep: '4',
  1143. calledFunctions: stepsSet['3'].concat(stepsSet['2'], stepsSet['1'])
  1144. },
  1145. {
  1146. currentStep: '5',
  1147. calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
  1148. },
  1149. {
  1150. currentStep: '6',
  1151. calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
  1152. },
  1153. {
  1154. currentStep: '7',
  1155. calledFunctions: stepsSet['5'].concat(stepsSet['3'], stepsSet['2'], stepsSet[1])
  1156. },
  1157. {
  1158. currentStep: '8',
  1159. calledFunctions: []
  1160. }
  1161. ];
  1162. var functionsToCall = [
  1163. 'loadServiceConfigProperties',
  1164. 'getServiceConfigGroups',
  1165. 'loadClients',
  1166. 'loadServices',
  1167. 'loadMasterComponentHosts',
  1168. 'loadSlaveComponentHosts',
  1169. 'load'
  1170. ];
  1171. beforeEach(function () {
  1172. this.mock = sinon.stub(controller, 'get');
  1173. sinon.stub(controller, 'loadServiceConfigProperties', Em.K);
  1174. sinon.stub(controller, 'getServiceConfigGroups', Em.K);
  1175. sinon.stub(controller, 'loadClients', Em.K);
  1176. sinon.stub(controller, 'loadServices', Em.K);
  1177. sinon.stub(controller, 'loadMasterComponentHosts', Em.K);
  1178. sinon.stub(controller, 'loadSlaveComponentHosts', Em.K);
  1179. sinon.stub(controller, 'load', 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. });
  1191. testCases.forEach(function (test) {
  1192. it("current step - " + test.currentStep, function () {
  1193. this.mock.returns(test.currentStep);
  1194. controller.loadAllPriorSteps();
  1195. functionsToCall.forEach(function (fName) {
  1196. var callStack = test.calledFunctions.filterProperty('name', fName);
  1197. if (callStack.length > 0) {
  1198. callStack.forEach(function (f, index) {
  1199. expect(controller[f.name].getCall(index).args).to.eql(f.args);
  1200. }, this);
  1201. } else {
  1202. expect(controller[fName].called).to.be.false;
  1203. }
  1204. }, this);
  1205. });
  1206. }, this);
  1207. });
  1208. describe("#clearAllSteps()", function () {
  1209. beforeEach(function () {
  1210. sinon.stub(controller, 'clearInstallOptions', Em.K);
  1211. sinon.stub(controller, 'getCluster').returns({});
  1212. });
  1213. afterEach(function () {
  1214. controller.clearInstallOptions.restore();
  1215. controller.getCluster.restore();
  1216. });
  1217. it("", function () {
  1218. controller.clearAllSteps();
  1219. expect(controller.getCluster.calledOnce).to.be.true;
  1220. expect(controller.clearInstallOptions.calledOnce).to.be.true;
  1221. expect(controller.get('content.cluster')).to.eql({});
  1222. });
  1223. });
  1224. describe("#clearStorageData()", function () {
  1225. beforeEach(function () {
  1226. sinon.stub(controller, 'resetDbNamespace', Em.K);
  1227. });
  1228. afterEach(function () {
  1229. controller.resetDbNamespace.restore();
  1230. });
  1231. it("launch resetDbNamespace", function () {
  1232. controller.clearStorageData();
  1233. expect(controller.resetDbNamespace.calledOnce).to.be.true;
  1234. });
  1235. });
  1236. describe("#finish()", function () {
  1237. var mock = {
  1238. updateAll: Em.K,
  1239. getAllHostNames: Em.K
  1240. };
  1241. beforeEach(function () {
  1242. sinon.stub(controller, 'setCurrentStep', Em.K);
  1243. sinon.stub(controller, 'clearAllSteps', Em.K);
  1244. sinon.stub(controller, 'clearStorageData', Em.K);
  1245. sinon.stub(App.updater, 'immediateRun', Em.K);
  1246. sinon.stub(App.router, 'get').returns(mock);
  1247. sinon.spy(mock, 'updateAll');
  1248. sinon.spy(mock, 'getAllHostNames');
  1249. });
  1250. afterEach(function () {
  1251. controller.setCurrentStep.restore();
  1252. controller.clearAllSteps.restore();
  1253. controller.clearStorageData.restore();
  1254. App.updater.immediateRun.restore();
  1255. App.router.get.restore();
  1256. mock.updateAll.restore();
  1257. mock.getAllHostNames.restore();
  1258. });
  1259. it("", function () {
  1260. controller.finish();
  1261. expect(controller.setCurrentStep.calledWith('1')).to.be.true;
  1262. expect(controller.clearAllSteps.calledOnce).to.be.true;
  1263. expect(controller.clearStorageData.calledOnce).to.be.true;
  1264. expect(mock.updateAll.calledOnce).to.be.true;
  1265. expect(App.updater.immediateRun.calledWith('updateHost')).to.be.true;
  1266. expect(mock.getAllHostNames.calledOnce).to.be.true;
  1267. });
  1268. });
  1269. });