step6_test.js 15 KB

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