step5_test.js 38 KB

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