step6_test.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412
  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 Ember = require('ember');
  19. var App = require('app');
  20. var validationUtils = require('utils/validator');
  21. require('utils/helper');
  22. require('controllers/wizard/step6_controller');
  23. var controller,
  24. services = [
  25. Em.Object.create({
  26. serviceName: 'YARN',
  27. isSelected: true
  28. }),
  29. Em.Object.create({
  30. serviceName: 'HBASE',
  31. isSelected: true
  32. }),
  33. Em.Object.create({
  34. serviceName: 'HDFS',
  35. isSelected: true
  36. }),
  37. Em.Object.create({
  38. serviceName: 'STORM',
  39. isSelected: true
  40. }),
  41. Em.Object.create({
  42. serviceName: 'FLUME',
  43. isSelected: true
  44. })
  45. ];
  46. describe('App.WizardStep6Controller', function () {
  47. beforeEach(function () {
  48. controller = App.WizardStep6Controller.create();
  49. controller.set('content', Em.Object.create({
  50. hosts: {},
  51. masterComponentHosts: {},
  52. services: services
  53. }));
  54. var h = {}, m = [];
  55. Em.A(['host0', 'host1', 'host2', 'host3']).forEach(function (hostName) {
  56. var obj = Em.Object.create({
  57. name: hostName,
  58. hostName: hostName,
  59. bootStatus: 'REGISTERED'
  60. });
  61. h[hostName] = obj;
  62. m.push(obj);
  63. });
  64. controller.set('content.hosts', h);
  65. controller.set('content.masterComponentHosts', m);
  66. controller.set('isMasters', false);
  67. });
  68. describe('#isAddHostWizard', function () {
  69. it('true if content.controllerName is addHostController', function () {
  70. controller.set('content.controllerName', 'addHostController');
  71. expect(controller.get('isAddHostWizard')).to.equal(true);
  72. });
  73. it('false if content.controllerName is not addHostController', function () {
  74. controller.set('content.controllerName', 'mainController');
  75. expect(controller.get('isAddHostWizard')).to.equal(false);
  76. });
  77. });
  78. describe('#installedServiceNames', function () {
  79. it(' should filter content.services by isInstalled property', function () {
  80. var services = Em.A([]);
  81. services.pushObjects(Em.A([{isInstalled: true, serviceName: "service1"},
  82. {isInstalled: false, serviceName: "service2"},
  83. {isInstalled: true, serviceName: "service3"},
  84. {isInstalled: false, serviceName: "service4"},
  85. {isInstalled: true, serviceName: "service5"}]));
  86. controller.set('content.services', services);
  87. expect(controller.get('installedServiceNames')).to.eql(["service1", "service3", "service5"]);
  88. });
  89. });
  90. describe('#showValidationIssuesAcceptBox', function () {
  91. it('should return true if success callback', function () {
  92. var deffer = jQuery.Deferred();
  93. function callback() {
  94. deffer.resolve(true);
  95. }
  96. controller.showValidationIssuesAcceptBox(callback);
  97. jQuery.when(deffer.promise()).then(function(data) {
  98. expect(data).to.equal(true);
  99. });
  100. });
  101. });
  102. describe('#selectAllNodes', function () {
  103. it('should make checkbox checked', function () {
  104. var hostsObj = Em.A([Em.Object.create({
  105. hasMaster: false,
  106. isInstalled: false,
  107. checkboxes: Em.A([
  108. Em.Object.create({
  109. title: 'l1',
  110. component: 'name',
  111. isInstalled: false,
  112. checked: false
  113. })
  114. ])
  115. })]);
  116. var obj = Em.Object.create({
  117. context: {
  118. name: "name"
  119. }
  120. });
  121. var clientComponents = Em.A([{component_name: "name1"}]);
  122. controller.set('hosts', hostsObj);
  123. controller.set('content.clients', clientComponents);
  124. controller.selectAllNodes(obj);
  125. expect(controller.get('hosts')).to.eql(Em.A([Em.Object.create({
  126. hasMaster: false,
  127. isInstalled: false,
  128. checkboxes: Em.A([
  129. Em.Object.create({
  130. title: 'l1',
  131. component: 'name',
  132. isInstalled: false,
  133. checked: true
  134. })
  135. ])
  136. })]));
  137. });
  138. });
  139. describe('#deselectAllNodes', function () {
  140. it('should uncheck checkbox', function () {
  141. var hostsObj = Em.A([Em.Object.create({
  142. hasMaster: false,
  143. isInstalled: false,
  144. checkboxes: Em.A([
  145. Em.Object.create({
  146. title: 'l1',
  147. component: 'name',
  148. isInstalled: false,
  149. checked: true
  150. })
  151. ])
  152. })]);
  153. var obj = Em.Object.create({
  154. context: {
  155. name: "name"
  156. }
  157. });
  158. var clientComponents = Em.A([{component_name: "name1"}]);
  159. controller.set('hosts', hostsObj);
  160. controller.set('content.clients', clientComponents);
  161. controller.deselectAllNodes(obj);
  162. expect(controller.get('hosts')).to.eql(Em.A([Em.Object.create({
  163. hasMaster: false,
  164. isInstalled: false,
  165. checkboxes: Em.A([
  166. Em.Object.create({
  167. title: 'l1',
  168. component: 'name',
  169. isInstalled: false,
  170. checked: false
  171. })
  172. ])
  173. })]));
  174. });
  175. });
  176. describe('#renderSlaves', function () {
  177. it('should change false checkboxes state to true', function () {
  178. var hostsObj = Em.A([Em.Object.create({
  179. hasMaster: false,
  180. isInstalled: false,
  181. checkboxes: Em.A([
  182. Em.Object.create({
  183. title: 'l1',
  184. component: 'c1',
  185. isInstalled: false,
  186. checked: false
  187. })
  188. ])
  189. })]);
  190. var slaveComponentHosts = Em.A([{componentName: "c1", hosts: hostsObj,isInstalled: false}]);
  191. controller.set('content.slaveComponentHosts', slaveComponentHosts);
  192. var headers = Em.A([
  193. Em.Object.create({name: "c1", label: 'l1', isDisabled: true}),
  194. Em.Object.create({name: "c2", label: 'l2', isDisabled: false})
  195. ]);
  196. controller.set('headers', headers);
  197. controller.renderSlaves(hostsObj);
  198. expect(slaveComponentHosts[0].hosts[0].checkboxes[0].checked).to.equal(true);
  199. });
  200. });
  201. describe('#anyGeneralErrors', function () {
  202. beforeEach(function () {
  203. controller.set('errorMessage', undefined);
  204. });
  205. it('should return errorMessage', function () {
  206. controller.set('errorMessage', "error 404");
  207. expect(controller.get('anyGeneralErrors')).to.equal("error 404");
  208. });
  209. it('true if generalErrorMessages is non empty array and errorMessage is undefined', function () {
  210. controller.set('generalErrorMessages', ["error1", "error2"]);
  211. expect(controller.get('anyGeneralErrors')).to.equal(true);
  212. });
  213. it('false if generalErrorMessages is empty array and errorMessage is undefined', function () {
  214. controller.set('generalErrorMessages', []);
  215. expect(controller.get('anyGeneralErrors')).to.equal(false);
  216. });
  217. it('undefined if generalErrorMessages is undefined and errorMessage is undefined', function () {
  218. controller.set('generalErrorMessages', undefined);
  219. expect(controller.get('anyGeneralErrors')).to.equal(undefined);
  220. });
  221. });
  222. describe('#render', function () {
  223. it('true if loaded', function () {
  224. var hosts = {
  225. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  226. h2: {bootStatus: 'REGISTERED', name: 'h2'},
  227. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  228. };
  229. var headers = Em.A([
  230. Em.Object.create({name: "c1", label: 'l1', isDisabled: true}),
  231. Em.Object.create({name: "c2", label: 'l2', isDisabled: false})
  232. ]);
  233. var masterComponentHosts = Em.A([
  234. {hostName: 'h1', component: 'c1'}
  235. ]);
  236. var recommendations = {
  237. blueprint: {
  238. host_groups: [
  239. {
  240. components: [
  241. {
  242. name: 'c6'
  243. }
  244. ],
  245. name: 'host-group-1'
  246. },
  247. {
  248. components: [
  249. {
  250. name: 'c8'
  251. }
  252. ],
  253. name: 'host-group-2'
  254. }
  255. ]
  256. },
  257. blueprint_cluster_binding: {
  258. host_groups: [
  259. {
  260. hosts: [
  261. {
  262. fqdn: 'h0'
  263. }
  264. ],
  265. name: 'host-group-1'
  266. },
  267. {
  268. hosts: [
  269. {
  270. fqdn: 'h1'
  271. }
  272. ],
  273. name: 'host-group-2'
  274. }]
  275. }
  276. };
  277. controller.set('content.hosts', hosts);
  278. controller.set('content.masterComponentHosts', masterComponentHosts);
  279. controller.set('content.recommendations', recommendations);
  280. controller.set('headers', headers);
  281. controller.render();
  282. expect(controller.get('isLoaded')).to.equal(true);
  283. });
  284. });
  285. describe('#anyGeneralWarnings', function () {
  286. it('true if generalWarningMessages is non empty array and warningMessage is undefined', function () {
  287. controller.set('generalWarningMessages', ["warning1", "warning2"]);
  288. expect(controller.get('anyGeneralWarnings')).to.equal(true);
  289. });
  290. it('false if generalWarningMessages is empty array', function () {
  291. controller.set('generalWarningMessages', []);
  292. expect(controller.get('anyGeneralWarnings')).to.equal(false);
  293. });
  294. it('undefined if generalWarningMessages is undefined', function () {
  295. controller.set('generalWarningMessages', false);
  296. expect(controller.get('anyGeneralWarnings')).to.equal(false);
  297. });
  298. });
  299. describe('#anyGeneralIssues', function () {
  300. it('should return error message if errorMessage', function () {
  301. controller.set('errorMessage', "error 404");
  302. expect(controller.get('anyGeneralIssues')).to.equal("error 404");
  303. });
  304. it('should return true if we have several errors', function () {
  305. controller.set('generalErrorMessages', ["error 404", "error"]);
  306. expect(controller.get('anyGeneralIssues')).to.equal(true);
  307. });
  308. it('should return true if we have several warnings', function () {
  309. controller.set('generalWarningMessages', ["error 404", "error"]);
  310. expect(controller.get('anyGeneralIssues')).to.equal(true);
  311. });
  312. });
  313. describe('#anyErrors', function () {
  314. it('true if generalErrorMessages is non empty', function () {
  315. controller.set('generalErrorMessages', ["error 404", "error"]);
  316. expect(controller.get('anyErrors')).to.equal(true);
  317. });
  318. it('false if generalErrorMessages is empty', function () {
  319. controller.set('generalErrorMessages', []);
  320. expect(controller.get('anyErrors')).to.equal(false);
  321. });
  322. });
  323. describe('#anyWarnings', function () {
  324. it('true if generalWarningMessages is non empty', function () {
  325. controller.set('generalWarningMessages', ["error 404", "error"]);
  326. expect(controller.get('anyWarnings')).to.equal(true);
  327. });
  328. it('false if generalWarningMessages is empty', function () {
  329. controller.set('generalWarningMessages', []);
  330. expect(controller.get('anyWarnings')).to.equal(false);
  331. });
  332. });
  333. describe('#isInstallerWizard', function () {
  334. it('true if content.controllerName is addHostController', function () {
  335. controller.set('content.controllerName', 'installerController');
  336. expect(controller.get('isInstallerWizard')).to.equal(true);
  337. });
  338. it('false if content.controllerName is not addHostController', function () {
  339. controller.set('content.controllerName', 'mainController');
  340. expect(controller.get('isInstallerWizard')).to.equal(false);
  341. });
  342. });
  343. describe('#isAddServiceWizard', function () {
  344. it('true if content.controllerName is addServiceController', function () {
  345. controller.set('content.controllerName', 'addServiceController');
  346. expect(controller.get('isAddServiceWizard')).to.equal(true);
  347. });
  348. it('false if content.controllerName is not addServiceController', function () {
  349. controller.set('content.controllerName', 'mainController');
  350. expect(controller.get('isAddServiceWizard')).to.equal(false);
  351. });
  352. });
  353. describe('#selectClientHost', function () {
  354. it('true if isClientsSet false', function () {
  355. var hostsObj = Em.A([Em.Object.create({
  356. hasMaster: false,
  357. checkboxes: Em.A([
  358. Em.Object.create({
  359. component: 'c1',
  360. isInstalled: false,
  361. checked: true
  362. })
  363. ])
  364. })]);
  365. controller.set('isClientsSet', false);
  366. controller.selectClientHost(hostsObj);
  367. expect(controller.get('isClientsSet')).to.equal(true);
  368. });
  369. });
  370. describe('#updateValidationsSuccessCallback', function () {
  371. beforeEach(function () {
  372. sinon.stub(validationUtils, 'filterNotInstalledComponents', function () {
  373. return Em.A([Em.Object.create({
  374. componentName: 'c0',
  375. isSlave: true,
  376. type: 'host-component',
  377. level: 'ERROR'
  378. }),
  379. Em.Object.create({
  380. componentName: 'c1',
  381. isSlave: true,
  382. type: 'host-component',
  383. level: 'WARN',
  384. isShownOnInstallerSlaveClientPage: true
  385. })]);
  386. });
  387. sinon.stub(App.StackServiceComponent, 'find', function () {
  388. return [
  389. Em.Object.create({
  390. componentName: 'c0',
  391. isSlave: true
  392. }),
  393. Em.Object.create({
  394. componentName: 'c1',
  395. isSlave: true,
  396. isShownOnInstallerSlaveClientPage: true
  397. }),
  398. Em.Object.create({
  399. componentName: 'c2',
  400. isSlave: true,
  401. isShownOnInstallerSlaveClientPage: false
  402. }),
  403. Em.Object.create({
  404. componentName: 'c3',
  405. isClient: true
  406. }),
  407. Em.Object.create({
  408. componentName: 'c4',
  409. isClient: true,
  410. isRequiredOnAllHosts: false
  411. }),
  412. Em.Object.create({
  413. componentName: 'c5',
  414. isClient: true,
  415. isRequiredOnAllHosts: true
  416. }),
  417. Em.Object.create({
  418. componentName: 'c6',
  419. isMaster: true,
  420. isShownOnInstallerAssignMasterPage: true
  421. }),
  422. Em.Object.create({
  423. componentName: 'c7',
  424. isMaster: true,
  425. isShownOnInstallerAssignMasterPage: false
  426. }),
  427. Em.Object.create({
  428. componentName: 'HDFS_CLIENT',
  429. isMaster: true,
  430. isShownOnAddServiceAssignMasterPage: true
  431. }),
  432. Em.Object.create({
  433. componentName: 'c9',
  434. isMaster: true,
  435. isShownOnAddServiceAssignMasterPage: false
  436. })
  437. ];
  438. });
  439. });
  440. afterEach(function () {
  441. App.StackServiceComponent.find.restore();
  442. validationUtils.filterNotInstalledComponents.restore();
  443. });
  444. it('should return modified hosts', function () {
  445. var hosts = Em.A([Em.Object.create({
  446. warnMessages: "warn",
  447. errorMessages: "error",
  448. anyMessage: true,
  449. checkboxes: Em.A([Em.Object.create({
  450. hasWarnMessage: true,
  451. hasErrorMessage: true
  452. })])
  453. })]);
  454. controller.set('hosts', hosts);
  455. var validationData = Em.Object.create({
  456. resources: Em.A([
  457. Em.Object.create({
  458. items: Em.A([
  459. Em.Object.create({
  460. "component-name": 'HDFS_CLIENT',
  461. host: "1",
  462. isMaster: true
  463. })
  464. ])
  465. })
  466. ])
  467. });
  468. controller.updateValidationsSuccessCallback(validationData);
  469. expect(controller.get('generalErrorMessages').length).to.equal(0);
  470. expect(controller.get('generalWarningMessages').length).to.equal(0);
  471. expect(JSON.parse(JSON.stringify(controller.get('hosts')))).to.eql(JSON.parse(JSON.stringify(Em.A([Em.Object.create({
  472. warnMessages: [null],
  473. errorMessages: [null],
  474. anyMessage: true,
  475. checkboxes: Em.A([Em.Object.create({
  476. hasWarnMessage: true,
  477. hasErrorMessage: true
  478. })])
  479. })]))));
  480. });
  481. });
  482. describe('#clearError', function () {
  483. it('true if is one of checkboxes checked false', function () {
  484. var hosts = Em.A([
  485. Em.Object.create({
  486. checkboxes: Em.A([
  487. Em.Object.create({
  488. component: 'c1',
  489. isInstalled: false,
  490. checked: true
  491. }),
  492. Em.Object.create({
  493. component: 'c2',
  494. isInstalled: false,
  495. checked: true
  496. })])
  497. })
  498. ]);
  499. var headers = Em.A([
  500. Em.Object.create({name: "c1"}),
  501. Em.Object.create({name: "c2"})]);
  502. controller.set('errorMessage', 'error');
  503. controller.set('hosts', hosts);
  504. controller.set('headers', headers);
  505. controller.clearError();
  506. expect(controller.get('errorMessage')).to.equal('');
  507. });
  508. it('true if is one of checkboxes checked false', function () {
  509. var hosts = Em.A([
  510. Em.Object.create({
  511. checkboxes: Em.A([
  512. Em.Object.create({
  513. title: "t1",
  514. component: 'c1',
  515. isInstalled: false,
  516. checked: false
  517. }),
  518. Em.Object.create({
  519. title: "t2",
  520. component: 'c2',
  521. isInstalled: false,
  522. checked: true
  523. })])
  524. })
  525. ]);
  526. var headers = Em.A([
  527. Em.Object.create({name: "c1", label: 't1'}),
  528. Em.Object.create({name: "c2", label: 't2'})]);
  529. controller.set('errorMessage', 'error');
  530. controller.set('hosts', hosts);
  531. controller.set('headers', headers);
  532. controller.set('isAddHostWizard', true);
  533. controller.clearError();
  534. expect(controller.get('errorMessage')).to.equal('error');
  535. });
  536. });
  537. describe('#clearStep', function () {
  538. beforeEach(function () {
  539. sinon.stub(controller, 'clearError', Em.K);
  540. });
  541. afterEach(function () {
  542. controller.clearError.restore();
  543. });
  544. it('should call clearError', function () {
  545. controller.clearStep();
  546. expect(controller.clearError.calledOnce).to.equal(true);
  547. });
  548. it('should clear hosts', function () {
  549. controller.set('hosts', [
  550. {},
  551. {}
  552. ]);
  553. controller.clearStep();
  554. expect(controller.get('hosts')).to.eql([]);
  555. });
  556. it('should clear headers', function () {
  557. controller.set('headers', [
  558. {},
  559. {}
  560. ]);
  561. controller.clearStep();
  562. expect(controller.get('headers')).to.eql([]);
  563. });
  564. it('should set isLoaded to false', function () {
  565. controller.set('isLoaded', true);
  566. controller.clearStep();
  567. expect(controller.get('isLoaded')).to.equal(false);
  568. });
  569. });
  570. describe('#checkCallback', function () {
  571. beforeEach(function () {
  572. sinon.stub(controller, 'clearError', Em.K);
  573. });
  574. afterEach(function () {
  575. controller.clearError.restore();
  576. });
  577. it('should call clearError', function () {
  578. controller.checkCallback('');
  579. expect(controller.clearError.calledOnce).to.equal(true);
  580. });
  581. Em.A([
  582. {
  583. m: 'all checked, isInstalled false',
  584. headers: Em.A([
  585. Em.Object.create({name: 'c1'})
  586. ]),
  587. hosts: Em.A([
  588. Em.Object.create({
  589. checkboxes: Em.A([
  590. Em.Object.create({
  591. component: 'c1',
  592. isInstalled: false,
  593. checked: true
  594. })
  595. ])
  596. })
  597. ]),
  598. component: 'c1',
  599. e: {
  600. allChecked: true,
  601. noChecked: false
  602. }
  603. },
  604. {
  605. m: 'all checked, isInstalled true',
  606. headers: Em.A([
  607. Em.Object.create({name: 'c1'})
  608. ]),
  609. hosts: Em.A([
  610. Em.Object.create({
  611. checkboxes: Em.A([
  612. Em.Object.create({
  613. component: 'c1',
  614. isInstalled: true,
  615. checked: true
  616. })
  617. ])
  618. })
  619. ]),
  620. component: 'c1',
  621. e: {
  622. allChecked: true,
  623. noChecked: true
  624. }
  625. },
  626. {
  627. m: 'no one checked',
  628. headers: Em.A([
  629. Em.Object.create({name: 'c1'})
  630. ]),
  631. hosts: Em.A([
  632. Em.Object.create({
  633. checkboxes: Em.A([
  634. Em.Object.create({
  635. component: 'c1',
  636. isInstalled: false,
  637. checked: false
  638. })
  639. ])
  640. })
  641. ]),
  642. component: 'c1',
  643. e: {
  644. allChecked: false,
  645. noChecked: true
  646. }
  647. },
  648. {
  649. m: 'some checked',
  650. headers: Em.A([
  651. Em.Object.create({name: 'c1'})
  652. ]),
  653. hosts: Em.A([
  654. Em.Object.create({
  655. checkboxes: Em.A([
  656. Em.Object.create({
  657. component: 'c1',
  658. isInstalled: false,
  659. checked: true
  660. }),
  661. Em.Object.create({
  662. component: 'c1',
  663. isInstalled: false,
  664. checked: false
  665. })
  666. ])
  667. })
  668. ]),
  669. component: 'c1',
  670. e: {
  671. allChecked: false,
  672. noChecked: false
  673. }
  674. },
  675. {
  676. m: 'some checked, some isInstalled true',
  677. headers: Em.A([
  678. Em.Object.create({name: 'c1'})
  679. ]),
  680. hosts: Em.A([
  681. Em.Object.create({
  682. checkboxes: Em.A([
  683. Em.Object.create({
  684. component: 'c1',
  685. isInstalled: true,
  686. checked: true
  687. }),
  688. Em.Object.create({
  689. component: 'c1',
  690. isInstalled: true,
  691. checked: true
  692. })
  693. ])
  694. })
  695. ]),
  696. component: 'c1',
  697. e: {
  698. allChecked: true,
  699. noChecked: true
  700. }
  701. },
  702. {
  703. m: 'some checked, some isInstalled true (2)',
  704. headers: Em.A([
  705. Em.Object.create({name: 'c1'})
  706. ]),
  707. hosts: Em.A([
  708. Em.Object.create({
  709. checkboxes: Em.A([
  710. Em.Object.create({
  711. component: 'c1',
  712. isInstalled: false,
  713. checked: false
  714. }),
  715. Em.Object.create({
  716. component: 'c1',
  717. isInstalled: true,
  718. checked: true
  719. })
  720. ])
  721. })
  722. ]),
  723. component: 'c1',
  724. e: {
  725. allChecked: false,
  726. noChecked: true
  727. }
  728. }
  729. ]).forEach(function (test) {
  730. it(test.m, function () {
  731. controller.clearStep();
  732. controller.set('headers', test.headers);
  733. controller.set('hosts', test.hosts);
  734. controller.checkCallback(test.component);
  735. var header = controller.get('headers').findProperty('name', test.component);
  736. expect(header.get('allChecked')).to.equal(test.e.allChecked);
  737. expect(header.get('noChecked')).to.equal(test.e.noChecked);
  738. });
  739. });
  740. });
  741. describe('#getHostNames', function () {
  742. var tests = Em.A([
  743. {
  744. hosts: {
  745. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  746. h2: {bootStatus: 'REGISTERED', name: 'h2'},
  747. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  748. },
  749. m: 'All REGISTERED',
  750. e: ['h1', 'h2', 'h3']
  751. },
  752. {
  753. hosts: {
  754. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  755. h2: {bootStatus: 'FAILED', name: 'h2'},
  756. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  757. },
  758. m: 'Some REGISTERED',
  759. e: ['h1', 'h3']
  760. },
  761. {
  762. hosts: {
  763. h1: {bootStatus: 'FAILED', name: 'h1'},
  764. h2: {bootStatus: 'FAILED', name: 'h2'},
  765. h3: {bootStatus: 'FAILED', name: 'h3'}
  766. },
  767. m: 'No one REGISTERED',
  768. e: []
  769. },
  770. {
  771. hosts: {},
  772. m: 'Empty hosts',
  773. e: []
  774. }
  775. ]);
  776. tests.forEach(function (test) {
  777. it(test.m, function () {
  778. controller.set('content.hosts', test.hosts);
  779. var r = controller.getHostNames();
  780. expect(r).to.eql(test.e);
  781. });
  782. });
  783. });
  784. describe('#getMasterComponentsForHost', function () {
  785. var tests = Em.A([
  786. {
  787. masterComponentHosts: Em.A([
  788. {hostName: 'h1', component: 'c1'}
  789. ]),
  790. hostName: 'h1',
  791. m: 'host exists',
  792. e: ['c1']
  793. },
  794. {
  795. masterComponentHosts: Em.A([
  796. {hostName: 'h1', component: 'c1'}
  797. ]),
  798. hostName: 'h2',
  799. m: 'host donesn\'t exists',
  800. e: []
  801. }
  802. ]);
  803. tests.forEach(function (test) {
  804. it(test.m, function () {
  805. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  806. var r = controller.getMasterComponentsForHost(test.hostName);
  807. expect(r).to.eql(test.e);
  808. });
  809. });
  810. });
  811. describe('#selectMasterComponents', function () {
  812. var tests = Em.A([
  813. {
  814. masterComponentHosts: Em.A([
  815. {
  816. hostName: 'h1',
  817. component: 'c1'
  818. }
  819. ]),
  820. hostsObj: [
  821. Em.Object.create({
  822. hostName: 'h1',
  823. checkboxes: [
  824. Em.Object.create({
  825. component: 'c1',
  826. checked: false
  827. })
  828. ]
  829. })
  830. ],
  831. e: true,
  832. m: 'host and component exist'
  833. },
  834. {
  835. masterComponentHosts: Em.A([
  836. {
  837. hostName: 'h1',
  838. component: 'c2'
  839. }
  840. ]),
  841. hostsObj: [
  842. Em.Object.create({
  843. hostName: 'h1',
  844. checkboxes: [
  845. Em.Object.create({
  846. component: 'c1',
  847. checked: false
  848. })
  849. ]
  850. })
  851. ],
  852. e: false,
  853. m: 'host exists'
  854. },
  855. {
  856. masterComponentHosts: Em.A([
  857. {
  858. hostName: 'h2',
  859. component: 'c2'
  860. }
  861. ]),
  862. hostsObj: [
  863. Em.Object.create({
  864. hostName: 'h1',
  865. checkboxes: [
  866. Em.Object.create({
  867. component: 'c1',
  868. checked: false
  869. })
  870. ]
  871. })
  872. ],
  873. e: false,
  874. m: 'host and component don\'t exist'
  875. }
  876. ]);
  877. tests.forEach(function (test) {
  878. it(test.m, function () {
  879. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  880. var r = controller.selectMasterComponents(test.hostsObj);
  881. expect(r.findProperty('hostName', 'h1').get('checkboxes').findProperty('component', 'c1').get('checked')).to.equal(test.e);
  882. });
  883. });
  884. });
  885. describe('#getCurrentMastersBlueprint', function () {
  886. var tests = Em.A([
  887. {
  888. masterComponentHosts: Em.A([
  889. {hostName: 'h1', component: 'c1'}
  890. ]),
  891. hosts: {'h1': {}},
  892. m: 'one host and one component',
  893. e:{
  894. blueprint: {
  895. host_groups: [
  896. {
  897. name: 'host-group-1',
  898. components: [
  899. { name: 'c1' }
  900. ]
  901. }
  902. ]
  903. },
  904. blueprint_cluster_binding: {
  905. host_groups: [
  906. {
  907. name: 'host-group-1',
  908. hosts: [
  909. { fqdn: 'h1' }
  910. ]
  911. }
  912. ]
  913. }
  914. }
  915. },
  916. {
  917. masterComponentHosts: Em.A([
  918. {hostName: 'h1', component: 'c1'},
  919. {hostName: 'h2', component: 'c2'},
  920. {hostName: 'h2', component: 'c3'}
  921. ]),
  922. hosts: {'h1': {}, 'h2': {}, 'h3': {}},
  923. m: 'multiple hosts and multiple components',
  924. e: {
  925. blueprint: {
  926. host_groups: [
  927. {
  928. name: 'host-group-1',
  929. components: [
  930. { name: 'c1' }
  931. ]
  932. },
  933. {
  934. name: 'host-group-2',
  935. components: [
  936. { name: 'c2' },
  937. { name: 'c3' }
  938. ]
  939. },
  940. {
  941. name: 'host-group-3',
  942. components: []
  943. }
  944. ]
  945. },
  946. blueprint_cluster_binding: {
  947. host_groups: [
  948. {
  949. name: 'host-group-1',
  950. hosts: [
  951. { fqdn: 'h1' }
  952. ]
  953. },
  954. {
  955. name: 'host-group-2',
  956. hosts: [
  957. { fqdn: 'h2' }
  958. ]
  959. },
  960. {
  961. name: 'host-group-3',
  962. hosts: [
  963. { fqdn: 'h3' }
  964. ]
  965. }
  966. ]
  967. }
  968. }
  969. }
  970. ]);
  971. tests.forEach(function (test) {
  972. it(test.m, function () {
  973. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  974. controller.set('content.hosts', test.hosts);
  975. var r = controller.getCurrentMastersBlueprint();
  976. expect(r).to.eql(test.e);
  977. });
  978. });
  979. });
  980. describe('#getCurrentBlueprint', function () {
  981. var tests = Em.A([
  982. {
  983. clientComponents: Em.A([{component_name: "name1"}]),
  984. hosts: Em.A([
  985. Em.Object.create({
  986. checkboxes: Em.A([
  987. Em.Object.create({
  988. component: 'c1',
  989. checked: true
  990. }),
  991. Em.Object.create({
  992. component: 'CLIENT',
  993. checked: true
  994. })
  995. ])
  996. })
  997. ]),
  998. m: 'one host and one component',
  999. e:{
  1000. blueprint: {
  1001. host_groups: [
  1002. {
  1003. name: 'host-group-1',
  1004. components: [
  1005. { name: 'c1' },
  1006. { name: 'name1' }
  1007. ]
  1008. }
  1009. ]
  1010. },
  1011. blueprint_cluster_binding: {
  1012. host_groups: [
  1013. {
  1014. name: 'host-group-1',
  1015. hosts: [
  1016. {}
  1017. ]
  1018. }
  1019. ]
  1020. }
  1021. }
  1022. }
  1023. ]);
  1024. tests.forEach(function (test) {
  1025. it(test.m, function () {
  1026. controller.set('content.clients', test.clientComponents);
  1027. controller.set('hosts', test.hosts);
  1028. var r = controller.getCurrentBlueprint();
  1029. expect(JSON.parse(JSON.stringify(r))).to.eql(JSON.parse(JSON.stringify(test.e)));
  1030. });
  1031. });
  1032. });
  1033. describe('#callServerSideValidation', function () {
  1034. var cases = [
  1035. {
  1036. controllerName: 'installerController',
  1037. hosts: [
  1038. {
  1039. hostName: 'h0'
  1040. },
  1041. {
  1042. hostName: 'h1'
  1043. }
  1044. ],
  1045. expected: [
  1046. ['c0', 'c6'],
  1047. ['c1', 'c3', 'c8']
  1048. ]
  1049. },
  1050. {
  1051. controllerName: 'addServiceController',
  1052. hosts: [
  1053. {
  1054. hostName: 'h0'
  1055. },
  1056. {
  1057. hostName: 'h1'
  1058. }
  1059. ],
  1060. expected: [
  1061. ['c0', 'c6'],
  1062. ['c1', 'c3', 'c8']
  1063. ]
  1064. },
  1065. {
  1066. controllerName: 'addHostController',
  1067. hosts: [
  1068. {
  1069. hostName: 'h0'
  1070. }
  1071. ],
  1072. expected: [
  1073. ['c0', 'c2', 'c5', 'c6'],
  1074. ['c1', 'c2', 'c3', 'c5', 'c8']
  1075. ]
  1076. }
  1077. ],
  1078. expectedHostGroups = [
  1079. {
  1080. name: 'host-group-1',
  1081. fqdn: 'h0'
  1082. },
  1083. {
  1084. name: 'host-group-2',
  1085. fqdn: 'h1'
  1086. }
  1087. ];
  1088. beforeEach(function () {
  1089. controller.get('content').setProperties({
  1090. recommendations: {
  1091. blueprint: {
  1092. host_groups: [
  1093. {
  1094. components: [
  1095. {
  1096. name: 'c6'
  1097. }
  1098. ],
  1099. name: 'host-group-1'
  1100. },
  1101. {
  1102. components: [
  1103. {
  1104. name: 'c8'
  1105. }
  1106. ],
  1107. name: 'host-group-2'
  1108. }
  1109. ]
  1110. },
  1111. blueprint_cluster_binding: {
  1112. host_groups: [
  1113. {
  1114. hosts: [
  1115. {
  1116. fqdn: 'h0'
  1117. }
  1118. ],
  1119. name: 'host-group-1'
  1120. },
  1121. {
  1122. hosts: [
  1123. {
  1124. fqdn: 'h1'
  1125. }
  1126. ],
  1127. name: 'host-group-2'
  1128. }]
  1129. }
  1130. },
  1131. clients: [
  1132. {
  1133. component_name: 'c3'
  1134. }
  1135. ]
  1136. });
  1137. sinon.stub(App.StackService, 'find', function () {
  1138. return [
  1139. Em.Object.create({
  1140. serviceName: 's0',
  1141. isSelected: true
  1142. }),
  1143. Em.Object.create({
  1144. serviceName: 's1',
  1145. isInstalled: true,
  1146. isSelected: true
  1147. })
  1148. ];
  1149. });
  1150. sinon.stub(App.StackServiceComponent, 'find', function () {
  1151. return [
  1152. Em.Object.create({
  1153. componentName: 'c0',
  1154. isSlave: true
  1155. }),
  1156. Em.Object.create({
  1157. componentName: 'c1',
  1158. isSlave: true,
  1159. isShownOnInstallerSlaveClientPage: true
  1160. }),
  1161. Em.Object.create({
  1162. componentName: 'c2',
  1163. isSlave: true,
  1164. isShownOnInstallerSlaveClientPage: false
  1165. }),
  1166. Em.Object.create({
  1167. componentName: 'c3',
  1168. isClient: true
  1169. }),
  1170. Em.Object.create({
  1171. componentName: 'c4',
  1172. isClient: true,
  1173. isRequiredOnAllHosts: false
  1174. }),
  1175. Em.Object.create({
  1176. componentName: 'c5',
  1177. isClient: true,
  1178. isRequiredOnAllHosts: true
  1179. }),
  1180. Em.Object.create({
  1181. componentName: 'c6',
  1182. isMaster: true,
  1183. isShownOnInstallerAssignMasterPage: true
  1184. }),
  1185. Em.Object.create({
  1186. componentName: 'c7',
  1187. isMaster: true,
  1188. isShownOnInstallerAssignMasterPage: false
  1189. }),
  1190. Em.Object.create({
  1191. componentName: 'c8',
  1192. isMaster: true,
  1193. isShownOnAddServiceAssignMasterPage: true
  1194. }),
  1195. Em.Object.create({
  1196. componentName: 'c9',
  1197. isMaster: true,
  1198. isShownOnAddServiceAssignMasterPage: false
  1199. })
  1200. ];
  1201. });
  1202. sinon.stub(controller, 'getCurrentBlueprint', function () {
  1203. return {
  1204. blueprint: {
  1205. host_groups: [
  1206. {
  1207. components: [
  1208. {
  1209. name: 'c0'
  1210. }
  1211. ],
  1212. name: 'host-group-1'
  1213. },
  1214. {
  1215. components: [
  1216. {
  1217. name: 'c1'
  1218. },
  1219. {
  1220. name: 'c3'
  1221. }
  1222. ],
  1223. name: 'host-group-2'
  1224. }
  1225. ]
  1226. },
  1227. blueprint_cluster_binding: {
  1228. host_groups: [
  1229. {
  1230. hosts: [
  1231. {
  1232. fqdn: 'h0'
  1233. }
  1234. ],
  1235. name: 'host-group-1'
  1236. },
  1237. {
  1238. hosts: [
  1239. {
  1240. fqdn: 'h1'
  1241. }
  1242. ],
  1243. name: 'host-group-2'
  1244. }]
  1245. }
  1246. };
  1247. });
  1248. sinon.stub(controller, 'getCurrentMastersBlueprint', function () {
  1249. return {
  1250. blueprint: {
  1251. host_groups: [
  1252. {
  1253. components: [
  1254. {
  1255. name: 'c6'
  1256. }
  1257. ],
  1258. name: 'host-group-1'
  1259. },
  1260. {
  1261. components: [
  1262. {
  1263. name: 'c8'
  1264. }
  1265. ],
  1266. name: 'host-group-2'
  1267. }
  1268. ]
  1269. },
  1270. blueprint_cluster_binding: {
  1271. host_groups: [
  1272. {
  1273. hosts: [
  1274. {
  1275. fqdn: 'h0'
  1276. }
  1277. ],
  1278. name: 'host-group-1'
  1279. },
  1280. {
  1281. hosts: [
  1282. {
  1283. fqdn: 'h1'
  1284. }
  1285. ],
  1286. name: 'host-group-2'
  1287. }]
  1288. }
  1289. };
  1290. });
  1291. sinon.stub(App, 'get').withArgs('components.clients').returns(['c3', 'c4']);
  1292. sinon.stub(controller, 'getCurrentMasterSlaveBlueprint', function () {
  1293. return {
  1294. blueprint: {
  1295. host_groups: [
  1296. {
  1297. components: [
  1298. {
  1299. name: 'c6'
  1300. }
  1301. ],
  1302. name: 'host-group-1'
  1303. },
  1304. {
  1305. components: [
  1306. {
  1307. name: 'c8'
  1308. }
  1309. ],
  1310. name: 'host-group-2'
  1311. }
  1312. ]
  1313. },
  1314. blueprint_cluster_binding: {
  1315. host_groups: [
  1316. {
  1317. hosts: [
  1318. {
  1319. fqdn: 'h0'
  1320. }
  1321. ],
  1322. name: 'host-group-1'
  1323. },
  1324. {
  1325. hosts: [
  1326. {
  1327. fqdn: 'h1'
  1328. }
  1329. ],
  1330. name: 'host-group-2'
  1331. }]
  1332. }
  1333. };
  1334. });
  1335. sinon.stub(App.Host, 'find', function () {
  1336. return [
  1337. {
  1338. hostName: 'h1'
  1339. }
  1340. ];
  1341. });
  1342. sinon.stub(App.ajax, 'send', function () {
  1343. return {
  1344. then: Em.K
  1345. };
  1346. });
  1347. });
  1348. afterEach(function () {
  1349. App.StackService.find.restore();
  1350. App.StackServiceComponent.find.restore();
  1351. controller.getCurrentBlueprint.restore();
  1352. controller.getCurrentMastersBlueprint.restore();
  1353. App.get.restore();
  1354. controller.getCurrentMasterSlaveBlueprint.restore();
  1355. App.Host.find.restore();
  1356. App.ajax.send.restore();
  1357. });
  1358. cases.forEach(function (item) {
  1359. it(item.controllerName, function () {
  1360. controller.set('hosts', item.hosts);
  1361. controller.set('content.controllerName', item.controllerName);
  1362. controller.callServerSideValidation();
  1363. expect(controller.get('content.recommendationsHostGroups.blueprint.host_groups.length')).to.equal(expectedHostGroups.length);
  1364. expect(controller.get('content.recommendationsHostGroups.blueprint_cluster_binding.host_groups.length')).to.equal(expectedHostGroups.length);
  1365. controller.get('content.recommendationsHostGroups.blueprint.host_groups').forEach(function (group, index) {
  1366. expect(group.components.mapProperty('name').sort()).to.eql(item.expected[index]);
  1367. });
  1368. expectedHostGroups.forEach(function (group) {
  1369. var bpGroup = controller.get('content.recommendationsHostGroups.blueprint_cluster_binding.host_groups').findProperty('name', group.name);
  1370. expect(bpGroup.hosts).to.have.length(1);
  1371. expect(bpGroup.hosts[0].fqdn).to.equal(group.fqdn);
  1372. });
  1373. });
  1374. });
  1375. });
  1376. });