step5_test.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192
  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. services: Em.A([
  232. Em.Object.create({isInstalled: true, serviceName: 'HBASE'})
  233. ]),
  234. selectedServicesMasters: Em.A([
  235. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'}),
  236. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  237. ]),
  238. hosts: Em.A([
  239. Em.Object.create({})
  240. ]),
  241. controllerName: 'addServiceController',
  242. m: 'service is installed',
  243. e: {
  244. showAddControl: true,
  245. showRemoveControl: false
  246. }
  247. },
  248. {
  249. componentName: 'HBASE_SERVER',
  250. services: Em.A([
  251. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  252. ]),
  253. selectedServicesMasters: Em.A([
  254. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  255. ]),
  256. hosts: Em.A([
  257. Em.Object.create({})
  258. ]),
  259. controllerName: 'addServiceController',
  260. m: 'service not installed, but all host already have provided component',
  261. e: {
  262. showAddControl: true,
  263. showRemoveControl: false
  264. }
  265. },
  266. {
  267. componentName: 'HBASE_SERVER',
  268. services: Em.A([
  269. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  270. ]),
  271. selectedServicesMasters: Em.A([
  272. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
  273. ]),
  274. hosts: Em.A([
  275. Em.Object.create({}),
  276. Em.Object.create({})
  277. ]),
  278. controllerName: 'addServiceController',
  279. m: 'service not installed, not all host already have provided component',
  280. e: {
  281. showAddControl: true,
  282. showRemoveControl: true
  283. }
  284. },
  285. {
  286. componentName: 'HBASE_SERVER',
  287. services: Em.A([
  288. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  289. ]),
  290. selectedServicesMasters: Em.A([
  291. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
  292. ]),
  293. hosts: Em.A([
  294. Em.Object.create({}),
  295. Em.Object.create({})
  296. ]),
  297. controllerName: 'reassignMasterController',
  298. m: 'service not installed, not all host already have provided component, but is reassignMasterController',
  299. e: {
  300. showAddControl: false,
  301. showRemoveControl: false
  302. }
  303. }
  304. ]);
  305. tests.forEach(function (test) {
  306. it(test.m, function () {
  307. sinon.stub(App.StackService, 'find', function () {
  308. return test.services;
  309. });
  310. c.reopen({
  311. content: Em.Object.create({
  312. controllerName: test.controllerName
  313. }),
  314. selectedServicesMasters: test.selectedServicesMasters,
  315. hosts: test.hosts
  316. });
  317. c.updateComponent(test.componentName);
  318. App.StackService.find.restore();
  319. Em.keys(test.e).forEach(function (k) {
  320. expect(c.last(test.componentName).get(k)).to.equal(test.e[k]);
  321. });
  322. });
  323. });
  324. });
  325. describe('#renderComponents', function () {
  326. var tests = Em.A([
  327. {
  328. masterComponents: Em.A([
  329. {component_name: 'ZOOKEEPER_SERVER'}
  330. ]),
  331. services: Em.A([
  332. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
  333. ]),
  334. controllerName: 'reassignMasterController',
  335. m: 'One component',
  336. isHaEnabled: false,
  337. component_name: 'ZOOKEEPER_SERVER',
  338. e: {
  339. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  340. servicesMasters: ['ZOOKEEPER_SERVER'],
  341. showRemoveControl: [false],
  342. isInstalled: [false],
  343. serviceComponentId: [1]
  344. }
  345. },
  346. {
  347. masterComponents: Em.A([
  348. {component_name: 'ZOOKEEPER_SERVER'}
  349. ]),
  350. services: Em.A([
  351. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
  352. ]),
  353. controllerName: 'addServiceController',
  354. m: 'One component, service is not installed',
  355. component_name: 'ZOOKEEPER_SERVER',
  356. e: {
  357. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  358. servicesMasters: ['ZOOKEEPER_SERVER'],
  359. showRemoveControl: [false],
  360. serviceComponentId: [1]
  361. }
  362. },
  363. {
  364. masterComponents: Em.A([
  365. {component_name: 'ZOOKEEPER_SERVER'},
  366. {component_name: 'ZOOKEEPER_SERVER'}
  367. ]),
  368. services: Em.A([
  369. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: true})
  370. ]),
  371. controllerName: 'addServiceController',
  372. m: 'Two components, but service is installed',
  373. component_name: 'ZOOKEEPER_SERVER',
  374. e: {
  375. selectedServicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  376. servicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  377. showRemoveControl: [false, false],
  378. serviceComponentId: [1, 2]
  379. }
  380. }
  381. ]);
  382. tests.forEach(function (test) {
  383. beforeEach(function () {
  384. App.reopen({isHaEnabled: test.isHaEnabled});
  385. });
  386. it(test.m, function () {
  387. modelSetup.setupStackServiceComponent();
  388. sinon.stub(App.StackService, 'find', function () {
  389. return test.services;
  390. });
  391. App.set('isHaEnabled', test.isHaEnabled);
  392. c.reopen({
  393. content: Em.Object.create({
  394. services: test.services,
  395. controllerName: test.controllerName,
  396. reassign: {component_name: test.component_name}
  397. })
  398. });
  399. c.renderComponents(test.masterComponents);
  400. App.StackService.find.restore();
  401. modelSetup.cleanStackServiceComponent();
  402. expect(c.get('selectedServicesMasters').mapProperty('component_name')).to.eql(test.e.selectedServicesMasters);
  403. expect(c.get('servicesMasters').mapProperty('component_name')).to.eql(test.e.servicesMasters);
  404. expect(c.get('selectedServicesMasters').mapProperty('showRemoveControl')).to.eql(test.e.showRemoveControl);
  405. expect(c.get('selectedServicesMasters').mapProperty('serviceComponentId')).to.eql(test.e.serviceComponentId);
  406. if (c.get('isReasignController')) {
  407. expect(c.get('servicesMasters').mapProperty('isInstalled')).to.eql(test.e.isInstalled);
  408. }
  409. });
  410. });
  411. });
  412. describe('#assignHostToMaster', function () {
  413. var tests = Em.A([
  414. {
  415. componentName: 'c1',
  416. selectedHost: 'h2',
  417. serviceComponentId: '1',
  418. e: {
  419. indx: 0
  420. }
  421. },
  422. {
  423. componentName: 'c2',
  424. selectedHost: 'h3',
  425. serviceComponentId: '2',
  426. e: {
  427. indx: 3
  428. }
  429. },
  430. {
  431. componentName: 'c3',
  432. selectedHost: 'h1',
  433. e: {
  434. indx: 2
  435. }
  436. },
  437. {
  438. componentName: 'c2',
  439. selectedHost: 'h4',
  440. e: {
  441. indx: 1
  442. }
  443. }
  444. ]),
  445. selectedServicesMasters = Em.A([
  446. Em.Object.create({component_name: 'c1', serviceComponentId: '1', selectedHost: 'h1'}),
  447. Em.Object.create({component_name: 'c2', serviceComponentId: '1', selectedHost: 'h1'}),
  448. Em.Object.create({component_name: 'c3', serviceComponentId: '1', selectedHost: 'h3'}),
  449. Em.Object.create({component_name: 'c2', serviceComponentId: '2', selectedHost: 'h2'})
  450. ]);
  451. tests.forEach(function (test) {
  452. it(test.componentName + ' ' + test.selectedHost + ' ' + test.serviceComponentId, function () {
  453. c.set('selectedServicesMasters', selectedServicesMasters);
  454. c.assignHostToMaster(test.componentName, test.selectedHost, test.serviceComponentId);
  455. expect(c.get('selectedServicesMasters').objectAt(test.e.indx).get('selectedHost')).to.equal(test.selectedHost);
  456. })
  457. });
  458. });
  459. describe('#removeComponent', function () {
  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. ]),
  512. hosts: [
  513. {}
  514. ],
  515. m: 'two components, add not allowed, remove not allowed',
  516. e: true,
  517. showAddControl: false,
  518. showRemoveControl: false
  519. },
  520. {
  521. componentName: 'ZOOKEPEER_SERVER',
  522. serviceComponentId: 2,
  523. selectedServicesMasters: Em.A([
  524. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  525. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  526. Em.Object.create({serviceComponentId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
  527. ]),
  528. hosts: [
  529. {},
  530. {}
  531. ],
  532. m: 'three components, add not allowed, remove allowed',
  533. e: true,
  534. showAddControl: false,
  535. showRemoveControl: true
  536. },
  537. {
  538. componentName: 'ZOOKEPEER_SERVER',
  539. serviceComponentId: 2,
  540. selectedServicesMasters: Em.A([
  541. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  542. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  543. Em.Object.create({serviceComponentId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
  544. ]),
  545. hosts: [
  546. {},
  547. {},
  548. {}
  549. ],
  550. m: 'three components, add allowed, remove allowed',
  551. e: true,
  552. showAddControl: true,
  553. showRemoveControl: true
  554. }
  555. ]);
  556. tests.forEach(function (test) {
  557. it(test.m, function () {
  558. c.set('selectedServicesMasters', test.selectedServicesMasters);
  559. c.set('hosts', test.hosts);
  560. expect(c.removeComponent(test.componentName, test.serviceComponentId)).to.equal(test.e);
  561. if (test.e) {
  562. expect(c.get('selectedServicesMasters.lastObject.showRemoveControl')).to.equal(test.showRemoveControl);
  563. expect(c.get('selectedServicesMasters.lastObject.showAddControl')).to.equal(test.showAddControl);
  564. }
  565. })
  566. });
  567. });
  568. describe('#addComponent', function () {
  569. var tests = Em.A([
  570. {
  571. componentName: 'c1',
  572. selectedServicesMasters: Em.A([]),
  573. hosts: [],
  574. m: 'empty selectedServicesMasters',
  575. e: false
  576. },
  577. {
  578. componentName: 'ZOOKEPEER_SERVER',
  579. selectedServicesMasters: Em.A([
  580. Em.Object.create({serviceComponentId: 1, component_name: 'HBASE_SERVER'})
  581. ]),
  582. hosts: [],
  583. m: 'no such components',
  584. e: false
  585. },
  586. {
  587. componentName: 'ZOOKEPEER_SERVER',
  588. selectedServicesMasters: Em.A([
  589. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER'})
  590. ]),
  591. hosts: [],
  592. m: 'one component, 0 hosts',
  593. e: false
  594. },
  595. {
  596. componentName: 'ZOOKEPEER_SERVER',
  597. selectedServicesMasters: Em.A([
  598. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  599. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  600. ]),
  601. hosts: [Em.Object.create({}), Em.Object.create({})],
  602. m: 'two components, two hosts',
  603. e: false
  604. },
  605. {
  606. componentName: 'ZOOKEPEER_SERVER',
  607. selectedServicesMasters: Em.A([
  608. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  609. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  610. ]),
  611. hosts: [Em.Object.create({}), Em.Object.create({}), Em.Object.create({})],
  612. m: 'two components, 3 hosts',
  613. e: true
  614. }
  615. ]);
  616. tests.forEach(function (test) {
  617. it(test.m, function () {
  618. c.set('selectedServicesMasters', test.selectedServicesMasters);
  619. c.set('hosts', test.hosts);
  620. expect(c.addComponent(test.componentName)).to.equal(test.e);
  621. });
  622. });
  623. });
  624. describe('#title', function () {
  625. it('should be custom title for reassignMasterController', function () {
  626. c.set('content', {controllerName: 'reassignMasterController'});
  627. expect(c.get('title')).to.equal(Em.I18n.t('installer.step5.reassign.header'));
  628. });
  629. it('should be default for other', function () {
  630. c.set('content', {controllerName: 'notReassignMasterController'});
  631. expect(c.get('title')).to.equal(Em.I18n.t('installer.step5.header'));
  632. });
  633. });
  634. describe('#masterHostMapping', function () {
  635. Em.A([
  636. {
  637. selectedServicesMasters: [
  638. Em.Object.create({selectedHost: 'h1'}),
  639. Em.Object.create({selectedHost: 'h2'}),
  640. Em.Object.create({selectedHost: 'h1'})
  641. ],
  642. hosts: [
  643. Em.Object.create({host_name: 'h1', host_info: {}}),
  644. Em.Object.create({host_name: 'h2', host_info: {}})
  645. ],
  646. m: 'Two hosts',
  647. e: [
  648. {host_name: 'h1', hostInfo: {}, masterServices: [
  649. {},
  650. {}
  651. ]},
  652. {host_name: 'h2', hostInfo: {}, masterServices: [
  653. {}
  654. ]}
  655. ]
  656. },
  657. {
  658. selectedServicesMasters: [],
  659. hosts: [],
  660. m: 'No hosts',
  661. e: []
  662. },
  663. {
  664. selectedServicesMasters: [
  665. Em.Object.create({selectedHost: 'h1'}),
  666. Em.Object.create({selectedHost: 'h1'})
  667. ],
  668. hosts: [
  669. Em.Object.create({host_name: 'h1', host_info: {}})
  670. ],
  671. m: 'One host',
  672. e: [
  673. {host_name: 'h1', hostInfo: {}, masterServices: [
  674. {},
  675. {}
  676. ]}
  677. ]
  678. }
  679. ]).forEach(function (test) {
  680. it(test.m, function () {
  681. c.reopen({
  682. selectedServicesMasters: test.selectedServicesMasters,
  683. hosts: test.hosts
  684. });
  685. var result = c.get('masterHostMapping');
  686. expect(result.length).to.equal(test.e.length);
  687. result.forEach(function (r, i) {
  688. expect(r.get('host_name')).to.equal(test.e[i].host_name);
  689. expect(r.get('masterServices.length')).to.equal(test.e[i].masterServices.length);
  690. expect(r.get('hostInfo')).to.be.an.object;
  691. });
  692. });
  693. });
  694. });
  695. describe('#anyError', function () {
  696. Em.A([
  697. {
  698. servicesMasters: [
  699. Em.Object.create({errorMessage: 'some message'}),
  700. Em.Object.create({errorMessage: ''})
  701. ],
  702. generalErrorMessages: [],
  703. e: true
  704. },
  705. {
  706. servicesMasters: [
  707. Em.Object.create({errorMessage: ''}),
  708. Em.Object.create({errorMessage: ''})
  709. ],
  710. generalErrorMessages: [],
  711. e: false
  712. },
  713. {
  714. servicesMasters: [
  715. Em.Object.create({errorMessage: 'some message'}),
  716. Em.Object.create({errorMessage: 'some message 2'})
  717. ],
  718. generalErrorMessages: ['some message'],
  719. e: true
  720. },
  721. {
  722. servicesMasters: [
  723. Em.Object.create({errorMessage: ''}),
  724. Em.Object.create({errorMessage: ''})
  725. ],
  726. generalErrorMessages: ['some message'],
  727. e: true
  728. }
  729. ]).forEach(function (test, i) {
  730. it('test #' + i.toString(), function () {
  731. c.setProperties({
  732. servicesMasters: test.servicesMasters,
  733. generalErrorMessages: test.generalErrorMessages
  734. });
  735. expect(c.get('anyError')).to.equal(test.e);
  736. });
  737. });
  738. });
  739. describe('#anyWarning', function () {
  740. Em.A([
  741. {
  742. servicesMasters: [
  743. Em.Object.create({warnMessage: 'some message'}),
  744. Em.Object.create({warnMessage: ''})
  745. ],
  746. generalWarningMessages: [],
  747. e: true
  748. },
  749. {
  750. servicesMasters: [
  751. Em.Object.create({warnMessage: ''}),
  752. Em.Object.create({warnMessage: ''})
  753. ],
  754. generalWarningMessages: [],
  755. e: false
  756. },
  757. {
  758. servicesMasters: [
  759. Em.Object.create({warnMessage: 'some message'}),
  760. Em.Object.create({warnMessage: 'some message 2'})
  761. ],
  762. generalWarningMessages: ['some message'],
  763. e: true
  764. },
  765. {
  766. servicesMasters: [
  767. Em.Object.create({warnMessage: ''}),
  768. Em.Object.create({warnMessage: ''})
  769. ],
  770. generalWarningMessages: ['some message'],
  771. e: true
  772. }
  773. ]).forEach(function (test, i) {
  774. it('test #' + i.toString(), function () {
  775. c.setProperties({
  776. servicesMasters: test.servicesMasters,
  777. generalWarningMessages: test.generalWarningMessages
  778. });
  779. expect(c.get('anyWarning')).to.equal(test.e);
  780. });
  781. });
  782. });
  783. describe('#clearRecommendations', function () {
  784. it('should clear content.recommendations', function () {
  785. c.set('content', {recommendations: {'s': {}}});
  786. c.clearRecommendations();
  787. expect(c.get('content.recommendations')).to.be.null;
  788. });
  789. });
  790. describe('#updateIsSubmitDisabled', function () {
  791. beforeEach(function () {
  792. c.set('selectedServicesMasters', [
  793. {isInstalled: false}
  794. ]);
  795. });
  796. it('shouldn\'t change submitDisabled if thereIsNoMasters returns false', function () {
  797. c.set('selectedServicesMasters', [
  798. {isInstalled: true}
  799. ]);
  800. c.set('submitDisabled', false);
  801. c.updateIsSubmitDisabled();
  802. expect(c.get('submitDisabled')).to.equal(false);
  803. });
  804. it('should check servicesMasters.@each.isHostNameValid if useServerValidation is false', function () {
  805. c.set('useServerValidation', false);
  806. c.set('servicesMasters', [
  807. {isHostNameValid: false},
  808. {isHostNameValid: true}
  809. ]);
  810. c.updateIsSubmitDisabled();
  811. expect(c.get('submitDisabled')).to.equal(true);
  812. c.set('servicesMasters', [
  813. {isHostNameValid: true},
  814. {isHostNameValid: true}
  815. ]);
  816. c.updateIsSubmitDisabled();
  817. expect(c.get('submitDisabled')).to.equal(false);
  818. });
  819. });
  820. describe('#isHostNameValid', function () {
  821. beforeEach(function () {
  822. c.setProperties({
  823. hosts: [
  824. {host_name: 'h1'},
  825. {host_name: 'h2'},
  826. {host_name: 'h3'}
  827. ],
  828. selectedServicesMasters: [
  829. {component_name: 'c1', selectedHost: 'h1'},
  830. {component_name: 'c2', selectedHost: 'h2'},
  831. {component_name: 'c3', selectedHost: 'h3'},
  832. {component_name: 'c3', selectedHost: 'h1'}
  833. ]
  834. });
  835. });
  836. Em.A([
  837. {
  838. componentName: 'c1',
  839. selectedHost: ' ',
  840. m: 'empty hostName is invalid',
  841. e: false
  842. },
  843. {
  844. componentName: 'c1',
  845. selectedHost: 'h4',
  846. m: 'hostName not exists',
  847. e: false
  848. },
  849. {
  850. componentName: 'c4',
  851. selectedHost: 'h3',
  852. m: 'component not exists on host',
  853. e: true
  854. }
  855. ]).forEach(function (test) {
  856. it(test.m, function () {
  857. expect(c.isHostNameValid(test.componentName, test.selectedHost)).to.equal(test.e);
  858. });
  859. });
  860. });
  861. describe('#createComponentInstallationObject', function () {
  862. afterEach(function () {
  863. App.StackServiceComponent.find.restore();
  864. });
  865. Em.A([
  866. {
  867. fullComponent: Em.Object.create({
  868. componentName: 'c1',
  869. serviceName: 's1'
  870. }),
  871. hostName: 'h1',
  872. controllerName: 'reassignMasterController',
  873. savedComponent: {
  874. hostName: 'h2',
  875. isInstalled: true
  876. },
  877. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  878. e: {
  879. component_name: 'c1',
  880. display_name: 'C1',
  881. serviceId: 's1',
  882. selectedHost: 'h2',
  883. isInstalled: true,
  884. isServiceCoHost: false
  885. }
  886. },
  887. {
  888. fullComponent: Em.Object.create({
  889. componentName: 'c1',
  890. serviceName: 's1'
  891. }),
  892. hostName: 'h1',
  893. controllerName: 'installerController',
  894. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: false})],
  895. e: {
  896. component_name: 'c1',
  897. display_name: 'C1',
  898. serviceId: 's1',
  899. selectedHost: 'h1',
  900. isInstalled: false,
  901. isServiceCoHost: false
  902. }
  903. },
  904. {
  905. fullComponent: Em.Object.create({
  906. componentName: 'c1',
  907. serviceName: 's1'
  908. }),
  909. hostName: 'h1',
  910. controllerName: 'installerController',
  911. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  912. e: {
  913. component_name: 'c1',
  914. display_name: 'C1',
  915. serviceId: 's1',
  916. selectedHost: 'h1',
  917. isInstalled: false,
  918. isServiceCoHost: true
  919. }
  920. }
  921. ]).forEach(function (test, i) {
  922. it('test #' + i, function () {
  923. sinon.stub(App.StackServiceComponent, 'find', function () {
  924. return test.stackServiceComponents;
  925. });
  926. c.set('content', {controllerName: test.controllerName});
  927. expect(c.createComponentInstallationObject(test.fullComponent, test.hostName, test.savedComponent)).to.eql(test.e);
  928. });
  929. });
  930. });
  931. describe('#createComponentInstallationObjects', function () {
  932. beforeEach(function() {
  933. sinon.stub(App.StackServiceComponent, 'find', function() {
  934. return [
  935. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  936. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  937. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c4', serviceName: 's2'}),
  938. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  939. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  940. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c4', serviceName: 's2'})
  941. ];
  942. });
  943. c.set('content', {
  944. masterComponentHosts: [],
  945. services: [
  946. {serviceName: 's1', isSelected: true, isInstalled: false},
  947. {serviceName: 's2', isSelected: true, isInstalled: false}
  948. ],
  949. recommendations: {
  950. "blueprint": {
  951. "host_groups": [
  952. {
  953. "name": "host-group-1",
  954. "components": [ {"name": "c1"}, {"name": "c2"} ]
  955. },
  956. {
  957. "name": "host-group-2",
  958. "components": [ {"name": "c1"}, {"name": "c2"} ]
  959. },
  960. {
  961. "name": "host-group-3",
  962. "components": [ {"name": "c1"} ]
  963. }
  964. ]
  965. },
  966. "blueprint_cluster_binding": {
  967. "host_groups": [
  968. {
  969. "name": "host-group-1",
  970. "hosts": [ {"fqdn": "h1"} ]
  971. },
  972. {
  973. "name": "host-group-2",
  974. "hosts": [ {"fqdn": "h2"} ]
  975. },
  976. {
  977. "name": "host-group-3",
  978. "hosts": [ {"fqdn": "h3"} ]
  979. }
  980. ]
  981. }
  982. }
  983. });
  984. });
  985. afterEach(function() {
  986. App.StackServiceComponent.find.restore();
  987. });
  988. it('simple map without nothing stored/saved etc', function() {
  989. var r = c.createComponentInstallationObjects();
  990. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1']);
  991. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1']);
  992. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3']);
  993. });
  994. it('some saved components exist', function() {
  995. c.set('content.controllerName', 'addServiceController');
  996. c.get('multipleComponents').push('c4');
  997. c.set('content.masterComponentHosts', [
  998. {hostName: 'h3', component: 'c4'}
  999. ]);
  1000. c.get('content.recommendations.blueprint.host_groups')[2].components.push({name: 'c4'});
  1001. var r = c.createComponentInstallationObjects();
  1002. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1', 'c4']);
  1003. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1', 's2']);
  1004. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3', 'h3']);
  1005. });
  1006. });
  1007. describe('#getCurrentBlueprint', function () {
  1008. beforeEach(function() {
  1009. sinon.stub(c, 'getCurrentSlaveBlueprint', function() {
  1010. return {
  1011. blueprint_cluster_binding: {
  1012. host_groups: []
  1013. },
  1014. blueprint: {
  1015. host_groups: []
  1016. }
  1017. };
  1018. });
  1019. });
  1020. afterEach(function() {
  1021. c.getCurrentSlaveBlueprint.restore();
  1022. });
  1023. it('should map masterHostMapping', function () {
  1024. c.reopen({masterHostMapping: [
  1025. {host_name: 'h1', hostInfo:{}, masterServices: [
  1026. {serviceId: 's1', component_name: 'c1'},
  1027. {serviceId: 's2', component_name: 'c2'}
  1028. ]},
  1029. {host_name: 'h2', hostInfo:{}, masterServices: [
  1030. {serviceId: 's1', component_name: 'c1'},
  1031. {serviceId: 's3', component_name: 'c3'}
  1032. ]}
  1033. ]});
  1034. var r = c.getCurrentBlueprint();
  1035. expect(r).to.eql({"blueprint": {"host_groups": [
  1036. {"name": "host-group-1", "components": [
  1037. {"name": "c1"},
  1038. {"name": "c2"}
  1039. ]},
  1040. {"name": "host-group-2", "components": [
  1041. {"name": "c1"},
  1042. {"name": "c3"}
  1043. ]}
  1044. ]}, "blueprint_cluster_binding": {"host_groups": [
  1045. {"name": "host-group-1", "hosts": [
  1046. {"fqdn": "h1"}
  1047. ]},
  1048. {"name": "host-group-2", "hosts": [
  1049. {"fqdn": "h2"}
  1050. ]}
  1051. ]}}
  1052. );
  1053. });
  1054. });
  1055. describe('#updateValidationsSuccessCallback', function() {
  1056. beforeEach(function() {
  1057. sinon.stub(App.HostComponent, 'find', function() {
  1058. return [];
  1059. });
  1060. });
  1061. afterEach(function() {
  1062. App.HostComponent.find.restore();
  1063. });
  1064. it('should map messages to generalErrorMessages, generalWarningMessages', function() {
  1065. var data = [
  1066. {
  1067. type: 'host-component',
  1068. 'component-name': 'c1',
  1069. host: 'h1',
  1070. level: 'ERROR',
  1071. message: 'm1'
  1072. },
  1073. {
  1074. type: 'host-component',
  1075. 'component-name': 'c2',
  1076. host: 'h2',
  1077. level: 'WARN',
  1078. message: 'm2'
  1079. },
  1080. {
  1081. type: 'host-component',
  1082. 'component-name': 'c3',
  1083. host: 'h3',
  1084. level: 'ERROR',
  1085. message: 'm3'
  1086. },
  1087. {
  1088. type: 'host-component',
  1089. 'component-name': 'c4',
  1090. host: 'h4',
  1091. level: 'WARN',
  1092. message: 'm4'
  1093. }
  1094. ],
  1095. servicesMasters = [
  1096. Em.Object.create({selectedHost: 'h1', component_name: 'c1'}),
  1097. Em.Object.create({selectedHost: 'h2', component_name: 'c2'})
  1098. ];
  1099. c.set('servicesMasters', servicesMasters);
  1100. c.updateValidationsSuccessCallback({resources: [{items: data}]});
  1101. expect(c.get('submitDisabled')).to.equal(false);
  1102. expect(c.get('servicesMasters').findProperty('component_name', 'c1').get('errorMessage')).to.equal('m1');
  1103. expect(c.get('servicesMasters').findProperty('component_name', 'c2').get('warnMessage')).to.equal('m2');
  1104. expect(c.get('generalErrorMessages')).to.be.empty;
  1105. expect(c.get('generalWarningMessages')).to.be.empty;
  1106. });
  1107. });
  1108. });