add_controller_test.js 36 KB

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