step6_test.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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. var h = {}, m = [];
  58. Em.A(['host0', 'host1', 'host2', 'host3']).forEach(function (hostName) {
  59. var obj = Em.Object.create({
  60. name: hostName,
  61. hostName: hostName,
  62. bootStatus: 'REGISTERED'
  63. });
  64. h[hostName] = obj;
  65. m.push(obj);
  66. });
  67. controller.set('content.hosts', h);
  68. controller.set('content.masterComponentHosts', m);
  69. controller.set('isMasters', false);
  70. });
  71. describe('#isAddHostWizard', function () {
  72. it('true if content.controllerName is addHostController', function () {
  73. controller.set('content.controllerName', 'addHostController');
  74. expect(controller.get('isAddHostWizard')).to.equal(true);
  75. });
  76. it('false if content.controllerName is not addHostController', function () {
  77. controller.set('content.controllerName', 'mainController');
  78. expect(controller.get('isAddHostWizard')).to.equal(false);
  79. });
  80. });
  81. describe('#isInstallerWizard', function () {
  82. it('true if content.controllerName is addHostController', function () {
  83. controller.set('content.controllerName', 'installerController');
  84. expect(controller.get('isInstallerWizard')).to.equal(true);
  85. });
  86. it('false if content.controllerName is not addHostController', function () {
  87. controller.set('content.controllerName', 'mainController');
  88. expect(controller.get('isInstallerWizard')).to.equal(false);
  89. });
  90. });
  91. describe('#isAddServiceWizard', function () {
  92. it('true if content.controllerName is addServiceController', function () {
  93. controller.set('content.controllerName', 'addServiceController');
  94. expect(controller.get('isAddServiceWizard')).to.equal(true);
  95. });
  96. it('false if content.controllerName is not addServiceController', function () {
  97. controller.set('content.controllerName', 'mainController');
  98. expect(controller.get('isAddServiceWizard')).to.equal(false);
  99. });
  100. });
  101. describe('#clearStep', function () {
  102. beforeEach(function () {
  103. sinon.stub(controller, 'clearError', Em.K);
  104. });
  105. afterEach(function () {
  106. controller.clearError.restore();
  107. });
  108. it('should call clearError', function () {
  109. controller.clearStep();
  110. expect(controller.clearError.calledOnce).to.equal(true);
  111. });
  112. it('should clear hosts', function () {
  113. controller.set('hosts', [
  114. {},
  115. {}
  116. ]);
  117. controller.clearStep();
  118. expect(controller.get('hosts')).to.eql([]);
  119. });
  120. it('should clear headers', function () {
  121. controller.set('headers', [
  122. {},
  123. {}
  124. ]);
  125. controller.clearStep();
  126. expect(controller.get('headers')).to.eql([]);
  127. });
  128. it('should set isLoaded to false', function () {
  129. controller.set('isLoaded', true);
  130. controller.clearStep();
  131. expect(controller.get('isLoaded')).to.equal(false);
  132. });
  133. });
  134. describe('#checkCallback', function () {
  135. beforeEach(function () {
  136. sinon.stub(controller, 'clearError', Em.K);
  137. });
  138. afterEach(function () {
  139. controller.clearError.restore();
  140. });
  141. it('should call clearError', function () {
  142. controller.checkCallback('');
  143. expect(controller.clearError.calledOnce).to.equal(true);
  144. });
  145. Em.A([
  146. {
  147. m: 'all checked, isInstalled false',
  148. headers: Em.A([
  149. Em.Object.create({name: 'c1'})
  150. ]),
  151. hosts: Em.A([
  152. Em.Object.create({
  153. checkboxes: Em.A([
  154. Em.Object.create({
  155. component: 'c1',
  156. isInstalled: false,
  157. checked: true
  158. })
  159. ])
  160. })
  161. ]),
  162. component: 'c1',
  163. e: {
  164. allChecked: true,
  165. noChecked: false
  166. }
  167. },
  168. {
  169. m: 'all checked, isInstalled true',
  170. headers: Em.A([
  171. Em.Object.create({name: 'c1'})
  172. ]),
  173. hosts: Em.A([
  174. Em.Object.create({
  175. checkboxes: Em.A([
  176. Em.Object.create({
  177. component: 'c1',
  178. isInstalled: true,
  179. checked: true
  180. })
  181. ])
  182. })
  183. ]),
  184. component: 'c1',
  185. e: {
  186. allChecked: true,
  187. noChecked: true
  188. }
  189. },
  190. {
  191. m: 'no one checked',
  192. headers: Em.A([
  193. Em.Object.create({name: 'c1'})
  194. ]),
  195. hosts: Em.A([
  196. Em.Object.create({
  197. checkboxes: Em.A([
  198. Em.Object.create({
  199. component: 'c1',
  200. isInstalled: false,
  201. checked: false
  202. })
  203. ])
  204. })
  205. ]),
  206. component: 'c1',
  207. e: {
  208. allChecked: false,
  209. noChecked: true
  210. }
  211. },
  212. {
  213. m: 'some checked',
  214. headers: Em.A([
  215. Em.Object.create({name: 'c1'})
  216. ]),
  217. hosts: Em.A([
  218. Em.Object.create({
  219. checkboxes: Em.A([
  220. Em.Object.create({
  221. component: 'c1',
  222. isInstalled: false,
  223. checked: true
  224. }),
  225. Em.Object.create({
  226. component: 'c1',
  227. isInstalled: false,
  228. checked: false
  229. })
  230. ])
  231. })
  232. ]),
  233. component: 'c1',
  234. e: {
  235. allChecked: false,
  236. noChecked: false
  237. }
  238. },
  239. {
  240. m: 'some checked, some isInstalled true',
  241. headers: Em.A([
  242. Em.Object.create({name: 'c1'})
  243. ]),
  244. hosts: Em.A([
  245. Em.Object.create({
  246. checkboxes: Em.A([
  247. Em.Object.create({
  248. component: 'c1',
  249. isInstalled: true,
  250. checked: true
  251. }),
  252. Em.Object.create({
  253. component: 'c1',
  254. isInstalled: true,
  255. checked: true
  256. })
  257. ])
  258. })
  259. ]),
  260. component: 'c1',
  261. e: {
  262. allChecked: true,
  263. noChecked: true
  264. }
  265. },
  266. {
  267. m: 'some checked, some isInstalled true (2)',
  268. headers: Em.A([
  269. Em.Object.create({name: 'c1'})
  270. ]),
  271. hosts: Em.A([
  272. Em.Object.create({
  273. checkboxes: Em.A([
  274. Em.Object.create({
  275. component: 'c1',
  276. isInstalled: false,
  277. checked: false
  278. }),
  279. Em.Object.create({
  280. component: 'c1',
  281. isInstalled: true,
  282. checked: true
  283. })
  284. ])
  285. })
  286. ]),
  287. component: 'c1',
  288. e: {
  289. allChecked: false,
  290. noChecked: true
  291. }
  292. }
  293. ]).forEach(function (test) {
  294. it(test.m, function () {
  295. controller.clearStep();
  296. controller.set('headers', test.headers);
  297. controller.set('hosts', test.hosts);
  298. controller.checkCallback(test.component);
  299. var header = controller.get('headers').findProperty('name', test.component);
  300. expect(header.get('allChecked')).to.equal(test.e.allChecked);
  301. expect(header.get('noChecked')).to.equal(test.e.noChecked);
  302. });
  303. });
  304. });
  305. describe('#getHostNames', function () {
  306. var tests = Em.A([
  307. {
  308. hosts: {
  309. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  310. h2: {bootStatus: 'REGISTERED', name: 'h2'},
  311. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  312. },
  313. m: 'All REGISTERED',
  314. e: ['h1', 'h2', 'h3']
  315. },
  316. {
  317. hosts: {
  318. h1: {bootStatus: 'REGISTERED', name: 'h1'},
  319. h2: {bootStatus: 'FAILED', name: 'h2'},
  320. h3: {bootStatus: 'REGISTERED', name: 'h3'}
  321. },
  322. m: 'Some REGISTERED',
  323. e: ['h1', 'h3']
  324. },
  325. {
  326. hosts: {
  327. h1: {bootStatus: 'FAILED', name: 'h1'},
  328. h2: {bootStatus: 'FAILED', name: 'h2'},
  329. h3: {bootStatus: 'FAILED', name: 'h3'}
  330. },
  331. m: 'No one REGISTERED',
  332. e: []
  333. },
  334. {
  335. hosts: {},
  336. m: 'Empty hosts',
  337. e: []
  338. }
  339. ]);
  340. tests.forEach(function (test) {
  341. it(test.m, function () {
  342. controller.set('content.hosts', test.hosts);
  343. var r = controller.getHostNames();
  344. expect(r).to.eql(test.e);
  345. });
  346. });
  347. });
  348. describe('#getMasterComponentsForHost', function () {
  349. var tests = Em.A([
  350. {
  351. masterComponentHosts: Em.A([
  352. {hostName: 'h1', component: 'c1'}
  353. ]),
  354. hostName: 'h1',
  355. m: 'host exists',
  356. e: ['c1']
  357. },
  358. {
  359. masterComponentHosts: Em.A([
  360. {hostName: 'h1', component: 'c1'}
  361. ]),
  362. hostName: 'h2',
  363. m: 'host donesn\'t exists',
  364. e: []
  365. }
  366. ]);
  367. tests.forEach(function (test) {
  368. it(test.m, function () {
  369. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  370. var r = controller.getMasterComponentsForHost(test.hostName);
  371. expect(r).to.eql(test.e);
  372. });
  373. });
  374. });
  375. describe('#selectMasterComponents', function () {
  376. var tests = Em.A([
  377. {
  378. masterComponentHosts: Em.A([
  379. {
  380. hostName: 'h1',
  381. component: 'c1'
  382. }
  383. ]),
  384. hostsObj: [
  385. Em.Object.create({
  386. hostName: 'h1',
  387. checkboxes: [
  388. Em.Object.create({
  389. component: 'c1',
  390. checked: false
  391. })
  392. ]
  393. })
  394. ],
  395. e: true,
  396. m: 'host and component exist'
  397. },
  398. {
  399. masterComponentHosts: Em.A([
  400. {
  401. hostName: 'h1',
  402. component: 'c2'
  403. }
  404. ]),
  405. hostsObj: [
  406. Em.Object.create({
  407. hostName: 'h1',
  408. checkboxes: [
  409. Em.Object.create({
  410. component: 'c1',
  411. checked: false
  412. })
  413. ]
  414. })
  415. ],
  416. e: false,
  417. m: 'host exists'
  418. },
  419. {
  420. masterComponentHosts: Em.A([
  421. {
  422. hostName: 'h2',
  423. component: 'c2'
  424. }
  425. ]),
  426. hostsObj: [
  427. Em.Object.create({
  428. hostName: 'h1',
  429. checkboxes: [
  430. Em.Object.create({
  431. component: 'c1',
  432. checked: false
  433. })
  434. ]
  435. })
  436. ],
  437. e: false,
  438. m: 'host and component don\'t exist'
  439. }
  440. ]);
  441. tests.forEach(function (test) {
  442. it(test.m, function () {
  443. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  444. var r = controller.selectMasterComponents(test.hostsObj);
  445. expect(r.findProperty('hostName', 'h1').get('checkboxes').findProperty('component', 'c1').get('checked')).to.equal(test.e);
  446. });
  447. });
  448. });
  449. describe('#getCurrentMastersBlueprint', function () {
  450. var tests = Em.A([
  451. {
  452. masterComponentHosts: Em.A([
  453. {hostName: 'h1', component: 'c1'}
  454. ]),
  455. hosts: {'h1': {}},
  456. m: 'one host and one component',
  457. e:{
  458. blueprint: {
  459. host_groups: [
  460. {
  461. name: 'host-group-1',
  462. components: [
  463. { name: 'c1' }
  464. ]
  465. }
  466. ]
  467. },
  468. blueprint_cluster_binding: {
  469. host_groups: [
  470. {
  471. name: 'host-group-1',
  472. hosts: [
  473. { fqdn: 'h1' }
  474. ]
  475. }
  476. ]
  477. }
  478. }
  479. },
  480. {
  481. masterComponentHosts: Em.A([
  482. {hostName: 'h1', component: 'c1'},
  483. {hostName: 'h2', component: 'c2'},
  484. {hostName: 'h2', component: 'c3'}
  485. ]),
  486. hosts: {'h1': {}, 'h2': {}, 'h3': {}},
  487. m: 'multiple hosts and multiple components',
  488. e: {
  489. blueprint: {
  490. host_groups: [
  491. {
  492. name: 'host-group-1',
  493. components: [
  494. { name: 'c1' }
  495. ]
  496. },
  497. {
  498. name: 'host-group-2',
  499. components: [
  500. { name: 'c2' },
  501. { name: 'c3' }
  502. ]
  503. },
  504. {
  505. name: 'host-group-3',
  506. components: []
  507. }
  508. ]
  509. },
  510. blueprint_cluster_binding: {
  511. host_groups: [
  512. {
  513. name: 'host-group-1',
  514. hosts: [
  515. { fqdn: 'h1' }
  516. ]
  517. },
  518. {
  519. name: 'host-group-2',
  520. hosts: [
  521. { fqdn: 'h2' }
  522. ]
  523. },
  524. {
  525. name: 'host-group-3',
  526. hosts: [
  527. { fqdn: 'h3' }
  528. ]
  529. }
  530. ]
  531. }
  532. }
  533. }
  534. ]);
  535. tests.forEach(function (test) {
  536. it(test.m, function () {
  537. controller.set('content.masterComponentHosts', test.masterComponentHosts);
  538. controller.set('content.hosts', test.hosts);
  539. var r = controller.getCurrentMastersBlueprint();
  540. expect(r).to.eql(test.e);
  541. });
  542. });
  543. });
  544. });