step6_test.js 39 KB

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