installer_test.js 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270
  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('models/cluster');
  20. require('controllers/wizard');
  21. require('controllers/installer');
  22. describe('App.InstallerController', function () {
  23. var installerController = App.InstallerController.create();
  24. after(function () {
  25. installerController.destroy();
  26. });
  27. describe('#init', function () {
  28. var c;
  29. beforeEach(function () {
  30. c = App.InstallerController.create({});
  31. });
  32. it('all steps are disabled by default', function () {
  33. expect(c.get('isStepDisabled.length')).to.be.above(0);
  34. expect(c.get('isStepDisabled').everyProperty('value', true)).to.be.ok;
  35. });
  36. });
  37. describe('#getCluster', function() {
  38. it ('Should return merged clusterStatusTemplate', function() {
  39. installerController.set('clusterStatusTemplate', {
  40. name: 'template'
  41. });
  42. expect(installerController.getCluster()).to.eql({
  43. name: 'template'
  44. });
  45. });
  46. });
  47. describe('#getHosts', function() {
  48. it ('Should return empty array', function() {
  49. expect(installerController.getHosts()).to.eql([]);
  50. });
  51. });
  52. describe('#loadServices', function() {
  53. it ('Should resolve nothing', function() {
  54. var res = installerController.loadServices();
  55. res.then(function(data){
  56. expect(data).to.be.undefined;
  57. });
  58. });
  59. });
  60. describe('#checkRepoURL', function() {
  61. var stacks = Em.A([
  62. Em.Object.create({
  63. isSelected: false
  64. }),
  65. Em.Object.create({
  66. isSelected: true,
  67. reload: false,
  68. id: 'nn-cc',
  69. stackNameVersion: 'nn-cc',
  70. repositories: Em.A([
  71. Em.Object.create({
  72. isSelected: true,
  73. isEmpty: false
  74. })
  75. ]),
  76. operatingSystems: Em.A([
  77. Em.Object.create({
  78. isSelected: true,
  79. isEmpty: false,
  80. repositories: Em.A([
  81. Em.Object.create({
  82. isEmpty: false,
  83. errorTitle: '1',
  84. errorContent: '1',
  85. validation: ''
  86. })
  87. ])
  88. })
  89. ])
  90. })
  91. ]);
  92. var wizard = Em.Object.create({
  93. skipValidationChecked: true
  94. });
  95. it ('Should reload installed stacks', function() {
  96. installerController.set('content.stacks', stacks);
  97. installerController.checkRepoURL(wizard);
  98. var expected = [
  99. {
  100. "isSelected": false
  101. },
  102. {
  103. "isSelected": true,
  104. "reload": true,
  105. "id": "nn-cc",
  106. "stackNameVersion": 'nn-cc',
  107. "repositories": [
  108. {
  109. "isSelected": true,
  110. "isEmpty": false
  111. }
  112. ],
  113. "operatingSystems": [
  114. {
  115. "isSelected": true,
  116. "isEmpty": false,
  117. "repositories": [
  118. {
  119. "isEmpty": false,
  120. "errorTitle": "",
  121. "errorContent": "",
  122. "validation": "icon-repeat"
  123. }
  124. ]
  125. }
  126. ]
  127. }
  128. ];
  129. var res = JSON.parse(JSON.stringify(installerController.get('content.stacks')));
  130. expect(res).to.be.eql(expected);
  131. });
  132. });
  133. describe('#checkRepoURLSuccessCallback', function() {
  134. var stacks = Em.A([
  135. Em.Object.create({
  136. isSelected: false
  137. }),
  138. Em.Object.create({
  139. isSelected: true,
  140. reload: false,
  141. id: 'nn-cc',
  142. repositories: Em.A([
  143. Em.Object.create({
  144. repoId: 11,
  145. isSelected: true,
  146. isEmpty: false
  147. })
  148. ]),
  149. operatingSystems: Em.A([
  150. Em.Object.create({
  151. isSelected: true,
  152. isEmpty: false,
  153. id: 1,
  154. repositories: Em.A([
  155. Em.Object.create({
  156. repoId: 11,
  157. isEmpty: false,
  158. errorTitle: '1',
  159. errorContent: '1',
  160. validation: ''
  161. })
  162. ])
  163. })
  164. ])
  165. })
  166. ]);
  167. var resolve = false;
  168. var data = {
  169. osId: 1,
  170. repoId: 11,
  171. dfd: {
  172. resolve: function() {
  173. resolve = true;
  174. }
  175. }
  176. };
  177. it ('Should check stacks for sucess', function() {
  178. installerController.set('content.stacks', stacks);
  179. installerController.checkRepoURLSuccessCallback(null,null,data);
  180. var expected = [
  181. {
  182. "isSelected": false
  183. },
  184. {
  185. "isSelected": true,
  186. "reload": false,
  187. "id": "nn-cc",
  188. "repositories": [
  189. {
  190. "repoId": 11,
  191. "isSelected": true,
  192. "isEmpty": false
  193. }
  194. ],
  195. "operatingSystems": [
  196. {
  197. "isSelected": true,
  198. "isEmpty": false,
  199. "id": 1,
  200. "repositories": [
  201. {
  202. "repoId": 11,
  203. "isEmpty": false,
  204. "errorTitle": "1",
  205. "errorContent": "1",
  206. "validation": "icon-ok"
  207. }
  208. ]
  209. }
  210. ]
  211. }
  212. ];
  213. var res = JSON.parse(JSON.stringify(installerController.get('content.stacks')));
  214. expect(resolve).to.be.true;
  215. expect(res).to.be.eql(expected);
  216. });
  217. });
  218. describe('#checkRepoURLErrorCallback', function() {
  219. var stacks = Em.A([
  220. Em.Object.create({
  221. isSelected: false
  222. }),
  223. Em.Object.create({
  224. isSelected: true,
  225. reload: false,
  226. id: 'nn-cc',
  227. repositories: Em.A([
  228. Em.Object.create({
  229. repoId: 11,
  230. isSelected: true
  231. })
  232. ]),
  233. operatingSystems: Em.A([
  234. Em.Object.create({
  235. isSelected: true,
  236. id: 1,
  237. repositories: Em.A([
  238. Em.Object.create({
  239. repoId: 11,
  240. errorTitle: '1',
  241. errorContent: '1',
  242. validation: ''
  243. })
  244. ])
  245. })
  246. ])
  247. })
  248. ]);
  249. var resolve = false;
  250. var data = {
  251. osId: 1,
  252. repoId: 11,
  253. dfd: {
  254. reject: function() {
  255. resolve = true;
  256. }
  257. }
  258. };
  259. it ('Should check stacks for error', function() {
  260. var req = {
  261. status: 500,
  262. statusText: 'error'
  263. };
  264. installerController.set('content.stacks', stacks);
  265. installerController.checkRepoURLErrorCallback(req,{},{},{},data);
  266. var expected = [
  267. {
  268. "isSelected": false
  269. },
  270. {
  271. "isSelected": true,
  272. "reload": false,
  273. "id": "nn-cc",
  274. "repositories": [
  275. {
  276. "repoId": 11,
  277. "isSelected": true
  278. }
  279. ],
  280. "operatingSystems": [
  281. {
  282. "isSelected": true,
  283. "id": 1,
  284. "repositories": [
  285. {
  286. "repoId": 11,
  287. "errorTitle": "500:error",
  288. "errorContent": "",
  289. "validation": "icon-exclamation-sign"
  290. }
  291. ]
  292. }
  293. ]
  294. }
  295. ];
  296. var res = JSON.parse(JSON.stringify(installerController.get('content.stacks')));
  297. expect(resolve).to.be.true;
  298. expect(res).to.be.eql(expected);
  299. });
  300. });
  301. describe('#setLowerStepsDisable', function() {
  302. beforeEach(function () {
  303. var steps = Em.A([
  304. Em.Object.create({
  305. step: 0,
  306. value: false
  307. }),
  308. Em.Object.create({
  309. step: 1,
  310. value: false
  311. }),
  312. Em.Object.create({
  313. step: 2,
  314. value: false
  315. }),
  316. Em.Object.create({
  317. step: 3,
  318. value: false
  319. }),
  320. Em.Object.create({
  321. step: 4,
  322. value: false
  323. })
  324. ]);
  325. installerController.set('isStepDisabled', steps);
  326. installerController.setLowerStepsDisable(3);
  327. });
  328. it ('Should disable lower steps', function() {
  329. var expected = [
  330. {
  331. "step": 0,
  332. "value": true
  333. },
  334. {
  335. "step": 1,
  336. "value": true
  337. },
  338. {
  339. "step": 2,
  340. "value": true
  341. },
  342. {
  343. "step": 3,
  344. "value": false
  345. },
  346. {
  347. "step": 4,
  348. "value": false
  349. }
  350. ];
  351. var res = JSON.parse(JSON.stringify(installerController.get('isStepDisabled')));
  352. expect(res).to.eql(expected);
  353. });
  354. });
  355. describe('#setStepsEnable', function() {
  356. beforeEach(function () {
  357. var steps = Em.A([
  358. Em.Object.create({
  359. step: 0,
  360. value: false
  361. }),
  362. Em.Object.create({
  363. step: 1,
  364. value: false
  365. }),
  366. Em.Object.create({
  367. step: 2,
  368. value: false
  369. }),
  370. Em.Object.create({
  371. step: 3,
  372. value: false
  373. }),
  374. Em.Object.create({
  375. step: 4,
  376. value: false
  377. })
  378. ]);
  379. installerController.set('isStepDisabled', steps);
  380. installerController.totalSteps = steps.length - 1;
  381. installerController.set('currentStep',2);
  382. });
  383. it ('Should enable next steps', function() {
  384. var expected = [
  385. {
  386. "step": 0,
  387. "value": false
  388. },
  389. {
  390. "step": 1,
  391. "value": true
  392. },
  393. {
  394. "step": 2,
  395. "value": true
  396. },
  397. {
  398. "step": 3,
  399. "value": true
  400. },
  401. {
  402. "step": 4,
  403. "value": true
  404. }
  405. ];
  406. var res = JSON.parse(JSON.stringify(installerController.get('isStepDisabled')));
  407. expect(res).to.eql(expected);
  408. });
  409. });
  410. describe('#loadMap', function() {
  411. describe('Should load cluster', function() {
  412. var loadCluster = false;
  413. var checker = {
  414. load: function() {
  415. loadCluster = true;
  416. }
  417. };
  418. beforeEach(function () {
  419. installerController.loadMap['0'][0].callback.call(checker);
  420. });
  421. it('cluster info is loaded', function () {
  422. expect(loadCluster).to.be.true;
  423. });
  424. });
  425. describe('Should load stacks', function() {
  426. var loadStacks = false;
  427. var checker = {
  428. loadStacks: function() {
  429. return {
  430. always: function() {
  431. loadStacks = true;
  432. }
  433. };
  434. }
  435. };
  436. beforeEach(function () {
  437. installerController.loadMap['1'][0].callback.call(checker);
  438. });
  439. it('stack info is loaded', function () {
  440. expect(loadStacks).to.be.true;
  441. });
  442. });
  443. describe ('Should load stacks async', function() {
  444. var loadStacksVersions = false;
  445. var checker = {
  446. loadStacksVersions: function() {
  447. loadStacksVersions = true;
  448. }
  449. };
  450. it('stack versions are loaded', function () {
  451. installerController.loadMap['1'][1].callback.call(checker, true).then(function(data){
  452. expect(data).to.be.true;
  453. });
  454. expect(loadStacksVersions).to.be.false;
  455. });
  456. });
  457. describe('Should load installOptions', function() {
  458. var installOptions = false;
  459. var checker = {
  460. load: function() {
  461. installOptions = true;
  462. }
  463. };
  464. beforeEach(function () {
  465. installerController.loadMap['2'][0].callback.call(checker);
  466. });
  467. it('install option are loaded', function () {
  468. expect(installOptions).to.be.true;
  469. });
  470. });
  471. describe('Should load loadConfirmedHosts', function() {
  472. var loadConfirmedHosts = false;
  473. var checker = {
  474. loadConfirmedHosts: function() {
  475. loadConfirmedHosts = true;
  476. }
  477. };
  478. beforeEach(function () {
  479. installerController.loadMap['3'][0].callback.call(checker);
  480. });
  481. it('confirmed hosts are loaded', function () {
  482. expect(loadConfirmedHosts).to.be.true;
  483. });
  484. });
  485. describe('Should load loadServices', function() {
  486. var loadServices = false;
  487. var checker = {
  488. loadServices: function() {
  489. loadServices = true;
  490. }
  491. };
  492. beforeEach(function () {
  493. installerController.loadMap['4'][0].callback.call(checker);
  494. });
  495. it('services are loaded', function () {
  496. expect(loadServices).to.be.true;
  497. });
  498. });
  499. describe('Should load loadServices (2)', function() {
  500. var setSkipSlavesStep = false;
  501. var loadMasterComponentHosts = false;
  502. var loadConfirmedHosts = false;
  503. var loadComponentsFromConfigs = false;
  504. var loadRecommendations = false;
  505. var checker = {
  506. setSkipSlavesStep: function() {
  507. setSkipSlavesStep = true;
  508. },
  509. loadMasterComponentHosts: function() {
  510. loadMasterComponentHosts = true;
  511. },
  512. loadConfirmedHosts: function() {
  513. loadConfirmedHosts = true;
  514. },
  515. loadComponentsFromConfigs: function() {
  516. loadComponentsFromConfigs = true;
  517. },
  518. loadRecommendations: function() {
  519. loadRecommendations = true;
  520. }
  521. };
  522. beforeEach(function () {
  523. installerController.loadMap['5'][0].callback.call(checker);
  524. });
  525. it('confirmed hosts are loaded', function() {
  526. expect(loadConfirmedHosts).to.be.true;
  527. });
  528. it('`skipSlavesStep` is loaded', function() {
  529. expect(setSkipSlavesStep).to.be.true;
  530. });
  531. it('master components hosts are loaded', function() {
  532. expect(loadMasterComponentHosts).to.be.true;
  533. });
  534. it('components added via configs are loaded', function () {
  535. expect(loadComponentsFromConfigs).to.be.true;
  536. });
  537. it('recommendations are loaded', function() {
  538. expect(loadRecommendations).to.be.true;
  539. });
  540. });
  541. describe ('Should load serviceConfigGroups', function() {
  542. var loadServiceConfigGroups = false;
  543. var loadServiceConfigProperties = false;
  544. var loadCurrentHostGroups = false;
  545. var loadRecommendationsConfigs = false;
  546. var loadComponentsFromConfigs = false;
  547. var loadConfigThemes = false;
  548. var checker = {
  549. loadServiceConfigGroups: function() {
  550. loadServiceConfigGroups = true;
  551. },
  552. loadServiceConfigProperties: function() {
  553. loadServiceConfigProperties = true;
  554. return $.Deferred().resolve().promise();
  555. },
  556. loadCurrentHostGroups: function() {
  557. loadCurrentHostGroups = true;
  558. },
  559. loadRecommendationsConfigs: function() {
  560. loadRecommendationsConfigs = true;
  561. },
  562. loadComponentsFromConfigs: function() {
  563. loadComponentsFromConfigs = true;
  564. },
  565. loadConfigThemes: function() {
  566. loadConfigThemes = true;
  567. return $.Deferred().resolve().promise();
  568. }
  569. };
  570. beforeEach(function () {
  571. installerController.loadMap['7'][0].callback.call(checker);
  572. });
  573. it('config groups are loaded', function () {
  574. expect(loadServiceConfigGroups).to.be.true;
  575. });
  576. it('config properties are loaded', function () {
  577. expect(loadServiceConfigProperties).to.be.true;
  578. });
  579. it('current host groups are loaded', function () {
  580. expect(loadCurrentHostGroups).to.be.true;
  581. });
  582. it('recommendations are loaded', function () {
  583. expect(loadRecommendationsConfigs).to.be.true;
  584. });
  585. it('components added via configs are loaded', function () {
  586. expect(loadComponentsFromConfigs).to.be.true;
  587. });
  588. it('config themes are loaded', function () {
  589. expect(loadConfigThemes).to.be.true;
  590. });
  591. });
  592. describe('Should load clients', function() {
  593. var loadSlaveComponentHosts = false;
  594. var loadClients = false;
  595. var loadRecommendations = false;
  596. var loadComponentsFromConfigs = false;
  597. var checker = {
  598. loadSlaveComponentHosts: function() {
  599. loadSlaveComponentHosts = true;
  600. },
  601. loadClients: function() {
  602. loadClients = true;
  603. },
  604. loadComponentsFromConfigs: function() {
  605. loadComponentsFromConfigs = true;
  606. },
  607. loadRecommendations: function() {
  608. loadRecommendations = true;
  609. }
  610. };
  611. beforeEach(function () {
  612. installerController.loadMap['6'][0].callback.call(checker);
  613. });
  614. it('slave components hosts are loaded', function () {
  615. expect(loadSlaveComponentHosts).to.be.true;
  616. });
  617. it('clients are loaded', function () {
  618. expect(loadClients).to.be.true;
  619. });
  620. it('components added via configs are loaded', function () {
  621. expect(loadComponentsFromConfigs).to.be.true;
  622. });
  623. it('recommendations are loaded', function () {
  624. expect(loadRecommendations).to.be.true;
  625. });
  626. });
  627. });
  628. describe('#removeHosts', function() {
  629. var hostsDb = {
  630. 'h1': {},
  631. 'h2': {},
  632. 'h3': {},
  633. 'h4': {}
  634. };
  635. beforeEach(function () {
  636. sinon.stub(installerController, 'getDBProperty').returns(hostsDb);
  637. });
  638. afterEach(function () {
  639. installerController.getDBProperty.restore();
  640. });
  641. it ('Should remove hosts from the list', function() {
  642. var hosts = Em.A([
  643. {
  644. name: 'h1'
  645. },
  646. {
  647. name: 'h2'
  648. },
  649. {
  650. name: 'h3'
  651. }
  652. ]);
  653. installerController.removeHosts(hosts);
  654. expect(hostsDb).to.eql({
  655. 'h4': {}
  656. });
  657. });
  658. });
  659. describe('#allHosts', function() {
  660. it ('Should return hosts', function() {
  661. var hosts = {
  662. 'h1': {
  663. disk_info: Em.A([{
  664. available: 1,
  665. size: 10
  666. }]),
  667. hostComponents: Em.A([])
  668. }
  669. };
  670. var masterComponentHosts = Em.A([
  671. {
  672. hostName: 'h1',
  673. component: 'component',
  674. display_name: 'n1'
  675. }
  676. ]);
  677. var slaveComponentHosts = Em.A([
  678. {
  679. hosts: Em.A([
  680. {
  681. hostName: 'h1'
  682. }
  683. ])
  684. }
  685. ]);
  686. installerController.set('content.hosts', hosts);
  687. installerController.set('content.masterComponentHosts', masterComponentHosts);
  688. installerController.set('content.slaveComponentHosts', slaveComponentHosts);
  689. var res = JSON.parse(JSON.stringify(installerController.get('allHosts')));
  690. expect(res).to.eql([
  691. {
  692. "diskInfo": [
  693. {
  694. "available": 1,
  695. "size": 10
  696. }
  697. ],
  698. "diskTotal": 0.0000095367431640625,
  699. "diskFree": 9.5367431640625e-7,
  700. "hostComponents": [
  701. {
  702. "componentName": "component",
  703. "displayName": "n1"
  704. },
  705. {}
  706. ]
  707. }
  708. ]);
  709. });
  710. });
  711. describe('#loadServiceConfigProperties', function() {
  712. beforeEach(function () {
  713. sinon.stub(installerController, 'getPersistentProperty').returns($.Deferred().resolve({
  714. value: 2
  715. }).promise());
  716. });
  717. afterEach(function () {
  718. installerController.getPersistentProperty.restore();
  719. });
  720. it ('Should load service config property', function() {
  721. installerController.loadServiceConfigProperties();
  722. expect(installerController.get('content.serviceConfigProperties')).to.eql({
  723. "value": 2
  724. });
  725. });
  726. });
  727. describe('#saveServices', function() {
  728. it ('Should return correct names', function() {
  729. var stepController = Em.A([
  730. Em.Object.create({
  731. isInstalled: true,
  732. isSelected: true,
  733. serviceName: 'i1'
  734. }),
  735. Em.Object.create({
  736. isInstalled: false,
  737. isSelected: true,
  738. serviceName: 'i2'
  739. }),
  740. Em.Object.create({
  741. isInstalled: true,
  742. isSelected: false,
  743. serviceName: 'i3'
  744. })
  745. ]);
  746. installerController.saveServices(stepController);
  747. expect(installerController.get('content.selectedServiceNames')).to.eql(['i1','i2']);
  748. expect(installerController.get('content.installedServiceNames')).to.eql(['i1','i3']);
  749. });
  750. });
  751. describe('#saveClients', function() {
  752. var stepController;
  753. beforeEach(function () {
  754. stepController = Em.Object.create({
  755. content: Em.A([
  756. Em.Object.create({
  757. isInstalled: true,
  758. isSelected: true,
  759. serviceName: 'i1',
  760. serviceComponents: Em.A([
  761. Em.Object.create({
  762. isClient: true,
  763. componentName: 'name',
  764. displayName: 'dname'
  765. })
  766. ])
  767. }),
  768. Em.Object.create({
  769. isInstalled: false,
  770. isSelected: true,
  771. serviceName: 'i2',
  772. serviceComponents: Em.A([
  773. Em.Object.create({
  774. isClient: false
  775. })
  776. ])
  777. }),
  778. Em.Object.create({
  779. isInstalled: true,
  780. isSelected: false,
  781. serviceName: 'i3',
  782. serviceComponents: Em.A([
  783. Em.Object.create({
  784. isClient: false
  785. })
  786. ])
  787. })
  788. ])
  789. });
  790. });
  791. it ('Should return correct clients names', function() {
  792. installerController.saveClients(stepController);
  793. var res = JSON.parse(JSON.stringify(installerController.get('content.clients')));
  794. expect(res).to.eql([
  795. {
  796. "component_name": "name",
  797. "display_name": "dname",
  798. "isInstalled": false
  799. }
  800. ]);
  801. });
  802. });
  803. describe('#saveMasterComponentHosts', function() {
  804. beforeEach(function () {
  805. sinon.stub(installerController, 'getDBProperty').returns({
  806. 'h1': {
  807. id: 11
  808. },
  809. 'h3': {
  810. id: 13
  811. },
  812. 'h2': {
  813. id: 12
  814. }
  815. });
  816. });
  817. afterEach(function () {
  818. installerController.getDBProperty.restore();
  819. });
  820. it ('Should return hosts', function() {
  821. var stepController = Em.Object.create({
  822. selectedServicesMasters: Em.A([
  823. Em.Object.create({
  824. display_name: 'n1',
  825. component_name: 'c1',
  826. serviceId: 1,
  827. selectedHost: 'h1'
  828. })
  829. ])
  830. });
  831. installerController.saveMasterComponentHosts(stepController);
  832. expect(installerController.get('content.masterComponentHosts')).to.eql([
  833. {
  834. "display_name": "n1",
  835. "component": "c1",
  836. "serviceId": 1,
  837. "isInstalled": false,
  838. "host_id": 11
  839. }
  840. ]);
  841. });
  842. });
  843. describe('#loadConfirmedHosts', function() {
  844. beforeEach(function () {
  845. sinon.stub(installerController, 'getDBProperty').returns({
  846. 'h1': {
  847. id: 11
  848. },
  849. 'h3': {
  850. id: 13
  851. },
  852. 'h2': {
  853. id: 12
  854. }
  855. });
  856. });
  857. afterEach(function () {
  858. installerController.getDBProperty.restore();
  859. });
  860. it ('Should load hosts from db', function() {
  861. installerController.loadConfirmedHosts();
  862. expect(installerController.get('content.hosts')).to.eql({
  863. 'h1': {
  864. id: 11
  865. },
  866. 'h3': {
  867. id: 13
  868. },
  869. 'h2': {
  870. id: 12
  871. }
  872. });
  873. });
  874. });
  875. describe('#loadMasterComponentHosts', function() {
  876. beforeEach(function () {
  877. sinon.stub(installerController, 'getDBProperties', function() {
  878. return {
  879. masterComponentHosts: Em.A([
  880. {
  881. hostName: '',
  882. host_id: 11
  883. }
  884. ]),
  885. hosts: {
  886. 'h1': {
  887. id: 11
  888. },
  889. 'h3': {
  890. id: 13
  891. },
  892. 'h2': {
  893. id: 12
  894. }
  895. }
  896. }
  897. });
  898. });
  899. afterEach(function () {
  900. installerController.getDBProperties.restore();
  901. });
  902. it ('Should load hosts', function() {
  903. installerController.loadMasterComponentHosts();
  904. expect(installerController.get('content.masterComponentHosts')).to.eql([
  905. {
  906. "hostName": "h1",
  907. "host_id": 11
  908. }
  909. ]);
  910. });
  911. });
  912. describe('#loadSlaveComponentHosts', function() {
  913. beforeEach(function () {
  914. sinon.stub(installerController, 'getDBProperties', function() {
  915. return {
  916. hosts: {
  917. 'h1': {
  918. id: 11
  919. },
  920. 'h3': {
  921. id: 13
  922. },
  923. 'h2': {
  924. id: 12
  925. }
  926. },
  927. slaveComponentHosts: Em.A([
  928. {
  929. hosts: Em.A([
  930. {
  931. hostName: '',
  932. host_id: 11
  933. }
  934. ])
  935. }
  936. ])
  937. };
  938. });
  939. });
  940. afterEach(function () {
  941. installerController.getDBProperties.restore();
  942. });
  943. it ('Should load slave hosts', function() {
  944. installerController.loadSlaveComponentHosts();
  945. expect(installerController.get('content.slaveComponentHosts')).to.eql([
  946. {
  947. "hosts": [
  948. {
  949. "hostName": "h1",
  950. "host_id": 11
  951. }
  952. ]
  953. }
  954. ]);
  955. });
  956. });
  957. describe('#getServerVersionSuccessCallback', function () {
  958. var cases = [
  959. {
  960. osFamily: 'redhat5',
  961. expected: false
  962. },
  963. {
  964. osFamily: 'redhat6',
  965. expected: true
  966. },
  967. {
  968. osFamily: 'suse11',
  969. expected: false
  970. }
  971. ],
  972. title = 'App.isManagedMySQLForHiveEnabled should be {0} for {1}';
  973. cases.forEach(function (item) {
  974. it(title.format(item.expected, item.osFamily), function () {
  975. installerController.getServerVersionSuccessCallback({
  976. 'RootServiceComponents': {
  977. 'component_version': '',
  978. 'properties': {
  979. 'server.os_family': item.osFamily
  980. }
  981. }
  982. });
  983. expect(App.get('isManagedMySQLForHiveEnabled')).to.equal(item.expected);
  984. });
  985. });
  986. });
  987. describe('#validateJDKVersion', function() {
  988. var tests = [
  989. {
  990. isCustomJDK: false,
  991. ambariProperties: {
  992. 'java.version': '1.8'
  993. },
  994. successCallbackCalled: false,
  995. popupCalled: true,
  996. stacks: [Em.Object.create({
  997. minJdkVersion: '1.6',
  998. maxJdkVersion: '1.7',
  999. isSelected: true
  1000. })],
  1001. m: 'JDK 1.8, stack supports 1.6-1.7 popup should be displayed'
  1002. },
  1003. {
  1004. isCustomJDK: false,
  1005. ambariProperties: {
  1006. 'java.version': '1.8'
  1007. },
  1008. successCallbackCalled: true,
  1009. popupCalled: false,
  1010. stacks: [Em.Object.create({
  1011. minJdkVersion: '1.6',
  1012. maxJdkVersion: '1.8',
  1013. isSelected: true
  1014. })],
  1015. m: 'JDK 1.8, stack supports 1.7-1.8 procceed installation without warning'
  1016. },
  1017. {
  1018. isCustomJDK: false,
  1019. ambariProperties: {
  1020. 'java.version': '1.5'
  1021. },
  1022. successCallbackCalled: false,
  1023. popupCalled: true,
  1024. stacks: [Em.Object.create({
  1025. minJdkVersion: '1.6',
  1026. maxJdkVersion: '1.8',
  1027. isSelected: true
  1028. })],
  1029. m: 'JDK 1.5, stack supports 1.6-1.8, popup should be displayed'
  1030. },
  1031. {
  1032. isCustomJDK: false,
  1033. ambariProperties: {
  1034. 'java.version': '1.5'
  1035. },
  1036. successCallbackCalled: true,
  1037. popupCalled: false,
  1038. stacks: [Em.Object.create({
  1039. minJdkVersion: null,
  1040. maxJdkVersion: null,
  1041. isSelected: true
  1042. })],
  1043. m: 'JDK 1.5, stack supports max and min are null, procceed installation without warning'
  1044. },
  1045. {
  1046. isCustomJDK: false,
  1047. ambariProperties: {
  1048. 'java.version': '1.5'
  1049. },
  1050. successCallbackCalled: true,
  1051. popupCalled: false,
  1052. stacks: [Em.Object.create({
  1053. minJdkVersion: '1.5',
  1054. maxJdkVersion: null,
  1055. isSelected: true
  1056. })],
  1057. m: 'JDK 1.5, stack supports max is missed and min is 1.5, procceed installation without warning'
  1058. },
  1059. {
  1060. isCustomJDK: false,
  1061. ambariProperties: {
  1062. 'java.version': '1.6'
  1063. },
  1064. successCallbackCalled: false,
  1065. popupCalled: true,
  1066. stacks: [Em.Object.create({
  1067. minJdkVersion: '1.5',
  1068. maxJdkVersion: null,
  1069. isSelected: true
  1070. })],
  1071. m: 'JDK 1.6, stack supports max is missed and min is 1.5, popup should be displayed'
  1072. },
  1073. {
  1074. isCustomJDK: false,
  1075. ambariProperties: {
  1076. 'java.version': '1.5'
  1077. },
  1078. successCallbackCalled: true,
  1079. popupCalled: false,
  1080. stacks: [Em.Object.create({
  1081. minJdkVersion: null,
  1082. maxJdkVersion: '1.5',
  1083. isSelected: true
  1084. })],
  1085. m: 'JDK 1.5, stack supports max 1.5 and min is missed, procceed installation without warning'
  1086. },
  1087. {
  1088. isCustomJDK: false,
  1089. ambariProperties: {
  1090. 'java.version': '1.5'
  1091. },
  1092. successCallbackCalled: false,
  1093. popupCalled: true,
  1094. stacks: [Em.Object.create({
  1095. minJdkVersion: null,
  1096. maxJdkVersion: '1.8',
  1097. isSelected: true
  1098. })],
  1099. m: 'JDK 1.5, stack supports max 1.8 and min is missed, popup should be displayed'
  1100. },
  1101. {
  1102. isCustomJDK: false,
  1103. ambariProperties: {
  1104. 'java.version': '1.8'
  1105. },
  1106. successCallbackCalled: true,
  1107. popupCalled: false,
  1108. stacks: [Em.Object.create({
  1109. isSelected: true
  1110. })],
  1111. m: 'JDK 1.8, min, max jdk missed in stack definition, procceed installation without warning'
  1112. },
  1113. {
  1114. isCustomJDK: true,
  1115. ambariProperties: {
  1116. 'java.version': '1.8'
  1117. },
  1118. successCallbackCalled: true,
  1119. popupCalled: false,
  1120. stacks: [Em.Object.create({
  1121. minJdkVersion: '1.6',
  1122. maxJdkVersion: '1.8',
  1123. isSelected: true
  1124. })],
  1125. m: 'JDK 1.8, custom jdk location used, procceed installation without warning'
  1126. }
  1127. ];
  1128. tests.forEach(function(test) {
  1129. describe(test.m, function() {
  1130. var successCallback;
  1131. beforeEach(function () {
  1132. sinon.stub(App.Stack, 'find').returns(test.stacks);
  1133. sinon.stub(App.router, 'get').withArgs('clusterController.isCustomJDK').returns(test.isCustomJDK)
  1134. .withArgs('clusterController.ambariProperties').returns(test.ambariProperties);
  1135. sinon.stub(App, 'showConfirmationPopup', Em.K);
  1136. successCallback = sinon.spy();
  1137. installerController.validateJDKVersion(successCallback);
  1138. });
  1139. afterEach(function () {
  1140. App.router.get.restore();
  1141. App.Stack.find.restore();
  1142. App.showConfirmationPopup.restore();
  1143. });
  1144. it('successCallback is ' + (test.successCallbackCalled ? '' : 'not') + ' called', function () {
  1145. expect(successCallback.called).to.be.equal(test.successCallbackCalled);
  1146. });
  1147. it('App.showConfirmationPopup. is ' + (test.popupCalled ? '' : 'not') + ' called', function () {
  1148. expect(App.showConfirmationPopup.called).to.be.equal(test.popupCalled);
  1149. });
  1150. });
  1151. });
  1152. });
  1153. describe('#postVersionDefinitionFileErrorCallback', function () {
  1154. beforeEach(function () {
  1155. sinon.stub(App, 'showAlertPopup', Em.K);
  1156. });
  1157. afterEach(function () {
  1158. App.showAlertPopup.restore();
  1159. });
  1160. it('should delete VDF-data', function () {
  1161. App.db.setLocalRepoVDFData({});
  1162. expect(App.db.getLocalRepoVDFData()).to.not.be.an.object;
  1163. installerController.postVersionDefinitionFileErrorCallback({}, {}, {}, {}, {dfd: $.Deferred()});
  1164. expect(App.db.getLocalRepoVDFData()).to.be.undefined;
  1165. });
  1166. });
  1167. });