step5_test.js 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251
  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. var clearCases = [
  804. {
  805. isHostNameValid: true,
  806. isInitialLayout: true,
  807. isInitialLayoutResulting: false,
  808. clearRecommendationsCallCount: 0,
  809. recommendAndValidateCallCount: 1,
  810. title: 'initial masters-hosts layout'
  811. },
  812. {
  813. isHostNameValid: true,
  814. isInitialLayout: false,
  815. isInitialLayoutResulting: false,
  816. clearRecommendationsCallCount: 1,
  817. recommendAndValidateCallCount: 1,
  818. title: 'master-hosts layout changed'
  819. },
  820. {
  821. isHostNameValid: false,
  822. isInitialLayout: false,
  823. isInitialLayoutResulting: false,
  824. clearRecommendationsCallCount: 0,
  825. recommendAndValidateCallCount: 0,
  826. title: 'invalid host name specified'
  827. }
  828. ];
  829. beforeEach(function () {
  830. c.set('selectedServicesMasters', [
  831. {isInstalled: false}
  832. ]);
  833. sinon.stub(c, 'clearRecommendations', Em.K);
  834. sinon.stub(c, 'recommendAndValidate', Em.K);
  835. });
  836. afterEach(function () {
  837. c.clearRecommendations.restore();
  838. c.recommendAndValidate.restore();
  839. });
  840. it('shouldn\'t change submitDisabled if thereIsNoMasters returns false', function () {
  841. c.set('selectedServicesMasters', [
  842. {isInstalled: true}
  843. ]);
  844. c.set('submitDisabled', false);
  845. c.updateIsSubmitDisabled();
  846. expect(c.get('submitDisabled')).to.equal(false);
  847. });
  848. it('should check servicesMasters.@each.isHostNameValid if useServerValidation is false', function () {
  849. c.set('useServerValidation', false);
  850. c.set('servicesMasters', [
  851. {isHostNameValid: false},
  852. {isHostNameValid: true}
  853. ]);
  854. c.updateIsSubmitDisabled();
  855. expect(c.get('submitDisabled')).to.equal(true);
  856. c.set('servicesMasters', [
  857. {isHostNameValid: true},
  858. {isHostNameValid: true}
  859. ]);
  860. c.updateIsSubmitDisabled();
  861. expect(c.get('submitDisabled')).to.equal(false);
  862. });
  863. clearCases.forEach(function (item) {
  864. it(item.title, function () {
  865. c.setProperties({
  866. isInitialLayout: item.isInitialLayout,
  867. servicesMasters: [{
  868. isHostNameValid: item.isHostNameValid
  869. }]
  870. });
  871. expect(c.get('isInitialLayout')).to.equal(item.isInitialLayoutResulting);
  872. expect(c.clearRecommendations.callCount).to.equal(item.clearRecommendationsCallCount);
  873. expect(c.recommendAndValidate.callCount).to.equal(item.recommendAndValidateCallCount);
  874. });
  875. });
  876. });
  877. describe('#isHostNameValid', function () {
  878. beforeEach(function () {
  879. c.setProperties({
  880. hosts: [
  881. {host_name: 'h1'},
  882. {host_name: 'h2'},
  883. {host_name: 'h3'}
  884. ],
  885. selectedServicesMasters: [
  886. {component_name: 'c1', selectedHost: 'h1'},
  887. {component_name: 'c2', selectedHost: 'h2'},
  888. {component_name: 'c3', selectedHost: 'h3'},
  889. {component_name: 'c3', selectedHost: 'h1'}
  890. ]
  891. });
  892. });
  893. Em.A([
  894. {
  895. componentName: 'c1',
  896. selectedHost: ' ',
  897. m: 'empty hostName is invalid',
  898. e: false
  899. },
  900. {
  901. componentName: 'c1',
  902. selectedHost: 'h4',
  903. m: 'hostName not exists',
  904. e: false
  905. },
  906. {
  907. componentName: 'c4',
  908. selectedHost: 'h3',
  909. m: 'component not exists on host',
  910. e: true
  911. }
  912. ]).forEach(function (test) {
  913. it(test.m, function () {
  914. expect(c.isHostNameValid(test.componentName, test.selectedHost)).to.equal(test.e);
  915. });
  916. });
  917. });
  918. describe('#createComponentInstallationObject', function () {
  919. afterEach(function () {
  920. App.StackServiceComponent.find.restore();
  921. });
  922. Em.A([
  923. {
  924. fullComponent: Em.Object.create({
  925. componentName: 'c1',
  926. serviceName: 's1'
  927. }),
  928. hostName: 'h1',
  929. controllerName: 'reassignMasterController',
  930. savedComponent: {
  931. hostName: 'h2',
  932. isInstalled: true
  933. },
  934. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  935. e: {
  936. component_name: 'c1',
  937. display_name: 'C1',
  938. serviceId: 's1',
  939. selectedHost: 'h2',
  940. isInstalled: true,
  941. isServiceCoHost: false
  942. }
  943. },
  944. {
  945. fullComponent: Em.Object.create({
  946. componentName: 'c1',
  947. serviceName: 's1'
  948. }),
  949. hostName: 'h1',
  950. controllerName: 'installerController',
  951. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: false})],
  952. e: {
  953. component_name: 'c1',
  954. display_name: 'C1',
  955. serviceId: 's1',
  956. selectedHost: 'h1',
  957. isInstalled: false,
  958. isServiceCoHost: false
  959. }
  960. },
  961. {
  962. fullComponent: Em.Object.create({
  963. componentName: 'c1',
  964. serviceName: 's1'
  965. }),
  966. hostName: 'h1',
  967. controllerName: 'installerController',
  968. stackServiceComponents: [Em.Object.create({componentName: 'c1', isCoHostedComponent: true})],
  969. e: {
  970. component_name: 'c1',
  971. display_name: 'C1',
  972. serviceId: 's1',
  973. selectedHost: 'h1',
  974. isInstalled: false,
  975. isServiceCoHost: true
  976. }
  977. }
  978. ]).forEach(function (test, i) {
  979. it('test #' + i, function () {
  980. sinon.stub(App.StackServiceComponent, 'find', function () {
  981. return test.stackServiceComponents;
  982. });
  983. c.set('content', {controllerName: test.controllerName});
  984. expect(c.createComponentInstallationObject(test.fullComponent, test.hostName, test.savedComponent)).to.eql(test.e);
  985. });
  986. });
  987. });
  988. describe('#createComponentInstallationObjects', function () {
  989. beforeEach(function() {
  990. sinon.stub(App.StackServiceComponent, 'find', function() {
  991. return [
  992. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  993. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  994. Em.Object.create({isShownOnAddServiceAssignMasterPage: true, componentName: 'c4', serviceName: 's2'}),
  995. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c1', serviceName: 's1'}),
  996. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c2', serviceName: 's2'}),
  997. Em.Object.create({isShownOnInstallerAssignMasterPage: true, componentName: 'c4', serviceName: 's2'})
  998. ];
  999. });
  1000. c.set('content', {
  1001. masterComponentHosts: [],
  1002. services: [
  1003. {serviceName: 's1', isSelected: true, isInstalled: false},
  1004. {serviceName: 's2', isSelected: true, isInstalled: false}
  1005. ],
  1006. recommendations: {
  1007. "blueprint": {
  1008. "host_groups": [
  1009. {
  1010. "name": "host-group-1",
  1011. "components": [ {"name": "c1"}, {"name": "c2"} ]
  1012. },
  1013. {
  1014. "name": "host-group-2",
  1015. "components": [ {"name": "c1"}, {"name": "c2"} ]
  1016. },
  1017. {
  1018. "name": "host-group-3",
  1019. "components": [ {"name": "c1"} ]
  1020. }
  1021. ]
  1022. },
  1023. "blueprint_cluster_binding": {
  1024. "host_groups": [
  1025. {
  1026. "name": "host-group-1",
  1027. "hosts": [ {"fqdn": "h1"} ]
  1028. },
  1029. {
  1030. "name": "host-group-2",
  1031. "hosts": [ {"fqdn": "h2"} ]
  1032. },
  1033. {
  1034. "name": "host-group-3",
  1035. "hosts": [ {"fqdn": "h3"} ]
  1036. }
  1037. ]
  1038. }
  1039. }
  1040. });
  1041. });
  1042. afterEach(function() {
  1043. App.StackServiceComponent.find.restore();
  1044. });
  1045. it('simple map without nothing stored/saved etc', function() {
  1046. var r = c.createComponentInstallationObjects();
  1047. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1']);
  1048. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1']);
  1049. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3']);
  1050. });
  1051. it('some saved components exist', function() {
  1052. c.set('content.controllerName', 'addServiceController');
  1053. c.get('multipleComponents').push('c4');
  1054. c.set('content.masterComponentHosts', [
  1055. {hostName: 'h3', component: 'c4'}
  1056. ]);
  1057. c.get('content.recommendations.blueprint.host_groups')[2].components.push({name: 'c4'});
  1058. var r = c.createComponentInstallationObjects();
  1059. expect(r.mapProperty('component_name')).to.eql(['c1', 'c2', 'c1', 'c2', 'c1', 'c4']);
  1060. expect(r.mapProperty('serviceId')).to.eql(['s1', 's2', 's1', 's2', 's1', 's2']);
  1061. expect(r.mapProperty('selectedHost')).to.eql(['h1', 'h1', 'h2', 'h2', 'h3', 'h3']);
  1062. });
  1063. });
  1064. describe('#getCurrentBlueprint', function () {
  1065. beforeEach(function() {
  1066. sinon.stub(c, 'getCurrentSlaveBlueprint', function() {
  1067. return {
  1068. blueprint_cluster_binding: {
  1069. host_groups: []
  1070. },
  1071. blueprint: {
  1072. host_groups: []
  1073. }
  1074. };
  1075. });
  1076. });
  1077. afterEach(function() {
  1078. c.getCurrentSlaveBlueprint.restore();
  1079. });
  1080. it('should map masterHostMapping', function () {
  1081. c.reopen({masterHostMapping: [
  1082. {host_name: 'h1', hostInfo:{}, masterServices: [
  1083. {serviceId: 's1', component_name: 'c1'},
  1084. {serviceId: 's2', component_name: 'c2'}
  1085. ]},
  1086. {host_name: 'h2', hostInfo:{}, masterServices: [
  1087. {serviceId: 's1', component_name: 'c1'},
  1088. {serviceId: 's3', component_name: 'c3'}
  1089. ]}
  1090. ]});
  1091. var r = c.getCurrentBlueprint();
  1092. expect(r).to.eql({"blueprint": {"host_groups": [
  1093. {"name": "host-group-1", "components": [
  1094. {"name": "c1"},
  1095. {"name": "c2"}
  1096. ]},
  1097. {"name": "host-group-2", "components": [
  1098. {"name": "c1"},
  1099. {"name": "c3"}
  1100. ]}
  1101. ]}, "blueprint_cluster_binding": {"host_groups": [
  1102. {"name": "host-group-1", "hosts": [
  1103. {"fqdn": "h1"}
  1104. ]},
  1105. {"name": "host-group-2", "hosts": [
  1106. {"fqdn": "h2"}
  1107. ]}
  1108. ]}}
  1109. );
  1110. });
  1111. });
  1112. describe('#updateValidationsSuccessCallback', function() {
  1113. beforeEach(function() {
  1114. sinon.stub(App.HostComponent, 'find', function() {
  1115. return [];
  1116. });
  1117. });
  1118. afterEach(function() {
  1119. App.HostComponent.find.restore();
  1120. });
  1121. it('should map messages to generalErrorMessages, generalWarningMessages', function() {
  1122. var data = [
  1123. {
  1124. type: 'host-component',
  1125. 'component-name': 'c1',
  1126. host: 'h1',
  1127. level: 'ERROR',
  1128. message: 'm1'
  1129. },
  1130. {
  1131. type: 'host-component',
  1132. 'component-name': 'c2',
  1133. host: 'h2',
  1134. level: 'WARN',
  1135. message: 'm2'
  1136. },
  1137. {
  1138. type: 'host-component',
  1139. 'component-name': 'c3',
  1140. host: 'h3',
  1141. level: 'ERROR',
  1142. message: 'm3'
  1143. },
  1144. {
  1145. type: 'host-component',
  1146. 'component-name': 'c4',
  1147. host: 'h4',
  1148. level: 'WARN',
  1149. message: 'm4'
  1150. }
  1151. ],
  1152. servicesMasters = [
  1153. Em.Object.create({selectedHost: 'h1', component_name: 'c1'}),
  1154. Em.Object.create({selectedHost: 'h2', component_name: 'c2'})
  1155. ];
  1156. c.set('servicesMasters', servicesMasters);
  1157. c.updateValidationsSuccessCallback({resources: [{items: data}]});
  1158. expect(c.get('submitDisabled')).to.equal(false);
  1159. expect(c.get('servicesMasters').findProperty('component_name', 'c1').get('errorMessage')).to.equal('m1');
  1160. expect(c.get('servicesMasters').findProperty('component_name', 'c2').get('warnMessage')).to.equal('m2');
  1161. expect(c.get('generalErrorMessages')).to.be.empty;
  1162. expect(c.get('generalWarningMessages')).to.be.empty;
  1163. });
  1164. });
  1165. });