step4_controller_test.js 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648
  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 App = require('app');
  19. require('controllers/main/service/reassign/step4_controller');
  20. var testHelpers = require('test/helpers');
  21. describe('App.ReassignMasterWizardStep4Controller', function () {
  22. var controller = App.ReassignMasterWizardStep4Controller.create({
  23. content: Em.Object.create({
  24. reassign: Em.Object.create(),
  25. reassignHosts: Em.Object.create()
  26. })
  27. });
  28. describe('#setAdditionalConfigs()', function () {
  29. beforeEach(function () {
  30. sinon.stub(App, 'get').withArgs('isHaEnabled').returns(true);
  31. });
  32. afterEach(function () {
  33. App.get.restore();
  34. });
  35. it('Component is absent', function () {
  36. controller.set('additionalConfigsMap', []);
  37. var configs = {};
  38. expect(controller.setAdditionalConfigs(configs, 'COMP1', '')).to.be.false;
  39. expect(configs).to.eql({});
  40. });
  41. it('configs for Hadoop 2 is present', function () {
  42. controller.set('additionalConfigsMap', [
  43. {
  44. componentName: 'COMP1',
  45. configs: {
  46. 'test-site': {
  47. 'property1': '<replace-value>:1111'
  48. }
  49. },
  50. configs_Hadoop2: {
  51. 'test-site': {
  52. 'property2': '<replace-value>:2222'
  53. }
  54. }
  55. }
  56. ]);
  57. var configs = {
  58. 'test-site': {}
  59. };
  60. expect(controller.setAdditionalConfigs(configs, 'COMP1', 'host1')).to.be.true;
  61. expect(configs).to.eql({
  62. 'test-site': {
  63. 'property2': 'host1:2222'
  64. }
  65. });
  66. });
  67. it('ignore some configs for NameNode after HA', function () {
  68. controller.set('additionalConfigsMap', [
  69. {
  70. componentName: 'NAMENODE',
  71. configs: {
  72. 'test-site': {
  73. 'fs.defaultFS': '<replace-value>:1111',
  74. 'dfs.namenode.rpc-address': '<replace-value>:1111'
  75. }
  76. }
  77. }
  78. ]);
  79. var configs = {'test-site': {}};
  80. expect(controller.setAdditionalConfigs(configs, 'NAMENODE', 'host1')).to.be.true;
  81. expect(configs).to.eql({'test-site': {}});
  82. });
  83. });
  84. describe('#getHostComponentsNames()', function () {
  85. it('No host-components', function () {
  86. controller.set('hostComponents', []);
  87. expect(controller.getHostComponentsNames()).to.be.empty;
  88. });
  89. it('one host-components', function () {
  90. controller.set('hostComponents', ['COMP1']);
  91. expect(controller.getHostComponentsNames()).to.equal('Comp1');
  92. });
  93. it('ZKFC host-components', function () {
  94. controller.set('hostComponents', ['COMP1', 'ZKFC']);
  95. expect(controller.getHostComponentsNames()).to.equal('Comp1+ZKFC');
  96. });
  97. });
  98. describe('#testDBConnection', function() {
  99. beforeEach(function() {
  100. controller.set('requiredProperties', Em.A([]));
  101. controller.set('content.serviceProperties', Em.Object.create({'javax.jdo.option.ConnectionDriverName': 'mysql'}));
  102. controller.set('content.reassign.component_name', 'HIVE_SERVER');
  103. sinon.stub(controller, 'getConnectionProperty', Em.K);
  104. sinon.stub(App.router, 'get', Em.K);
  105. });
  106. afterEach(function() {
  107. controller.getConnectionProperty.restore();
  108. App.router.get.restore();
  109. });
  110. describe('tests database connection', function() {
  111. beforeEach(function () {
  112. sinon.stub(controller, 'prepareDBCheckAction', Em.K);
  113. });
  114. afterEach(function () {
  115. controller.prepareDBCheckAction.restore();
  116. });
  117. it('prepareDBCheckAction is called once', function() {
  118. controller.testDBConnection();
  119. expect(controller.prepareDBCheckAction.calledOnce).to.be.true;
  120. });
  121. });
  122. it('tests prepareDBCheckAction', function() {
  123. controller.prepareDBCheckAction();
  124. var args = testHelpers.findAjaxRequest('name', 'cluster.custom_action.create');
  125. expect(args).exists;
  126. });
  127. });
  128. describe('#removeUnneededTasks()', function () {
  129. var isHaEnabled = false;
  130. var commands;
  131. var commandsForDB;
  132. beforeEach(function () {
  133. sinon.stub(App, 'get', function () {
  134. return isHaEnabled;
  135. });
  136. commands = [
  137. { id: 1, command: 'stopRequiredServices' },
  138. { id: 2, command: 'cleanMySqlServer' },
  139. { id: 3, command: 'createHostComponents' },
  140. { id: 4, command: 'putHostComponentsInMaintenanceMode' },
  141. { id: 5, command: 'reconfigure' },
  142. { id: 6, command: 'installHostComponents' },
  143. { id: 7, command: 'startZooKeeperServers' },
  144. { id: 8, command: 'startNameNode' },
  145. { id: 9, command: 'deleteHostComponents' },
  146. { id: 10, command: 'configureMySqlServer' },
  147. { id: 11, command: 'startMySqlServer' },
  148. { id: 12, command: 'startNewMySqlServer' },
  149. { id: 13, command: 'startRequiredServices' }
  150. ];
  151. commandsForDB = [
  152. { id: 1, command: 'createHostComponents' },
  153. { id: 2, command: 'installHostComponents' },
  154. { id: 3, command: 'configureMySqlServer' },
  155. { id: 4, command: 'restartMySqlServer' },
  156. { id: 5, command: 'testDBConnection' },
  157. { id: 6, command: 'stopRequiredServices' },
  158. { id: 7, command: 'cleanMySqlServer' },
  159. { id: 8, command: 'putHostComponentsInMaintenanceMode' },
  160. { id: 9, command: 'reconfigure' },
  161. { id: 10, command: 'deleteHostComponents' },
  162. { id: 11, command: 'configureMySqlServer' },
  163. { id: 12, command: 'startRequiredServices' }
  164. ];
  165. });
  166. afterEach(function () {
  167. App.get.restore();
  168. });
  169. it('hasManualSteps is false', function () {
  170. controller.set('tasks', commands);
  171. controller.set('content.hasManualSteps', false);
  172. controller.removeUnneededTasks();
  173. expect(controller.get('tasks').mapProperty('id')).to.eql([1,3,4,5,6,9,12,13]);
  174. });
  175. it('reassign component is not NameNode and HA disabled', function () {
  176. controller.set('tasks', commands);
  177. controller.set('content.hasManualSteps', true);
  178. controller.set('content.reassign.component_name', 'COMP1');
  179. isHaEnabled = false;
  180. controller.removeUnneededTasks();
  181. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 3, 4, 5, 6]);
  182. });
  183. it('reassign component is not NameNode and HA enabled', function () {
  184. controller.set('tasks', commands);
  185. controller.set('content.hasManualSteps', true);
  186. controller.set('content.reassign.component_name', 'COMP1');
  187. isHaEnabled = true;
  188. controller.removeUnneededTasks();
  189. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 3, 4, 5, 6]);
  190. });
  191. it('reassign component is NameNode and HA disabled', function () {
  192. controller.set('tasks', commands);
  193. controller.set('content.hasManualSteps', true);
  194. controller.set('content.reassign.component_name', 'NAMENODE');
  195. isHaEnabled = false;
  196. controller.removeUnneededTasks();
  197. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 3, 4, 5, 6]);
  198. });
  199. it('reassign component is NameNode and HA enabled', function () {
  200. controller.set('tasks', commands);
  201. controller.set('content.hasManualSteps', true);
  202. controller.set('content.reassign.component_name', 'NAMENODE');
  203. isHaEnabled = true;
  204. controller.removeUnneededTasks();
  205. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 3, 4, 5, 6, 7, 8]);
  206. });
  207. it('reassign component is HiveServer and db type is mysql', function () {
  208. controller.set('tasks', commandsForDB);
  209. controller.set('content.hasManualSteps', false);
  210. controller.set('content.databaseType', 'mysql');
  211. controller.set('content.reassign.component_name', 'HIVE_SERVER');
  212. isHaEnabled = false;
  213. controller.removeUnneededTasks();
  214. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]);
  215. });
  216. it('reassign component is HiveServer and db type is not mysql', function () {
  217. controller.set('tasks', commandsForDB);
  218. controller.set('content.hasManualSteps', false);
  219. controller.set('content.databaseType', 'derby');
  220. controller.set('content.reassign.component_name', 'HIVE_SERVER');
  221. isHaEnabled = false;
  222. controller.removeUnneededTasks();
  223. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 6, 8, 9, 10, 12]);
  224. });
  225. it('reassign component is Oozie Server and db type is derby', function () {
  226. controller.set('tasks', commandsForDB);
  227. controller.set('content.hasManualSteps', true);
  228. controller.set('content.databaseType', 'derby');
  229. controller.set('content.reassign.component_name', 'OOZIE_SERVER');
  230. isHaEnabled = false;
  231. controller.removeUnneededTasks();
  232. expect(controller.get('tasks').mapProperty('id')).to.eql([1,2,6,8,9]);
  233. });
  234. it('reassign component is Oozie Server and db type is mysql', function () {
  235. controller.set('content.hasManualSteps', false);
  236. controller.set('content.databaseType', 'mysql');
  237. controller.set('content.reassign.component_name', 'OOZIE_SERVER');
  238. isHaEnabled = false;
  239. controller.set('tasks', commandsForDB);
  240. controller.removeUnneededTasks();
  241. expect(controller.get('tasks').mapProperty('id')).to.eql([1,2,3,4,5,6,7,8,9,10,11,12]);
  242. });
  243. it('reassign component is Metrics Collector', function () {
  244. controller.set('content.hasManualSteps', false);
  245. controller.set('content.databaseType', 'mysql');
  246. controller.set('content.reassign.component_name', 'METRICS_COLLECTOR');
  247. isHaEnabled = false;
  248. controller.set('tasks', commandsForDB);
  249. controller.removeUnneededTasks();
  250. expect(controller.get('tasks').mapProperty('id')).to.eql([1,2,5,6,8,9,10,12]);
  251. });
  252. it('reassign component is Mysql Server', function () {
  253. controller.set('content.hasManualSteps', false);
  254. controller.set('content.databaseType', 'mysql');
  255. controller.set('content.reassign.component_name', 'MYSQL_SERVER');
  256. isHaEnabled = false;
  257. controller.set('tasks', commandsForDB);
  258. controller.removeUnneededTasks();
  259. expect(controller.get('tasks').mapProperty('id')).to.eql([1,2,3,4,5,6,8,9,10,11,12]);
  260. });
  261. });
  262. describe("#stopRequiredServices()", function() {
  263. before(function () {
  264. sinon.stub(controller, 'stopServices', Em.K);
  265. });
  266. after(function () {
  267. controller.stopServices.restore();
  268. });
  269. it('stopServices is called with valid list of services', function() {
  270. controller.set('content.reassign.component_name', 'JOBTRACKER');
  271. controller.stopRequiredServices();
  272. expect(controller.stopServices.calledWith(['PIG', 'OOZIE'], true)).to.be.true;
  273. });
  274. });
  275. describe('#initializeTasks()', function () {
  276. beforeEach(function () {
  277. controller.set('tasks', []);
  278. sinon.stub(controller, 'getHostComponentsNames', Em.K);
  279. sinon.stub(controller, 'removeUnneededTasks', Em.K);
  280. this.mock = sinon.stub(controller, 'isComponentWithDB');
  281. });
  282. afterEach(function () {
  283. controller.removeUnneededTasks.restore();
  284. controller.getHostComponentsNames.restore();
  285. this.mock.restore();
  286. });
  287. it('No commands (isComponentWithDB = false)', function () {
  288. controller.set('commands', []);
  289. controller.set('commandsForDB', []);
  290. this.mock.returns(false);
  291. controller.initializeTasks();
  292. expect(controller.get('tasks')).to.be.empty;
  293. });
  294. it('No commands (isComponentWithDB = true)', function () {
  295. controller.set('commands', []);
  296. controller.set('commandsForDB', []);
  297. this.mock.returns(true);
  298. controller.initializeTasks();
  299. expect(controller.get('tasks')).to.be.empty;
  300. });
  301. it('One command', function () {
  302. controller.set('commands', ['COMMAND1']);
  303. controller.set('commandsForDB', ['COMMAND1']);
  304. controller.initializeTasks();
  305. expect(controller.get('tasks')[0].get('id')).to.equal(0);
  306. expect(controller.get('tasks')[0].get('command')).to.equal('COMMAND1');
  307. });
  308. });
  309. describe('#hideRollbackButton()', function () {
  310. it('No showRollback command', function () {
  311. controller.set('tasks', [Em.Object.create({
  312. showRollback: false
  313. })]);
  314. controller.hideRollbackButton();
  315. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  316. });
  317. it('showRollback command is present', function () {
  318. controller.set('tasks', [Em.Object.create({
  319. showRollback: true
  320. })]);
  321. controller.hideRollbackButton();
  322. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  323. });
  324. });
  325. describe('#onComponentsTasksSuccess()', function () {
  326. beforeEach(function () {
  327. sinon.stub(controller, 'onTaskCompleted', Em.K);
  328. });
  329. afterEach(function () {
  330. controller.onTaskCompleted.restore();
  331. });
  332. it('One host-component', function () {
  333. controller.set('multiTaskCounter', 1);
  334. controller.set('hostComponents', [
  335. {}
  336. ]);
  337. controller.onComponentsTasksSuccess();
  338. expect(controller.get('multiTaskCounter')).to.equal(0);
  339. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  340. });
  341. it('two host-components', function () {
  342. controller.set('multiTaskCounter', 2);
  343. controller.set('hostComponents', [
  344. {},
  345. {}
  346. ]);
  347. controller.onComponentsTasksSuccess();
  348. expect(controller.get('multiTaskCounter')).to.equal(1);
  349. expect(controller.onTaskCompleted.called).to.be.false;
  350. });
  351. });
  352. describe('#stopServices()', function () {
  353. it('request is sent', function () {
  354. controller.stopServices();
  355. var args = testHelpers.findAjaxRequest('name', 'common.services.update');
  356. expect(args).exists;
  357. });
  358. });
  359. describe('#createHostComponents()', function () {
  360. beforeEach(function () {
  361. sinon.stub(controller, 'createComponent', Em.K);
  362. });
  363. afterEach(function () {
  364. controller.createComponent.restore();
  365. });
  366. it('One host-component', function () {
  367. controller.set('hostComponents', ['COMP1']);
  368. controller.set('content.reassignHosts.target', 'host1');
  369. controller.set('content.reassign.service_id', 'SERVICE1');
  370. controller.createHostComponents();
  371. expect(controller.get('multiTaskCounter')).to.equal(1);
  372. expect(controller.createComponent.calledWith('COMP1', 'host1', 'SERVICE1')).to.be.true;
  373. });
  374. });
  375. describe('#onCreateComponent()', function () {
  376. beforeEach(function () {
  377. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  378. });
  379. afterEach(function () {
  380. controller.onComponentsTasksSuccess.restore();
  381. });
  382. it('onComponentsTasksSuccess is called once', function () {
  383. controller.onCreateComponent();
  384. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  385. });
  386. });
  387. describe('#putHostComponentsInMaintenanceMode()', function () {
  388. beforeEach(function(){
  389. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  390. controller.set('content.reassignHosts.source', 'source');
  391. });
  392. afterEach(function(){
  393. controller.onComponentsTasksSuccess.restore();
  394. });
  395. it('No host-components', function () {
  396. controller.set('hostComponents', []);
  397. controller.putHostComponentsInMaintenanceMode();
  398. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
  399. expect(args).not.exists;
  400. expect(controller.get('multiTaskCounter')).to.equal(0);
  401. });
  402. it('One host-components', function () {
  403. controller.set('hostComponents', [{}]);
  404. controller.putHostComponentsInMaintenanceMode();
  405. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
  406. expect(args).exists;
  407. expect(controller.get('multiTaskCounter')).to.equal(1);
  408. });
  409. });
  410. describe('#installHostComponents()', function () {
  411. beforeEach(function () {
  412. sinon.stub(controller, 'updateComponent', Em.K);
  413. });
  414. afterEach(function () {
  415. controller.updateComponent.restore();
  416. });
  417. it('No host-components', function () {
  418. controller.set('hostComponents', []);
  419. controller.installHostComponents();
  420. expect(controller.get('multiTaskCounter')).to.equal(0);
  421. expect(controller.updateComponent.called).to.be.false;
  422. });
  423. it('One host-component', function () {
  424. controller.set('hostComponents', ['COMP1']);
  425. controller.set('content.reassignHosts.target', 'host1');
  426. controller.set('content.reassign.service_id', 'SERVICE1');
  427. controller.installHostComponents();
  428. expect(controller.get('multiTaskCounter')).to.equal(1);
  429. expect(controller.updateComponent.calledWith('COMP1', 'host1', 'SERVICE1', 'Install', 1)).to.be.true;
  430. });
  431. });
  432. describe('#reconfigure()', function () {
  433. beforeEach(function () {
  434. sinon.stub(controller, 'loadConfigsTags', Em.K);
  435. });
  436. afterEach(function () {
  437. controller.loadConfigsTags.restore();
  438. });
  439. it('loadConfigsTags is called once', function () {
  440. controller.reconfigure();
  441. expect(controller.loadConfigsTags.calledOnce).to.be.true;
  442. });
  443. });
  444. describe('#loadConfigsTags()', function () {
  445. it('request is sent', function () {
  446. controller.loadConfigsTags();
  447. var args = testHelpers.findAjaxRequest('name', 'config.tags');
  448. expect(args).exists;
  449. });
  450. });
  451. describe('#getConfigUrlParams()', function () {
  452. var testCases = [
  453. {
  454. componentName: 'NAMENODE',
  455. result: [
  456. "(type=hdfs-site&tag=1)",
  457. "(type=core-site&tag=2)"
  458. ]
  459. },
  460. {
  461. componentName: 'SECONDARY_NAMENODE',
  462. result: [
  463. "(type=hdfs-site&tag=1)",
  464. "(type=core-site&tag=2)"
  465. ]
  466. },
  467. {
  468. componentName: 'JOBTRACKER',
  469. result: [
  470. "(type=mapred-site&tag=4)"
  471. ]
  472. },
  473. {
  474. componentName: 'RESOURCEMANAGER',
  475. result: [
  476. "(type=yarn-site&tag=5)"
  477. ]
  478. },
  479. {
  480. componentName: 'APP_TIMELINE_SERVER',
  481. result: [
  482. "(type=yarn-site&tag=5)",
  483. "(type=yarn-env&tag=8)"
  484. ]
  485. },
  486. {
  487. componentName: 'OOZIE_SERVER',
  488. result: [
  489. "(type=oozie-site&tag=6)",
  490. "(type=core-site&tag=2)",
  491. "(type=oozie-env&tag=2)"
  492. ]
  493. },
  494. {
  495. componentName: 'WEBHCAT_SERVER',
  496. result: [
  497. "(type=hive-env&tag=11)",
  498. "(type=webhcat-site&tag=7)",
  499. "(type=core-site&tag=2)"
  500. ]
  501. },
  502. {
  503. componentName: 'HIVE_SERVER',
  504. result: [
  505. '(type=hive-site&tag=10)',
  506. '(type=webhcat-site&tag=7)',
  507. '(type=hive-env&tag=11)',
  508. '(type=core-site&tag=2)'
  509. ]
  510. },
  511. {
  512. componentName: 'HIVE_METASTORE',
  513. result: [
  514. '(type=hive-site&tag=10)',
  515. '(type=webhcat-site&tag=7)',
  516. '(type=hive-env&tag=11)',
  517. '(type=core-site&tag=2)'
  518. ]
  519. },
  520. {
  521. componentName: 'MYSQL_SERVER',
  522. result: [
  523. '(type=hive-site&tag=10)'
  524. ]
  525. },
  526. {
  527. componentName: 'HISTORYSERVER',
  528. result: [
  529. '(type=mapred-site&tag=4)'
  530. ]
  531. }
  532. ];
  533. var data = {
  534. Clusters: {
  535. desired_configs: {
  536. 'hdfs-site': {tag: 1},
  537. 'core-site': {tag: 2},
  538. 'hbase-site': {tag: 3},
  539. 'mapred-site': {tag: 4},
  540. 'yarn-site': {tag: 5},
  541. 'oozie-site': {tag: 6},
  542. 'oozie-env': {tag: 2},
  543. 'webhcat-site': {tag: 7},
  544. 'yarn-env': {tag: 8},
  545. 'accumulo-site': {tag: 9},
  546. 'hive-site': {tag: 10},
  547. 'hive-env': {tag: 11}
  548. }
  549. }
  550. };
  551. var services = [];
  552. beforeEach(function () {
  553. sinon.stub(App.Service, 'find', function () {
  554. return services;
  555. });
  556. });
  557. afterEach(function () {
  558. App.Service.find.restore();
  559. });
  560. testCases.forEach(function (test) {
  561. it('get config of ' + test.componentName, function () {
  562. expect(controller.getConfigUrlParams(test.componentName, data)).to.eql(test.result);
  563. });
  564. });
  565. it('get config of NAMENODE when HBASE installed', function () {
  566. services = [
  567. {
  568. serviceName: 'HBASE'
  569. }
  570. ];
  571. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  572. "(type=hdfs-site&tag=1)",
  573. "(type=core-site&tag=2)",
  574. "(type=hbase-site&tag=3)"
  575. ]);
  576. });
  577. it('get config of NAMENODE when ACCUMULO installed', function () {
  578. services = [
  579. {
  580. serviceName: 'ACCUMULO'
  581. }
  582. ];
  583. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  584. "(type=hdfs-site&tag=1)",
  585. "(type=core-site&tag=2)",
  586. "(type=accumulo-site&tag=9)"
  587. ]);
  588. });
  589. });
  590. describe('#onLoadConfigsTags()', function () {
  591. var dummyData = {
  592. Clusters: {
  593. desired_configs : {}
  594. }
  595. };
  596. beforeEach(function () {
  597. sinon.stub(controller, 'getConfigUrlParams', function () {
  598. return [];
  599. });
  600. controller.set('content.reassign.component_name', 'COMP1');
  601. controller.onLoadConfigsTags(dummyData);
  602. this.args = testHelpers.findAjaxRequest('name', 'reassign.load_configs');
  603. });
  604. afterEach(function () {
  605. controller.getConfigUrlParams.restore();
  606. });
  607. it('request is sent', function () {
  608. expect(this.args).exists;
  609. });
  610. it('getConfigUrlParams is called with correct data', function () {
  611. expect(controller.getConfigUrlParams.calledWith('COMP1', dummyData)).to.be.true;
  612. });
  613. });
  614. describe('#loadStep()', function () {
  615. var isHaEnabled = true;
  616. beforeEach(function () {
  617. controller.set('content.reassign.service_id', 'service1');
  618. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  619. sinon.stub(controller, 'initializeTasks', Em.K);
  620. sinon.stub(App, 'get', function () {
  621. return isHaEnabled;
  622. });
  623. });
  624. afterEach(function () {
  625. controller.onTaskStatusChange.restore();
  626. controller.initializeTasks.restore();
  627. App.get.restore();
  628. });
  629. it('reassign component is NameNode and HA enabled', function () {
  630. isHaEnabled = true;
  631. controller.set('content.reassign.component_name', 'NAMENODE');
  632. controller.loadStep();
  633. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  634. expect(controller.get('serviceName')).to.eql(['service1']);
  635. });
  636. it('reassign component is NameNode and HA disabled', function () {
  637. isHaEnabled = false;
  638. controller.set('content.reassign.component_name', 'NAMENODE');
  639. controller.loadStep();
  640. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  641. expect(controller.get('serviceName')).to.eql(['service1']);
  642. });
  643. it('reassign component is JOBTRACKER and HA enabled', function () {
  644. isHaEnabled = true;
  645. controller.set('content.reassign.component_name', 'JOBTRACKER');
  646. controller.loadStep();
  647. expect(controller.get('hostComponents')).to.eql(['JOBTRACKER']);
  648. expect(controller.get('serviceName')).to.eql(['service1']);
  649. });
  650. it('reassign component is RESOURCEMANAGER and HA enabled', function () {
  651. isHaEnabled = true;
  652. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  653. controller.loadStep();
  654. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  655. expect(controller.get('serviceName')).to.eql(['service1']);
  656. });
  657. });
  658. describe('#saveConfigsToServer()', function () {
  659. beforeEach(function () {
  660. sinon.stub(controller, 'getServiceConfigData', Em.K);
  661. controller.saveConfigsToServer([1]);
  662. this.args = testHelpers.findAjaxRequest('name', 'common.across.services.configurations');
  663. });
  664. afterEach(function () {
  665. controller.getServiceConfigData.restore();
  666. });
  667. it('getServiceConfigData is called with valid data', function () {
  668. expect(controller.getServiceConfigData.calledWith([1])).to.be.true;
  669. });
  670. it('request is sent', function () {
  671. expect(this.args).exists;
  672. });
  673. });
  674. describe('#setSecureConfigs()', function () {
  675. beforeEach(function () {
  676. this.stub = sinon.stub(App, 'get');
  677. });
  678. afterEach(function () {
  679. Em.tryInvoke(App.get, 'restore');
  680. });
  681. it('undefined component and security disabled', function () {
  682. var secureConfigs = [];
  683. this.stub.withArgs('isKerberosEnabled').returns(false);
  684. controller.set('secureConfigsMap', []);
  685. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  686. expect(secureConfigs).to.eql([]);
  687. });
  688. it('component exist and security disabled', function () {
  689. var secureConfigs = [];
  690. this.stub.withArgs('isKerberosEnabled').returns(false);
  691. controller.set('secureConfigsMap', [{
  692. componentName: 'COMP1'
  693. }]);
  694. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  695. expect(secureConfigs).to.eql([]);
  696. });
  697. it('undefined component and security enabled', function () {
  698. var secureConfigs = [];
  699. this.stub.withArgs('isKerberosEnabled').returns(true);
  700. controller.set('secureConfigsMap', []);
  701. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  702. expect(secureConfigs).to.eql([]);
  703. });
  704. it('component exist and security enabled', function () {
  705. var secureConfigs = [];
  706. this.stub.withArgs('isKerberosEnabled').returns(true);
  707. var configs = {'s1': {
  708. 'k1': 'kValue',
  709. 'p1': 'pValue'
  710. }};
  711. controller.set('secureConfigsMap', [{
  712. componentName: 'COMP1',
  713. configs: [{
  714. site: 's1',
  715. keytab: 'k1',
  716. principal: 'p1'
  717. }]
  718. }]);
  719. expect(controller.setSecureConfigs(secureConfigs, configs, 'COMP1')).to.be.true;
  720. expect(secureConfigs).to.eql([
  721. {
  722. "keytab": "kValue",
  723. "principal": "pValue"
  724. }
  725. ]);
  726. });
  727. });
  728. describe('#getComponentDir()', function () {
  729. var configs = {
  730. 'hdfs-site': {
  731. 'dfs.name.dir': 'case1',
  732. 'dfs.namenode.name.dir': 'case2',
  733. 'dfs.namenode.checkpoint.dir': 'case3'
  734. },
  735. 'core-site': {
  736. 'fs.checkpoint.dir': 'case4'
  737. }
  738. };
  739. it('unknown component name', function () {
  740. expect(controller.getComponentDir(configs, 'COMP1')).to.be.empty;
  741. });
  742. it('NAMENODE component', function () {
  743. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case2');
  744. });
  745. it('SECONDARY_NAMENODE component', function () {
  746. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case3');
  747. });
  748. });
  749. describe('#saveClusterStatus()', function () {
  750. var mock = {
  751. saveComponentDir: Em.K,
  752. saveSecureConfigs: Em.K
  753. };
  754. beforeEach(function () {
  755. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  756. sinon.stub(App.router, 'get', function() {
  757. return mock;
  758. });
  759. sinon.spy(mock, 'saveComponentDir');
  760. sinon.spy(mock, 'saveSecureConfigs');
  761. });
  762. afterEach(function () {
  763. App.clusterStatus.setClusterStatus.restore();
  764. App.router.get.restore();
  765. mock.saveSecureConfigs.restore();
  766. mock.saveComponentDir.restore();
  767. });
  768. it('componentDir undefined and secureConfigs is empty', function () {
  769. expect(controller.saveClusterStatus([], null)).to.be.false;
  770. });
  771. it('componentDir defined and secureConfigs is empty', function () {
  772. expect(controller.saveClusterStatus([], 'dir1')).to.be.true;
  773. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  774. expect(mock.saveSecureConfigs.calledWith([])).to.be.true;
  775. });
  776. it('componentDir undefined and secureConfigs has data', function () {
  777. expect(controller.saveClusterStatus([1], null)).to.be.true;
  778. expect(mock.saveComponentDir.calledWith(null)).to.be.true;
  779. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  780. });
  781. it('componentDir defined and secureConfigs has data', function () {
  782. expect(controller.saveClusterStatus([1], 'dir1')).to.be.true;
  783. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  784. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  785. });
  786. });
  787. describe('#onSaveConfigs()', function () {
  788. beforeEach(function () {
  789. sinon.stub(controller, 'onTaskCompleted', Em.K);
  790. });
  791. afterEach(function () {
  792. controller.onTaskCompleted.restore();
  793. });
  794. it('onTaskCompleted called once', function () {
  795. controller.onSaveConfigs();
  796. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  797. });
  798. });
  799. describe('#startZooKeeperServers()', function () {
  800. beforeEach(function () {
  801. sinon.stub(controller, 'updateComponent', Em.K);
  802. });
  803. afterEach(function () {
  804. controller.updateComponent.restore();
  805. });
  806. it('updateComponent called with valid arguments', function () {
  807. controller.set('content.masterComponentHosts', [{
  808. component: 'ZOOKEEPER_SERVER',
  809. hostName: 'host1'
  810. }]);
  811. controller.startZooKeeperServers();
  812. expect(controller.updateComponent.calledWith('ZOOKEEPER_SERVER', ['host1'], 'ZOOKEEPER', 'Start')).to.be.true;
  813. });
  814. });
  815. describe('#startNameNode()', function () {
  816. beforeEach(function () {
  817. sinon.stub(controller, 'updateComponent', Em.K);
  818. controller.set('content.masterComponentHosts', [
  819. {
  820. component: 'NAMENODE',
  821. hostName: 'host1'
  822. },
  823. {
  824. component: 'NAMENODE',
  825. hostName: 'host2'
  826. }
  827. ]);
  828. });
  829. afterEach(function () {
  830. controller.updateComponent.restore();
  831. });
  832. it('reassign host does not match current', function () {
  833. controller.set('content.reassignHosts.source', 'host3');
  834. controller.set('content.reassignHosts.target', 'host2');
  835. controller.startNameNode();
  836. expect(controller.updateComponent.getCall(0).args[0]).to.be.equal('NAMENODE');
  837. expect(controller.updateComponent.getCall(0).args[1][0]).to.be.equal('host1');
  838. expect(controller.updateComponent.getCall(0).args[2]).to.be.equal('HDFS');
  839. expect(controller.updateComponent.getCall(0).args[3]).to.be.equal('Start');
  840. });
  841. it('reassign host matches current', function () {
  842. controller.set('content.reassignHosts.target', 'host2');
  843. controller.startNameNode();
  844. expect(controller.updateComponent.calledWith('NAMENODE', ['host1'], 'HDFS', 'Start')).to.be.true;
  845. });
  846. });
  847. describe('#startServices()', function () {
  848. beforeEach(function () {
  849. sinon.stub(App.router, 'get').returns({"skip.service.checks": "false"});
  850. controller.startServices();
  851. this.args = testHelpers.findAjaxRequest('name', 'common.services.update');
  852. });
  853. afterEach(function () {
  854. App.router.get.restore();
  855. });
  856. it('request is sent', function () {
  857. expect(this.args).exists;
  858. });
  859. });
  860. describe('#deleteHostComponents()', function () {
  861. it('No host components', function () {
  862. controller.set('hostComponents', []);
  863. controller.set('content.reassignHosts.source', 'host1');
  864. controller.deleteHostComponents();
  865. var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
  866. expect(args).not.exists;
  867. });
  868. it('delete two components', function () {
  869. controller.set('hostComponents', [1, 2]);
  870. controller.set('content.reassignHosts.source', 'host1');
  871. controller.deleteHostComponents();
  872. var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
  873. expect(args).to.have.property('length').equal(2);
  874. expect(args[0][0].data).to.eql({
  875. "hostName": "host1",
  876. "componentName": 1
  877. });
  878. expect(args[1][0].data).to.eql({
  879. "hostName": "host1",
  880. "componentName": 2
  881. });
  882. });
  883. });
  884. describe('#onDeleteHostComponentsError()', function () {
  885. beforeEach(function () {
  886. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  887. sinon.stub(controller, 'onTaskError', Em.K);
  888. });
  889. afterEach(function () {
  890. controller.onComponentsTasksSuccess.restore();
  891. controller.onTaskError.restore();
  892. });
  893. it('task success', function () {
  894. var error = {
  895. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  896. };
  897. controller.onDeleteHostComponentsError(error);
  898. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  899. });
  900. it('unknown error', function () {
  901. var error = {
  902. responseText: ''
  903. };
  904. controller.onDeleteHostComponentsError(error);
  905. expect(controller.onTaskError.calledOnce).to.be.true;
  906. });
  907. });
  908. describe('#done()', function () {
  909. beforeEach(function () {
  910. sinon.stub(controller, 'removeObserver', Em.K);
  911. sinon.stub(App.router, 'send', Em.K);
  912. });
  913. afterEach(function () {
  914. controller.removeObserver.restore();
  915. App.router.send.restore();
  916. });
  917. it('submit disabled', function () {
  918. controller.set('isSubmitDisabled', true);
  919. controller.done();
  920. expect(App.router.send.called).to.be.false;
  921. });
  922. it('submit enabled and does not have manual steps', function () {
  923. controller.set('isSubmitDisabled', false);
  924. controller.set('content.hasManualSteps', false);
  925. controller.done();
  926. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  927. expect(App.router.send.calledWith('complete')).to.be.true;
  928. });
  929. it('submit enabled and has manual steps', function () {
  930. controller.set('isSubmitDisabled', false);
  931. controller.set('content.hasManualSteps', true);
  932. controller.done();
  933. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  934. expect(App.router.send.calledWith('next')).to.be.true;
  935. });
  936. });
  937. describe('#getServiceConfigData()', function () {
  938. var services = [];
  939. var stackServices = [];
  940. beforeEach(function () {
  941. sinon.stub(App.Service, 'find', function () {
  942. return services;
  943. });
  944. sinon.stub(App.StackService, 'find', function () {
  945. return stackServices;
  946. });
  947. });
  948. afterEach(function () {
  949. App.Service.find.restore();
  950. App.StackService.find.restore();
  951. });
  952. it('No services', function () {
  953. services = [];
  954. controller.set('content.reassign.component_name', 'COMP1');
  955. expect(controller.getServiceConfigData([])).to.eql([]);
  956. });
  957. it('No services in stackServices', function () {
  958. services = [Em.Object.create({serviceName: 'S1'})];
  959. stackServices = [];
  960. controller.set('content.reassign.component_name', 'COMP1');
  961. expect(controller.getServiceConfigData([])).to.eql([]);
  962. });
  963. it('Services in stackServices, but configTypesRendered is empty', function () {
  964. services = [Em.Object.create({serviceName: 'S1'})];
  965. stackServices = [Em.Object.create({
  966. serviceName: 'S1',
  967. configTypesRendered: {}
  968. })];
  969. controller.set('content.reassign.component_name', 'COMP1');
  970. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  971. });
  972. it('Services in stackServices, and configTypesRendered has data, but configs is empty', function () {
  973. services = [Em.Object.create({serviceName: 'S1'})];
  974. stackServices = [
  975. Em.Object.create({
  976. serviceName: 'S1',
  977. configTypesRendered: {'type1': {}}
  978. })
  979. ];
  980. controller.set('content.reassign.component_name', 'COMP1');
  981. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  982. });
  983. it('Services in stackServices, and configTypesRendered has data, and configs present', function () {
  984. services = [Em.Object.create({serviceName: 'S1'})];
  985. stackServices = [
  986. Em.Object.create({
  987. serviceName: 'S1',
  988. configTypesRendered: {'type1': {}}
  989. })
  990. ];
  991. var configs = {
  992. 'type1': {
  993. 'prop1': 'value1'
  994. }
  995. };
  996. controller.set('content.reassign.component_name', 'COMP1');
  997. expect(JSON.parse(controller.getServiceConfigData(configs)[0]).Clusters.desired_config.length).to.equal(1);
  998. });
  999. });
  1000. describe('#cleanMySqlServer()', function () {
  1001. beforeEach(function() {
  1002. sinon.stub(App.HostComponent, 'find', function() {
  1003. return Em.A([
  1004. Em.Object.create({
  1005. 'componentName': 'MYSQL_SERVER',
  1006. 'hostName': 'host1'
  1007. })
  1008. ]);
  1009. });
  1010. });
  1011. afterEach(function() {
  1012. App.HostComponent.find.restore();
  1013. });
  1014. it('component_name is C1', function () {
  1015. controller.set('content.reassign.component_name', 'C1');
  1016. controller.cleanMySqlServer();
  1017. var args = testHelpers.findAjaxRequest('name', 'service.mysql.clean');
  1018. expect(args[0]).exists;
  1019. expect(args[0].sender).to.be.eql(controller);
  1020. expect(args[0].data).to.be.eql({
  1021. host: 'host1'
  1022. });
  1023. });
  1024. it('component_name is MYSQL_SERVER', function () {
  1025. controller.set('content.reassign.component_name', 'MYSQL_SERVER');
  1026. controller.set('content.reassignHosts.target', 'host2');
  1027. controller.cleanMySqlServer();
  1028. var args = testHelpers.findAjaxRequest('name', 'service.mysql.clean');
  1029. expect(args[0]).exists;
  1030. expect(args[0].sender).to.be.eql(controller);
  1031. expect(args[0].data).to.be.eql({
  1032. host: 'host2'
  1033. });
  1034. });
  1035. });
  1036. describe('#configureMySqlServer()', function () {
  1037. beforeEach(function() {
  1038. sinon.stub(App.HostComponent, 'find', function() {
  1039. return Em.A([
  1040. Em.Object.create({
  1041. 'componentName': 'MYSQL_SERVER',
  1042. 'hostName': 'host1'
  1043. })
  1044. ]);
  1045. });
  1046. });
  1047. afterEach(function() {
  1048. App.HostComponent.find.restore();
  1049. });
  1050. it('component_name is C1', function () {
  1051. controller.set('content.reassign.component_name', 'C1');
  1052. controller.configureMySqlServer();
  1053. var args = testHelpers.findAjaxRequest('name', 'service.mysql.configure');
  1054. expect(args[0]).exists;
  1055. expect(args[0].sender).to.be.eql(controller);
  1056. expect(args[0].data).to.be.eql({
  1057. host: 'host1'
  1058. });
  1059. });
  1060. it('component_name is MYSQL_SERVER', function () {
  1061. controller.set('content.reassign.component_name', 'MYSQL_SERVER');
  1062. controller.set('content.reassignHosts.target', 'host2');
  1063. controller.configureMySqlServer();
  1064. var args = testHelpers.findAjaxRequest('name', 'service.mysql.configure');
  1065. expect(args[0]).exists;
  1066. expect(args[0].sender).to.be.eql(controller);
  1067. expect(args[0].data).to.be.eql({
  1068. host: 'host2'
  1069. });
  1070. });
  1071. });
  1072. describe("#startRequiredServices()", function() {
  1073. beforeEach(function () {
  1074. sinon.stub(controller, 'startServices', Em.K);
  1075. });
  1076. afterEach(function () {
  1077. controller.startServices.restore();
  1078. });
  1079. it("component has related services", function() {
  1080. controller.set('content.reassign.component_name', 'JOBTRACKER');
  1081. controller.startRequiredServices();
  1082. expect(controller.startServices.calledWith(false, ['PIG', 'OOZIE'], true)).to.be.true;
  1083. });
  1084. it("component does not have related services", function() {
  1085. controller.set('content.reassign.component_name', 'C1');
  1086. controller.startRequiredServices();
  1087. expect(controller.startServices.calledWith(true)).to.be.true;
  1088. });
  1089. });
  1090. describe("#startMySqlServer()", function() {
  1091. beforeEach(function () {
  1092. sinon.stub(App.HostComponent, 'find').returns([
  1093. Em.Object.create({
  1094. componentName: 'MYSQL_SERVER',
  1095. hostName: 'host1'
  1096. })
  1097. ]);
  1098. });
  1099. afterEach(function () {
  1100. App.HostComponent.find.restore();
  1101. });
  1102. it("valid request is sent", function() {
  1103. controller.startMySqlServer();
  1104. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
  1105. expect(args[0]).exists;
  1106. expect(args[0].sender).to.be.eql(controller);
  1107. expect(args[0].data).to.be.eql({
  1108. context: "Start MySQL Server",
  1109. hostName: 'host1',
  1110. serviceName: "HIVE",
  1111. componentName: "MYSQL_SERVER",
  1112. HostRoles: {
  1113. state: "STARTED"
  1114. }
  1115. });
  1116. });
  1117. });
  1118. describe("#restartMySqlServer()", function() {
  1119. beforeEach(function () {
  1120. sinon.stub(App.HostComponent, 'find').returns([
  1121. Em.Object.create({
  1122. componentName: 'MYSQL_SERVER',
  1123. hostName: 'host1'
  1124. })
  1125. ]);
  1126. });
  1127. afterEach(function () {
  1128. App.HostComponent.find.restore();
  1129. });
  1130. it("valid request is sent", function() {
  1131. controller.set('content', Em.Object.create({
  1132. cluster: Em.Object.create({
  1133. name: 'cl1'
  1134. })
  1135. }));
  1136. controller.restartMySqlServer();
  1137. var args = testHelpers.findAjaxRequest('name', 'restart.hostComponents');
  1138. expect(args[0]).exists;
  1139. expect(args[0].sender).to.be.eql(controller);
  1140. expect(args[0].data).to.be.eql({
  1141. context: 'Restart MySql Server',
  1142. resource_filters: [{
  1143. component_name: "MYSQL_SERVER",
  1144. hosts: 'host1',
  1145. service_name: "HIVE"
  1146. }],
  1147. operation_level: {
  1148. level: "HOST_COMPONENT",
  1149. cluster_name: 'cl1',
  1150. service_name: "HIVE",
  1151. hostcomponent_name: "MYSQL_SERVER"
  1152. }
  1153. });
  1154. });
  1155. });
  1156. describe("#startNewMySqlServer()", function() {
  1157. beforeEach(function () {
  1158. controller.set('content', Em.Object.create({
  1159. reassignHosts: Em.Object.create({
  1160. target: 'host1'
  1161. })
  1162. }));
  1163. controller.startNewMySqlServer();
  1164. this.args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
  1165. });
  1166. it('valid request is sent', function() {
  1167. expect(this.args[0]).exists;
  1168. expect(this.args[0].sender).to.be.eql(controller);
  1169. expect(this.args[0].data).to.be.eql({
  1170. context: "Start MySQL Server",
  1171. hostName: 'host1',
  1172. serviceName: "HIVE",
  1173. componentName: "MYSQL_SERVER",
  1174. HostRoles: {
  1175. state: "STARTED"
  1176. }
  1177. });
  1178. });
  1179. });
  1180. describe("#setDynamicConfigs HIVE", function() {
  1181. beforeEach(function () {
  1182. controller.set('content.masterComponentHosts', [
  1183. {component: 'HIVE_METASTORE', hostName: 'host1'},
  1184. {component: 'HIVE_METASTORE', hostName: 'host3'},
  1185. {component: 'HIVE_SERVER', hostName: 'host4'}
  1186. ]);
  1187. controller.set('content.reassignHosts.source', 'host1');
  1188. controller.set('content.reassignHosts.target', 'host2');
  1189. });
  1190. it("reassign component is HIVE_METASTORE", function() {
  1191. var configs = {
  1192. 'hive-env': {
  1193. 'hive_user': 'hive_user'
  1194. },
  1195. 'hive-site': {
  1196. 'hive.metastore.uris': ''
  1197. },
  1198. 'webhcat-site': {
  1199. 'templeton.hive.properties': 'thrift'
  1200. },
  1201. 'core-site': {
  1202. 'hadoop.proxyuser.hive_user.hosts': ''
  1203. }
  1204. };
  1205. App.MoveHmConfigInitializer.setup(controller._getHiveInitializerSettings(configs));
  1206. configs = controller.setDynamicConfigs(configs, App.MoveHmConfigInitializer);
  1207. expect(configs['hive-site']['hive.metastore.uris']).to.equal('thrift://host3:9083,thrift://host2:9083');
  1208. expect(configs['webhcat-site']['templeton.hive.properties']).to.equal('thrift');
  1209. expect(configs['core-site']['hadoop.proxyuser.hive_user.hosts']).to.equal('host2,host3,host4');
  1210. });
  1211. it("reassign component is HIVE_SERVER", function() {
  1212. controller.get('content.masterComponentHosts').pushObject({component: 'HIVE_SERVER', hostName: 'host1'});
  1213. var configs = {
  1214. 'hive-env': {
  1215. 'hive_user': 'hive_user'
  1216. },
  1217. 'hive-site': {
  1218. 'hive.metastore.uris': ''
  1219. },
  1220. 'webhcat-site': {
  1221. 'templeton.hive.properties': 'thrift'
  1222. },
  1223. 'core-site': {
  1224. 'hadoop.proxyuser.hive_user.hosts': ''
  1225. }
  1226. };
  1227. App.MoveHsConfigInitializer.setup(controller._getHiveInitializerSettings(configs));
  1228. configs = controller.setDynamicConfigs(configs, App.MoveHsConfigInitializer);
  1229. expect(configs['core-site']['hadoop.proxyuser.hive_user.hosts']).to.equal('host1,host2,host3,host4');
  1230. });
  1231. it("reassign component is WEBHCAT_SERVER", function() {
  1232. controller.get('content.masterComponentHosts').pushObject({component: 'WEBHCAT_SERVER', hostName: 'host1'});
  1233. var configs = {
  1234. 'hive-env': {
  1235. 'webhcat_user': 'webhcat_user'
  1236. },
  1237. 'hive-site': {
  1238. 'hive.metastore.uris': ''
  1239. },
  1240. 'webhcat-site': {
  1241. 'templeton.hive.properties': 'thrift'
  1242. },
  1243. 'core-site': {
  1244. 'hadoop.proxyuser.webhcat_user.hosts': ''
  1245. }
  1246. };
  1247. App.MoveWsConfigInitializer.setup(controller._getWsInitializerSettings(configs));
  1248. configs = controller.setDynamicConfigs(configs, App.MoveWsConfigInitializer);
  1249. expect(configs['core-site']['hadoop.proxyuser.webhcat_user.hosts']).to.equal('host2');
  1250. });
  1251. });
  1252. describe('#setDynamicConfigs RESOURCEMANAGER', function () {
  1253. beforeEach(function () {
  1254. sinon.stub(App, 'get').withArgs('isRMHaEnabled').returns(true);
  1255. });
  1256. afterEach(function () {
  1257. App.get.restore();
  1258. App.MoveRmConfigInitializer.cleanup();
  1259. });
  1260. it('HA enabled and resource manager 1', function () {
  1261. controller.set('content.reassignHosts.source', 'host1');
  1262. controller.set('content.reassignHosts.target', 'host3');
  1263. var configs = {
  1264. 'yarn-site': {
  1265. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1266. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1267. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1268. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1269. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1270. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1271. }
  1272. };
  1273. var additionalDependencies = controller._getRmAdditionalDependencies(configs);
  1274. App.MoveRmConfigInitializer.setup(controller._getRmInitializerSettings(configs));
  1275. configs = controller.setDynamicConfigs(configs, App.MoveRmConfigInitializer, additionalDependencies);
  1276. expect(configs['yarn-site']).to.eql({
  1277. 'yarn.resourcemanager.hostname.rm1': 'host3',
  1278. 'yarn.resourcemanager.webapp.address.rm1': 'host3:8088',
  1279. 'yarn.resourcemanager.webapp.https.address.rm1': 'host3:8443',
  1280. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1281. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1282. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1283. });
  1284. });
  1285. it('HA enabled and resource manager 2', function () {
  1286. controller.set('content.reassignHosts.source', 'host2');
  1287. controller.set('content.reassignHosts.target', 'host3');
  1288. var configs = {
  1289. 'yarn-site': {
  1290. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1291. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1292. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1293. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1294. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1295. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1296. }
  1297. };
  1298. var additionalDependencies = controller._getRmAdditionalDependencies(configs);
  1299. App.MoveRmConfigInitializer.setup(controller._getRmInitializerSettings(configs));
  1300. configs = controller.setDynamicConfigs(configs, App.MoveRmConfigInitializer, additionalDependencies);
  1301. expect(configs['yarn-site']).to.eql({
  1302. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1303. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1304. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1305. 'yarn.resourcemanager.hostname.rm2': 'host3',
  1306. 'yarn.resourcemanager.webapp.address.rm2': 'host3:8088',
  1307. 'yarn.resourcemanager.webapp.https.address.rm2': 'host3:8443'
  1308. });
  1309. });
  1310. });
  1311. describe('#setDynamicConfigs NAMENODE', function () {
  1312. var isHaEnabled = false;
  1313. beforeEach(function () {
  1314. sinon.stub(App, 'get', function () {
  1315. return isHaEnabled;
  1316. });
  1317. sinon.stub(App.Service, 'find', function () {
  1318. return [
  1319. {serviceName: 'HDFS'},
  1320. {serviceName: 'ACCUMULO'},
  1321. {serviceName: 'HBASE'},
  1322. {serviceName: 'HAWQ'}
  1323. ];
  1324. });
  1325. controller.set('content.reassignHosts.source', 'host1');
  1326. });
  1327. afterEach(function () {
  1328. App.get.restore();
  1329. App.Service.find.restore();
  1330. App.MoveNameNodeConfigInitializer.cleanup();
  1331. });
  1332. it('HA isn\'t enabled and HBASE, HAWQ and ACCUMULO service', function () {
  1333. isHaEnabled = false;
  1334. var configs = {
  1335. 'hbase-site': {
  1336. 'hbase.rootdir': 'hdfs://localhost:8020/apps/hbase/data'
  1337. },
  1338. 'accumulo-site': {
  1339. 'instance.volumes': 'hdfs://localhost:8020/apps/accumulo/data',
  1340. 'instance.volumes.replacements': ''
  1341. },
  1342. 'hawq-site': {
  1343. 'hawq_dfs_url': 'localhost:8020/hawq/data'
  1344. }
  1345. };
  1346. controller.set('content.reassignHosts.target', 'host2');
  1347. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1348. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1349. expect(configs['hbase-site']['hbase.rootdir']).to.equal('hdfs://host2:8020/apps/hbase/data');
  1350. expect(configs['accumulo-site']['instance.volumes']).to.equal('hdfs://host2:8020/apps/accumulo/data');
  1351. expect(configs['accumulo-site']['instance.volumes.replacements']).to.equal('hdfs://host1:8020/apps/accumulo/data hdfs://host2:8020/apps/accumulo/data');
  1352. expect(configs['hawq-site'].hawq_dfs_url).to.equal('host2:8020/hawq/data');
  1353. });
  1354. it('HA enabled and namenode 1', function () {
  1355. isHaEnabled = true;
  1356. var configs = {
  1357. 'hdfs-site': {
  1358. 'dfs.nameservices': 's',
  1359. 'dfs.namenode.http-address.s.nn1': 'host1:50070',
  1360. 'dfs.namenode.https-address.s.nn1': 'host1:50470',
  1361. 'dfs.namenode.rpc-address.s.nn1': 'host1:8020'
  1362. },
  1363. 'hdfs-client': {
  1364. 'dfs.namenode.rpc-address.s.nn1': '',
  1365. 'dfs.namenode.http-address.s.nn1': 'host1:50070'
  1366. }
  1367. };
  1368. controller.set('content.reassignHosts.target', 'host2');
  1369. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1370. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1371. expect(configs['hdfs-site']).to.eql({
  1372. "dfs.nameservices": "s",
  1373. "dfs.namenode.http-address.s.nn1": "host2:50070",
  1374. "dfs.namenode.https-address.s.nn1": "host2:50470",
  1375. "dfs.namenode.rpc-address.s.nn1": "host2:8020"
  1376. });
  1377. expect(configs['hdfs-client']).to.eql({
  1378. "dfs.namenode.http-address.s.nn1": "host2:50070",
  1379. "dfs.namenode.rpc-address.s.nn1": "host2:8020"
  1380. });
  1381. });
  1382. it('HA enabled and namenode 2', function () {
  1383. isHaEnabled = true;
  1384. var configs = {
  1385. 'hdfs-site': {
  1386. 'dfs.nameservices': 's',
  1387. "dfs.namenode.http-address.s.nn1": "host1:50070",
  1388. 'dfs.namenode.http-address.s.nn2': 'host2:50070',
  1389. 'dfs.namenode.https-address.s.nn2': 'host2:50470',
  1390. 'dfs.namenode.rpc-address.s.nn2': 'host2:8020'
  1391. },
  1392. 'hdfs-client': {
  1393. 'dfs.namenode.rpc-address.s.nn2': '',
  1394. 'dfs.namenode.http-address.s.nn2': 'host2:50070'
  1395. }
  1396. };
  1397. controller.set('content.reassignHosts.source', 'host2');
  1398. controller.set('content.reassignHosts.target', 'host3');
  1399. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1400. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1401. expect(configs['hdfs-site']).to.eql({
  1402. "dfs.nameservices": "s",
  1403. "dfs.namenode.http-address.s.nn1": "host1:50070",
  1404. "dfs.namenode.http-address.s.nn2": "host3:50070",
  1405. "dfs.namenode.https-address.s.nn2": "host3:50470",
  1406. "dfs.namenode.rpc-address.s.nn2": "host3:8020"
  1407. });
  1408. expect(configs['hdfs-client']).to.eql({
  1409. "dfs.namenode.http-address.s.nn2": "host3:50070",
  1410. "dfs.namenode.rpc-address.s.nn2": "host3:8020"
  1411. });
  1412. });
  1413. });
  1414. describe('#setDynamicConfigs OOZIE_SERVER', function () {
  1415. it('should upodate hadoop.proxyuser.${oozie_user}.hosts', function () {
  1416. var configs = {
  1417. 'oozie-env': {
  1418. 'oozie_user': 'cool_dude'
  1419. },
  1420. 'core-site': {
  1421. 'hadoop.proxyuser.cool_dude.hosts': ''
  1422. }
  1423. };
  1424. controller.set('content.masterComponentHosts', [
  1425. {component: 'OOZIE_SERVER', hostName: 'host2'},
  1426. {component: 'OOZIE_SERVER', hostName: 'host3'},
  1427. {component: 'OOZIE_SERVER', hostName: 'host1'}
  1428. ]);
  1429. controller.set('content.reassignHosts.source', 'host1');
  1430. controller.set('content.reassignHosts.target', 'host4');
  1431. App.MoveOSConfigInitializer.setup(controller._getOsInitializerSettings(configs));
  1432. configs = controller.setDynamicConfigs(configs, App.MoveOSConfigInitializer);
  1433. App.MoveOSConfigInitializer.cleanup();
  1434. expect(configs['core-site']['hadoop.proxyuser.cool_dude.hosts']).to.equal('host2,host3,host4');
  1435. });
  1436. });
  1437. describe.skip("#prepareDBCheckAction()", function() {
  1438. beforeEach(function () {
  1439. sinon.stub(App.router, 'get').returns({
  1440. 'jdk_location': 'jdk_location',
  1441. 'jdk.name': 'jdk.name',
  1442. 'java.home': 'java.home'
  1443. });
  1444. sinon.stub(controller, 'getConnectionProperty').returns('prop1');
  1445. controller.set('content.reassignHosts', Em.Object.create({target: 'host1'}));
  1446. controller.reopen({
  1447. dbType: 'type1',
  1448. requiredProperties: [],
  1449. preparedDBProperties: {}
  1450. });
  1451. controller.prepareDBCheckAction();
  1452. this.args = testHelpers.findAjaxRequest('name', 'cluster.custom_action.create');
  1453. });
  1454. afterEach(function () {
  1455. App.router.get.restore();
  1456. controller.getConnectionProperty.restore();
  1457. });
  1458. it('valid request is sent', function () {
  1459. expect(this.args[0]).exists;
  1460. expect(this.args[0].data).to.eql({
  1461. requestInfo: {
  1462. "context": "Check host",
  1463. "action": "check_host",
  1464. "parameters": {
  1465. "db_name": "type1",
  1466. "jdk_location": "jdk_location",
  1467. "jdk_name": "jdk.name",
  1468. "java_home": "java.home",
  1469. "threshold": 60,
  1470. "ambari_server_host": "",
  1471. "check_execute_list": "db_connection_check"
  1472. }
  1473. },
  1474. filteredHosts: ['host1']
  1475. });
  1476. });
  1477. });
  1478. });