add_controller_test.js 38 KB

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