step5_test.js 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277
  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 App = require('app');
  19. require('controllers/wizard/step5_controller');
  20. var modelSetup = require('test/init_model_test');
  21. require('utils/ajax/ajax');
  22. var c;
  23. describe('App.WizardStep5Controller', function () {
  24. beforeEach(function () {
  25. c = App.WizardStep5Controller.create();
  26. sinon.stub(App.router, 'send', Em.K);
  27. App.router.nextBtnClickInProgress = false;
  28. });
  29. afterEach(function () {
  30. App.router.send.restore();
  31. App.router.nextBtnClickInProgress = false;
  32. });
  33. var controller = App.WizardStep5Controller.create();
  34. controller.set('content', {});
  35. controller.set('content', {});
  36. describe('#sortHosts', function () {
  37. var tests = Em.A([
  38. {
  39. hosts: [
  40. Em.Object.create({memory: 4, cpu: 1, host_name: 'host1', id: 1}),
  41. Em.Object.create({memory: 3, cpu: 1, host_name: 'host2', id: 2}),
  42. Em.Object.create({memory: 2, cpu: 1, host_name: 'host3', id: 3}),
  43. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
  44. ],
  45. m: 'memory',
  46. e: [1, 2, 3, 4]
  47. },
  48. {
  49. hosts: [
  50. Em.Object.create({memory: 1, cpu: 4, host_name: 'host1', id: 1}),
  51. Em.Object.create({memory: 1, cpu: 3, host_name: 'host2', id: 2}),
  52. Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 3}),
  53. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
  54. ],
  55. m: 'cpu',
  56. e: [1, 2, 3, 4]
  57. },
  58. {
  59. hosts: [
  60. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 1}),
  61. Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 2}),
  62. Em.Object.create({memory: 1, cpu: 1, host_name: 'host3', id: 3}),
  63. Em.Object.create({memory: 1, cpu: 1, host_name: 'host1', id: 4})
  64. ],
  65. m: 'host_name',
  66. e: [4, 2, 3, 1]
  67. },
  68. {
  69. hosts: [
  70. Em.Object.create({memory: 2, cpu: 1, host_name: 'host1', id: 1}),
  71. Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 2}),
  72. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 3}),
  73. Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 4})
  74. ],
  75. m: 'mix',
  76. e: [1, 2, 4, 3]
  77. }
  78. ]);
  79. tests.forEach(function (test) {
  80. it(test.m, function () {
  81. var hosts = Em.copy(test.hosts);
  82. controller.sortHosts(hosts);
  83. expect(Em.A(hosts).mapProperty('id')).to.eql(test.e);
  84. });
  85. });
  86. });
  87. describe('#renderHostInfo', function () {
  88. var tests = Em.A([
  89. {
  90. hosts: {
  91. h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'INIT'},
  92. h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'INIT'},
  93. h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'INIT'},
  94. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'INIT'}
  95. },
  96. m: 'no one host is REGISTERED',
  97. e: []
  98. },
  99. {
  100. hosts: {
  101. h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
  102. h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
  103. h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
  104. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
  105. },
  106. m: 'all hosts are REGISTERED, memory',
  107. e: ['host1', 'host2', 'host3', 'host4']
  108. },
  109. {
  110. hosts: {
  111. h1: {memory: 1, cpu: 4, name: 'host1', bootStatus: 'REGISTERED'},
  112. h2: {memory: 1, cpu: 3, name: 'host2', bootStatus: 'REGISTERED'},
  113. h3: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'REGISTERED'},
  114. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
  115. },
  116. m: 'all hosts are REGISTERED, cpu',
  117. e: ['host1', 'host2', 'host3', 'host4']
  118. },
  119. {
  120. hosts: {
  121. h1: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
  122. h2: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
  123. h3: {memory: 1, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
  124. h4: {memory: 1, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'}
  125. },
  126. m: 'all hosts are REGISTERED, host_name',
  127. e: ['host1', 'host2', 'host3', 'host4']
  128. },
  129. {
  130. hosts: {
  131. h1: {memory: 2, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
  132. h2: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'INIT'},
  133. h3: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
  134. h4: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'INIT'}
  135. },
  136. m: 'mix',
  137. e: ['host1', 'host4']
  138. }
  139. ]);
  140. tests.forEach(function (test) {
  141. it(test.m, function () {
  142. controller.set('content', {hosts: test.hosts});
  143. controller.renderHostInfo();
  144. var r = controller.get('hosts');
  145. expect(Em.A(r).mapProperty('host_name')).to.eql(test.e);
  146. });
  147. });
  148. });
  149. describe('#last', function () {
  150. var tests = Em.A([
  151. {
  152. selectedServicesMasters: Em.A([
  153. {component_name: 'c1', indx: 1},
  154. {component_name: 'c2', indx: 2},
  155. {component_name: 'c1', indx: 2}
  156. ]),
  157. m: 'Components exists',
  158. c: 'c1',
  159. e: 2
  160. },
  161. {
  162. selectedServicesMasters: Em.A([
  163. {component_name: 'c1', indx: 1},
  164. {component_name: 'c2', indx: 2},
  165. {component_name: 'c1', indx: 2}
  166. ]),
  167. m: 'Components don\'t exists',
  168. c: 'c3',
  169. e: null
  170. }
  171. ]);
  172. tests.forEach(function (test) {
  173. it(test.m, function () {
  174. controller.set('selectedServicesMasters', test.selectedServicesMasters);
  175. if (!Em.isNone(test.e)) {
  176. expect(controller.last(test.c).indx).to.equal(test.e);
  177. }
  178. else {
  179. expect(Em.isNone(controller.last(test.c))).to.equal(true);
  180. }
  181. })
  182. });
  183. });
  184. describe('#remainingHosts', function () {
  185. it('should show count of hosts without masters', function () {
  186. c.reopen({masterHostMapping: [
  187. {}
  188. ]});
  189. c.set('hosts', [
  190. {},
  191. {},
  192. {}
  193. ]);
  194. expect(c.get('remainingHosts')).to.equal(2);
  195. });
  196. });
  197. describe('#clearStep', function () {
  198. var tests = Em.A([
  199. {p: 'hosts'},
  200. {p: 'selectedServicesMasters'},
  201. {p: 'servicesMasters'}
  202. ]);
  203. tests.forEach(function (test) {
  204. it('should cleanup ' + test.p, function () {
  205. c.set(test.p, [Em.Object.create({}), Em.Object.create({})]);
  206. c.clearStep();
  207. expect(c.get(test.p).length).to.equal(0);
  208. });
  209. });
  210. });
  211. describe('#updateComponent', function () {
  212. var tests = Em.A([
  213. {
  214. componentName: 'HBASE_SERVER',
  215. serviceComponents: [
  216. Em.Object.create({
  217. componentName: 'HBASE_SERVER',
  218. stackService: Em.Object.create({isInstalled: true, serviceName: 'HBASE'})
  219. })
  220. ],
  221. selectedServicesMasters: Em.A([
  222. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'}),
  223. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  224. ]),
  225. hosts: Em.A([
  226. Em.Object.create({})
  227. ]),
  228. controllerName: 'addServiceController',
  229. m: 'service is installed',
  230. e: {
  231. showAddControl: true,
  232. showRemoveControl: false
  233. }
  234. },
  235. {
  236. componentName: 'HBASE_SERVER',
  237. serviceComponents: [
  238. Em.Object.create({
  239. componentName: 'HBASE_SERVER',
  240. stackService: Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  241. })
  242. ],
  243. selectedServicesMasters: Em.A([
  244. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  245. ]),
  246. hosts: Em.A([
  247. Em.Object.create({})
  248. ]),
  249. controllerName: 'addServiceController',
  250. m: 'service not installed, but all host already have provided component',
  251. e: {
  252. showAddControl: true,
  253. showRemoveControl: false
  254. }
  255. },
  256. {
  257. componentName: 'HBASE_SERVER',
  258. serviceComponents: [
  259. Em.Object.create({
  260. componentName: 'HBASE_SERVER',
  261. stackService: Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  262. })
  263. ],
  264. selectedServicesMasters: Em.A([
  265. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
  266. ]),
  267. hosts: Em.A([
  268. Em.Object.create({}),
  269. Em.Object.create({})
  270. ]),
  271. controllerName: 'reassignMasterController',
  272. m: 'service not installed, not all host already have provided component, but is reassignMasterController',
  273. e: {
  274. showAddControl: false,
  275. showRemoveControl: false
  276. }
  277. }
  278. ]);
  279. tests.forEach(function (test) {
  280. describe(test.m, function () {
  281. beforeEach(function () {
  282. sinon.stub(App.StackServiceComponent, 'find', function () {
  283. return test.serviceComponents;
  284. });
  285. c.reopen({
  286. content: Em.Object.create({
  287. controllerName: test.controllerName
  288. }),
  289. selectedServicesMasters: test.selectedServicesMasters,
  290. hosts: test.hosts
  291. });
  292. c.updateComponent(test.componentName);
  293. });
  294. afterEach(function () {
  295. App.StackServiceComponent.find.restore();
  296. });
  297. Em.keys(test.e).forEach(function (k) {
  298. it(k, function () {
  299. expect(c.last(test.componentName).get(k)).to.equal(test.e[k]);
  300. });
  301. });
  302. });
  303. });
  304. });
  305. describe('#renderComponents', function () {
  306. var tests = Em.A([
  307. {
  308. masterComponents: Em.A([
  309. {component_name: 'ZOOKEEPER_SERVER'}
  310. ]),
  311. services: Em.A([
  312. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
  313. ]),
  314. controllerName: 'reassignMasterController',
  315. m: 'One component',
  316. isHaEnabled: false,
  317. component_name: 'ZOOKEEPER_SERVER',
  318. e: {
  319. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  320. servicesMasters: ['ZOOKEEPER_SERVER'],
  321. showRemoveControl: [false],
  322. isInstalled: [false],
  323. serviceComponentId: [1]
  324. }
  325. },
  326. {
  327. masterComponents: Em.A([
  328. {component_name: 'ZOOKEEPER_SERVER'}
  329. ]),
  330. services: Em.A([
  331. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
  332. ]),
  333. controllerName: 'addServiceController',
  334. m: 'One component, service is not installed',
  335. component_name: 'ZOOKEEPER_SERVER',
  336. e: {
  337. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  338. servicesMasters: ['ZOOKEEPER_SERVER'],
  339. showRemoveControl: [false],
  340. serviceComponentId: [1]
  341. }
  342. },
  343. {
  344. masterComponents: Em.A([
  345. {component_name: 'ZOOKEEPER_SERVER'},
  346. {component_name: 'ZOOKEEPER_SERVER'}
  347. ]),
  348. services: Em.A([
  349. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: true})
  350. ]),
  351. controllerName: 'addServiceController',
  352. m: 'Two components, but service is installed',
  353. component_name: 'ZOOKEEPER_SERVER',
  354. e: {
  355. selectedServicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  356. servicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  357. showRemoveControl: [false, false],
  358. serviceComponentId: [1, 2]
  359. }
  360. }
  361. ]);
  362. tests.forEach(function (test) {
  363. describe(test.m, function () {
  364. beforeEach(function () {
  365. sinon.stub(App, 'get').withArgs('isHaEnabled').returns(test.isHaEnabled);
  366. sinon.stub(App.StackService, 'find', function () {
  367. return test.services;
  368. });
  369. modelSetup.setupStackServiceComponent();
  370. c.reopen({
  371. content: Em.Object.create({
  372. services: test.services,
  373. controllerName: test.controllerName,
  374. reassign: {component_name: test.component_name}
  375. })
  376. });
  377. c.renderComponents(test.masterComponents);
  378. });
  379. afterEach(function () {
  380. App.get.restore();
  381. App.StackService.find.restore();
  382. modelSetup.cleanStackServiceComponent();
  383. });
  384. it('all selectedServicesMasters.component_name are valid', function () {
  385. expect(c.get('selectedServicesMasters').mapProperty('component_name')).to.eql(test.e.selectedServicesMasters);
  386. });
  387. it('all servicesMasters.component_name are valid', function () {
  388. expect(c.get('servicesMasters').mapProperty('component_name')).to.eql(test.e.servicesMasters);
  389. });
  390. it('all showRemoveControl are valid', function () {
  391. expect(c.get('selectedServicesMasters').mapProperty('showRemoveControl')).to.eql(test.e.showRemoveControl);
  392. });
  393. it('all serviceComponentId are valid', function () {
  394. expect(c.get('selectedServicesMasters').mapProperty('serviceComponentId')).to.eql(test.e.serviceComponentId);
  395. });
  396. it('servicesMasters.@each.isInstalled is valid', function () {
  397. if (c.get('isReasignController')) {
  398. expect(c.get('servicesMasters').mapProperty('isInstalled')).to.eql(test.e.isInstalled);
  399. }
  400. });
  401. });
  402. });
  403. });
  404. describe('#assignHostToMaster', function () {
  405. var tests = Em.A([
  406. {
  407. componentName: 'c1',
  408. selectedHost: 'h2',
  409. serviceComponentId: '1',
  410. e: {
  411. indx: 0
  412. }
  413. },
  414. {
  415. componentName: 'c2',
  416. selectedHost: 'h3',
  417. serviceComponentId: '2',
  418. e: {
  419. indx: 3
  420. }
  421. },
  422. {
  423. componentName: 'c3',
  424. selectedHost: 'h1',
  425. e: {
  426. indx: 2
  427. }
  428. },
  429. {
  430. componentName: 'c2',
  431. selectedHost: 'h4',
  432. e: {
  433. indx: 1
  434. }
  435. }
  436. ]),
  437. selectedServicesMasters = Em.A([
  438. Em.Object.create({component_name: 'c1', serviceComponentId: '1', selectedHost: 'h1'}),
  439. Em.Object.create({component_name: 'c2', serviceComponentId: '1', selectedHost: 'h1'}),
  440. Em.Object.create({component_name: 'c3', serviceComponentId: '1', selectedHost: 'h3'}),
  441. Em.Object.create({component_name: 'c2', serviceComponentId: '2', selectedHost: 'h2'})
  442. ]);
  443. tests.forEach(function (test) {
  444. it(test.componentName + ' ' + test.selectedHost + ' ' + test.serviceComponentId, function () {
  445. c.set('selectedServicesMasters', selectedServicesMasters);
  446. c.assignHostToMaster(test.componentName, test.selectedHost, test.serviceComponentId);
  447. expect(c.get('selectedServicesMasters').objectAt(test.e.indx).get('selectedHost')).to.equal(test.selectedHost);
  448. })
  449. });
  450. });
  451. describe('#removeComponent', function () {
  452. beforeEach(function () {
  453. sinon.stub(c, 'getMaxNumberOfMasters', function () {
  454. return Infinity;
  455. });
  456. });
  457. afterEach(function(){
  458. c.getMaxNumberOfMasters.restore();
  459. });
  460. var tests = Em.A([
  461. {
  462. componentName: 'c1',
  463. serviceComponentId: 1,
  464. selectedServicesMasters: Em.A([]),
  465. hosts: [],
  466. m: 'empty selectedServicesMasters',
  467. e: false
  468. },
  469. {
  470. componentName: 'ZOOKEPEER_SERVER',
  471. serviceComponentId: 1,
  472. selectedServicesMasters: Em.A([
  473. Em.Object.create({serviceComponentId: 1, component_name: 'HBASE_SERVER'})
  474. ]),
  475. hosts: [],
  476. m: 'no such components',
  477. e: false
  478. },
  479. {
  480. componentName: 'ZOOKEPEER_SERVER',
  481. serviceComponentId: 1,
  482. selectedServicesMasters: Em.A([
  483. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER'})
  484. ]),
  485. hosts: [],
  486. m: 'component is only 1',
  487. e: false
  488. },
  489. {
  490. componentName: 'ZOOKEPEER_SERVER',
  491. serviceComponentId: 2,
  492. selectedServicesMasters: Em.A([
  493. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  494. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  495. ]),
  496. hosts: [
  497. {},
  498. {}
  499. ],
  500. m: 'two components, add allowed, remove not allowed',
  501. e: true,
  502. showAddControl: true,
  503. showRemoveControl: false
  504. },
  505. {
  506. componentName: 'ZOOKEPEER_SERVER',
  507. serviceComponentId: 2,
  508. selectedServicesMasters: Em.A([
  509. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  510. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  511. Em.Object.create({serviceComponentId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
  512. ]),
  513. hosts: [
  514. {},
  515. {},
  516. {}
  517. ],
  518. m: 'three components, add allowed, remove allowed',
  519. e: true,
  520. showAddControl: true,
  521. showRemoveControl: true
  522. }
  523. ]);
  524. tests.forEach(function (test) {
  525. describe(test.m, function () {
  526. beforeEach(function () {
  527. c.set('selectedServicesMasters', JSON.parse(JSON.stringify(test.selectedServicesMasters)));
  528. c.set('hosts', test.hosts);
  529. this.result = c.removeComponent(test.componentName, test.serviceComponentId);
  530. });
  531. it('removeComponent returns ' + test.e, function () {
  532. expect(this.result).to.equal(test.e);
  533. });
  534. if (test.e) {
  535. it('showRemoveControl is correct', function () {
  536. expect(c.get('selectedServicesMasters.lastObject.showRemoveControl')).to.equal(test.showRemoveControl);
  537. });
  538. it('showAddControl is correct', function () {
  539. expect(c.get('selectedServicesMasters.lastObject.showAddControl')).to.equal(test.showAddControl);
  540. });
  541. it('componentToRebalance is correct', function () {
  542. expect(c.get('componentToRebalance')).to.equal(test.componentName);
  543. });
  544. it('lastChangedComponent is correct', function () {
  545. expect(c.get('lastChangedComponent')).to.equal(test.componentName);
  546. });
  547. }
  548. })
  549. });
  550. });
  551. describe('#addComponent', function () {
  552. beforeEach(function () {
  553. sinon.stub(c, 'getMaxNumberOfMasters', function () {
  554. return Infinity;
  555. });
  556. });
  557. afterEach(function(){
  558. c.getMaxNumberOfMasters.restore();
  559. });
  560. var tests = Em.A([
  561. {
  562. componentName: 'c1',
  563. selectedServicesMasters: Em.A([]),
  564. hosts: [],
  565. m: 'empty selectedServicesMasters',
  566. e: false
  567. },
  568. {
  569. componentName: 'ZOOKEPEER_SERVER',
  570. selectedServicesMasters: Em.A([
  571. Em.Object.create({serviceComponentId: 1, component_name: 'HBASE_SERVER'})
  572. ]),
  573. hosts: [],
  574. m: 'no such components',
  575. e: false
  576. },
  577. {
  578. componentName: 'ZOOKEPEER_SERVER',
  579. selectedServicesMasters: Em.A([
  580. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  581. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  582. ]),
  583. hosts: [Em.Object.create({}), Em.Object.create({}), Em.Object.create({})],
  584. m: 'two components, 3 hosts',
  585. e: true
  586. }
  587. ]);
  588. tests.forEach(function (test) {
  589. it(test.m, function () {
  590. c.set('selectedServicesMasters', test.selectedServicesMasters);
  591. c.set('hosts', test.hosts);
  592. expect(c.addComponent(test.componentName)).to.equal(test.e);
  593. if (test.e) {
  594. expect(c.get('componentToRebalance')).to.equal(test.componentName);
  595. expect(c.get('lastChangedComponent')).to.equal(test.componentName);
  596. }
  597. });
  598. });
  599. });
  600. describe('#masterHostMapping', function () {
  601. Em.A([
  602. {
  603. selectedServicesMasters: [
  604. Em.Object.create({selectedHost: 'h1'}),
  605. Em.Object.create({selectedHost: 'h2'}),
  606. Em.Object.create({selectedHost: 'h1'})
  607. ],
  608. hosts: [
  609. Em.Object.create({host_name: 'h1', host_info: {}}),
  610. Em.Object.create({host_name: 'h2', host_info: {}})
  611. ],
  612. m: 'Two hosts',
  613. e: [
  614. {host_name: 'h1', hostInfo: {}, masterServices: [
  615. {},
  616. {}
  617. ]},
  618. {host_name: 'h2', hostInfo: {}, masterServices: [
  619. {}
  620. ]}
  621. ]
  622. },
  623. {
  624. selectedServicesMasters: [],
  625. hosts: [],
  626. m: 'No hosts',
  627. e: []
  628. },
  629. {
  630. selectedServicesMasters: [
  631. Em.Object.create({selectedHost: 'h1'}),
  632. Em.Object.create({selectedHost: 'h1'})
  633. ],
  634. hosts: [
  635. Em.Object.create({host_name: 'h1', host_info: {}})
  636. ],
  637. m: 'One host',
  638. e: [
  639. {host_name: 'h1', hostInfo: {}, masterServices: [
  640. {},
  641. {}
  642. ]}
  643. ]
  644. }
  645. ]).forEach(function (test) {
  646. describe(test.m, function () {
  647. var result;
  648. beforeEach(function () {
  649. c.reopen({
  650. selectedServicesMasters: test.selectedServicesMasters,
  651. hosts: test.hosts
  652. });
  653. result = c.get('masterHostMapping');
  654. });
  655. it('all needed hosts are mapped', function () {
  656. expect(result.length).to.equal(test.e.length);
  657. });
  658. it('all needed hosts have valid data', function () {
  659. expect(result.mapProperty('host_name')).to.be.eql(test.e.mapProperty('host_name'));
  660. expect(result.mapProperty('masterServices.length')).to.be.eql(test.e.mapProperty('masterServices.length'));
  661. });
  662. });
  663. });
  664. });
  665. describe('#anyError', function () {
  666. Em.A([
  667. {
  668. servicesMasters: [
  669. Em.Object.create({errorMessage: 'some message'}),
  670. Em.Object.create({errorMessage: ''})
  671. ],
  672. generalErrorMessages: [],
  673. e: true
  674. },
  675. {
  676. servicesMasters: [
  677. Em.Object.create({errorMessage: ''}),
  678. Em.Object.create({errorMessage: ''})
  679. ],
  680. generalErrorMessages: [],
  681. e: false
  682. },
  683. {
  684. servicesMasters: [
  685. Em.Object.create({errorMessage: 'some message'}),
  686. Em.Object.create({errorMessage: 'some message 2'})
  687. ],
  688. generalErrorMessages: ['some message'],
  689. e: true
  690. },
  691. {
  692. servicesMasters: [
  693. Em.Object.create({errorMessage: ''}),
  694. Em.Object.create({errorMessage: ''})
  695. ],
  696. generalErrorMessages: ['some message'],
  697. e: true
  698. }
  699. ]).forEach(function (test, i) {
  700. it('test #' + i.toString(), function () {
  701. c.setProperties({
  702. servicesMasters: test.servicesMasters,
  703. generalErrorMessages: test.generalErrorMessages
  704. });
  705. expect(c.get('anyError')).to.equal(test.e);
  706. });
  707. });
  708. });
  709. describe('#anyWarning', function () {
  710. Em.A([
  711. {
  712. servicesMasters: [
  713. Em.Object.create({warnMessage: 'some message'}),
  714. Em.Object.create({warnMessage: ''})
  715. ],
  716. generalWarningMessages: [],
  717. e: true
  718. },
  719. {
  720. servicesMasters: [
  721. Em.Object.create({warnMessage: ''}),
  722. Em.Object.create({warnMessage: ''})
  723. ],
  724. generalWarningMessages: [],
  725. e: false
  726. },
  727. {
  728. servicesMasters: [
  729. Em.Object.create({warnMessage: 'some message'}),
  730. Em.Object.create({warnMessage: 'some message 2'})
  731. ],
  732. generalWarningMessages: ['some message'],
  733. e: true
  734. },
  735. {
  736. servicesMasters: [
  737. Em.Object.create({warnMessage: ''}),
  738. Em.Object.create({warnMessage: ''})
  739. ],
  740. generalWarningMessages: ['some message'],
  741. e: true
  742. }
  743. ]).forEach(function (test, i) {
  744. it('test #' + i.toString(), function () {
  745. c.setProperties({
  746. servicesMasters: test.servicesMasters,
  747. generalWarningMessages: test.generalWarningMessages
  748. });
  749. expect(c.get('anyWarning')).to.equal(test.e);
  750. });
  751. });
  752. });
  753. describe('#clearRecommendations', function () {
  754. it('should clear content.recommendations', function () {
  755. c.set('content', {recommendations: {'s': {}}});
  756. c.clearRecommendations();
  757. expect(c.get('content.recommendations')).to.be.null;
  758. });
  759. });
  760. describe('#updateIsSubmitDisabled', function () {
  761. var clearCases = [
  762. {
  763. isHostNameValid: true,
  764. isInitialLayout: true,
  765. isInitialLayoutResulting: false,
  766. clearRecommendationsCallCount: 0,
  767. recommendAndValidateCallCount: 1,
  768. title: 'initial masters-hosts layout'
  769. },
  770. {
  771. isHostNameValid: true,
  772. isInitialLayout: false,
  773. isInitialLayoutResulting: false,
  774. clearRecommendationsCallCount: 1,
  775. recommendAndValidateCallCount: 1,
  776. title: 'master-hosts layout changed'
  777. },
  778. {
  779. isHostNameValid: false,
  780. isInitialLayout: false,
  781. isInitialLayoutResulting: false,
  782. clearRecommendationsCallCount: 0,
  783. recommendAndValidateCallCount: 0,
  784. title: 'invalid host name specified'
  785. }
  786. ];
  787. beforeEach(function () {
  788. c.set('selectedServicesMasters', [
  789. {isInstalled: false}
  790. ]);
  791. sinon.stub(c, 'clearRecommendations', Em.K);
  792. sinon.stub(c, 'recommendAndValidate', Em.K);
  793. });
  794. afterEach(function () {
  795. c.clearRecommendations.restore();
  796. c.recommendAndValidate.restore();
  797. });
  798. it('shouldn\'t change submitDisabled if thereIsNoMasters returns false', function () {
  799. c.set('selectedServicesMasters', [
  800. {isInstalled: true}
  801. ]);
  802. c.set('submitDisabled', false);
  803. c.updateIsSubmitDisabled();
  804. expect(c.get('submitDisabled')).to.equal(false);
  805. });
  806. it('should check servicesMasters.@each.isHostNameValid if useServerValidation is false', function () {
  807. c.set('useServerValidation', false);
  808. c.set('servicesMasters', [
  809. {isHostNameValid: false},
  810. {isHostNameValid: true}
  811. ]);
  812. c.updateIsSubmitDisabled();
  813. expect(c.get('submitDisabled')).to.equal(true);
  814. c.set('servicesMasters', [
  815. {isHostNameValid: true},
  816. {isHostNameValid: true}
  817. ]);
  818. c.updateIsSubmitDisabled();
  819. expect(c.get('submitDisabled')).to.equal(false);
  820. });
  821. clearCases.forEach(function (item) {
  822. it(item.title, function () {
  823. c.setProperties({
  824. isInitialLayout: item.isInitialLayout,
  825. servicesMasters: [{
  826. isHostNameValid: item.isHostNameValid
  827. }]
  828. });
  829. expect(c.get('isInitialLayout')).to.equal(item.isInitialLayoutResulting);
  830. expect(c.clearRecommendations.callCount).to.equal(item.clearRecommendationsCallCount);
  831. expect(c.recommendAndValidate.callCount).to.equal(item.recommendAndValidateCallCount);
  832. });
  833. });
  834. });
  835. describe('#isHostNameValid', function () {
  836. beforeEach(function () {
  837. c.setProperties({
  838. hosts: [
  839. {host_name: 'h1'},
  840. {host_name: 'h2'},
  841. {host_name: 'h3'}
  842. ],
  843. selectedServicesMasters: [
  844. {component_name: 'c1', selectedHost: 'h1'},
  845. {component_name: 'c2', selectedHost: 'h2'},
  846. {component_name: 'c3', selectedHost: 'h3'},
  847. {component_name: 'c3', selectedHost: 'h1'}
  848. ]
  849. });
  850. });
  851. Em.A([
  852. {
  853. componentName: 'c1',
  854. selectedHost: ' ',
  855. m: 'empty hostName is invalid',
  856. e: false
  857. },
  858. {
  859. componentName: 'c1',
  860. selectedHost: 'h4',
  861. m: 'hostName not exists',
  862. e: false
  863. },
  864. {
  865. componentName: 'c4',
  866. selectedHost: 'h3',
  867. m: 'component not exists on host',
  868. e: true
  869. }
  870. ]).forEach(function (test) {
  871. it(test.m, function () {
  872. expect(c.isHostNameValid(test.componentName, test.selectedHost)).to.equal(test.e);
  873. });
  874. });
  875. });
  876. describe('#createComponentInstallationObject', function () {
  877. afterEach(function () {
  878. App.StackServiceComponent.find.restore();
  879. });
  880. Em.A([
  881. {
  882. fullComponent: Em.Object.create({
  883. componentName: 'c1',
  884. serviceName: 's1'
  885. }),
  886. hostName: 'h1',
  887. mastersToMove: ['c1'],
  888. savedComponent: {
  889. hostName: 'h2',
  890. isInstalled: true
  891. },
  892. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  893. e: {
  894. component_name: 'c1',
  895. display_name: 'C1',
  896. serviceId: 's1',
  897. selectedHost: 'h2',
  898. isInstalled: true,
  899. isServiceCoHost: false
  900. }
  901. },
  902. {
  903. fullComponent: Em.Object.create({
  904. componentName: 'c1',
  905. serviceName: 's1'
  906. }),
  907. hostName: 'h1',
  908. mastersToMove: [],
  909. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: false})],
  910. e: {
  911. component_name: 'c1',
  912. display_name: 'C1',
  913. serviceId: 's1',
  914. selectedHost: 'h1',
  915. isInstalled: false,
  916. isServiceCoHost: false
  917. }
  918. },
  919. {
  920. fullComponent: Em.Object.create({
  921. componentName: 'c1',
  922. serviceName: 's1'
  923. }),
  924. hostName: 'h1',
  925. mastersToMove: [],
  926. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  927. e: {
  928. component_name: 'c1',
  929. display_name: 'C1',
  930. serviceId: 's1',
  931. selectedHost: 'h1',
  932. isInstalled: false,
  933. isServiceCoHost: true
  934. }
  935. }
  936. ]).forEach(function (test, i) {
  937. describe('test #' + i, function () {
  938. beforeEach(function () {
  939. sinon.stub(App.StackServiceComponent, 'find', function () {
  940. return test.stackServiceComponents;
  941. });
  942. c.set('mastersToMove', test.mastersToMove);
  943. c.set('content', {controllerName: test.controllerName});
  944. });
  945. it('component-object is valid', function () {
  946. expect(c.createComponentInstallationObject(test.fullComponent, test.hostName, test.savedComponent)).to.eql(test.e);
  947. });
  948. });
  949. });
  950. });
  951. describe('#createComponentInstallationObjects', function () {
  952. beforeEach(function() {
  953. sinon.stub(App.StackServiceComponent, 'find', function() {
  954. return [
  955. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  956. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  957. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c4', serviceName: 's2'}),
  958. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  959. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  960. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c4', serviceName: 's2'})
  961. ];
  962. });
  963. c.set('content', {
  964. masterComponentHosts: [],
  965. services: [
  966. {serviceName: 's1', isSelected: true, isInstalled: false},
  967. {serviceName: 's2', isSelected: true, isInstalled: false}
  968. ],
  969. recommendations: {
  970. "blueprint": {
  971. "host_groups": [
  972. {
  973. "name": "host-group-1",
  974. "components": [ {"name": "c1"}, {"name": "c2"} ]
  975. },
  976. {
  977. "name": "host-group-2",
  978. "components": [ {"name": "c1"}, {"name": "c2"} ]
  979. },
  980. {
  981. "name": "host-group-3",
  982. "components": [ {"name": "c1"} ]
  983. }
  984. ]
  985. },
  986. "blueprint_cluster_binding": {
  987. "host_groups": [
  988. {
  989. "name": "host-group-1",
  990. "hosts": [ {"fqdn": "h1"} ]
  991. },
  992. {
  993. "name": "host-group-2",
  994. "hosts": [ {"fqdn": "h2"} ]
  995. },
  996. {
  997. "name": "host-group-3",
  998. "hosts": [ {"fqdn": "h3"} ]
  999. }
  1000. ]
  1001. }
  1002. }
  1003. });
  1004. });
  1005. afterEach(function() {
  1006. App.StackServiceComponent.find.restore();
  1007. });
  1008. it('simple map without nothing stored/saved etc', function() {
  1009. var r = c.createComponentInstallationObjects();
  1010. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1']);
  1011. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1']);
  1012. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3']);
  1013. });
  1014. describe('some saved components exist', function() {
  1015. beforeEach(function () {
  1016. c.set('content.controllerName', 'addServiceController');
  1017. c.get('multipleComponents').push('c4');
  1018. c.set('content.masterComponentHosts', [
  1019. {hostName: 'h3', component: 'c4'}
  1020. ]);
  1021. c.get('content.recommendations.blueprint.host_groups')[2].components.push({name: 'c4'});
  1022. });
  1023. it('data contains save components', function () {
  1024. var r = c.createComponentInstallationObjects();
  1025. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1', 'c4']);
  1026. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1', 's2']);
  1027. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3', 'h3']);
  1028. });
  1029. });
  1030. });
  1031. describe('#getCurrentBlueprint', function () {
  1032. beforeEach(function() {
  1033. sinon.stub(c, 'getCurrentSlaveBlueprint', function() {
  1034. return {
  1035. blueprint_cluster_binding: {
  1036. host_groups: []
  1037. },
  1038. blueprint: {
  1039. host_groups: []
  1040. }
  1041. };
  1042. });
  1043. });
  1044. afterEach(function() {
  1045. c.getCurrentSlaveBlueprint.restore();
  1046. });
  1047. it('should map masterHostMapping', function () {
  1048. c.reopen({masterHostMapping: [
  1049. {host_name: 'h1', hostInfo:{}, masterServices: [
  1050. {serviceId: 's1', component_name: 'c1'},
  1051. {serviceId: 's2', component_name: 'c2'}
  1052. ]},
  1053. {host_name: 'h2', hostInfo:{}, masterServices: [
  1054. {serviceId: 's1', component_name: 'c1'},
  1055. {serviceId: 's3', component_name: 'c3'}
  1056. ]}
  1057. ]});
  1058. var r = c.getCurrentBlueprint();
  1059. expect(r).to.eql({"blueprint": {"host_groups": [
  1060. {"name": "host-group-1", "components": [
  1061. {"name": "c1"},
  1062. {"name": "c2"}
  1063. ]},
  1064. {"name": "host-group-2", "components": [
  1065. {"name": "c1"},
  1066. {"name": "c3"}
  1067. ]}
  1068. ]}, "blueprint_cluster_binding": {"host_groups": [
  1069. {"name": "host-group-1", "hosts": [
  1070. {"fqdn": "h1"}
  1071. ]},
  1072. {"name": "host-group-2", "hosts": [
  1073. {"fqdn": "h2"}
  1074. ]}
  1075. ]}}
  1076. );
  1077. });
  1078. });
  1079. describe('#updateValidationsSuccessCallback', function() {
  1080. beforeEach(function() {
  1081. sinon.stub(App.HostComponent, 'find', function() {
  1082. return [];
  1083. });
  1084. });
  1085. afterEach(function() {
  1086. App.HostComponent.find.restore();
  1087. });
  1088. describe('should map messages to generalErrorMessages, generalWarningMessages', function() {
  1089. var data = [
  1090. {
  1091. type: 'host-component',
  1092. 'component-name': 'c1',
  1093. host: 'h1',
  1094. level: 'ERROR',
  1095. message: 'm1'
  1096. },
  1097. {
  1098. type: 'host-component',
  1099. 'component-name': 'c2',
  1100. host: 'h2',
  1101. level: 'WARN',
  1102. message: 'm2'
  1103. },
  1104. {
  1105. type: 'host-component',
  1106. 'component-name': 'c3',
  1107. host: 'h3',
  1108. level: 'ERROR',
  1109. message: 'm3'
  1110. },
  1111. {
  1112. type: 'host-component',
  1113. 'component-name': 'c4',
  1114. host: 'h4',
  1115. level: 'WARN',
  1116. message: 'm4'
  1117. }
  1118. ],
  1119. servicesMasters = [
  1120. Em.Object.create({selectedHost: 'h1', component_name: 'c1'}),
  1121. Em.Object.create({selectedHost: 'h2', component_name: 'c2'})
  1122. ];
  1123. beforeEach(function () {
  1124. c.set('servicesMasters', servicesMasters);
  1125. c.updateValidationsSuccessCallback({resources: [{items: data}]});
  1126. });
  1127. it('submitDisabled is false', function () {
  1128. expect(c.get('submitDisabled')).to.equal(false);
  1129. });
  1130. it('errorMessage for c1 is `m1`', function () {
  1131. expect(c.get('servicesMasters').findProperty('component_name', 'c1').get('errorMessage')).to.equal('m1');
  1132. });
  1133. it('errorMessage for c2 is `m2`', function () {
  1134. expect(c.get('servicesMasters').findProperty('component_name', 'c2').get('warnMessage')).to.equal('m2');
  1135. });
  1136. it('no general errors', function () {
  1137. expect(c.get('generalErrorMessages')).to.be.empty;
  1138. });
  1139. it('no general warnings', function () {
  1140. expect(c.get('generalWarningMessages')).to.be.empty;
  1141. });
  1142. });
  1143. });
  1144. describe('#submit',function(){
  1145. it('if Next button is clicked multiple times before the next step renders, it must not be processed',function(){
  1146. c.reopen({isSubmitDisabled:false, submitDisabled:false, useServerValidation:false});
  1147. c.submit();
  1148. expect(App.router.send.calledWith('next')).to.equal(true);
  1149. App.router.send.reset();
  1150. c.submit();
  1151. expect(App.router.send.calledWith('next')).to.equal(false);
  1152. });
  1153. });
  1154. });