step5_test.js 37 KB

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