installer_test.js 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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. },
  555. loadCurrentHostGroups: function() {
  556. loadCurrentHostGroups = true;
  557. },
  558. loadRecommendationsConfigs: function() {
  559. loadRecommendationsConfigs = true;
  560. },
  561. loadComponentsFromConfigs: function() {
  562. loadComponentsFromConfigs = true;
  563. },
  564. loadConfigThemes: function() {
  565. loadConfigThemes = true;
  566. }
  567. };
  568. beforeEach(function () {
  569. installerController.loadMap['7'][0].callback.call(checker);
  570. });
  571. it('config groups are loaded', function () {
  572. expect(loadServiceConfigGroups).to.be.true;
  573. });
  574. it('config properties are loaded', function () {
  575. expect(loadServiceConfigProperties).to.be.true;
  576. });
  577. it('current host groups are loaded', function () {
  578. expect(loadCurrentHostGroups).to.be.true;
  579. });
  580. it('recommendations are loaded', function () {
  581. expect(loadRecommendationsConfigs).to.be.true;
  582. });
  583. it('components added via configs are loaded', function () {
  584. expect(loadComponentsFromConfigs).to.be.true;
  585. });
  586. it('config themes are loaded', function () {
  587. expect(loadConfigThemes).to.be.true;
  588. });
  589. });
  590. describe('Should load clients', function() {
  591. var loadSlaveComponentHosts = false;
  592. var loadClients = false;
  593. var loadRecommendations = false;
  594. var loadComponentsFromConfigs = false;
  595. var checker = {
  596. loadSlaveComponentHosts: function() {
  597. loadSlaveComponentHosts = true;
  598. },
  599. loadClients: function() {
  600. loadClients = true;
  601. },
  602. loadComponentsFromConfigs: function() {
  603. loadComponentsFromConfigs = true;
  604. },
  605. loadRecommendations: function() {
  606. loadRecommendations = true;
  607. }
  608. };
  609. beforeEach(function () {
  610. installerController.loadMap['6'][0].callback.call(checker);
  611. });
  612. it('slave components hosts are loaded', function () {
  613. expect(loadSlaveComponentHosts).to.be.true;
  614. });
  615. it('clients are loaded', function () {
  616. expect(loadClients).to.be.true;
  617. });
  618. it('components added via configs are loaded', function () {
  619. expect(loadComponentsFromConfigs).to.be.true;
  620. });
  621. it('recommendations are loaded', function () {
  622. expect(loadRecommendations).to.be.true;
  623. });
  624. });
  625. });
  626. describe('#removeHosts', function() {
  627. var hostsDb = {
  628. 'h1': {},
  629. 'h2': {},
  630. 'h3': {},
  631. 'h4': {}
  632. };
  633. beforeEach(function () {
  634. sinon.stub(installerController, 'getDBProperty').returns(hostsDb);
  635. });
  636. afterEach(function () {
  637. installerController.getDBProperty.restore();
  638. });
  639. it ('Should remove hosts from the list', function() {
  640. var hosts = Em.A([
  641. {
  642. name: 'h1'
  643. },
  644. {
  645. name: 'h2'
  646. },
  647. {
  648. name: 'h3'
  649. }
  650. ]);
  651. installerController.removeHosts(hosts);
  652. expect(hostsDb).to.eql({
  653. 'h4': {}
  654. });
  655. });
  656. });
  657. describe('#allHosts', function() {
  658. it ('Should return hosts', function() {
  659. var hosts = {
  660. 'h1': {
  661. disk_info: Em.A([{
  662. available: 1,
  663. size: 10
  664. }]),
  665. hostComponents: Em.A([])
  666. }
  667. };
  668. var masterComponentHosts = Em.A([
  669. {
  670. hostName: 'h1',
  671. component: 'component',
  672. display_name: 'n1'
  673. }
  674. ]);
  675. var slaveComponentHosts = Em.A([
  676. {
  677. hosts: Em.A([
  678. {
  679. hostName: 'h1'
  680. }
  681. ])
  682. }
  683. ]);
  684. installerController.set('content.hosts', hosts);
  685. installerController.set('content.masterComponentHosts', masterComponentHosts);
  686. installerController.set('content.slaveComponentHosts', slaveComponentHosts);
  687. var res = JSON.parse(JSON.stringify(installerController.get('allHosts')));
  688. expect(res).to.eql([
  689. {
  690. "diskInfo": [
  691. {
  692. "available": 1,
  693. "size": 10
  694. }
  695. ],
  696. "diskTotal": 0.0000095367431640625,
  697. "diskFree": 9.5367431640625e-7,
  698. "hostComponents": [
  699. {
  700. "componentName": "component",
  701. "displayName": "n1"
  702. },
  703. {}
  704. ]
  705. }
  706. ]);
  707. });
  708. });
  709. describe('#loadServiceConfigProperties', function() {
  710. beforeEach(function () {
  711. sinon.stub(installerController, 'getDBProperty').returns({
  712. value: 2
  713. });
  714. });
  715. afterEach(function () {
  716. installerController.getDBProperty.restore();
  717. });
  718. it ('Should load service config property', function() {
  719. installerController.loadServiceConfigProperties();
  720. expect(installerController.get('content.serviceConfigProperties')).to.eql({
  721. "value": 2
  722. });
  723. });
  724. });
  725. describe('#saveServices', function() {
  726. it ('Should return correct names', function() {
  727. var stepController = Em.A([
  728. Em.Object.create({
  729. isInstalled: true,
  730. isSelected: true,
  731. serviceName: 'i1'
  732. }),
  733. Em.Object.create({
  734. isInstalled: false,
  735. isSelected: true,
  736. serviceName: 'i2'
  737. }),
  738. Em.Object.create({
  739. isInstalled: true,
  740. isSelected: false,
  741. serviceName: 'i3'
  742. })
  743. ]);
  744. installerController.saveServices(stepController);
  745. expect(installerController.get('content.selectedServiceNames')).to.eql(['i1','i2']);
  746. expect(installerController.get('content.installedServiceNames')).to.eql(['i1','i3']);
  747. });
  748. });
  749. describe('#saveClients', function() {
  750. var stepController;
  751. beforeEach(function () {
  752. stepController = Em.Object.create({
  753. content: Em.A([
  754. Em.Object.create({
  755. isInstalled: true,
  756. isSelected: true,
  757. serviceName: 'i1',
  758. serviceComponents: Em.A([
  759. Em.Object.create({
  760. isClient: true,
  761. componentName: 'name',
  762. displayName: 'dname'
  763. })
  764. ])
  765. }),
  766. Em.Object.create({
  767. isInstalled: false,
  768. isSelected: true,
  769. serviceName: 'i2',
  770. serviceComponents: Em.A([
  771. Em.Object.create({
  772. isClient: false
  773. })
  774. ])
  775. }),
  776. Em.Object.create({
  777. isInstalled: true,
  778. isSelected: false,
  779. serviceName: 'i3',
  780. serviceComponents: Em.A([
  781. Em.Object.create({
  782. isClient: false
  783. })
  784. ])
  785. })
  786. ])
  787. });
  788. });
  789. it ('Should return correct clients names', function() {
  790. installerController.saveClients(stepController);
  791. var res = JSON.parse(JSON.stringify(installerController.get('content.clients')));
  792. expect(res).to.eql([
  793. {
  794. "component_name": "name",
  795. "display_name": "dname",
  796. "isInstalled": false
  797. }
  798. ]);
  799. });
  800. });
  801. describe('#saveMasterComponentHosts', function() {
  802. beforeEach(function () {
  803. sinon.stub(installerController, 'getDBProperty').returns({
  804. 'h1': {
  805. id: 11
  806. },
  807. 'h3': {
  808. id: 13
  809. },
  810. 'h2': {
  811. id: 12
  812. }
  813. });
  814. });
  815. afterEach(function () {
  816. installerController.getDBProperty.restore();
  817. });
  818. it ('Should return hosts', function() {
  819. var stepController = Em.Object.create({
  820. selectedServicesMasters: Em.A([
  821. Em.Object.create({
  822. display_name: 'n1',
  823. component_name: 'c1',
  824. serviceId: 1,
  825. selectedHost: 'h1'
  826. })
  827. ])
  828. });
  829. installerController.saveMasterComponentHosts(stepController);
  830. expect(installerController.get('content.masterComponentHosts')).to.eql([
  831. {
  832. "display_name": "n1",
  833. "component": "c1",
  834. "serviceId": 1,
  835. "isInstalled": false,
  836. "host_id": 11
  837. }
  838. ]);
  839. });
  840. });
  841. describe('#loadConfirmedHosts', function() {
  842. beforeEach(function () {
  843. sinon.stub(installerController, 'getDBProperty').returns({
  844. 'h1': {
  845. id: 11
  846. },
  847. 'h3': {
  848. id: 13
  849. },
  850. 'h2': {
  851. id: 12
  852. }
  853. });
  854. });
  855. afterEach(function () {
  856. installerController.getDBProperty.restore();
  857. });
  858. it ('Should load hosts from db', function() {
  859. installerController.loadConfirmedHosts();
  860. expect(installerController.get('content.hosts')).to.eql({
  861. 'h1': {
  862. id: 11
  863. },
  864. 'h3': {
  865. id: 13
  866. },
  867. 'h2': {
  868. id: 12
  869. }
  870. });
  871. });
  872. });
  873. describe('#loadMasterComponentHosts', function() {
  874. beforeEach(function () {
  875. sinon.stub(installerController, 'getDBProperties', function() {
  876. return {
  877. masterComponentHosts: Em.A([
  878. {
  879. hostName: '',
  880. host_id: 11
  881. }
  882. ]),
  883. hosts: {
  884. 'h1': {
  885. id: 11
  886. },
  887. 'h3': {
  888. id: 13
  889. },
  890. 'h2': {
  891. id: 12
  892. }
  893. }
  894. }
  895. });
  896. });
  897. afterEach(function () {
  898. installerController.getDBProperties.restore();
  899. });
  900. it ('Should load hosts', function() {
  901. installerController.loadMasterComponentHosts();
  902. expect(installerController.get('content.masterComponentHosts')).to.eql([
  903. {
  904. "hostName": "h1",
  905. "host_id": 11
  906. }
  907. ]);
  908. });
  909. });
  910. describe('#loadSlaveComponentHosts', function() {
  911. beforeEach(function () {
  912. sinon.stub(installerController, 'getDBProperties', function() {
  913. return {
  914. hosts: {
  915. 'h1': {
  916. id: 11
  917. },
  918. 'h3': {
  919. id: 13
  920. },
  921. 'h2': {
  922. id: 12
  923. }
  924. },
  925. slaveComponentHosts: Em.A([
  926. {
  927. hosts: Em.A([
  928. {
  929. hostName: '',
  930. host_id: 11
  931. }
  932. ])
  933. }
  934. ])
  935. };
  936. });
  937. });
  938. afterEach(function () {
  939. installerController.getDBProperties.restore();
  940. });
  941. it ('Should load slave hosts', function() {
  942. installerController.loadSlaveComponentHosts();
  943. expect(installerController.get('content.slaveComponentHosts')).to.eql([
  944. {
  945. "hosts": [
  946. {
  947. "hostName": "h1",
  948. "host_id": 11
  949. }
  950. ]
  951. }
  952. ]);
  953. });
  954. });
  955. describe('#getServerVersionSuccessCallback', function () {
  956. var cases = [
  957. {
  958. osFamily: 'redhat5',
  959. expected: false
  960. },
  961. {
  962. osFamily: 'redhat6',
  963. expected: true
  964. },
  965. {
  966. osFamily: 'suse11',
  967. expected: false
  968. }
  969. ],
  970. title = 'App.isManagedMySQLForHiveEnabled should be {0} for {1}';
  971. cases.forEach(function (item) {
  972. it(title.format(item.expected, item.osFamily), function () {
  973. installerController.getServerVersionSuccessCallback({
  974. 'RootServiceComponents': {
  975. 'component_version': '',
  976. 'properties': {
  977. 'server.os_family': item.osFamily
  978. }
  979. }
  980. });
  981. expect(App.get('isManagedMySQLForHiveEnabled')).to.equal(item.expected);
  982. });
  983. });
  984. });
  985. describe('#validateJDKVersion', function() {
  986. var tests = [
  987. {
  988. isCustomJDK: false,
  989. ambariProperties: {
  990. 'java.version': '1.8'
  991. },
  992. successCallbackCalled: false,
  993. popupCalled: true,
  994. stacks: [Em.Object.create({
  995. minJdkVersion: '1.6',
  996. maxJdkVersion: '1.7',
  997. isSelected: true
  998. })],
  999. m: 'JDK 1.8, stack supports 1.6-1.7 popup should be displayed'
  1000. },
  1001. {
  1002. isCustomJDK: false,
  1003. ambariProperties: {
  1004. 'java.version': '1.8'
  1005. },
  1006. successCallbackCalled: true,
  1007. popupCalled: false,
  1008. stacks: [Em.Object.create({
  1009. minJdkVersion: '1.6',
  1010. maxJdkVersion: '1.8',
  1011. isSelected: true
  1012. })],
  1013. m: 'JDK 1.8, stack supports 1.7-1.8 procceed installation without warning'
  1014. },
  1015. {
  1016. isCustomJDK: false,
  1017. ambariProperties: {
  1018. 'java.version': '1.5'
  1019. },
  1020. successCallbackCalled: false,
  1021. popupCalled: true,
  1022. stacks: [Em.Object.create({
  1023. minJdkVersion: '1.6',
  1024. maxJdkVersion: '1.8',
  1025. isSelected: true
  1026. })],
  1027. m: 'JDK 1.5, stack supports 1.6-1.8, popup should be displayed'
  1028. },
  1029. {
  1030. isCustomJDK: false,
  1031. ambariProperties: {
  1032. 'java.version': '1.5'
  1033. },
  1034. successCallbackCalled: true,
  1035. popupCalled: false,
  1036. stacks: [Em.Object.create({
  1037. minJdkVersion: null,
  1038. maxJdkVersion: null,
  1039. isSelected: true
  1040. })],
  1041. m: 'JDK 1.5, stack supports max and min are null, procceed installation without warning'
  1042. },
  1043. {
  1044. isCustomJDK: false,
  1045. ambariProperties: {
  1046. 'java.version': '1.5'
  1047. },
  1048. successCallbackCalled: true,
  1049. popupCalled: false,
  1050. stacks: [Em.Object.create({
  1051. minJdkVersion: '1.5',
  1052. maxJdkVersion: null,
  1053. isSelected: true
  1054. })],
  1055. m: 'JDK 1.5, stack supports max is missed and min is 1.5, procceed installation without warning'
  1056. },
  1057. {
  1058. isCustomJDK: false,
  1059. ambariProperties: {
  1060. 'java.version': '1.6'
  1061. },
  1062. successCallbackCalled: false,
  1063. popupCalled: true,
  1064. stacks: [Em.Object.create({
  1065. minJdkVersion: '1.5',
  1066. maxJdkVersion: null,
  1067. isSelected: true
  1068. })],
  1069. m: 'JDK 1.6, stack supports max is missed and min is 1.5, popup should be displayed'
  1070. },
  1071. {
  1072. isCustomJDK: false,
  1073. ambariProperties: {
  1074. 'java.version': '1.5'
  1075. },
  1076. successCallbackCalled: true,
  1077. popupCalled: false,
  1078. stacks: [Em.Object.create({
  1079. minJdkVersion: null,
  1080. maxJdkVersion: '1.5',
  1081. isSelected: true
  1082. })],
  1083. m: 'JDK 1.5, stack supports max 1.5 and min is missed, procceed installation without warning'
  1084. },
  1085. {
  1086. isCustomJDK: false,
  1087. ambariProperties: {
  1088. 'java.version': '1.5'
  1089. },
  1090. successCallbackCalled: false,
  1091. popupCalled: true,
  1092. stacks: [Em.Object.create({
  1093. minJdkVersion: null,
  1094. maxJdkVersion: '1.8',
  1095. isSelected: true
  1096. })],
  1097. m: 'JDK 1.5, stack supports max 1.8 and min is missed, popup should be displayed'
  1098. },
  1099. {
  1100. isCustomJDK: false,
  1101. ambariProperties: {
  1102. 'java.version': '1.8'
  1103. },
  1104. successCallbackCalled: true,
  1105. popupCalled: false,
  1106. stacks: [Em.Object.create({
  1107. isSelected: true
  1108. })],
  1109. m: 'JDK 1.8, min, max jdk missed in stack definition, procceed installation without warning'
  1110. },
  1111. {
  1112. isCustomJDK: true,
  1113. ambariProperties: {
  1114. 'java.version': '1.8'
  1115. },
  1116. successCallbackCalled: true,
  1117. popupCalled: false,
  1118. stacks: [Em.Object.create({
  1119. minJdkVersion: '1.6',
  1120. maxJdkVersion: '1.8',
  1121. isSelected: true
  1122. })],
  1123. m: 'JDK 1.8, custom jdk location used, procceed installation without warning'
  1124. }
  1125. ];
  1126. tests.forEach(function(test) {
  1127. describe(test.m, function() {
  1128. var successCallback;
  1129. beforeEach(function () {
  1130. sinon.stub(App.Stack, 'find').returns(test.stacks);
  1131. sinon.stub(App.router, 'get').withArgs('clusterController.isCustomJDK').returns(test.isCustomJDK)
  1132. .withArgs('clusterController.ambariProperties').returns(test.ambariProperties);
  1133. sinon.stub(App, 'showConfirmationPopup', Em.K);
  1134. successCallback = sinon.spy();
  1135. installerController.validateJDKVersion(successCallback);
  1136. });
  1137. afterEach(function () {
  1138. App.router.get.restore();
  1139. App.Stack.find.restore();
  1140. App.showConfirmationPopup.restore();
  1141. });
  1142. it('successCallback is ' + (test.successCallbackCalled ? '' : 'not') + ' called', function () {
  1143. expect(successCallback.called).to.be.equal(test.successCallbackCalled);
  1144. });
  1145. it('App.showConfirmationPopup. is ' + (test.popupCalled ? '' : 'not') + ' called', function () {
  1146. expect(App.showConfirmationPopup.called).to.be.equal(test.popupCalled);
  1147. });
  1148. });
  1149. });
  1150. });
  1151. describe('#postVersionDefinitionFileErrorCallback', function () {
  1152. beforeEach(function () {
  1153. sinon.stub(App, 'showAlertPopup', Em.K);
  1154. });
  1155. afterEach(function () {
  1156. App.showAlertPopup.restore();
  1157. });
  1158. it('should delete VDF-data', function () {
  1159. App.db.setLocalRepoVDFData({});
  1160. expect(App.db.getLocalRepoVDFData()).to.not.be.an.object;
  1161. installerController.postVersionDefinitionFileErrorCallback({}, {}, {}, {}, {dfd: $.Deferred()});
  1162. expect(App.db.getLocalRepoVDFData()).to.be.undefined;
  1163. });
  1164. });
  1165. });