add_controller_test.js 38 KB

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