step5_test.js 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356
  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. describe('#title', function() {
  980. it('should be custom title for reassignMasterController', function() {
  981. c.set('content', {controllerName: 'reassignMasterController'});
  982. expect(c.get('title')).to.equal(Em.I18n.t('installer.step5.reassign.header'));
  983. });
  984. it('should be default for other', function() {
  985. c.set('content', {controllerName: 'notReassignMasterController'});
  986. expect(c.get('title')).to.equal(Em.I18n.t('installer.step5.header'));
  987. });
  988. });
  989. describe('#isSubmitDisabled', function() {
  990. it('should be false if no isReassignWizard', function() {
  991. c.reopen({isReassignWizard: false});
  992. expect(c.get('isSubmitDisabled')).to.equal(false);
  993. });
  994. it('should be true if isReassignWizard', function() {
  995. var hostComponents = Em.A([
  996. Em.Object.create({componentName: 'c1', host: Em.Object.create({hostName: 'h1'})}),
  997. Em.Object.create({componentName: 'c1', host: Em.Object.create({hostName: 'h2'})})
  998. ]);
  999. sinon.stub(App.HostComponent, 'find', function() {
  1000. return hostComponents;
  1001. });
  1002. c.reopen({
  1003. isReassignWizard: true,
  1004. content:{
  1005. reassign:{
  1006. component_name: 'c1'
  1007. }
  1008. },
  1009. servicesMasters: [
  1010. {selectedHost: 'h5'},
  1011. {selectedHost: 'h4'},
  1012. {selectedHost: 'h3'}
  1013. ]
  1014. });
  1015. expect(c.get('isSubmitDisabled')).to.equal(true);
  1016. App.HostComponent.find.restore();
  1017. });
  1018. it('should be false if isReassignWizard', function() {
  1019. var hostComponents = Em.A([
  1020. Em.Object.create({componentName: 'c1', host: Em.Object.create({hostName: 'h1'})}),
  1021. Em.Object.create({componentName: 'c1', host: Em.Object.create({hostName: 'h2'})}),
  1022. Em.Object.create({componentName: 'c1', host: Em.Object.create({hostName: 'h3'})})
  1023. ]);
  1024. sinon.stub(App.HostComponent, 'find', function() {
  1025. return hostComponents;
  1026. });
  1027. c.reopen({
  1028. isReassignWizard: true,
  1029. content:{
  1030. reassign:{
  1031. component_name: 'c1'
  1032. }
  1033. },
  1034. servicesMasters: [
  1035. {selectedHost: 'h1'},
  1036. {selectedHost: 'h2'}
  1037. ]
  1038. });
  1039. expect(c.get('isSubmitDisabled')).to.equal(false);
  1040. App.HostComponent.find.restore();
  1041. });
  1042. });
  1043. describe('#masterHostMapping', function() {
  1044. Em.A([
  1045. {
  1046. selectedServicesMasters: [
  1047. Em.Object.create({selectedHost: 'h1'}),
  1048. Em.Object.create({selectedHost: 'h2'}),
  1049. Em.Object.create({selectedHost: 'h1'})
  1050. ],
  1051. hosts: [
  1052. Em.Object.create({host_name: 'h1', host_info: {}}),
  1053. Em.Object.create({host_name: 'h2', host_info: {}})
  1054. ],
  1055. m: 'Two hosts',
  1056. e: [
  1057. {host_name: 'h1', hostInfo: {}, masterServices: [{}, {}]},
  1058. {host_name: 'h2', hostInfo: {}, masterServices: [{}]}
  1059. ]
  1060. },
  1061. {
  1062. selectedServicesMasters: [],
  1063. hosts: [],
  1064. m: 'No hosts',
  1065. e: []
  1066. },
  1067. {
  1068. selectedServicesMasters: [
  1069. Em.Object.create({selectedHost: 'h1'}),
  1070. Em.Object.create({selectedHost: 'h1'})
  1071. ],
  1072. hosts: [
  1073. Em.Object.create({host_name: 'h1', host_info: {}})
  1074. ],
  1075. m: 'One host',
  1076. e: [
  1077. {host_name: 'h1', hostInfo: {}, masterServices: [{}, {}]}
  1078. ]
  1079. }
  1080. ]).forEach(function (test) {
  1081. it(test.m, function () {
  1082. c.reopen({
  1083. selectedServicesMasters: test.selectedServicesMasters,
  1084. hosts: test.hosts
  1085. });
  1086. var result = c.get('masterHostMapping');
  1087. expect(result.length).to.equal(test.e.length);
  1088. result.forEach(function(r, i) {
  1089. expect(r.get('host_name')).to.equal(test.e[i].host_name);
  1090. expect(r.get('masterServices.length')).to.equal(test.e[i].masterServices.length);
  1091. expect(r.get('hostInfo')).to.be.an.object;
  1092. });
  1093. });
  1094. });
  1095. });
  1096. describe('#loadComponents', function() {
  1097. Em.A([
  1098. {
  1099. services: [
  1100. Em.Object.create({isSelected: true, serviceName: 's1'})
  1101. ],
  1102. masterComponents: Em.A([
  1103. Em.Object.create({displayName: 'c1d', serviceName: 's1', componentName: 'c1', isShownOnInstallerAssignMasterPage: true})
  1104. ]),
  1105. masterComponentHosts: Em.A([
  1106. {component: 'c1', hostName: 'h2', isInstalled: true}
  1107. ]),
  1108. selectHost: 'h3',
  1109. m: 'savedComponent exists',
  1110. e: {
  1111. component_name: 'c1',
  1112. display_name: 'c1d',
  1113. selectedHost: 'h2',
  1114. isInstalled: true,
  1115. serviceId: 's1'
  1116. }
  1117. },
  1118. {
  1119. services: [
  1120. Em.Object.create({isSelected: true, serviceName: 's1'})
  1121. ],
  1122. masterComponents: Em.A([
  1123. Em.Object.create({displayName: 'c1d', serviceName: 's1', componentName: 'c1', isShownOnInstallerAssignMasterPage: true})
  1124. ]),
  1125. masterComponentHosts: Em.A([
  1126. {component: 'c2', hostName: 'h2', isInstalled: true}
  1127. ]),
  1128. selectHost: 'h3',
  1129. m: 'savedComponent doesn\'t exist',
  1130. e: {
  1131. component_name: 'c1',
  1132. display_name: 'c1d',
  1133. selectedHost: 'h3',
  1134. isInstalled: false,
  1135. serviceId: 's1'
  1136. }
  1137. },
  1138. {
  1139. services: [
  1140. Em.Object.create({isSelected: true, serviceName: 's1'})
  1141. ],
  1142. masterComponents: Em.A([
  1143. Em.Object.create({displayName: 'c1d', serviceName: 's1', componentName: 'ZOOKEEPER_SERVER', isShownOnInstallerAssignMasterPage: true})
  1144. ]),
  1145. masterComponentHosts: Em.A([
  1146. {component: 'c1', hostName: 'h2', isInstalled: true}
  1147. ]),
  1148. selectHost: ['h3'],
  1149. m: 'component ZOOKEEPER_SERVER',
  1150. e: {
  1151. component_name: 'ZOOKEEPER_SERVER',
  1152. display_name: 'c1d',
  1153. selectedHost: 'h3',
  1154. isInstalled: false,
  1155. serviceId: 's1',
  1156. isHiveCoHost: false
  1157. }
  1158. },
  1159. {
  1160. services: [
  1161. Em.Object.create({isSelected: true, serviceName: 's1'})
  1162. ],
  1163. masterComponents: Em.A([
  1164. Em.Object.create({displayName: 'c1d', serviceName: 's1', componentName: 'HBASE_MASTER', isShownOnInstallerAssignMasterPage: true})
  1165. ]),
  1166. masterComponentHosts: Em.A([
  1167. {component: 'c1', hostName: 'h2', isInstalled: true}
  1168. ]),
  1169. selectHost: ['h3'],
  1170. m: 'component HBASE_MASTER',
  1171. e: {
  1172. component_name: 'HBASE_MASTER',
  1173. display_name: 'c1d',
  1174. selectedHost: 'h3',
  1175. isInstalled: false,
  1176. serviceId: 's1',
  1177. isHiveCoHost: false
  1178. }
  1179. },
  1180. {
  1181. services: [
  1182. Em.Object.create({isSelected: true, serviceName: 's1'})
  1183. ],
  1184. masterComponents: Em.A([
  1185. Em.Object.create({displayName: 'c1d', serviceName: 's1', componentName: 'ZOOKEEPER_SERVER', isShownOnInstallerAssignMasterPage: true})
  1186. ]),
  1187. masterComponentHosts: Em.A([
  1188. {component: 'ZOOKEEPER_SERVER', hostName: 'h2', isInstalled: true}
  1189. ]),
  1190. selectHost: ['h3'],
  1191. m: 'component ZOOKEEPER_SERVER(2)',
  1192. e: {
  1193. component_name: 'ZOOKEEPER_SERVER',
  1194. display_name: 'c1d',
  1195. selectedHost: 'h2',
  1196. isInstalled: true,
  1197. serviceId: 's1',
  1198. isHiveCoHost: false
  1199. }
  1200. },
  1201. {
  1202. services: [
  1203. Em.Object.create({isSelected: true, serviceName: 's1'})
  1204. ],
  1205. masterComponents: Em.A([
  1206. Em.Object.create({displayName: 'c1d', serviceName: 's1', componentName: 'HBASE_MASTER', isShownOnInstallerAssignMasterPage: true})
  1207. ]),
  1208. masterComponentHosts: Em.A([
  1209. {component: 'HBASE_MASTER', hostName: 'h2', isInstalled: true}
  1210. ]),
  1211. selectHost: ['h3'],
  1212. m: 'component HBASE_MASTER (2)',
  1213. e: {
  1214. component_name: 'HBASE_MASTER',
  1215. display_name: 'c1d',
  1216. selectedHost: 'h2',
  1217. isInstalled: true,
  1218. serviceId: 's1',
  1219. isHiveCoHost: false
  1220. }
  1221. }
  1222. ]).forEach(function (test) {
  1223. it(test.m, function() {
  1224. c.reopen({
  1225. content: {
  1226. services: test.services,
  1227. masterComponentHosts: test.masterComponentHosts
  1228. }
  1229. });
  1230. sinon.stub(App.StackServiceComponent, 'find', function() {
  1231. return test.masterComponents;
  1232. });
  1233. sinon.stub(c, 'selectHost', function() {
  1234. return test.selectHost;
  1235. });
  1236. var r = c.loadComponents();
  1237. App.StackServiceComponent.find.restore();
  1238. c.selectHost.restore();
  1239. expect(r.length).to.equal(1);
  1240. Em.keys(test.e).forEach(function(k) {
  1241. expect(r[0][k]).to.equal(test.e[k]);
  1242. });
  1243. });
  1244. });
  1245. });
  1246. describe('#_isHiveCoHost', function() {
  1247. Em.A([
  1248. {
  1249. componentName: 'HIVE_METASTORE',
  1250. isReassignWizard: false,
  1251. e: true
  1252. },
  1253. {
  1254. componentName: 'WEBHCAT_SERVER',
  1255. isReassignWizard: false,
  1256. e: true
  1257. },
  1258. {
  1259. componentName: 'HIVE_METASTORE',
  1260. isReassignWizard: true,
  1261. e: false
  1262. },
  1263. {
  1264. componentName: 'WEBHCAT_SERVER',
  1265. isReassignWizard: true,
  1266. e: false
  1267. },
  1268. {
  1269. componentName: 'C1',
  1270. isReassignWizard: false,
  1271. e: false
  1272. },
  1273. {
  1274. componentName: 'C1',
  1275. isReassignWizard: true,
  1276. e: false
  1277. }
  1278. ]).forEach(function (test) {
  1279. it(test.componentName.toString() + ' ' + test.isReassignWizard.toString(), function () {
  1280. c.reopen({
  1281. isReassignWizard: test.isReassignWizard
  1282. });
  1283. var r = c._isHiveCoHost(test.componentName);
  1284. expect(r).to.equal(test.e);
  1285. });
  1286. });
  1287. });
  1288. });