add_controller_test.js 38 KB

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