step6_test.js 39 KB

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