step5_test.js 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870
  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. describe('#getHostForComponent()', function () {
  32. before(function () {
  33. modelSetup.setupStackServiceComponent();
  34. });
  35. var componentHostsGenerator = function (componentName, hosts) {
  36. it('test hosts input valid', function () {
  37. expect(hosts.length).to.eql(5);
  38. });
  39. return {
  40. componentName: componentName,
  41. expectedLocation: hosts
  42. };
  43. },
  44. hostsCount = [1, 3, 6, 10, 31],
  45. tests = [
  46. componentHostsGenerator('NAMENODE', ['host0', 'host0', 'host0', 'host0', 'host0']),
  47. componentHostsGenerator('SECONDARY_NAMENODE', ['host0', 'host1', 'host1', 'host1', 'host1']),
  48. componentHostsGenerator('HBASE_MASTER', ['host0', 'host0', 'host2', 'host2', 'host3']),
  49. componentHostsGenerator('JOBTRACKER', ['host0', 'host1', 'host1', 'host1', 'host2']),
  50. componentHostsGenerator('OOZIE_SERVER', ['host0', 'host1', 'host2', 'host2', 'host3']),
  51. componentHostsGenerator('HIVE_SERVER', ['host0', 'host1', 'host2', 'host2', 'host4']),
  52. componentHostsGenerator('STORM_UI_SERVER', ['host0', 'host0', 'host0', 'host0', 'host0'])
  53. ],
  54. testMessage = 'should locate `{0}` to `{1}` with {2} node cluster';
  55. tests.forEach(function (test) {
  56. var componentName = test.componentName;
  57. hostsCount.forEach(function (count, index) {
  58. it(testMessage.format(componentName, test.expectedLocation[index], count), function () {
  59. var hosts = Array.apply(null, Array(count)).map(function (_, i) {
  60. return 'host' + i;
  61. });
  62. expect(controller.getHostForComponent(test.componentName, hosts)).to.eql(test.expectedLocation[index]);
  63. })
  64. });
  65. });
  66. after(function () {
  67. modelSetup.cleanStackServiceComponent();
  68. });
  69. });
  70. controller.set('content', {});
  71. describe('#isReassignWizard', function () {
  72. it('true if content.controllerName is reassignMasterController', function () {
  73. controller.set('content.controllerName', 'reassignMasterController');
  74. expect(controller.get('isReassignWizard')).to.equal(true);
  75. });
  76. it('false if content.controllerName is not reassignMasterController', function () {
  77. controller.set('content.controllerName', 'mainController');
  78. expect(controller.get('isReassignWizard')).to.equal(false);
  79. });
  80. });
  81. describe('#isAddServiceWizard', function () {
  82. it('true if content.controllerName is addServiceController', function () {
  83. controller.set('content.controllerName', 'addServiceController');
  84. expect(controller.get('isAddServiceWizard')).to.equal(true);
  85. });
  86. it('false if content.controllerName is not addServiceController', function () {
  87. controller.set('content.controllerName', 'mainController');
  88. expect(controller.get('isAddServiceWizard')).to.equal(false);
  89. });
  90. });
  91. describe('#sortHosts', function () {
  92. var tests = Em.A([
  93. {
  94. hosts: [
  95. Em.Object.create({memory: 4, cpu: 1, host_name: 'host1', id: 1}),
  96. Em.Object.create({memory: 3, cpu: 1, host_name: 'host2', id: 2}),
  97. Em.Object.create({memory: 2, cpu: 1, host_name: 'host3', id: 3}),
  98. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
  99. ],
  100. m: 'memory',
  101. e: [1, 2, 3, 4]
  102. },
  103. {
  104. hosts: [
  105. Em.Object.create({memory: 1, cpu: 4, host_name: 'host1', id: 1}),
  106. Em.Object.create({memory: 1, cpu: 3, host_name: 'host2', id: 2}),
  107. Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 3}),
  108. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
  109. ],
  110. m: 'cpu',
  111. e: [1, 2, 3, 4]
  112. },
  113. {
  114. hosts: [
  115. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 1}),
  116. Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 2}),
  117. Em.Object.create({memory: 1, cpu: 1, host_name: 'host3', id: 3}),
  118. Em.Object.create({memory: 1, cpu: 1, host_name: 'host1', id: 4})
  119. ],
  120. m: 'host_name',
  121. e: [4, 2, 3, 1]
  122. },
  123. {
  124. hosts: [
  125. Em.Object.create({memory: 2, cpu: 1, host_name: 'host1', id: 1}),
  126. Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 2}),
  127. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 3}),
  128. Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 4})
  129. ],
  130. m: 'mix',
  131. e: [1, 2, 4, 3]
  132. }
  133. ]);
  134. tests.forEach(function (test) {
  135. it(test.m, function () {
  136. var hosts = Em.copy(test.hosts);
  137. controller.sortHosts(hosts);
  138. expect(Em.A(hosts).mapProperty('id')).to.eql(test.e);
  139. });
  140. });
  141. });
  142. describe('#renderHostInfo', function () {
  143. var tests = Em.A([
  144. {
  145. hosts: {
  146. h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'INIT'},
  147. h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'INIT'},
  148. h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'INIT'},
  149. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'INIT'}
  150. },
  151. m: 'no one host is REGISTERED',
  152. e: []
  153. },
  154. {
  155. hosts: {
  156. h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
  157. h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
  158. h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
  159. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
  160. },
  161. m: 'all hosts are REGISTERED, memory',
  162. e: ['host1', 'host2', 'host3', 'host4']
  163. },
  164. {
  165. hosts: {
  166. h1: {memory: 1, cpu: 4, name: 'host1', bootStatus: 'REGISTERED'},
  167. h2: {memory: 1, cpu: 3, name: 'host2', bootStatus: 'REGISTERED'},
  168. h3: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'REGISTERED'},
  169. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
  170. },
  171. m: 'all hosts are REGISTERED, cpu',
  172. e: ['host1', 'host2', 'host3', 'host4']
  173. },
  174. {
  175. hosts: {
  176. h1: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
  177. h2: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
  178. h3: {memory: 1, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
  179. h4: {memory: 1, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'}
  180. },
  181. m: 'all hosts are REGISTERED, host_name',
  182. e: ['host1', 'host2', 'host3', 'host4']
  183. },
  184. {
  185. hosts: {
  186. h1: {memory: 2, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
  187. h2: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'INIT'},
  188. h3: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
  189. h4: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'INIT'}
  190. },
  191. m: 'mix',
  192. e: ['host1', 'host4']
  193. }
  194. ]);
  195. tests.forEach(function (test) {
  196. it(test.m, function () {
  197. controller.set('content', {hosts: test.hosts});
  198. controller.renderHostInfo();
  199. var r = controller.get('hosts');
  200. expect(Em.A(r).mapProperty('host_name')).to.eql(test.e);
  201. });
  202. });
  203. });
  204. describe('#selectHost', function () {
  205. before(function () {
  206. modelSetup.setupStackServiceComponent();
  207. App.store.load(App.StackServiceComponent, {
  208. id: 'KERBEROS_SERVER',
  209. component_name: 'KERBEROS_SERVER'
  210. });
  211. });
  212. var tests = Em.A([
  213. {componentName: 'NAMENODE', hostsCount: 1, e: 'host1'},
  214. {componentName: 'NAMENODE', hostsCount: 2, e: 'host1'},
  215. {componentName: 'SECONDARY_NAMENODE', hostsCount: 1, e: 'host1'},
  216. {componentName: 'SECONDARY_NAMENODE', hostsCount: 2, e: 'host2'},
  217. {componentName: 'JOBTRACKER', hostsCount: 1, e: 'host1'},
  218. {componentName: 'JOBTRACKER', hostsCount: 3, e: 'host2'},
  219. {componentName: 'JOBTRACKER', hostsCount: 6, e: 'host2'},
  220. {componentName: 'JOBTRACKER', hostsCount: 31, e: 'host3'},
  221. {componentName: 'JOBTRACKER', hostsCount: 32, e: 'host3'},
  222. {componentName: 'HISTORYSERVER', hostsCount: 1, e: 'host1'},
  223. {componentName: 'HISTORYSERVER', hostsCount: 3, e: 'host2'},
  224. {componentName: 'HISTORYSERVER', hostsCount: 6, e: 'host2'},
  225. {componentName: 'HISTORYSERVER', hostsCount: 31, e: 'host3'},
  226. {componentName: 'HISTORYSERVER', hostsCount: 32, e: 'host3'},
  227. {componentName: 'RESOURCEMANAGER', hostsCount: 1, e: 'host1'},
  228. {componentName: 'RESOURCEMANAGER', hostsCount: 3, e: 'host2'},
  229. {componentName: 'RESOURCEMANAGER', hostsCount: 6, e: 'host2'},
  230. {componentName: 'RESOURCEMANAGER', hostsCount: 31, e: 'host3'},
  231. {componentName: 'RESOURCEMANAGER', hostsCount: 32, e: 'host3'},
  232. {componentName: 'HBASE_MASTER', hostsCount: 1, e: ['host1']},
  233. {componentName: 'HBASE_MASTER', hostsCount: 3, e: ['host1']},
  234. {componentName: 'HBASE_MASTER', hostsCount: 6, e: ['host3']},
  235. {componentName: 'HBASE_MASTER', hostsCount: 31, e: ['host4']},
  236. {componentName: 'HBASE_MASTER', hostsCount: 32, e: ['host4']},
  237. {componentName: 'OOZIE_SERVER', hostsCount: 1, e: 'host1'},
  238. {componentName: 'OOZIE_SERVER', hostsCount: 3, e: 'host2'},
  239. {componentName: 'OOZIE_SERVER', hostsCount: 6, e: 'host3'},
  240. {componentName: 'OOZIE_SERVER', hostsCount: 31, e: 'host4'},
  241. {componentName: 'OOZIE_SERVER', hostsCount: 32, e: 'host4'},
  242. {componentName: 'HIVE_SERVER', hostsCount: 1, e: 'host1'},
  243. {componentName: 'HIVE_SERVER', hostsCount: 3, e: 'host2'},
  244. {componentName: 'HIVE_SERVER', hostsCount: 6, e: 'host3'},
  245. {componentName: 'HIVE_SERVER', hostsCount: 31, e: 'host5'},
  246. {componentName: 'HIVE_SERVER', hostsCount: 32, e: 'host5'},
  247. {componentName: 'HIVE_METASTORE', hostsCount: 1, e: 'host1'},
  248. {componentName: 'HIVE_METASTORE', hostsCount: 3, e: 'host2'},
  249. {componentName: 'HIVE_METASTORE', hostsCount: 6, e: 'host3'},
  250. {componentName: 'HIVE_METASTORE', hostsCount: 31, e: 'host5'},
  251. {componentName: 'HIVE_METASTORE', hostsCount: 32, e: 'host5'},
  252. {componentName: 'WEBHCAT_SERVER', hostsCount: 1, e: 'host1'},
  253. {componentName: 'WEBHCAT_SERVER', hostsCount: 3, e: 'host2'},
  254. {componentName: 'WEBHCAT_SERVER', hostsCount: 6, e: 'host3'},
  255. {componentName: 'WEBHCAT_SERVER', hostsCount: 31, e: 'host5'},
  256. {componentName: 'WEBHCAT_SERVER', hostsCount: 32, e: 'host5'},
  257. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 1, e: 'host1'},
  258. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 3, e: 'host2'},
  259. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 6, e: 'host2'},
  260. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 31, e: 'host3'},
  261. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 32, e: 'host3'},
  262. {componentName: 'FALCON_SERVER', hostsCount: 1, e: 'host1'},
  263. {componentName: 'FALCON_SERVER', hostsCount: 3, e: 'host2'},
  264. {componentName: 'FALCON_SERVER', hostsCount: 6, e: 'host3'},
  265. {componentName: 'FALCON_SERVER', hostsCount: 31, e: 'host4'},
  266. {componentName: 'FALCON_SERVER', hostsCount: 32, e: 'host4'}
  267. ]);
  268. tests.forEach(function (test) {
  269. it(test.componentName + ' ' + test.hostsCount, function () {
  270. controller.reopen({multipleComponents: ['HBASE_MASTER', 'ZOOKEEPER_SERVER']});
  271. controller.set('hosts', d3.range(1, test.hostsCount + 1).map(function (i) {
  272. return {host_name: 'host' + i.toString()};
  273. }));
  274. expect(controller.selectHost(test.componentName)).to.eql(test.e);
  275. });
  276. });
  277. after(function () {
  278. modelSetup.cleanStackServiceComponent();
  279. });
  280. });
  281. describe('#last', function () {
  282. var tests = Em.A([
  283. {
  284. selectedServicesMasters: Em.A([
  285. {component_name: 'c1', indx: 1},
  286. {component_name: 'c2', indx: 2},
  287. {component_name: 'c1', indx: 2}
  288. ]),
  289. m: 'Components exists',
  290. c: 'c1',
  291. e: 2
  292. },
  293. {
  294. selectedServicesMasters: Em.A([
  295. {component_name: 'c1', indx: 1},
  296. {component_name: 'c2', indx: 2},
  297. {component_name: 'c1', indx: 2}
  298. ]),
  299. m: 'Components don\'t exists',
  300. c: 'c3',
  301. e: null
  302. }
  303. ]);
  304. tests.forEach(function (test) {
  305. it(test.m, function () {
  306. controller.set('selectedServicesMasters', test.selectedServicesMasters);
  307. if (!Em.isNone(test.e)) {
  308. expect(controller.last(test.c).indx).to.equal(test.e);
  309. }
  310. else {
  311. expect(Em.isNone(controller.last(test.c))).to.equal(true);
  312. }
  313. })
  314. });
  315. });
  316. describe('#remainingHosts', function () {
  317. it('should show count of hosts without masters', function () {
  318. c.reopen({masterHostMapping: [
  319. {}
  320. ]});
  321. c.set('hosts', [
  322. {},
  323. {},
  324. {}
  325. ]);
  326. expect(c.get('remainingHosts')).to.equal(2);
  327. });
  328. });
  329. describe('#clearStep', function () {
  330. var tests = Em.A([
  331. {p: 'hosts'},
  332. {p: 'selectedServicesMasters'},
  333. {p: 'servicesMasters'}
  334. ]);
  335. tests.forEach(function (test) {
  336. it('should cleanup ' + test.p, function () {
  337. c.set(test.p, [Em.Object.create({}), Em.Object.create({})]);
  338. c.clearStep();
  339. expect(c.get(test.p).length).to.equal(0);
  340. });
  341. });
  342. });
  343. describe('#updateComponent', function () {
  344. var tests = Em.A([
  345. {
  346. componentName: 'HBASE_SERVER',
  347. services: Em.A([
  348. Em.Object.create({isInstalled: true, serviceName: 'HBASE'})
  349. ]),
  350. selectedServicesMasters: Em.A([
  351. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'}),
  352. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  353. ]),
  354. hosts: Em.A([
  355. Em.Object.create({})
  356. ]),
  357. controllerName: 'addServiceController',
  358. m: 'service is installed',
  359. e: {
  360. showAddControl: true,
  361. showRemoveControl: false
  362. }
  363. },
  364. {
  365. componentName: 'HBASE_SERVER',
  366. services: Em.A([
  367. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  368. ]),
  369. selectedServicesMasters: Em.A([
  370. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  371. ]),
  372. hosts: Em.A([
  373. Em.Object.create({})
  374. ]),
  375. controllerName: 'addServiceController',
  376. m: 'service not installed, but all host already have provided component',
  377. e: {
  378. showAddControl: true,
  379. showRemoveControl: false
  380. }
  381. },
  382. {
  383. componentName: 'HBASE_SERVER',
  384. services: Em.A([
  385. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  386. ]),
  387. selectedServicesMasters: Em.A([
  388. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
  389. ]),
  390. hosts: Em.A([
  391. Em.Object.create({}),
  392. Em.Object.create({})
  393. ]),
  394. controllerName: 'addServiceController',
  395. m: 'service not installed, not all host already have provided component',
  396. e: {
  397. showAddControl: true,
  398. showRemoveControl: true
  399. }
  400. },
  401. {
  402. componentName: 'HBASE_SERVER',
  403. services: Em.A([
  404. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  405. ]),
  406. selectedServicesMasters: Em.A([
  407. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
  408. ]),
  409. hosts: Em.A([
  410. Em.Object.create({}),
  411. Em.Object.create({})
  412. ]),
  413. controllerName: 'reassignMasterController',
  414. m: 'service not installed, not all host already have provided component, but is reassignMasterController',
  415. e: {
  416. showAddControl: false,
  417. showRemoveControl: false
  418. }
  419. }
  420. ]);
  421. tests.forEach(function (test) {
  422. it(test.m, function () {
  423. sinon.stub(App.StackService, 'find', function () {
  424. return test.services;
  425. });
  426. c.reopen({
  427. content: Em.Object.create({
  428. controllerName: test.controllerName
  429. }),
  430. selectedServicesMasters: test.selectedServicesMasters,
  431. hosts: test.hosts
  432. });
  433. c.updateComponent(test.componentName);
  434. App.StackService.find.restore();
  435. Em.keys(test.e).forEach(function (k) {
  436. expect(c.last(test.componentName).get(k)).to.equal(test.e[k]);
  437. });
  438. });
  439. });
  440. });
  441. describe('#renderComponents', function () {
  442. var tests = Em.A([
  443. {
  444. masterComponents: Em.A([
  445. {component_name: 'ZOOKEEPER_SERVER'}
  446. ]),
  447. services: Em.A([
  448. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
  449. ]),
  450. controllerName: 'reassignMasterController',
  451. m: 'One component',
  452. isHaEnabled: false,
  453. component_name: 'ZOOKEEPER_SERVER',
  454. e: {
  455. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  456. servicesMasters: ['ZOOKEEPER_SERVER'],
  457. showRemoveControl: [false],
  458. isInstalled: [false],
  459. serviceComponentId: [1]
  460. }
  461. },
  462. {
  463. masterComponents: Em.A([
  464. {component_name: 'ZOOKEEPER_SERVER'}
  465. ]),
  466. services: Em.A([
  467. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: false, isSelected: true})
  468. ]),
  469. controllerName: 'addServiceController',
  470. m: 'One component, service is not installed',
  471. component_name: 'ZOOKEEPER_SERVER',
  472. e: {
  473. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  474. servicesMasters: ['ZOOKEEPER_SERVER'],
  475. showRemoveControl: [false],
  476. serviceComponentId: [1]
  477. }
  478. },
  479. {
  480. masterComponents: Em.A([
  481. {component_name: 'ZOOKEEPER_SERVER'},
  482. {component_name: 'ZOOKEEPER_SERVER'}
  483. ]),
  484. services: Em.A([
  485. Em.Object.create({serviceName: 'ZOOKEEPER', isInstalled: true})
  486. ]),
  487. controllerName: 'addServiceController',
  488. m: 'Two components, but service is installed',
  489. component_name: 'ZOOKEEPER_SERVER',
  490. e: {
  491. selectedServicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  492. servicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  493. showRemoveControl: [false, false],
  494. serviceComponentId: [1, 2]
  495. }
  496. }
  497. ]);
  498. tests.forEach(function (test) {
  499. beforeEach(function () {
  500. App.reopen({isHaEnabled: test.isHaEnabled});
  501. });
  502. it(test.m, function () {
  503. modelSetup.setupStackServiceComponent();
  504. sinon.stub(App.StackService, 'find', function () {
  505. return test.services;
  506. });
  507. App.set('isHaEnabled', test.isHaEnabled);
  508. c.reopen({
  509. content: Em.Object.create({
  510. services: test.services,
  511. controllerName: test.controllerName,
  512. reassign: {component_name: test.component_name}
  513. })
  514. });
  515. c.renderComponents(test.masterComponents);
  516. App.StackService.find.restore();
  517. modelSetup.cleanStackServiceComponent();
  518. expect(c.get('selectedServicesMasters').mapProperty('component_name')).to.eql(test.e.selectedServicesMasters);
  519. expect(c.get('servicesMasters').mapProperty('component_name')).to.eql(test.e.servicesMasters);
  520. expect(c.get('selectedServicesMasters').mapProperty('showRemoveControl')).to.eql(test.e.showRemoveControl);
  521. expect(c.get('selectedServicesMasters').mapProperty('serviceComponentId')).to.eql(test.e.serviceComponentId);
  522. if (c.get('isReasignController')) {
  523. expect(c.get('servicesMasters').mapProperty('isInstalled')).to.eql(test.e.isInstalled);
  524. }
  525. });
  526. });
  527. });
  528. describe('#assignHostToMaster', function () {
  529. var tests = Em.A([
  530. {
  531. componentName: 'c1',
  532. selectedHost: 'h2',
  533. serviceComponentId: '1',
  534. e: {
  535. indx: 0
  536. }
  537. },
  538. {
  539. componentName: 'c2',
  540. selectedHost: 'h3',
  541. serviceComponentId: '2',
  542. e: {
  543. indx: 3
  544. }
  545. },
  546. {
  547. componentName: 'c3',
  548. selectedHost: 'h1',
  549. e: {
  550. indx: 2
  551. }
  552. },
  553. {
  554. componentName: 'c2',
  555. selectedHost: 'h4',
  556. e: {
  557. indx: 1
  558. }
  559. }
  560. ]),
  561. selectedServicesMasters = Em.A([
  562. Em.Object.create({component_name: 'c1', serviceComponentId: '1', selectedHost: 'h1'}),
  563. Em.Object.create({component_name: 'c2', serviceComponentId: '1', selectedHost: 'h1'}),
  564. Em.Object.create({component_name: 'c3', serviceComponentId: '1', selectedHost: 'h3'}),
  565. Em.Object.create({component_name: 'c2', serviceComponentId: '2', selectedHost: 'h2'})
  566. ]);
  567. tests.forEach(function (test) {
  568. it(test.componentName + ' ' + test.selectedHost + ' ' + test.serviceComponentId, function () {
  569. c.set('selectedServicesMasters', selectedServicesMasters);
  570. c.assignHostToMaster(test.componentName, test.selectedHost, test.serviceComponentId);
  571. expect(c.get('selectedServicesMasters').objectAt(test.e.indx).get('selectedHost')).to.equal(test.selectedHost);
  572. })
  573. });
  574. });
  575. describe('#submit', function () {
  576. beforeEach(function () {
  577. sinon.stub(App.router, 'send', Em.K);
  578. });
  579. afterEach(function () {
  580. App.router.send.restore();
  581. });
  582. it('should go next if not isSubmitDisabled', function () {
  583. c.reopen({isSubmitDisabled: false});
  584. c.submit();
  585. expect(App.router.send.calledWith('next')).to.equal(true);
  586. });
  587. it('shouldn\'t go next if submitDisabled true', function () {
  588. sinon.stub(c, 'getIsSubmitDisabled', Em.K);
  589. c.reopen({submitDisabled: true});
  590. c.submit();
  591. c.getIsSubmitDisabled.restore();
  592. expect(App.router.send.called).to.equal(false);
  593. });
  594. });
  595. describe('#removeComponent', function () {
  596. var tests = Em.A([
  597. {
  598. componentName: 'c1',
  599. serviceComponentId: 1,
  600. selectedServicesMasters: Em.A([]),
  601. hosts: [],
  602. m: 'empty selectedServicesMasters',
  603. e: false
  604. },
  605. {
  606. componentName: 'ZOOKEPEER_SERVER',
  607. serviceComponentId: 1,
  608. selectedServicesMasters: Em.A([
  609. Em.Object.create({serviceComponentId: 1, component_name: 'HBASE_SERVER'})
  610. ]),
  611. hosts: [],
  612. m: 'no such components',
  613. e: false
  614. },
  615. {
  616. componentName: 'ZOOKEPEER_SERVER',
  617. serviceComponentId: 1,
  618. selectedServicesMasters: Em.A([
  619. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER'})
  620. ]),
  621. hosts: [],
  622. m: 'component is only 1',
  623. e: false
  624. },
  625. {
  626. componentName: 'ZOOKEPEER_SERVER',
  627. serviceComponentId: 2,
  628. selectedServicesMasters: Em.A([
  629. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  630. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  631. ]),
  632. hosts: [
  633. {},
  634. {}
  635. ],
  636. m: 'two components, add allowed, remove not allowed',
  637. e: true,
  638. showAddControl: true,
  639. showRemoveControl: false
  640. },
  641. {
  642. componentName: 'ZOOKEPEER_SERVER',
  643. serviceComponentId: 2,
  644. selectedServicesMasters: Em.A([
  645. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  646. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  647. ]),
  648. hosts: [
  649. {}
  650. ],
  651. m: 'two components, add not allowed, remove not allowed',
  652. e: true,
  653. showAddControl: false,
  654. showRemoveControl: false
  655. },
  656. {
  657. componentName: 'ZOOKEPEER_SERVER',
  658. serviceComponentId: 2,
  659. selectedServicesMasters: Em.A([
  660. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  661. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  662. Em.Object.create({serviceComponentId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
  663. ]),
  664. hosts: [
  665. {},
  666. {}
  667. ],
  668. m: 'three components, add not allowed, remove allowed',
  669. e: true,
  670. showAddControl: false,
  671. showRemoveControl: true
  672. },
  673. {
  674. componentName: 'ZOOKEPEER_SERVER',
  675. serviceComponentId: 2,
  676. selectedServicesMasters: Em.A([
  677. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  678. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  679. Em.Object.create({serviceComponentId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
  680. ]),
  681. hosts: [
  682. {},
  683. {},
  684. {}
  685. ],
  686. m: 'three components, add allowed, remove allowed',
  687. e: true,
  688. showAddControl: true,
  689. showRemoveControl: true
  690. }
  691. ]);
  692. tests.forEach(function (test) {
  693. it(test.m, function () {
  694. c.set('selectedServicesMasters', test.selectedServicesMasters);
  695. c.set('hosts', test.hosts);
  696. expect(c.removeComponent(test.componentName, test.serviceComponentId)).to.equal(test.e);
  697. if (test.e) {
  698. expect(c.get('selectedServicesMasters.lastObject.showRemoveControl')).to.equal(test.showRemoveControl);
  699. expect(c.get('selectedServicesMasters.lastObject.showAddControl')).to.equal(test.showAddControl);
  700. }
  701. })
  702. });
  703. });
  704. describe('#addComponent', function () {
  705. var tests = Em.A([
  706. {
  707. componentName: 'c1',
  708. selectedServicesMasters: Em.A([]),
  709. hosts: [],
  710. m: 'empty selectedServicesMasters',
  711. e: false
  712. },
  713. {
  714. componentName: 'ZOOKEPEER_SERVER',
  715. selectedServicesMasters: Em.A([
  716. Em.Object.create({serviceComponentId: 1, component_name: 'HBASE_SERVER'})
  717. ]),
  718. hosts: [],
  719. m: 'no such components',
  720. e: false
  721. },
  722. {
  723. componentName: 'ZOOKEPEER_SERVER',
  724. selectedServicesMasters: Em.A([
  725. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER'})
  726. ]),
  727. hosts: [],
  728. m: 'one component, 0 hosts',
  729. e: false
  730. },
  731. {
  732. componentName: 'ZOOKEPEER_SERVER',
  733. selectedServicesMasters: Em.A([
  734. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  735. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  736. ]),
  737. hosts: [Em.Object.create({}), Em.Object.create({})],
  738. m: 'two components, two hosts',
  739. e: false
  740. },
  741. {
  742. componentName: 'ZOOKEPEER_SERVER',
  743. selectedServicesMasters: Em.A([
  744. Em.Object.create({serviceComponentId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  745. Em.Object.create({serviceComponentId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  746. ]),
  747. hosts: [Em.Object.create({}), Em.Object.create({}), Em.Object.create({})],
  748. m: 'two components, 3 hosts',
  749. e: true
  750. }
  751. ]);
  752. tests.forEach(function (test) {
  753. it(test.m, function () {
  754. c.set('selectedServicesMasters', test.selectedServicesMasters);
  755. c.set('hosts', test.hosts);
  756. expect(c.addComponent(test.componentName)).to.equal(test.e);
  757. });
  758. });
  759. });
  760. describe('#title', function () {
  761. it('should be custom title for reassignMasterController', function () {
  762. c.set('content', {controllerName: 'reassignMasterController'});
  763. expect(c.get('title')).to.equal(Em.I18n.t('installer.step5.reassign.header'));
  764. });
  765. it('should be default for other', function () {
  766. c.set('content', {controllerName: 'notReassignMasterController'});
  767. expect(c.get('title')).to.equal(Em.I18n.t('installer.step5.header'));
  768. });
  769. });
  770. describe('#masterHostMapping', function () {
  771. Em.A([
  772. {
  773. selectedServicesMasters: [
  774. Em.Object.create({selectedHost: 'h1'}),
  775. Em.Object.create({selectedHost: 'h2'}),
  776. Em.Object.create({selectedHost: 'h1'})
  777. ],
  778. hosts: [
  779. Em.Object.create({host_name: 'h1', host_info: {}}),
  780. Em.Object.create({host_name: 'h2', host_info: {}})
  781. ],
  782. m: 'Two hosts',
  783. e: [
  784. {host_name: 'h1', hostInfo: {}, masterServices: [
  785. {},
  786. {}
  787. ]},
  788. {host_name: 'h2', hostInfo: {}, masterServices: [
  789. {}
  790. ]}
  791. ]
  792. },
  793. {
  794. selectedServicesMasters: [],
  795. hosts: [],
  796. m: 'No hosts',
  797. e: []
  798. },
  799. {
  800. selectedServicesMasters: [
  801. Em.Object.create({selectedHost: 'h1'}),
  802. Em.Object.create({selectedHost: 'h1'})
  803. ],
  804. hosts: [
  805. Em.Object.create({host_name: 'h1', host_info: {}})
  806. ],
  807. m: 'One host',
  808. e: [
  809. {host_name: 'h1', hostInfo: {}, masterServices: [
  810. {},
  811. {}
  812. ]}
  813. ]
  814. }
  815. ]).forEach(function (test) {
  816. it(test.m, function () {
  817. c.reopen({
  818. selectedServicesMasters: test.selectedServicesMasters,
  819. hosts: test.hosts
  820. });
  821. var result = c.get('masterHostMapping');
  822. expect(result.length).to.equal(test.e.length);
  823. result.forEach(function (r, i) {
  824. expect(r.get('host_name')).to.equal(test.e[i].host_name);
  825. expect(r.get('masterServices.length')).to.equal(test.e[i].masterServices.length);
  826. expect(r.get('hostInfo')).to.be.an.object;
  827. });
  828. });
  829. });
  830. });
  831. });