step5_test.js 40 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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. result.forEach(function (r, i) {
  660. expect(r.get('host_name')).to.equal(test.e[i].host_name);
  661. expect(r.get('masterServices.length')).to.equal(test.e[i].masterServices.length);
  662. expect(r.get('hostInfo')).to.be.an.object;
  663. });
  664. });
  665. });
  666. });
  667. });
  668. describe('#anyError', function () {
  669. Em.A([
  670. {
  671. servicesMasters: [
  672. Em.Object.create({errorMessage: 'some message'}),
  673. Em.Object.create({errorMessage: ''})
  674. ],
  675. generalErrorMessages: [],
  676. e: true
  677. },
  678. {
  679. servicesMasters: [
  680. Em.Object.create({errorMessage: ''}),
  681. Em.Object.create({errorMessage: ''})
  682. ],
  683. generalErrorMessages: [],
  684. e: false
  685. },
  686. {
  687. servicesMasters: [
  688. Em.Object.create({errorMessage: 'some message'}),
  689. Em.Object.create({errorMessage: 'some message 2'})
  690. ],
  691. generalErrorMessages: ['some message'],
  692. e: true
  693. },
  694. {
  695. servicesMasters: [
  696. Em.Object.create({errorMessage: ''}),
  697. Em.Object.create({errorMessage: ''})
  698. ],
  699. generalErrorMessages: ['some message'],
  700. e: true
  701. }
  702. ]).forEach(function (test, i) {
  703. it('test #' + i.toString(), function () {
  704. c.setProperties({
  705. servicesMasters: test.servicesMasters,
  706. generalErrorMessages: test.generalErrorMessages
  707. });
  708. expect(c.get('anyError')).to.equal(test.e);
  709. });
  710. });
  711. });
  712. describe('#anyWarning', function () {
  713. Em.A([
  714. {
  715. servicesMasters: [
  716. Em.Object.create({warnMessage: 'some message'}),
  717. Em.Object.create({warnMessage: ''})
  718. ],
  719. generalWarningMessages: [],
  720. e: true
  721. },
  722. {
  723. servicesMasters: [
  724. Em.Object.create({warnMessage: ''}),
  725. Em.Object.create({warnMessage: ''})
  726. ],
  727. generalWarningMessages: [],
  728. e: false
  729. },
  730. {
  731. servicesMasters: [
  732. Em.Object.create({warnMessage: 'some message'}),
  733. Em.Object.create({warnMessage: 'some message 2'})
  734. ],
  735. generalWarningMessages: ['some message'],
  736. e: true
  737. },
  738. {
  739. servicesMasters: [
  740. Em.Object.create({warnMessage: ''}),
  741. Em.Object.create({warnMessage: ''})
  742. ],
  743. generalWarningMessages: ['some message'],
  744. e: true
  745. }
  746. ]).forEach(function (test, i) {
  747. it('test #' + i.toString(), function () {
  748. c.setProperties({
  749. servicesMasters: test.servicesMasters,
  750. generalWarningMessages: test.generalWarningMessages
  751. });
  752. expect(c.get('anyWarning')).to.equal(test.e);
  753. });
  754. });
  755. });
  756. describe('#clearRecommendations', function () {
  757. it('should clear content.recommendations', function () {
  758. c.set('content', {recommendations: {'s': {}}});
  759. c.clearRecommendations();
  760. expect(c.get('content.recommendations')).to.be.null;
  761. });
  762. });
  763. describe('#updateIsSubmitDisabled', function () {
  764. var clearCases = [
  765. {
  766. isHostNameValid: true,
  767. isInitialLayout: true,
  768. isInitialLayoutResulting: false,
  769. clearRecommendationsCallCount: 0,
  770. recommendAndValidateCallCount: 1,
  771. title: 'initial masters-hosts layout'
  772. },
  773. {
  774. isHostNameValid: true,
  775. isInitialLayout: false,
  776. isInitialLayoutResulting: false,
  777. clearRecommendationsCallCount: 1,
  778. recommendAndValidateCallCount: 1,
  779. title: 'master-hosts layout changed'
  780. },
  781. {
  782. isHostNameValid: false,
  783. isInitialLayout: false,
  784. isInitialLayoutResulting: false,
  785. clearRecommendationsCallCount: 0,
  786. recommendAndValidateCallCount: 0,
  787. title: 'invalid host name specified'
  788. }
  789. ];
  790. beforeEach(function () {
  791. c.set('selectedServicesMasters', [
  792. {isInstalled: false}
  793. ]);
  794. sinon.stub(c, 'clearRecommendations', Em.K);
  795. sinon.stub(c, 'recommendAndValidate', Em.K);
  796. });
  797. afterEach(function () {
  798. c.clearRecommendations.restore();
  799. c.recommendAndValidate.restore();
  800. });
  801. it('shouldn\'t change submitDisabled if thereIsNoMasters returns false', function () {
  802. c.set('selectedServicesMasters', [
  803. {isInstalled: true}
  804. ]);
  805. c.set('submitDisabled', false);
  806. c.updateIsSubmitDisabled();
  807. expect(c.get('submitDisabled')).to.equal(false);
  808. });
  809. it('should check servicesMasters.@each.isHostNameValid if useServerValidation is false', function () {
  810. c.set('useServerValidation', false);
  811. c.set('servicesMasters', [
  812. {isHostNameValid: false},
  813. {isHostNameValid: true}
  814. ]);
  815. c.updateIsSubmitDisabled();
  816. expect(c.get('submitDisabled')).to.equal(true);
  817. c.set('servicesMasters', [
  818. {isHostNameValid: true},
  819. {isHostNameValid: true}
  820. ]);
  821. c.updateIsSubmitDisabled();
  822. expect(c.get('submitDisabled')).to.equal(false);
  823. });
  824. clearCases.forEach(function (item) {
  825. it(item.title, function () {
  826. c.setProperties({
  827. isInitialLayout: item.isInitialLayout,
  828. servicesMasters: [{
  829. isHostNameValid: item.isHostNameValid
  830. }]
  831. });
  832. expect(c.get('isInitialLayout')).to.equal(item.isInitialLayoutResulting);
  833. expect(c.clearRecommendations.callCount).to.equal(item.clearRecommendationsCallCount);
  834. expect(c.recommendAndValidate.callCount).to.equal(item.recommendAndValidateCallCount);
  835. });
  836. });
  837. });
  838. describe('#isHostNameValid', function () {
  839. beforeEach(function () {
  840. c.setProperties({
  841. hosts: [
  842. {host_name: 'h1'},
  843. {host_name: 'h2'},
  844. {host_name: 'h3'}
  845. ],
  846. selectedServicesMasters: [
  847. {component_name: 'c1', selectedHost: 'h1'},
  848. {component_name: 'c2', selectedHost: 'h2'},
  849. {component_name: 'c3', selectedHost: 'h3'},
  850. {component_name: 'c3', selectedHost: 'h1'}
  851. ]
  852. });
  853. });
  854. Em.A([
  855. {
  856. componentName: 'c1',
  857. selectedHost: ' ',
  858. m: 'empty hostName is invalid',
  859. e: false
  860. },
  861. {
  862. componentName: 'c1',
  863. selectedHost: 'h4',
  864. m: 'hostName not exists',
  865. e: false
  866. },
  867. {
  868. componentName: 'c4',
  869. selectedHost: 'h3',
  870. m: 'component not exists on host',
  871. e: true
  872. }
  873. ]).forEach(function (test) {
  874. it(test.m, function () {
  875. expect(c.isHostNameValid(test.componentName, test.selectedHost)).to.equal(test.e);
  876. });
  877. });
  878. });
  879. describe('#createComponentInstallationObject', function () {
  880. afterEach(function () {
  881. App.StackServiceComponent.find.restore();
  882. });
  883. Em.A([
  884. {
  885. fullComponent: Em.Object.create({
  886. componentName: 'c1',
  887. serviceName: 's1'
  888. }),
  889. hostName: 'h1',
  890. mastersToMove: ['c1'],
  891. savedComponent: {
  892. hostName: 'h2',
  893. isInstalled: true
  894. },
  895. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  896. e: {
  897. component_name: 'c1',
  898. display_name: 'C1',
  899. serviceId: 's1',
  900. selectedHost: 'h2',
  901. isInstalled: true,
  902. isServiceCoHost: false
  903. }
  904. },
  905. {
  906. fullComponent: Em.Object.create({
  907. componentName: 'c1',
  908. serviceName: 's1'
  909. }),
  910. hostName: 'h1',
  911. mastersToMove: [],
  912. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: false})],
  913. e: {
  914. component_name: 'c1',
  915. display_name: 'C1',
  916. serviceId: 's1',
  917. selectedHost: 'h1',
  918. isInstalled: false,
  919. isServiceCoHost: false
  920. }
  921. },
  922. {
  923. fullComponent: Em.Object.create({
  924. componentName: 'c1',
  925. serviceName: 's1'
  926. }),
  927. hostName: 'h1',
  928. mastersToMove: [],
  929. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  930. e: {
  931. component_name: 'c1',
  932. display_name: 'C1',
  933. serviceId: 's1',
  934. selectedHost: 'h1',
  935. isInstalled: false,
  936. isServiceCoHost: true
  937. }
  938. }
  939. ]).forEach(function (test, i) {
  940. describe('test #' + i, function () {
  941. beforeEach(function () {
  942. sinon.stub(App.StackServiceComponent, 'find', function () {
  943. return test.stackServiceComponents;
  944. });
  945. c.set('mastersToMove', test.mastersToMove);
  946. c.set('content', {controllerName: test.controllerName});
  947. });
  948. it('component-object is valid', function () {
  949. expect(c.createComponentInstallationObject(test.fullComponent, test.hostName, test.savedComponent)).to.eql(test.e);
  950. });
  951. });
  952. });
  953. });
  954. describe('#createComponentInstallationObjects', function () {
  955. beforeEach(function() {
  956. sinon.stub(App.StackServiceComponent, 'find', function() {
  957. return [
  958. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  959. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  960. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c4', serviceName: 's2'}),
  961. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  962. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  963. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c4', serviceName: 's2'})
  964. ];
  965. });
  966. c.set('content', {
  967. masterComponentHosts: [],
  968. services: [
  969. {serviceName: 's1', isSelected: true, isInstalled: false},
  970. {serviceName: 's2', isSelected: true, isInstalled: false}
  971. ],
  972. recommendations: {
  973. "blueprint": {
  974. "host_groups": [
  975. {
  976. "name": "host-group-1",
  977. "components": [ {"name": "c1"}, {"name": "c2"} ]
  978. },
  979. {
  980. "name": "host-group-2",
  981. "components": [ {"name": "c1"}, {"name": "c2"} ]
  982. },
  983. {
  984. "name": "host-group-3",
  985. "components": [ {"name": "c1"} ]
  986. }
  987. ]
  988. },
  989. "blueprint_cluster_binding": {
  990. "host_groups": [
  991. {
  992. "name": "host-group-1",
  993. "hosts": [ {"fqdn": "h1"} ]
  994. },
  995. {
  996. "name": "host-group-2",
  997. "hosts": [ {"fqdn": "h2"} ]
  998. },
  999. {
  1000. "name": "host-group-3",
  1001. "hosts": [ {"fqdn": "h3"} ]
  1002. }
  1003. ]
  1004. }
  1005. }
  1006. });
  1007. });
  1008. afterEach(function() {
  1009. App.StackServiceComponent.find.restore();
  1010. });
  1011. it('simple map without nothing stored/saved etc', function() {
  1012. var r = c.createComponentInstallationObjects();
  1013. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1']);
  1014. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1']);
  1015. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3']);
  1016. });
  1017. describe('some saved components exist', function() {
  1018. beforeEach(function () {
  1019. c.set('content.controllerName', 'addServiceController');
  1020. c.get('multipleComponents').push('c4');
  1021. c.set('content.masterComponentHosts', [
  1022. {hostName: 'h3', component: 'c4'}
  1023. ]);
  1024. c.get('content.recommendations.blueprint.host_groups')[2].components.push({name: 'c4'});
  1025. });
  1026. it('data contains save components', function () {
  1027. var r = c.createComponentInstallationObjects();
  1028. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1', 'c4']);
  1029. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1', 's2']);
  1030. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3', 'h3']);
  1031. });
  1032. });
  1033. });
  1034. describe('#getCurrentBlueprint', function () {
  1035. beforeEach(function() {
  1036. sinon.stub(c, 'getCurrentSlaveBlueprint', function() {
  1037. return {
  1038. blueprint_cluster_binding: {
  1039. host_groups: []
  1040. },
  1041. blueprint: {
  1042. host_groups: []
  1043. }
  1044. };
  1045. });
  1046. });
  1047. afterEach(function() {
  1048. c.getCurrentSlaveBlueprint.restore();
  1049. });
  1050. it('should map masterHostMapping', function () {
  1051. c.reopen({masterHostMapping: [
  1052. {host_name: 'h1', hostInfo:{}, masterServices: [
  1053. {serviceId: 's1', component_name: 'c1'},
  1054. {serviceId: 's2', component_name: 'c2'}
  1055. ]},
  1056. {host_name: 'h2', hostInfo:{}, masterServices: [
  1057. {serviceId: 's1', component_name: 'c1'},
  1058. {serviceId: 's3', component_name: 'c3'}
  1059. ]}
  1060. ]});
  1061. var r = c.getCurrentBlueprint();
  1062. expect(r).to.eql({"blueprint": {"host_groups": [
  1063. {"name": "host-group-1", "components": [
  1064. {"name": "c1"},
  1065. {"name": "c2"}
  1066. ]},
  1067. {"name": "host-group-2", "components": [
  1068. {"name": "c1"},
  1069. {"name": "c3"}
  1070. ]}
  1071. ]}, "blueprint_cluster_binding": {"host_groups": [
  1072. {"name": "host-group-1", "hosts": [
  1073. {"fqdn": "h1"}
  1074. ]},
  1075. {"name": "host-group-2", "hosts": [
  1076. {"fqdn": "h2"}
  1077. ]}
  1078. ]}}
  1079. );
  1080. });
  1081. });
  1082. describe('#updateValidationsSuccessCallback', function() {
  1083. beforeEach(function() {
  1084. sinon.stub(App.HostComponent, 'find', function() {
  1085. return [];
  1086. });
  1087. });
  1088. afterEach(function() {
  1089. App.HostComponent.find.restore();
  1090. });
  1091. describe('should map messages to generalErrorMessages, generalWarningMessages', function() {
  1092. var data = [
  1093. {
  1094. type: 'host-component',
  1095. 'component-name': 'c1',
  1096. host: 'h1',
  1097. level: 'ERROR',
  1098. message: 'm1'
  1099. },
  1100. {
  1101. type: 'host-component',
  1102. 'component-name': 'c2',
  1103. host: 'h2',
  1104. level: 'WARN',
  1105. message: 'm2'
  1106. },
  1107. {
  1108. type: 'host-component',
  1109. 'component-name': 'c3',
  1110. host: 'h3',
  1111. level: 'ERROR',
  1112. message: 'm3'
  1113. },
  1114. {
  1115. type: 'host-component',
  1116. 'component-name': 'c4',
  1117. host: 'h4',
  1118. level: 'WARN',
  1119. message: 'm4'
  1120. }
  1121. ],
  1122. servicesMasters = [
  1123. Em.Object.create({selectedHost: 'h1', component_name: 'c1'}),
  1124. Em.Object.create({selectedHost: 'h2', component_name: 'c2'})
  1125. ];
  1126. beforeEach(function () {
  1127. c.set('servicesMasters', servicesMasters);
  1128. c.updateValidationsSuccessCallback({resources: [{items: data}]});
  1129. });
  1130. it('submitDisabled is false', function () {
  1131. expect(c.get('submitDisabled')).to.equal(false);
  1132. });
  1133. it('errorMessage for c1 is `m1`', function () {
  1134. expect(c.get('servicesMasters').findProperty('component_name', 'c1').get('errorMessage')).to.equal('m1');
  1135. });
  1136. it('errorMessage for c2 is `m2`', function () {
  1137. expect(c.get('servicesMasters').findProperty('component_name', 'c2').get('warnMessage')).to.equal('m2');
  1138. });
  1139. it('no general errors', function () {
  1140. expect(c.get('generalErrorMessages')).to.be.empty;
  1141. });
  1142. it('no general warnings', function () {
  1143. expect(c.get('generalWarningMessages')).to.be.empty;
  1144. });
  1145. });
  1146. });
  1147. describe('#sortComponentsByServiceName', function () {
  1148. var components = [{
  1149. "component_name": "METRICS_COLLECTOR",
  1150. "serviceId": "AMBARI_METRICS"
  1151. }, {"component_name": "ZOOKEEPER_SERVER", "serviceId": "ZOOKEEPER"}, {
  1152. "component_name": "NAMENODE",
  1153. "serviceId": "HDFS"
  1154. }, {"component_name": "DRPC_SERVER", "serviceId": "STORM"}, {
  1155. "component_name": "APP_TIMELINE_SERVER",
  1156. "serviceId": "YARN"
  1157. }, {"component_name": "RESOURCEMANAGER", "serviceId": "YARN"}, {
  1158. "component_name": "SECONDARY_NAMENODE",
  1159. "serviceId": "HDFS"
  1160. }, {"component_name": "ZOOKEEPER_SERVER", "serviceId": "ZOOKEEPER"}, {
  1161. "component_name": "HISTORYSERVER",
  1162. "serviceId": "MAPREDUCE2"
  1163. }, {"component_name": "NIMBUS", "serviceId": "STORM"}, {"component_name": "STORM_UI_SERVER", "serviceId": "STORM"}];
  1164. it('ZKS should be one after anothert', function () {
  1165. var sorted = c.sortComponentsByServiceName(components);
  1166. expect(sorted.mapProperty('component_name').join('|').contains('ZOOKEEPER_SERVER|ZOOKEEPER_SERVER')).to.be.true;
  1167. });
  1168. });
  1169. describe('#submit',function(){
  1170. it('if Next button is clicked multiple times before the next step renders, it must not be processed',function(){
  1171. c.reopen({isSubmitDisabled:false, submitDisabled:false, useServerValidation:false});
  1172. c.submit();
  1173. expect(App.router.send.calledWith('next')).to.equal(true);
  1174. App.router.send.reset();
  1175. c.submit();
  1176. expect(App.router.send.calledWith('next')).to.equal(false);
  1177. });
  1178. });
  1179. });