add_controller_test.js 36 KB

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