step5_test.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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('controllers/wizard/step5_controller');
  21. var modelSetup = require('test/init_model_test');
  22. require('utils/ajax/ajax');
  23. var c;
  24. describe('App.WizardStep5Controller', function () {
  25. beforeEach(function () {
  26. c = App.WizardStep5Controller.create();
  27. });
  28. var controller = App.WizardStep5Controller.create();
  29. controller.set('content', {});
  30. var cpu = 2, memory = 4;
  31. controller.set('content', {});
  32. describe('#isReassignWizard', function () {
  33. it('true if content.controllerName is reassignMasterController', function () {
  34. controller.set('content.controllerName', 'reassignMasterController');
  35. expect(controller.get('isReassignWizard')).to.equal(true);
  36. });
  37. it('false if content.controllerName is not reassignMasterController', function () {
  38. controller.set('content.controllerName', 'mainController');
  39. expect(controller.get('isReassignWizard')).to.equal(false);
  40. });
  41. });
  42. describe('#isAddServiceWizard', function () {
  43. it('true if content.controllerName is addServiceController', function () {
  44. controller.set('content.controllerName', 'addServiceController');
  45. expect(controller.get('isAddServiceWizard')).to.equal(true);
  46. });
  47. it('false if content.controllerName is not addServiceController', function () {
  48. controller.set('content.controllerName', 'mainController');
  49. expect(controller.get('isAddServiceWizard')).to.equal(false);
  50. });
  51. });
  52. describe('#sortHosts', function () {
  53. var tests = Em.A([
  54. {
  55. hosts: [
  56. Em.Object.create({memory: 4, cpu: 1, host_name: 'host1', id: 1}),
  57. Em.Object.create({memory: 3, cpu: 1, host_name: 'host2', id: 2}),
  58. Em.Object.create({memory: 2, cpu: 1, host_name: 'host3', id: 3}),
  59. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
  60. ],
  61. m: 'memory',
  62. e: [1, 2, 3, 4]
  63. },
  64. {
  65. hosts: [
  66. Em.Object.create({memory: 1, cpu: 4, host_name: 'host1', id: 1}),
  67. Em.Object.create({memory: 1, cpu: 3, host_name: 'host2', id: 2}),
  68. Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 3}),
  69. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
  70. ],
  71. m: 'cpu',
  72. e: [1, 2, 3, 4]
  73. },
  74. {
  75. hosts: [
  76. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 1}),
  77. Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 2}),
  78. Em.Object.create({memory: 1, cpu: 1, host_name: 'host3', id: 3}),
  79. Em.Object.create({memory: 1, cpu: 1, host_name: 'host1', id: 4})
  80. ],
  81. m: 'host_name',
  82. e: [4, 2, 3, 1]
  83. },
  84. {
  85. hosts: [
  86. Em.Object.create({memory: 2, cpu: 1, host_name: 'host1', id: 1}),
  87. Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 2}),
  88. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 3}),
  89. Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 4})
  90. ],
  91. m: 'mix',
  92. e: [1, 2, 4, 3]
  93. }
  94. ]);
  95. tests.forEach(function (test) {
  96. it(test.m, function () {
  97. var hosts = Em.copy(test.hosts);
  98. controller.sortHosts(hosts);
  99. expect(Em.A(hosts).mapProperty('id')).to.eql(test.e);
  100. });
  101. });
  102. });
  103. describe('#renderHostInfo', function () {
  104. var tests = Em.A([
  105. {
  106. hosts: {
  107. h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'INIT'},
  108. h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'INIT'},
  109. h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'INIT'},
  110. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'INIT'}
  111. },
  112. m: 'no one host is REGISTERED',
  113. e: []
  114. },
  115. {
  116. hosts: {
  117. h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
  118. h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
  119. h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
  120. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
  121. },
  122. m: 'all hosts are REGISTERED, memory',
  123. e: ['host1', 'host2', 'host3', 'host4']
  124. },
  125. {
  126. hosts: {
  127. h1: {memory: 1, cpu: 4, name: 'host1', bootStatus: 'REGISTERED'},
  128. h2: {memory: 1, cpu: 3, name: 'host2', bootStatus: 'REGISTERED'},
  129. h3: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'REGISTERED'},
  130. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
  131. },
  132. m: 'all hosts are REGISTERED, cpu',
  133. e: ['host1', 'host2', 'host3', 'host4']
  134. },
  135. {
  136. hosts: {
  137. h1: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
  138. h2: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
  139. h3: {memory: 1, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
  140. h4: {memory: 1, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'}
  141. },
  142. m: 'all hosts are REGISTERED, host_name',
  143. e: ['host1', 'host2', 'host3', 'host4']
  144. },
  145. {
  146. hosts: {
  147. h1: {memory: 2, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
  148. h2: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'INIT'},
  149. h3: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
  150. h4: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'INIT'}
  151. },
  152. m: 'mix',
  153. e: ['host1', 'host4']
  154. }
  155. ]);
  156. tests.forEach(function (test) {
  157. it(test.m, function () {
  158. controller.set('content', {hosts: test.hosts});
  159. controller.renderHostInfo();
  160. var r = controller.get('hosts');
  161. expect(Em.A(r).mapProperty('host_name')).to.eql(test.e);
  162. });
  163. });
  164. });
  165. describe('#last', function () {
  166. var tests = Em.A([
  167. {
  168. selectedServicesMasters: Em.A([
  169. {component_name: 'c1', indx: 1},
  170. {component_name: 'c2', indx: 2},
  171. {component_name: 'c1', indx: 2}
  172. ]),
  173. m: 'Components exists',
  174. c: 'c1',
  175. e: 2
  176. },
  177. {
  178. selectedServicesMasters: Em.A([
  179. {component_name: 'c1', indx: 1},
  180. {component_name: 'c2', indx: 2},
  181. {component_name: 'c1', indx: 2}
  182. ]),
  183. m: 'Components don\'t exists',
  184. c: 'c3',
  185. e: null
  186. }
  187. ]);
  188. tests.forEach(function (test) {
  189. it(test.m, function () {
  190. controller.set('selectedServicesMasters', test.selectedServicesMasters);
  191. if (!Em.isNone(test.e)) {
  192. expect(controller.last(test.c).indx).to.equal(test.e);
  193. }
  194. else {
  195. expect(Em.isNone(controller.last(test.c))).to.equal(true);
  196. }
  197. })
  198. });
  199. });
  200. describe('#remainingHosts', function () {
  201. it('should show count of hosts without masters', function () {
  202. c.reopen({masterHostMapping: [
  203. {}
  204. ]});
  205. c.set('hosts', [
  206. {},
  207. {},
  208. {}
  209. ]);
  210. expect(c.get('remainingHosts')).to.equal(2);
  211. });
  212. });
  213. describe('#clearStep', function () {
  214. var tests = Em.A([
  215. {p: 'hosts'},
  216. {p: 'selectedServicesMasters'},
  217. {p: 'servicesMasters'}
  218. ]);
  219. tests.forEach(function (test) {
  220. it('should cleanup ' + test.p, function () {
  221. c.set(test.p, [Em.Object.create({}), Em.Object.create({})]);
  222. c.clearStep();
  223. expect(c.get(test.p).length).to.equal(0);
  224. });
  225. });
  226. });
  227. describe('#updateComponent', function () {
  228. var tests = Em.A([
  229. {
  230. componentName: 'HBASE_SERVER',
  231. services: Em.A([
  232. Em.Object.create({isInstalled: true, serviceName: 'HBASE'})
  233. ]),
  234. selectedServicesMasters: Em.A([
  235. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'}),
  236. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  237. ]),
  238. hosts: Em.A([
  239. Em.Object.create({})
  240. ]),
  241. controllerName: 'addServiceController',
  242. m: 'service is installed',
  243. e: {
  244. showAddControl: true,
  245. showRemoveControl: false
  246. }
  247. },
  248. {
  249. componentName: 'HBASE_SERVER',
  250. services: Em.A([
  251. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  252. ]),
  253. selectedServicesMasters: Em.A([
  254. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  255. ]),
  256. hosts: Em.A([
  257. Em.Object.create({})
  258. ]),
  259. controllerName: 'addServiceController',
  260. m: 'service not installed, but all host already have provided component',
  261. e: {
  262. showAddControl: true,
  263. showRemoveControl: false
  264. }
  265. },
  266. {
  267. componentName: 'HBASE_SERVER',
  268. services: Em.A([
  269. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  270. ]),
  271. selectedServicesMasters: Em.A([
  272. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
  273. ]),
  274. hosts: Em.A([
  275. Em.Object.create({}),
  276. Em.Object.create({})
  277. ]),
  278. controllerName: 'addServiceController',
  279. m: 'service not installed, not all host already have provided component',
  280. e: {
  281. showAddControl: true,
  282. showRemoveControl: true
  283. }
  284. },
  285. {
  286. componentName: 'HBASE_SERVER',
  287. services: Em.A([
  288. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  289. ]),
  290. selectedServicesMasters: Em.A([
  291. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
  292. ]),
  293. hosts: Em.A([
  294. Em.Object.create({}),
  295. Em.Object.create({})
  296. ]),
  297. controllerName: 'reassignMasterController',
  298. m: 'service not installed, not all host already have provided component, but is reassignMasterController',
  299. e: {
  300. showAddControl: false,
  301. showRemoveControl: false
  302. }
  303. }
  304. ]);
  305. tests.forEach(function (test) {
  306. it(test.m, function () {
  307. sinon.stub(App.StackService, 'find', function () {
  308. return test.services;
  309. });
  310. c.reopen({
  311. content: Em.Object.create({
  312. controllerName: test.controllerName
  313. }),
  314. selectedServicesMasters: test.selectedServicesMasters,
  315. hosts: test.hosts
  316. });
  317. c.updateComponent(test.componentName);
  318. App.StackService.find.restore();
  319. Em.keys(test.e).forEach(function (k) {
  320. expect(c.last(test.componentName).get(k)).to.equal(test.e[k]);
  321. });
  322. });
  323. });
  324. });
  325. describe('#renderComponents', function () {
  326. var tests = Em.A([
  327. {
  328. masterComponents: Em.A([
  329. {component_name: 'ZOOKEEPER_SERVER'}
  330. ]),
  331. services: Em.A([
  332. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
  333. ]),
  334. controllerName: 'reassignMasterController',
  335. m: 'One component',
  336. isHaEnabled: false,
  337. component_name: 'ZOOKEEPER_SERVER',
  338. e: {
  339. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  340. servicesMasters: ['ZOOKEEPER_SERVER'],
  341. showRemoveControl: [false],
  342. isInstalled: [false],
  343. serviceComponentId: [1]
  344. }
  345. },
  346. {
  347. masterComponents: Em.A([
  348. {component_name: 'ZOOKEEPER_SERVER'}
  349. ]),
  350. services: Em.A([
  351. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
  352. ]),
  353. controllerName: 'addServiceController',
  354. m: 'One component, service is not installed',
  355. component_name: 'ZOOKEEPER_SERVER',
  356. e: {
  357. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  358. servicesMasters: ['ZOOKEEPER_SERVER'],
  359. showRemoveControl: [false],
  360. serviceComponentId: [1]
  361. }
  362. },
  363. {
  364. masterComponents: Em.A([
  365. {component_name: 'ZOOKEEPER_SERVER'},
  366. {component_name: 'ZOOKEEPER_SERVER'}
  367. ]),
  368. services: Em.A([
  369. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: true})
  370. ]),
  371. controllerName: 'addServiceController',
  372. m: 'Two components, but service is installed',
  373. component_name: 'ZOOKEEPER_SERVER',
  374. e: {
  375. selectedServicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  376. servicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  377. showRemoveControl: [false, false],
  378. serviceComponentId: [1, 2]
  379. }
  380. }
  381. ]);
  382. tests.forEach(function (test) {
  383. beforeEach(function () {
  384. App.reopen({isHaEnabled: test.isHaEnabled});
  385. });
  386. it(test.m, function () {
  387. modelSetup.setupStackServiceComponent();
  388. sinon.stub(App.StackService, 'find', function () {
  389. return test.services;
  390. });
  391. App.set('isHaEnabled', test.isHaEnabled);
  392. c.reopen({
  393. content: Em.Object.create({
  394. services: test.services,
  395. controllerName: test.controllerName,
  396. reassign: {component_name: test.component_name}
  397. })
  398. });
  399. c.renderComponents(test.masterComponents);
  400. App.StackService.find.restore();
  401. modelSetup.cleanStackServiceComponent();
  402. expect(c.get('selectedServicesMasters').mapProperty('component_name')).to.eql(test.e.selectedServicesMasters);
  403. expect(c.get('servicesMasters').mapProperty('component_name')).to.eql(test.e.servicesMasters);
  404. expect(c.get('selectedServicesMasters').mapProperty('showRemoveControl')).to.eql(test.e.showRemoveControl);
  405. expect(c.get('selectedServicesMasters').mapProperty('serviceComponentId')).to.eql(test.e.serviceComponentId);
  406. if (c.get('isReasignController')) {
  407. expect(c.get('servicesMasters').mapProperty('isInstalled')).to.eql(test.e.isInstalled);
  408. }
  409. });
  410. });
  411. });
  412. describe('#assignHostToMaster', function () {
  413. var tests = Em.A([
  414. {
  415. componentName: 'c1',
  416. selectedHost: 'h2',
  417. serviceComponentId: '1',
  418. e: {
  419. indx: 0
  420. }
  421. },
  422. {
  423. componentName: 'c2',
  424. selectedHost: 'h3',
  425. serviceComponentId: '2',
  426. e: {
  427. indx: 3
  428. }
  429. },
  430. {
  431. componentName: 'c3',
  432. selectedHost: 'h1',
  433. e: {
  434. indx: 2
  435. }
  436. },
  437. {
  438. componentName: 'c2',
  439. selectedHost: 'h4',
  440. e: {
  441. indx: 1
  442. }
  443. }
  444. ]),
  445. selectedServicesMasters = Em.A([
  446. Em.Object.create({component_name: 'c1', serviceComponentId: '1', selectedHost: 'h1'}),
  447. Em.Object.create({component_name: 'c2', serviceComponentId: '1', selectedHost: 'h1'}),
  448. Em.Object.create({component_name: 'c3', serviceComponentId: '1', selectedHost: 'h3'}),
  449. Em.Object.create({component_name: 'c2', serviceComponentId: '2', selectedHost: 'h2'})
  450. ]);
  451. tests.forEach(function (test) {
  452. it(test.componentName + ' ' + test.selectedHost + ' ' + test.serviceComponentId, function () {
  453. c.set('selectedServicesMasters', selectedServicesMasters);
  454. c.assignHostToMaster(test.componentName, test.selectedHost, test.serviceComponentId);
  455. expect(c.get('selectedServicesMasters').objectAt(test.e.indx).get('selectedHost')).to.equal(test.selectedHost);
  456. })
  457. });
  458. });
  459. describe('#submit', function () {
  460. beforeEach(function () {
  461. sinon.stub(App.router, 'send', Em.K);
  462. });
  463. afterEach(function () {
  464. App.router.send.restore();
  465. });
  466. it('should go next if not isSubmitDisabled', function () {
  467. c.reopen({isSubmitDisabled: false});
  468. c.submit();
  469. expect(App.router.send.calledWith('next')).to.equal(true);
  470. });
  471. it('shouldn\'t go next if submitDisabled true', function () {
  472. sinon.stub(c, 'getIsSubmitDisabled', Em.K);
  473. c.reopen({submitDisabled: true});
  474. c.submit();
  475. c.getIsSubmitDisabled.restore();
  476. expect(App.router.send.called).to.equal(false);
  477. });
  478. });
  479. describe('#removeComponent', function () {
  480. var tests = Em.A([
  481. {
  482. componentName: 'c1',
  483. serviceComponentId: 1,
  484. selectedServicesMasters: Em.A([]),
  485. hosts: [],
  486. m: 'empty selectedServicesMasters',
  487. e: false
  488. },
  489. {
  490. componentName: 'ZOOKEPEER_SERVER',
  491. serviceComponentId: 1,
  492. selectedServicesMasters: Em.A([
  493. Em.Object.create({serviceComponentId: 1, component_name: 'HBASE_SERVER'})
  494. ]),
  495. hosts: [],
  496. m: 'no such components',
  497. e: false
  498. },
  499. {
  500. componentName: 'ZOOKEPEER_SERVER',
  501. serviceComponentId: 1,
  502. selectedServicesMasters: Em.A([
  503. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER'})
  504. ]),
  505. hosts: [],
  506. m: 'component is only 1',
  507. e: false
  508. },
  509. {
  510. componentName: 'ZOOKEPEER_SERVER',
  511. serviceComponentId: 2,
  512. selectedServicesMasters: Em.A([
  513. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  514. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  515. ]),
  516. hosts: [
  517. {},
  518. {}
  519. ],
  520. m: 'two components, add allowed, remove not allowed',
  521. e: true,
  522. showAddControl: true,
  523. showRemoveControl: false
  524. },
  525. {
  526. componentName: 'ZOOKEPEER_SERVER',
  527. serviceComponentId: 2,
  528. selectedServicesMasters: Em.A([
  529. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  530. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  531. ]),
  532. hosts: [
  533. {}
  534. ],
  535. m: 'two components, add not allowed, remove not allowed',
  536. e: true,
  537. showAddControl: false,
  538. showRemoveControl: false
  539. },
  540. {
  541. componentName: 'ZOOKEPEER_SERVER',
  542. serviceComponentId: 2,
  543. selectedServicesMasters: Em.A([
  544. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  545. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  546. Em.Object.create({serviceComponentId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
  547. ]),
  548. hosts: [
  549. {},
  550. {}
  551. ],
  552. m: 'three components, add not allowed, remove allowed',
  553. e: true,
  554. showAddControl: false,
  555. showRemoveControl: true
  556. },
  557. {
  558. componentName: 'ZOOKEPEER_SERVER',
  559. serviceComponentId: 2,
  560. selectedServicesMasters: Em.A([
  561. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  562. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  563. Em.Object.create({serviceComponentId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
  564. ]),
  565. hosts: [
  566. {},
  567. {},
  568. {}
  569. ],
  570. m: 'three components, add allowed, remove allowed',
  571. e: true,
  572. showAddControl: true,
  573. showRemoveControl: true
  574. }
  575. ]);
  576. tests.forEach(function (test) {
  577. it(test.m, function () {
  578. c.set('selectedServicesMasters', test.selectedServicesMasters);
  579. c.set('hosts', test.hosts);
  580. expect(c.removeComponent(test.componentName, test.serviceComponentId)).to.equal(test.e);
  581. if (test.e) {
  582. expect(c.get('selectedServicesMasters.lastObject.showRemoveControl')).to.equal(test.showRemoveControl);
  583. expect(c.get('selectedServicesMasters.lastObject.showAddControl')).to.equal(test.showAddControl);
  584. }
  585. })
  586. });
  587. });
  588. describe('#addComponent', function () {
  589. var tests = Em.A([
  590. {
  591. componentName: 'c1',
  592. selectedServicesMasters: Em.A([]),
  593. hosts: [],
  594. m: 'empty selectedServicesMasters',
  595. e: false
  596. },
  597. {
  598. componentName: 'ZOOKEPEER_SERVER',
  599. selectedServicesMasters: Em.A([
  600. Em.Object.create({serviceComponentId: 1, component_name: 'HBASE_SERVER'})
  601. ]),
  602. hosts: [],
  603. m: 'no such components',
  604. e: false
  605. },
  606. {
  607. componentName: 'ZOOKEPEER_SERVER',
  608. selectedServicesMasters: Em.A([
  609. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER'})
  610. ]),
  611. hosts: [],
  612. m: 'one component, 0 hosts',
  613. e: false
  614. },
  615. {
  616. componentName: 'ZOOKEPEER_SERVER',
  617. selectedServicesMasters: Em.A([
  618. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  619. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  620. ]),
  621. hosts: [Em.Object.create({}), Em.Object.create({})],
  622. m: 'two components, two hosts',
  623. e: false
  624. },
  625. {
  626. componentName: 'ZOOKEPEER_SERVER',
  627. selectedServicesMasters: Em.A([
  628. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  629. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  630. ]),
  631. hosts: [Em.Object.create({}), Em.Object.create({}), Em.Object.create({})],
  632. m: 'two components, 3 hosts',
  633. e: true
  634. }
  635. ]);
  636. tests.forEach(function (test) {
  637. it(test.m, function () {
  638. c.set('selectedServicesMasters', test.selectedServicesMasters);
  639. c.set('hosts', test.hosts);
  640. expect(c.addComponent(test.componentName)).to.equal(test.e);
  641. });
  642. });
  643. });
  644. describe('#title', function () {
  645. it('should be custom title for reassignMasterController', function () {
  646. c.set('content', {controllerName: 'reassignMasterController'});
  647. expect(c.get('title')).to.equal(Em.I18n.t('installer.step5.reassign.header'));
  648. });
  649. it('should be default for other', function () {
  650. c.set('content', {controllerName: 'notReassignMasterController'});
  651. expect(c.get('title')).to.equal(Em.I18n.t('installer.step5.header'));
  652. });
  653. });
  654. describe('#masterHostMapping', function () {
  655. Em.A([
  656. {
  657. selectedServicesMasters: [
  658. Em.Object.create({selectedHost: 'h1'}),
  659. Em.Object.create({selectedHost: 'h2'}),
  660. Em.Object.create({selectedHost: 'h1'})
  661. ],
  662. hosts: [
  663. Em.Object.create({host_name: 'h1', host_info: {}}),
  664. Em.Object.create({host_name: 'h2', host_info: {}})
  665. ],
  666. m: 'Two hosts',
  667. e: [
  668. {host_name: 'h1', hostInfo: {}, masterServices: [
  669. {},
  670. {}
  671. ]},
  672. {host_name: 'h2', hostInfo: {}, masterServices: [
  673. {}
  674. ]}
  675. ]
  676. },
  677. {
  678. selectedServicesMasters: [],
  679. hosts: [],
  680. m: 'No hosts',
  681. e: []
  682. },
  683. {
  684. selectedServicesMasters: [
  685. Em.Object.create({selectedHost: 'h1'}),
  686. Em.Object.create({selectedHost: 'h1'})
  687. ],
  688. hosts: [
  689. Em.Object.create({host_name: 'h1', host_info: {}})
  690. ],
  691. m: 'One host',
  692. e: [
  693. {host_name: 'h1', hostInfo: {}, masterServices: [
  694. {},
  695. {}
  696. ]}
  697. ]
  698. }
  699. ]).forEach(function (test) {
  700. it(test.m, function () {
  701. c.reopen({
  702. selectedServicesMasters: test.selectedServicesMasters,
  703. hosts: test.hosts
  704. });
  705. var result = c.get('masterHostMapping');
  706. expect(result.length).to.equal(test.e.length);
  707. result.forEach(function (r, i) {
  708. expect(r.get('host_name')).to.equal(test.e[i].host_name);
  709. expect(r.get('masterServices.length')).to.equal(test.e[i].masterServices.length);
  710. expect(r.get('hostInfo')).to.be.an.object;
  711. });
  712. });
  713. });
  714. });
  715. });