step5_test.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285
  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.set('router.nextBtnClickInProgress', false);
  28. });
  29. afterEach(function () {
  30. App.router.send.restore();
  31. App.set('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', isInstalled: false},
  840. {host_name: 'h2', isInstalled: true, maintenance_state: 'ON'},
  841. {host_name: 'h3', isInstalled: true, maintenance_state: 'OFF'}
  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: 'c1',
  866. selectedHost: 'h1',
  867. m: 'not installed host',
  868. e: true
  869. },
  870. {
  871. componentName: 'c1',
  872. selectedHost: 'h2',
  873. m: 'installed host with maintenance ON',
  874. e: false
  875. },
  876. {
  877. componentName: 'c1',
  878. selectedHost: 'h3',
  879. m: 'installed host with maintenance OFF',
  880. e: true
  881. },
  882. {
  883. componentName: 'c4',
  884. selectedHost: 'h3',
  885. m: 'component not exists on host',
  886. e: true
  887. }
  888. ]).forEach(function (test) {
  889. it(test.m, function () {
  890. expect(c.isHostNameValid(test.componentName, test.selectedHost)).to.equal(test.e);
  891. });
  892. });
  893. });
  894. describe('#createComponentInstallationObject', function () {
  895. afterEach(function () {
  896. App.StackServiceComponent.find.restore();
  897. });
  898. Em.A([
  899. {
  900. fullComponent: Em.Object.create({
  901. componentName: 'c1',
  902. serviceName: 's1'
  903. }),
  904. hostName: 'h1',
  905. mastersToMove: ['c1'],
  906. savedComponent: {
  907. hostName: 'h2',
  908. isInstalled: true
  909. },
  910. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  911. e: {
  912. component_name: 'c1',
  913. display_name: 'C1',
  914. serviceId: 's1',
  915. selectedHost: 'h2',
  916. isInstalled: true,
  917. isServiceCoHost: false
  918. }
  919. },
  920. {
  921. fullComponent: Em.Object.create({
  922. componentName: 'c1',
  923. serviceName: 's1'
  924. }),
  925. hostName: 'h1',
  926. mastersToMove: [],
  927. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: false})],
  928. e: {
  929. component_name: 'c1',
  930. display_name: 'C1',
  931. serviceId: 's1',
  932. selectedHost: 'h1',
  933. isInstalled: false,
  934. isServiceCoHost: false
  935. }
  936. },
  937. {
  938. fullComponent: Em.Object.create({
  939. componentName: 'c1',
  940. serviceName: 's1'
  941. }),
  942. hostName: 'h1',
  943. mastersToMove: [],
  944. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  945. e: {
  946. component_name: 'c1',
  947. display_name: 'C1',
  948. serviceId: 's1',
  949. selectedHost: 'h1',
  950. isInstalled: false,
  951. isServiceCoHost: true
  952. }
  953. }
  954. ]).forEach(function (test, i) {
  955. describe('test #' + i, function () {
  956. beforeEach(function () {
  957. sinon.stub(App.StackServiceComponent, 'find', function () {
  958. return test.stackServiceComponents;
  959. });
  960. c.set('mastersToMove', test.mastersToMove);
  961. c.set('content', {controllerName: test.controllerName});
  962. });
  963. it('component-object is valid', function () {
  964. expect(c.createComponentInstallationObject(test.fullComponent, test.hostName, test.savedComponent)).to.eql(test.e);
  965. });
  966. });
  967. });
  968. });
  969. describe('#createComponentInstallationObjects', function () {
  970. beforeEach(function() {
  971. sinon.stub(App.StackServiceComponent, 'find', function() {
  972. return [
  973. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  974. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  975. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c4', serviceName: 's2'}),
  976. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  977. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  978. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c4', serviceName: 's2'})
  979. ];
  980. });
  981. var recommendations = {
  982. "blueprint": {
  983. "host_groups": [
  984. {
  985. "name": "host-group-1",
  986. "components": [ {"name": "c1"}, {"name": "c2"} ]
  987. },
  988. {
  989. "name": "host-group-2",
  990. "components": [ {"name": "c1"}, {"name": "c2"} ]
  991. },
  992. {
  993. "name": "host-group-3",
  994. "components": [ {"name": "c1"} ]
  995. }
  996. ]
  997. },
  998. "blueprint_cluster_binding": {
  999. "host_groups": [
  1000. {
  1001. "name": "host-group-1",
  1002. "hosts": [ {"fqdn": "h1"} ]
  1003. },
  1004. {
  1005. "name": "host-group-2",
  1006. "hosts": [ {"fqdn": "h2"} ]
  1007. },
  1008. {
  1009. "name": "host-group-3",
  1010. "hosts": [ {"fqdn": "h3"} ]
  1011. }
  1012. ]
  1013. }
  1014. };
  1015. c.set('recommendations', recommendations);
  1016. c.set('content', {
  1017. masterComponentHosts: [],
  1018. services: [
  1019. {serviceName: 's1', isSelected: true, isInstalled: false},
  1020. {serviceName: 's2', isSelected: true, isInstalled: false}
  1021. ],
  1022. recommendations: recommendations
  1023. });
  1024. });
  1025. afterEach(function() {
  1026. App.StackServiceComponent.find.restore();
  1027. });
  1028. it('simple map without nothing stored/saved etc', function() {
  1029. var r = c.createComponentInstallationObjects();
  1030. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1']);
  1031. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1']);
  1032. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3']);
  1033. });
  1034. describe('some saved components exist', function() {
  1035. beforeEach(function () {
  1036. c.set('content.controllerName', 'addServiceController');
  1037. c.get('multipleComponents').push('c4');
  1038. c.set('content.masterComponentHosts', [
  1039. {hostName: 'h3', component: 'c4'}
  1040. ]);
  1041. c.get('content.recommendations.blueprint.host_groups')[2].components.push({name: 'c4'});
  1042. });
  1043. it('data contains save components', function () {
  1044. var r = c.createComponentInstallationObjects();
  1045. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1', 'c4']);
  1046. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1', 's2']);
  1047. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3', 'h3']);
  1048. });
  1049. });
  1050. });
  1051. describe('#getCurrentBlueprint', function () {
  1052. beforeEach(function() {
  1053. sinon.stub(c, 'getCurrentSlaveBlueprint', function() {
  1054. return {
  1055. blueprint_cluster_binding: {
  1056. host_groups: []
  1057. },
  1058. blueprint: {
  1059. host_groups: []
  1060. }
  1061. };
  1062. });
  1063. });
  1064. afterEach(function() {
  1065. c.getCurrentSlaveBlueprint.restore();
  1066. });
  1067. it('should map masterHostMapping', function () {
  1068. c.reopen({masterHostMapping: [
  1069. {host_name: 'h1', hostInfo:{}, masterServices: [
  1070. {serviceId: 's1', component_name: 'c1'},
  1071. {serviceId: 's2', component_name: 'c2'}
  1072. ]},
  1073. {host_name: 'h2', hostInfo:{}, masterServices: [
  1074. {serviceId: 's1', component_name: 'c1'},
  1075. {serviceId: 's3', component_name: 'c3'}
  1076. ]}
  1077. ]});
  1078. var r = c.getCurrentBlueprint();
  1079. expect(r).to.eql({"blueprint": {"host_groups": [
  1080. {"name": "host-group-1", "components": [
  1081. {"name": "c1"},
  1082. {"name": "c2"}
  1083. ]},
  1084. {"name": "host-group-2", "components": [
  1085. {"name": "c1"},
  1086. {"name": "c3"}
  1087. ]}
  1088. ]}, "blueprint_cluster_binding": {"host_groups": [
  1089. {"name": "host-group-1", "hosts": [
  1090. {"fqdn": "h1"}
  1091. ]},
  1092. {"name": "host-group-2", "hosts": [
  1093. {"fqdn": "h2"}
  1094. ]}
  1095. ]}}
  1096. );
  1097. });
  1098. });
  1099. describe('#updateValidationsSuccessCallback', function() {
  1100. beforeEach(function() {
  1101. sinon.stub(App.HostComponent, 'find', function() {
  1102. return [];
  1103. });
  1104. });
  1105. afterEach(function() {
  1106. App.HostComponent.find.restore();
  1107. });
  1108. describe('should map messages to generalErrorMessages, generalWarningMessages', function() {
  1109. var data = [
  1110. {
  1111. type: 'host-component',
  1112. 'component-name': 'c1',
  1113. host: 'h1',
  1114. level: 'ERROR',
  1115. message: 'm1'
  1116. },
  1117. {
  1118. type: 'host-component',
  1119. 'component-name': 'c2',
  1120. host: 'h2',
  1121. level: 'WARN',
  1122. message: 'm2'
  1123. },
  1124. {
  1125. type: 'host-component',
  1126. 'component-name': 'c3',
  1127. host: 'h3',
  1128. level: 'ERROR',
  1129. message: 'm3'
  1130. },
  1131. {
  1132. type: 'host-component',
  1133. 'component-name': 'c4',
  1134. host: 'h4',
  1135. level: 'WARN',
  1136. message: 'm4'
  1137. }
  1138. ],
  1139. servicesMasters = [
  1140. Em.Object.create({selectedHost: 'h1', component_name: 'c1'}),
  1141. Em.Object.create({selectedHost: 'h2', component_name: 'c2'})
  1142. ];
  1143. beforeEach(function () {
  1144. c.set('servicesMasters', servicesMasters);
  1145. c.updateValidationsSuccessCallback({resources: [{items: data}]});
  1146. });
  1147. it('submitDisabled is false', function () {
  1148. expect(c.get('submitDisabled')).to.equal(false);
  1149. });
  1150. it('errorMessage for c1 is `m1`', function () {
  1151. expect(c.get('servicesMasters').findProperty('component_name', 'c1').get('errorMessage')).to.equal('m1');
  1152. });
  1153. it('errorMessage for c2 is `m2`', function () {
  1154. expect(c.get('servicesMasters').findProperty('component_name', 'c2').get('warnMessage')).to.equal('m2');
  1155. });
  1156. it('no general errors', function () {
  1157. expect(c.get('generalErrorMessages')).to.be.empty;
  1158. });
  1159. it('no general warnings', function () {
  1160. expect(c.get('generalWarningMessages')).to.be.empty;
  1161. });
  1162. });
  1163. });
  1164. });