step5_test.js 39 KB

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