step5_test.js 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040
  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 c;
  22. describe('App.WizardStep5Controller', function () {
  23. beforeEach(function() {
  24. c = App.WizardStep5Controller.create();
  25. });
  26. var controller = App.WizardStep5Controller.create();
  27. controller.set('content', {});
  28. var cpu = 2, memory = 4;
  29. var schemes = Em.A([
  30. {'description': 'empty condition'},
  31. {
  32. 'description': 'second host if amount more than 1',
  33. "else": 1
  34. },
  35. {
  36. 'description': 'first host if amount less than 3, third host if amount less than 6, fourth host if amount more than 5',
  37. "3": 0,
  38. "6": 2,
  39. "else": 3
  40. },
  41. {
  42. 'description': 'second host if amount less than 3, second host if amount less than 6, third host if amount less than 31, sixth host if amount more than 30',
  43. "3": 1,
  44. "6": 1,
  45. "31": 2,
  46. "else": 5
  47. }
  48. ]);
  49. var test_config = [
  50. {
  51. title: '1 host',
  52. hosts: ['host0'],
  53. equals: [0, 0, 0, 0]
  54. },
  55. {
  56. title: '2 hosts',
  57. hosts: ['host0', 'host1'],
  58. equals: [0, 1, 0, 1]
  59. },
  60. {
  61. title: '3 hosts',
  62. hosts: ['host0', 'host1', 'host2'],
  63. equals: [0, 1, 2, 1]
  64. },
  65. {
  66. title: '5 hosts',
  67. hosts: ['host0', 'host1', 'host2', 'host3', 'host4'],
  68. equals: [0, 1, 2, 1]
  69. },
  70. {
  71. title: '6 hosts',
  72. hosts: ['host0', 'host1', 'host2', 'host3', 'host4', 'host6'],
  73. equals: [0, 1, 3, 2]
  74. },
  75. {
  76. title: '10 hosts',
  77. hosts: ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9'],
  78. equals: [0, 1, 3, 2]
  79. },
  80. {
  81. title: '31 hosts',
  82. hosts: ['host0', 'host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8', 'host9', 'host10', 'host11', 'host12', 'host13', 'host14', 'host15', 'host16', 'host17', 'host18', 'host19', 'host20', 'host21', 'host22', 'host23', 'host24', 'host25', 'host26', 'host27', 'host28', 'host29', 'host30'],
  83. equals: [0, 1, 3, 5]
  84. }
  85. ];
  86. schemes.forEach(function(scheme, index) {
  87. describe('#getHostForComponent() condition: ' + scheme.description, function() {
  88. delete scheme['description'];
  89. test_config.forEach(function(test) {
  90. it(test.title, function () {
  91. controller.get('hosts').clear();
  92. test.hosts.forEach(function(_host) {
  93. controller.get('hosts').pushObject(Em.Object.create({
  94. host_name: _host,
  95. cpu: cpu,
  96. memory: memory
  97. }));
  98. });
  99. expect(controller.getHostForComponent(test.hosts.length, scheme).host_name).to.equal(test.hosts[test.equals[index]]);
  100. });
  101. });
  102. });
  103. });
  104. describe('#getZooKeeperServer', function() {
  105. it('should be array with three host names if hosts number more than three', function() {
  106. var hosts = [
  107. {host_name: 'host1'},
  108. {host_name: 'host2'},
  109. {host_name: 'host3'}
  110. ];
  111. controller.set('hosts', hosts);
  112. expect(controller.getZooKeeperServer(hosts.length)).to.eql(['host1', 'host2', 'host3']);
  113. });
  114. it('should be array with one host names if hosts number less than three', function() {
  115. var hosts = [
  116. {host_name: 'host1'},
  117. {host_name: 'host2'}
  118. ];
  119. controller.set('hosts', hosts);
  120. expect(controller.getZooKeeperServer(hosts.length)).to.eql(['host1']);
  121. });
  122. });
  123. describe('#getServerHost', function() {
  124. it('should be host name if one host ', function() {
  125. var hosts = [
  126. {host_name: 'host1'}
  127. ];
  128. controller.set('hosts', hosts);
  129. expect(controller.getServerHost(hosts.length)).to.eql('host1');
  130. });
  131. it('should be host name if hosts number more than one', function() {
  132. var hosts = [
  133. {host_name: 'host1'},
  134. {host_name: 'host2'}
  135. ];
  136. controller.set('hosts', hosts);
  137. expect(controller.getServerHost(hosts.length)).to.eql('host1');
  138. });
  139. it('should be host name different from localhost if hosts number more than one', function() {
  140. var hosts = [
  141. {host_name: location.hostname},
  142. {host_name: 'host2'}
  143. ];
  144. //first host_name is empty string, because of location.hostname = "" in console,
  145. //to implement current test case
  146. controller.set('hosts', hosts);
  147. expect(controller.getServerHost(hosts.length)).to.eql('host2');
  148. });
  149. });
  150. controller.set('content', {});
  151. describe('#isReassignWizard', function() {
  152. it('true if content.controllerName is reassignMasterController', function() {
  153. controller.set('content.controllerName', 'reassignMasterController');
  154. expect(controller.get('isReassignWizard')).to.equal(true);
  155. });
  156. it('false if content.controllerName is not reassignMasterController', function() {
  157. controller.set('content.controllerName', 'mainController');
  158. expect(controller.get('isReassignWizard')).to.equal(false);
  159. });
  160. });
  161. describe('#isAddServiceWizard', function() {
  162. it('true if content.controllerName is addServiceController', function() {
  163. controller.set('content.controllerName', 'addServiceController');
  164. expect(controller.get('isAddServiceWizard')).to.equal(true);
  165. });
  166. it('false if content.controllerName is not addServiceController', function() {
  167. controller.set('content.controllerName', 'mainController');
  168. expect(controller.get('isAddServiceWizard')).to.equal(false);
  169. });
  170. });
  171. describe('#isReassignHive', function() {
  172. var tests = Em.A([
  173. {
  174. servicesMasters: Em.A([{component_name: 'HIVE_SERVER'}]),
  175. controllerName: 'reassignMasterController',
  176. e: true
  177. },
  178. {
  179. servicesMasters: Em.A([{component_name: 'HIVE_SERVER'}]),
  180. controllerName: 'addServiceController',
  181. e: false
  182. },
  183. {
  184. servicesMasters: Em.A([{component_name: 'ZOOKEEPER_SERVER'}]),
  185. controllerName: 'reassignMasterController',
  186. e: false
  187. },
  188. {
  189. servicesMasters: Em.A([{component_name: 'ZOOKEEPER_SERVER'}]),
  190. controllerName: 'addServiceController',
  191. e: false
  192. }
  193. ]);
  194. tests.forEach(function(test) {
  195. it(test.controllerName + ' ' + test.servicesMasters.mapProperty('component_name').join(','), function() {
  196. controller.set('content.controllerName', test.controllerName);
  197. controller.set('servicesMasters', test.servicesMasters);
  198. expect(controller.get('isReassignHive')).to.equal(test.e);
  199. });
  200. });
  201. });
  202. describe('#sortHosts', function() {
  203. var tests = Em.A([
  204. {
  205. hosts: [
  206. Em.Object.create({memory: 4, cpu: 1, host_name: 'host1', id: 1}),
  207. Em.Object.create({memory: 3, cpu: 1, host_name: 'host2', id: 2}),
  208. Em.Object.create({memory: 2, cpu: 1, host_name: 'host3', id: 3}),
  209. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
  210. ],
  211. m: 'memory',
  212. e: [1,2,3,4]
  213. },
  214. {
  215. hosts: [
  216. Em.Object.create({memory: 1, cpu: 4, host_name: 'host1', id: 1}),
  217. Em.Object.create({memory: 1, cpu: 3, host_name: 'host2', id: 2}),
  218. Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 3}),
  219. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 4})
  220. ],
  221. m: 'cpu',
  222. e: [1,2,3,4]
  223. },
  224. {
  225. hosts: [
  226. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 1}),
  227. Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 2}),
  228. Em.Object.create({memory: 1, cpu: 1, host_name: 'host3', id: 3}),
  229. Em.Object.create({memory: 1, cpu: 1, host_name: 'host1', id: 4})
  230. ],
  231. m: 'host_name',
  232. e: [4,2,3,1]
  233. },
  234. {
  235. hosts: [
  236. Em.Object.create({memory: 2, cpu: 1, host_name: 'host1', id: 1}),
  237. Em.Object.create({memory: 1, cpu: 2, host_name: 'host3', id: 2}),
  238. Em.Object.create({memory: 1, cpu: 1, host_name: 'host4', id: 3}),
  239. Em.Object.create({memory: 1, cpu: 1, host_name: 'host2', id: 4})
  240. ],
  241. m: 'mix',
  242. e: [1,2,4,3]
  243. }
  244. ]);
  245. tests.forEach(function(test) {
  246. it(test.m, function() {
  247. var hosts = Em.copy(test.hosts);
  248. controller.sortHosts(hosts);
  249. expect(Em.A(hosts).mapProperty('id')).to.eql(test.e);
  250. });
  251. });
  252. });
  253. describe('#renderHostInfo', function() {
  254. var tests = Em.A([
  255. {
  256. hosts: {
  257. h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'INIT'},
  258. h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'INIT'},
  259. h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'INIT'},
  260. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'INIT'}
  261. },
  262. m: 'no one host is REGISTERED',
  263. e: []
  264. },
  265. {
  266. hosts: {
  267. h1: {memory: 4, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
  268. h2: {memory: 3, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
  269. h3: {memory: 2, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
  270. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
  271. },
  272. m: 'all hosts are REGISTERED, memory',
  273. e: ['host1', 'host2', 'host3', 'host4']
  274. },
  275. {
  276. hosts: {
  277. h1: {memory: 1, cpu: 4, name: 'host1', bootStatus: 'REGISTERED'},
  278. h2: {memory: 1, cpu: 3, name: 'host2', bootStatus: 'REGISTERED'},
  279. h3: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'REGISTERED'},
  280. h4: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'}
  281. },
  282. m: 'all hosts are REGISTERED, cpu',
  283. e: ['host1', 'host2', 'host3', 'host4']
  284. },
  285. {
  286. hosts: {
  287. h1: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
  288. h2: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'REGISTERED'},
  289. h3: {memory: 1, cpu: 1, name: 'host3', bootStatus: 'REGISTERED'},
  290. h4: {memory: 1, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'}
  291. },
  292. m: 'all hosts are REGISTERED, host_name',
  293. e: ['host1', 'host2', 'host3', 'host4']
  294. },
  295. {
  296. hosts: {
  297. h1: {memory: 2, cpu: 1, name: 'host1', bootStatus: 'REGISTERED'},
  298. h2: {memory: 1, cpu: 2, name: 'host3', bootStatus: 'INIT'},
  299. h3: {memory: 1, cpu: 1, name: 'host4', bootStatus: 'REGISTERED'},
  300. h4: {memory: 1, cpu: 1, name: 'host2', bootStatus: 'INIT'}
  301. },
  302. m: 'mix',
  303. e: ['host1', 'host4']
  304. }
  305. ]);
  306. tests.forEach(function(test) {
  307. it(test.m, function() {
  308. controller.set('content', {hosts: test.hosts});
  309. controller.renderHostInfo();
  310. var r = controller.get('hosts');
  311. expect(Em.A(r).mapProperty('host_name')).to.eql(test.e);
  312. });
  313. });
  314. });
  315. describe('#hasHiveServer', function() {
  316. var tests = Em.A([
  317. {
  318. selectedServicesMasters: Em.A([{component_name: 'HIVE_SERVER'}]),
  319. controllerName: 'reassignMasterController',
  320. e: false
  321. },
  322. {
  323. selectedServicesMasters: Em.A([{component_name: 'HIVE_SERVER'}]),
  324. controllerName: 'addServiceController',
  325. e: true
  326. },
  327. {
  328. selectedServicesMasters: Em.A([{component_name: 'ANOTHER'}]),
  329. controllerName: 'addServiceController',
  330. e: false
  331. },
  332. {
  333. selectedServicesMasters: Em.A([{component_name: 'ANOTHER'}]),
  334. controllerName: 'reassignMasterController',
  335. e: false
  336. }
  337. ]);
  338. tests.forEach(function(test) {
  339. it(test.controllerName + ' ' + test.selectedServicesMasters.mapProperty('component_name').join(','), function() {
  340. controller.set('content.controllerName', test.controllerName);
  341. controller.set('selectedServicesMasters', test.selectedServicesMasters);
  342. expect(controller.get('hasHiveServer')).to.equal(test.e);
  343. });
  344. });
  345. });
  346. describe('#selectHost', function() {
  347. var tests = Em.A([
  348. {componentName: 'KERBEROS_SERVER', hostsCount: 1, e: 'host1'},
  349. {componentName: 'KERBEROS_SERVER', hostsCount: 3, e: 'host2'},
  350. {componentName: 'KERBEROS_SERVER', hostsCount: 6, e: 'host4'},
  351. {componentName: 'KERBEROS_SERVER', hostsCount: 31, e: 'host6'},
  352. {componentName: 'KERBEROS_SERVER', hostsCount: 32, e: 'host6'},
  353. {componentName: 'NAMENODE', hostsCount: 1, e: 'host1'},
  354. {componentName: 'NAMENODE', hostsCount: 2, e: 'host1'},
  355. {componentName: 'SECONDARY_NAMENODE', hostsCount: 1, e: 'host1'},
  356. {componentName: 'SECONDARY_NAMENODE', hostsCount: 2, e: 'host2'},
  357. {componentName: 'JOBTRACKER', hostsCount: 1, e: 'host1'},
  358. {componentName: 'JOBTRACKER', hostsCount: 3, e: 'host2'},
  359. {componentName: 'JOBTRACKER', hostsCount: 6, e: 'host2'},
  360. {componentName: 'JOBTRACKER', hostsCount: 31, e: 'host3'},
  361. {componentName: 'JOBTRACKER', hostsCount: 32, e: 'host3'},
  362. {componentName: 'HISTORYSERVER', hostsCount: 1, e: 'host1'},
  363. {componentName: 'HISTORYSERVER', hostsCount: 3, e: 'host2'},
  364. {componentName: 'HISTORYSERVER', hostsCount: 6, e: 'host2'},
  365. {componentName: 'HISTORYSERVER', hostsCount: 31, e: 'host3'},
  366. {componentName: 'HISTORYSERVER', hostsCount: 32, e: 'host3'},
  367. {componentName: 'RESOURCEMANAGER', hostsCount: 1, e: 'host1'},
  368. {componentName: 'RESOURCEMANAGER', hostsCount: 3, e: 'host2'},
  369. {componentName: 'RESOURCEMANAGER', hostsCount: 6, e: 'host2'},
  370. {componentName: 'RESOURCEMANAGER', hostsCount: 31, e: 'host3'},
  371. {componentName: 'RESOURCEMANAGER', hostsCount: 32, e: 'host3'},
  372. {componentName: 'HBASE_MASTER', hostsCount: 1, e: ['host1']},
  373. {componentName: 'HBASE_MASTER', hostsCount: 3, e: ['host1']},
  374. {componentName: 'HBASE_MASTER', hostsCount: 6, e: ['host3']},
  375. {componentName: 'HBASE_MASTER', hostsCount: 31, e: ['host4']},
  376. {componentName: 'HBASE_MASTER', hostsCount: 32, e: ['host4']},
  377. {componentName: 'OOZIE_SERVER', hostsCount: 1, e: 'host1'},
  378. {componentName: 'OOZIE_SERVER', hostsCount: 3, e: 'host2'},
  379. {componentName: 'OOZIE_SERVER', hostsCount: 6, e: 'host3'},
  380. {componentName: 'OOZIE_SERVER', hostsCount: 31, e: 'host4'},
  381. {componentName: 'OOZIE_SERVER', hostsCount: 32, e: 'host4'},
  382. {componentName: 'HIVE_SERVER', hostsCount: 1, e: 'host1'},
  383. {componentName: 'HIVE_SERVER', hostsCount: 3, e: 'host2'},
  384. {componentName: 'HIVE_SERVER', hostsCount: 6, e: 'host3'},
  385. {componentName: 'HIVE_SERVER', hostsCount: 31, e: 'host5'},
  386. {componentName: 'HIVE_SERVER', hostsCount: 32, e: 'host5'},
  387. {componentName: 'HIVE_METASTORE', hostsCount: 1, e: 'host1'},
  388. {componentName: 'HIVE_METASTORE', hostsCount: 3, e: 'host2'},
  389. {componentName: 'HIVE_METASTORE', hostsCount: 6, e: 'host3'},
  390. {componentName: 'HIVE_METASTORE', hostsCount: 31, e: 'host5'},
  391. {componentName: 'HIVE_METASTORE', hostsCount: 32, e: 'host5'},
  392. {componentName: 'WEBHCAT_SERVER', hostsCount: 1, e: 'host1'},
  393. {componentName: 'WEBHCAT_SERVER', hostsCount: 3, e: 'host2'},
  394. {componentName: 'WEBHCAT_SERVER', hostsCount: 6, e: 'host3'},
  395. {componentName: 'WEBHCAT_SERVER', hostsCount: 31, e: 'host5'},
  396. {componentName: 'WEBHCAT_SERVER', hostsCount: 32, e: 'host5'},
  397. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 1, e: 'host1'},
  398. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 3, e: 'host2'},
  399. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 6, e: 'host2'},
  400. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 31, e: 'host3'},
  401. {componentName: 'APP_TIMELINE_SERVER', hostsCount: 32, e: 'host3'},
  402. {componentName: 'FALCON_SERVER', hostsCount: 1, e: 'host1'},
  403. {componentName: 'FALCON_SERVER', hostsCount: 3, e: 'host2'},
  404. {componentName: 'FALCON_SERVER', hostsCount: 6, e: 'host3'},
  405. {componentName: 'FALCON_SERVER', hostsCount: 31, e: 'host4'},
  406. {componentName: 'FALCON_SERVER', hostsCount: 32, e: 'host4'},
  407. ]);
  408. tests.forEach(function(test) {
  409. it(test.componentName + ' ' + test.hostsCount, function() {
  410. controller.set('hosts', d3.range(1, test.hostsCount + 1).map(function(i) { return {host_name: 'host' + i.toString()};}));
  411. expect(controller.selectHost(test.componentName)).to.eql(test.e);
  412. });
  413. });
  414. describe('getServerHost should be called for', function() {
  415. Em.A(['STORM_UI_SERVER','DRPC_SERVER','STORM_REST_API','NIMBUS','GANGLIA_SERVER','NAGIOS_SERVER','HUE_SERVER']).forEach(function(componentName) {
  416. it(componentName, function() {
  417. sinon.spy(controller, 'getServerHost');
  418. controller.selectHost(componentName);
  419. expect(controller.getServerHost.calledOnce).to.equal(true);
  420. controller.getServerHost.restore();
  421. });
  422. });
  423. });
  424. });
  425. describe('#last', function() {
  426. var tests = Em.A([
  427. {
  428. selectedServicesMasters: Em.A([
  429. {component_name: 'c1', indx: 1},
  430. {component_name: 'c2', indx: 2},
  431. {component_name: 'c1', indx: 2}
  432. ]),
  433. m: 'Components exists',
  434. c: 'c1',
  435. e: 2
  436. },
  437. {
  438. selectedServicesMasters: Em.A([
  439. {component_name: 'c1', indx: 1},
  440. {component_name: 'c2', indx: 2},
  441. {component_name: 'c1', indx: 2}
  442. ]),
  443. m: 'Components don\'t exists',
  444. c: 'c3',
  445. e: null
  446. }
  447. ]);
  448. tests.forEach(function(test) {
  449. it(test.m, function() {
  450. controller.set('selectedServicesMasters', test.selectedServicesMasters);
  451. if (!Em.isNone(test.e)) {
  452. expect(controller.last(test.c).indx).to.equal(test.e);
  453. }
  454. else {
  455. expect(Em.isNone(controller.last(test.c))).to.equal(true);
  456. }
  457. })
  458. });
  459. });
  460. describe('#isSubmitDisabled', function() {
  461. it('should be false if it\'s not a isReassignWizard', function() {
  462. c.set('controllerName', 'addServiceController');
  463. expect(c.get('isSubmitDisabled')).to.equal(false);
  464. });
  465. });
  466. describe('#remainingHosts', function() {
  467. it('should show count of hosts without masters', function() {
  468. c.reopen({masterHostMapping: [{}]});
  469. c.set('hosts', [{},{},{}]);
  470. expect(c.get('remainingHosts')).to.equal(2);
  471. });
  472. });
  473. describe('#clearStep', function() {
  474. var tests = Em.A([
  475. {p: 'hosts'},
  476. {p: 'selectedServicesMasters'},
  477. {p: 'servicesMasters'}
  478. ]);
  479. tests.forEach(function(test) {
  480. it('should cleanup ' + test.p, function() {
  481. c.set(test.p, [Em.Object.create({}),Em.Object.create({})]);
  482. c.clearStep();
  483. expect(c.get(test.p).length).to.equal(0);
  484. });
  485. });
  486. });
  487. describe('#updateComponent', function() {
  488. var tests = Em.A([
  489. {
  490. componentName: 'HBASE_SERVER',
  491. services: Em.A([
  492. Em.Object.create({isInstalled: true, serviceName: 'HBASE'})
  493. ]),
  494. selectedServicesMasters: Em.A([
  495. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'}),
  496. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  497. ]),
  498. hosts: Em.A([
  499. Em.Object.create({})
  500. ]),
  501. controllerName: 'addServiceController',
  502. m: 'service is installed',
  503. e: {
  504. showAddControl: true,
  505. showRemoveControl: false
  506. }
  507. },
  508. {
  509. componentName: 'HBASE_SERVER',
  510. services: Em.A([
  511. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  512. ]),
  513. selectedServicesMasters: Em.A([
  514. Em.Object.create({showAddControl: true, showRemoveControl: false, component_name: 'HBASE_SERVER'})
  515. ]),
  516. hosts: Em.A([
  517. Em.Object.create({})
  518. ]),
  519. controllerName: 'addServiceController',
  520. m: 'service not installed, but all host already have provided component',
  521. e: {
  522. showAddControl: true,
  523. showRemoveControl: false
  524. }
  525. },
  526. {
  527. componentName: 'HBASE_SERVER',
  528. services: Em.A([
  529. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  530. ]),
  531. selectedServicesMasters: Em.A([
  532. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
  533. ]),
  534. hosts: Em.A([
  535. Em.Object.create({}),
  536. Em.Object.create({})
  537. ]),
  538. controllerName: 'addServiceController',
  539. m: 'service not installed, not all host already have provided component',
  540. e: {
  541. showAddControl: true,
  542. showRemoveControl: true
  543. }
  544. },
  545. {
  546. componentName: 'HBASE_SERVER',
  547. services: Em.A([
  548. Em.Object.create({isInstalled: false, serviceName: 'HBASE'})
  549. ]),
  550. selectedServicesMasters: Em.A([
  551. Em.Object.create({showAddControl: false, showRemoveControl: true, component_name: 'HBASE_SERVER'})
  552. ]),
  553. hosts: Em.A([
  554. Em.Object.create({}),
  555. Em.Object.create({})
  556. ]),
  557. controllerName: 'reassignMasterController',
  558. m: 'service not installed, not all host already have provided component, but is reassignMasterController',
  559. e: {
  560. showAddControl: false,
  561. showRemoveControl: false
  562. }
  563. }
  564. ]);
  565. tests.forEach(function(test) {
  566. it(test.m, function() {
  567. c.reopen({
  568. content: Em.Object.create({
  569. services: test.services,
  570. controllerName: test.controllerName
  571. }),
  572. selectedServicesMasters: test.selectedServicesMasters
  573. });
  574. c.updateComponent(test.componentName);
  575. Em.keys(test.e).forEach(function(k) {
  576. expect(c.last(test.componentName).get(k)).to.equal(test.e[k]);
  577. });
  578. });
  579. });
  580. });
  581. describe('#renderComponents', function() {
  582. var tests = Em.A([
  583. {
  584. masterComponents: Em.A([
  585. {component_name: 'ZOOKEEPER_SERVER'}
  586. ]),
  587. services: Em.A([]),
  588. controllerName: 'reassignMasterController',
  589. m: 'One component',
  590. isHaEnabled: false,
  591. component_name: 'ZOOKEEPER_SERVER',
  592. e: {
  593. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  594. servicesMasters: ['ZOOKEEPER_SERVER'],
  595. showRemoveControl: [false],
  596. isInstalled: [false],
  597. zId: [1]
  598. }
  599. },
  600. {
  601. masterComponents: Em.A([
  602. {component_name: 'ZOOKEEPER_SERVER'},
  603. {component_name: 'SECONDARY_NAMENODE'}
  604. ]),
  605. services: Em.A([]),
  606. controllerName: 'addServiceController',
  607. m: 'One component',
  608. isHaEnabled: true,
  609. component_name: 'ZOOKEEPER_SERVER',
  610. e: {
  611. selectedServicesMasters: ['ZOOKEEPER_SERVER'],
  612. servicesMasters: ['ZOOKEEPER_SERVER'],
  613. showRemoveControl: [false],
  614. zId: [1]
  615. }
  616. },
  617. {
  618. masterComponents: Em.A([
  619. {component_name: 'ZOOKEEPER_SERVER'},
  620. {component_name: 'ZOOKEEPER_SERVER'}
  621. ]),
  622. services: Em.A([
  623. Em.Object.create({serviceName:'ZOOKEEPER', isInstalled: true})
  624. ]),
  625. controllerName: 'addServiceController',
  626. m: 'Two components, but service is installed',
  627. isHaEnabled: false,
  628. component_name: 'ZOOKEEPER_SERVER',
  629. e: {
  630. selectedServicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  631. servicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER'],
  632. showRemoveControl: [false, false],
  633. zId: [1, 2]
  634. }
  635. },
  636. {
  637. masterComponents: Em.A([
  638. {component_name: 'ZOOKEEPER_SERVER'},
  639. {component_name: 'ZOOKEEPER_SERVER'},
  640. {component_name: 'NAMENODE'}
  641. ]),
  642. services: Em.A([
  643. ]),
  644. controllerName: 'addServiceController',
  645. m: 'Two components, but service is installed',
  646. isHaEnabled: false,
  647. component_name: 'ZOOKEEPER_SERVER',
  648. e: {
  649. selectedServicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER', 'NAMENODE'],
  650. servicesMasters: ['ZOOKEEPER_SERVER', 'ZOOKEEPER_SERVER', 'NAMENODE'],
  651. showRemoveControl: [true, true, undefined],
  652. zId: [1, 2, 1]
  653. }
  654. }
  655. ]);
  656. tests.forEach(function(test) {
  657. beforeEach(function() {
  658. App.reopen({isHaEnabled: test.isHaEnabled});
  659. });
  660. it(test.m, function() {
  661. App.set('isHaEnabled', test.isHaEnabled);
  662. c.reopen({
  663. content: Em.Object.create({
  664. services: test.services,
  665. controllerName: test.controllerName,
  666. reassign: {component_name: test.component_name}
  667. })
  668. });
  669. c.renderComponents(test.masterComponents);
  670. expect(c.get('selectedServicesMasters').mapProperty('component_name')).to.eql(test.e.selectedServicesMasters);
  671. expect(c.get('servicesMasters').mapProperty('component_name')).to.eql(test.e.servicesMasters);
  672. expect(c.get('selectedServicesMasters').mapProperty('showRemoveControl')).to.eql(test.e.showRemoveControl);
  673. expect(c.get('selectedServicesMasters').mapProperty('zId')).to.eql(test.e.zId);
  674. if (c.get('isReasignController')) {
  675. expect(c.get('servicesMasters').mapProperty('isInstalled')).to.eql(test.e.isInstalled);
  676. }
  677. });
  678. });
  679. });
  680. describe('#updateHiveCoHosts', function() {
  681. var tests = Em.A([
  682. {
  683. selectedServicesMasters: Em.A([
  684. Em.Object.create({component_name: 'HIVE_SERVER', selectedHost: 'h1'}),
  685. Em.Object.create({component_name: 'HIVE_METASTORE', selectedHost: 'h2'}),
  686. Em.Object.create({component_name: 'WEBHCAT_SERVER', selectedHost: 'h3'})
  687. ]),
  688. servicesMasters: Em.A([
  689. Em.Object.create({component_name: 'HIVE_SERVER', selectedHost: 'h1'})
  690. ]),
  691. isReassignHive: false,
  692. m: 'should set new host for both',
  693. e: ['h1','h1','h1']
  694. },
  695. {
  696. selectedServicesMasters: Em.A([
  697. Em.Object.create({component_name: 'HIVE_SERVER', selectedHost: 'h1'}),
  698. Em.Object.create({component_name: 'HIVE_METASTORE', selectedHost: 'h2'}),
  699. Em.Object.create({component_name: 'WEBHCAT_SERVER', selectedHost: 'h3'})
  700. ]),
  701. servicesMasters: Em.A([
  702. Em.Object.create({component_name: 'HIVE_METASTORE', selectedHost: 'h1'})
  703. ]),
  704. isReassignHive: false,
  705. m: 'should set new host for WEBHCAT_SERVER',
  706. e: ['h1','h2','h1']
  707. },
  708. {
  709. selectedServicesMasters: Em.A([
  710. Em.Object.create({component_name: 'HIVE_METASTORE', selectedHost: 'h2'}),
  711. Em.Object.create({component_name: 'WEBHCAT_SERVER', selectedHost: 'h3'})
  712. ]),
  713. servicesMasters: Em.A([
  714. Em.Object.create({component_name: 'HIVE_METASTORE', selectedHost: 'h1'})
  715. ]),
  716. isReassignHive: false,
  717. m: 'missing HIVE_SERVER',
  718. e: ['h2','h3']
  719. }
  720. ]);
  721. tests.forEach(function(test) {
  722. it(test.m, function() {
  723. c.set('selectedServicesMasters', test.selectedServicesMasters);
  724. c.set('servicesMasters', test.servicesMasters);
  725. c.reopen({isReassignHive: test.isReassignHive});
  726. c.updateHiveCoHosts();
  727. expect(c.get('selectedServicesMasters').mapProperty('selectedHost')).to.eql(test.e);
  728. });
  729. });
  730. });
  731. describe('#assignHostToMaster', function() {
  732. var tests = Em.A([
  733. {
  734. componentName: 'c1',
  735. selectedHost: 'h2',
  736. zId: '1',
  737. e: {
  738. indx: 0
  739. }
  740. },
  741. {
  742. componentName: 'c2',
  743. selectedHost: 'h3',
  744. zId: '2',
  745. e: {
  746. indx: 3
  747. }
  748. },
  749. {
  750. componentName: 'c3',
  751. selectedHost: 'h1',
  752. e: {
  753. indx: 2
  754. }
  755. },
  756. {
  757. componentName: 'c2',
  758. selectedHost: 'h4',
  759. e: {
  760. indx: 1
  761. }
  762. }
  763. ]),
  764. selectedServicesMasters = Em.A([
  765. Em.Object.create({component_name: 'c1', zId: '1', selectedHost: 'h1'}),
  766. Em.Object.create({component_name: 'c2', zId: '1', selectedHost: 'h1'}),
  767. Em.Object.create({component_name: 'c3', zId: '1', selectedHost: 'h3'}),
  768. Em.Object.create({component_name: 'c2', zId: '2', selectedHost: 'h2'})
  769. ]);
  770. tests.forEach(function(test) {
  771. it(test.componentName + ' ' + test.selectedHost + ' ' + test.zId, function() {
  772. c.set('selectedServicesMasters', selectedServicesMasters);
  773. c.assignHostToMaster(test.componentName, test.selectedHost, test.zId);
  774. expect(c.get('selectedServicesMasters').objectAt(test.e.indx).get('selectedHost')).to.equal(test.selectedHost);
  775. })
  776. });
  777. });
  778. describe('#submit', function() {
  779. beforeEach(function() {
  780. sinon.spy(App.router, 'send');
  781. });
  782. afterEach(function() {
  783. App.router.send.restore();
  784. });
  785. it('should go next if not isSubmitDisabled', function() {
  786. c.reopen({isSubmitDisabled: false});
  787. c.submit();
  788. expect(App.router.send.calledWith('next')).to.equal(true);
  789. });
  790. it('shouldn\'t go next if isSubmitDisabled', function() {
  791. c.reopen({isSubmitDisabled: true});
  792. c.submit();
  793. expect(App.router.send.called).to.equal(false);
  794. });
  795. });
  796. describe('#removeComponent', function() {
  797. var tests = Em.A([
  798. {
  799. componentName: 'c1',
  800. zId: 1,
  801. selectedServicesMasters: Em.A([]),
  802. hosts: [],
  803. m: 'empty selectedServicesMasters',
  804. e: false
  805. },
  806. {
  807. componentName: 'ZOOKEPEER_SERVER',
  808. zId: 1,
  809. selectedServicesMasters: Em.A([
  810. Em.Object.create({zId: 1, component_name: 'HBASE_SERVER'})
  811. ]),
  812. hosts: [],
  813. m: 'no such components',
  814. e: false
  815. },
  816. {
  817. componentName: 'ZOOKEPEER_SERVER',
  818. zId: 1,
  819. selectedServicesMasters: Em.A([
  820. Em.Object.create({zId: 1, component_name: 'ZOOKEPEER_SERVER'})
  821. ]),
  822. hosts: [],
  823. m: 'component is only 1',
  824. e: false
  825. },
  826. {
  827. componentName: 'ZOOKEPEER_SERVER',
  828. zId: 2,
  829. selectedServicesMasters: Em.A([
  830. Em.Object.create({zId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  831. Em.Object.create({zId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  832. ]),
  833. hosts: [{},{}],
  834. m: 'two components, add allowed, remove not allowed',
  835. e: true,
  836. showAddControl: true,
  837. showRemoveControl: false
  838. },
  839. {
  840. componentName: 'ZOOKEPEER_SERVER',
  841. zId: 2,
  842. selectedServicesMasters: Em.A([
  843. Em.Object.create({zId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  844. Em.Object.create({zId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  845. ]),
  846. hosts: [{}],
  847. m: 'two components, add not allowed, remove not allowed',
  848. e: true,
  849. showAddControl: false,
  850. showRemoveControl: false
  851. },
  852. {
  853. componentName: 'ZOOKEPEER_SERVER',
  854. zId: 2,
  855. selectedServicesMasters: Em.A([
  856. Em.Object.create({zId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  857. Em.Object.create({zId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  858. Em.Object.create({zId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
  859. ]),
  860. hosts: [{},{}],
  861. m: 'three components, add not allowed, remove allowed',
  862. e: true,
  863. showAddControl: false,
  864. showRemoveControl: true
  865. },
  866. {
  867. componentName: 'ZOOKEPEER_SERVER',
  868. zId: 2,
  869. selectedServicesMasters: Em.A([
  870. Em.Object.create({zId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  871. Em.Object.create({zId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  872. Em.Object.create({zId: 3, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: true})
  873. ]),
  874. hosts: [{},{}, {}],
  875. m: 'three components, add allowed, remove allowed',
  876. e: true,
  877. showAddControl: true,
  878. showRemoveControl: true
  879. }
  880. ]);
  881. tests.forEach(function(test) {
  882. it(test.m, function() {
  883. c.set('selectedServicesMasters', test.selectedServicesMasters);
  884. c.set('hosts', test.hosts);
  885. expect(c.removeComponent(test.componentName, test.zId)).to.equal(test.e);
  886. if(test.e) {
  887. expect(c.get('selectedServicesMasters.lastObject.showRemoveControl')).to.equal(test.showRemoveControl);
  888. expect(c.get('selectedServicesMasters.lastObject.showAddControl')).to.equal(test.showAddControl);
  889. }
  890. })
  891. });
  892. });
  893. describe('#addComponent', function() {
  894. var tests = Em.A([
  895. {
  896. componentName: 'c1',
  897. selectedServicesMasters: Em.A([]),
  898. hosts: [],
  899. m: 'empty selectedServicesMasters',
  900. e: false
  901. },
  902. {
  903. componentName: 'ZOOKEPEER_SERVER',
  904. selectedServicesMasters: Em.A([
  905. Em.Object.create({zId: 1, component_name: 'HBASE_SERVER'})
  906. ]),
  907. hosts: [],
  908. m: 'no such components',
  909. e: false
  910. },
  911. {
  912. componentName: 'ZOOKEPEER_SERVER',
  913. selectedServicesMasters: Em.A([
  914. Em.Object.create({zId: 1, component_name: 'ZOOKEPEER_SERVER'})
  915. ]),
  916. hosts: [],
  917. m: 'one component, 0 hosts',
  918. e: false
  919. },
  920. {
  921. componentName: 'ZOOKEPEER_SERVER',
  922. selectedServicesMasters: Em.A([
  923. Em.Object.create({zId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  924. Em.Object.create({zId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  925. ]),
  926. hosts: [Em.Object.create({}), Em.Object.create({})],
  927. m: 'two components, two hosts',
  928. e: false
  929. },
  930. {
  931. componentName: 'ZOOKEPEER_SERVER',
  932. selectedServicesMasters: Em.A([
  933. Em.Object.create({zId: 1, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false}),
  934. Em.Object.create({zId: 2, component_name: 'ZOOKEPEER_SERVER', showAddControl: false, showRemoveControl: false})
  935. ]),
  936. hosts: [Em.Object.create({}), Em.Object.create({}), Em.Object.create({})],
  937. m: 'two components, 3 hosts',
  938. e: true
  939. }
  940. ]);
  941. tests.forEach(function(test) {
  942. it(test.m, function() {
  943. c.set('selectedServicesMasters', test.selectedServicesMasters);
  944. c.set('hosts', test.hosts);
  945. expect(c.addComponent(test.componentName)).to.equal(test.e);
  946. });
  947. });
  948. });
  949. describe('#loadStep', function() {
  950. var methods = Em.A(['clearStep', 'renderHostInfo', 'renderComponents', 'loadComponents']);
  951. describe('should call several methods', function() {
  952. beforeEach(function() {
  953. methods.forEach(function(m) {
  954. sinon.spy(c, m);
  955. });
  956. c.reopen({content: {services: Em.A([])}});
  957. });
  958. afterEach(function() {
  959. methods.forEach(function(m) {
  960. c[m].restore();
  961. });
  962. });
  963. methods.forEach(function(m) {
  964. it(m, function() {
  965. c.loadStep();
  966. expect(c[m].calledOnce).to.equal(true);
  967. });
  968. });
  969. });
  970. it('should update HBASE if App.supports.multipleHBaseMasters is true', function() {
  971. App.set('supports.multipleHBaseMasters', true);
  972. sinon.spy(c, 'updateComponent');
  973. c.reopen({content: {services: Em.A([])}});
  974. c.loadStep();
  975. expect(c.updateComponent.calledTwice).to.equal(true);
  976. c.updateComponent.restore();
  977. });
  978. });
  979. });