step4_controller_test.js 54 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624
  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,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=webhcat-site&tag=7)"
  498. ]
  499. },
  500. {
  501. componentName: 'HIVE_SERVER',
  502. result: [
  503. '(type=hive-site&tag=10)',
  504. '(type=webhcat-site&tag=7)',
  505. '(type=hive-env&tag=11)',
  506. '(type=core-site&tag=2)'
  507. ]
  508. },
  509. {
  510. componentName: 'HIVE_METASTORE',
  511. result: [
  512. '(type=hive-site&tag=10)',
  513. '(type=webhcat-site&tag=7)',
  514. '(type=hive-env&tag=11)',
  515. '(type=core-site&tag=2)'
  516. ]
  517. },
  518. {
  519. componentName: 'MYSQL_SERVER',
  520. result: [
  521. '(type=hive-site&tag=10)'
  522. ]
  523. },
  524. {
  525. componentName: 'HISTORYSERVER',
  526. result: [
  527. '(type=mapred-site&tag=4)'
  528. ]
  529. }
  530. ];
  531. var data = {
  532. Clusters: {
  533. desired_configs: {
  534. 'hdfs-site': {tag: 1},
  535. 'core-site': {tag: 2},
  536. 'hbase-site': {tag: 3},
  537. 'mapred-site': {tag: 4},
  538. 'yarn-site': {tag: 5},
  539. 'oozie-site': {tag: 6},
  540. 'oozie-env': {tag: 2},
  541. 'webhcat-site': {tag: 7},
  542. 'yarn-env': {tag: 8},
  543. 'accumulo-site': {tag: 9},
  544. 'hive-site': {tag: 10},
  545. 'hive-env': {tag: 11}
  546. }
  547. }
  548. };
  549. var services = [];
  550. beforeEach(function () {
  551. sinon.stub(App.Service, 'find', function () {
  552. return services;
  553. });
  554. });
  555. afterEach(function () {
  556. App.Service.find.restore();
  557. });
  558. testCases.forEach(function (test) {
  559. it('get config of ' + test.componentName, function () {
  560. expect(controller.getConfigUrlParams(test.componentName, data)).to.eql(test.result);
  561. });
  562. });
  563. it('get config of NAMENODE when HBASE installed', function () {
  564. services = [
  565. {
  566. serviceName: 'HBASE'
  567. }
  568. ];
  569. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  570. "(type=hdfs-site&tag=1)",
  571. "(type=core-site&tag=2)",
  572. "(type=hbase-site&tag=3)"
  573. ]);
  574. });
  575. it('get config of NAMENODE when ACCUMULO installed', function () {
  576. services = [
  577. {
  578. serviceName: 'ACCUMULO'
  579. }
  580. ];
  581. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  582. "(type=hdfs-site&tag=1)",
  583. "(type=core-site&tag=2)",
  584. "(type=accumulo-site&tag=9)"
  585. ]);
  586. });
  587. });
  588. describe('#onLoadConfigsTags()', function () {
  589. var dummyData = {
  590. Clusters: {
  591. desired_configs : {}
  592. }
  593. };
  594. beforeEach(function () {
  595. sinon.stub(controller, 'getConfigUrlParams', function () {
  596. return [];
  597. });
  598. controller.set('content.reassign.component_name', 'COMP1');
  599. controller.onLoadConfigsTags(dummyData);
  600. this.args = testHelpers.findAjaxRequest('name', 'reassign.load_configs');
  601. });
  602. afterEach(function () {
  603. controller.getConfigUrlParams.restore();
  604. });
  605. it('request is sent', function () {
  606. expect(this.args).exists;
  607. });
  608. it('getConfigUrlParams is called with correct data', function () {
  609. expect(controller.getConfigUrlParams.calledWith('COMP1', dummyData)).to.be.true;
  610. });
  611. });
  612. describe('#loadStep()', function () {
  613. var isHaEnabled = true;
  614. beforeEach(function () {
  615. controller.set('content.reassign.service_id', 'service1');
  616. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  617. sinon.stub(controller, 'initializeTasks', Em.K);
  618. sinon.stub(App, 'get', function () {
  619. return isHaEnabled;
  620. });
  621. });
  622. afterEach(function () {
  623. controller.onTaskStatusChange.restore();
  624. controller.initializeTasks.restore();
  625. App.get.restore();
  626. });
  627. it('reassign component is NameNode and HA enabled', function () {
  628. isHaEnabled = true;
  629. controller.set('content.reassign.component_name', 'NAMENODE');
  630. controller.loadStep();
  631. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  632. expect(controller.get('serviceName')).to.eql(['service1']);
  633. });
  634. it('reassign component is NameNode and HA disabled', function () {
  635. isHaEnabled = false;
  636. controller.set('content.reassign.component_name', 'NAMENODE');
  637. controller.loadStep();
  638. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  639. expect(controller.get('serviceName')).to.eql(['service1']);
  640. });
  641. it('reassign component is JOBTRACKER and HA enabled', function () {
  642. isHaEnabled = true;
  643. controller.set('content.reassign.component_name', 'JOBTRACKER');
  644. controller.loadStep();
  645. expect(controller.get('hostComponents')).to.eql(['JOBTRACKER']);
  646. expect(controller.get('serviceName')).to.eql(['service1']);
  647. });
  648. it('reassign component is RESOURCEMANAGER and HA enabled', function () {
  649. isHaEnabled = true;
  650. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  651. controller.loadStep();
  652. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  653. expect(controller.get('serviceName')).to.eql(['service1']);
  654. });
  655. });
  656. describe('#saveConfigsToServer()', function () {
  657. beforeEach(function () {
  658. sinon.stub(controller, 'getServiceConfigData', Em.K);
  659. controller.saveConfigsToServer([1]);
  660. this.args = testHelpers.findAjaxRequest('name', 'common.across.services.configurations');
  661. });
  662. afterEach(function () {
  663. controller.getServiceConfigData.restore();
  664. });
  665. it('getServiceConfigData is called with valid data', function () {
  666. expect(controller.getServiceConfigData.calledWith([1])).to.be.true;
  667. });
  668. it('request is sent', function () {
  669. expect(this.args).exists;
  670. });
  671. });
  672. describe('#setSecureConfigs()', function () {
  673. beforeEach(function () {
  674. this.stub = sinon.stub(App, 'get');
  675. });
  676. afterEach(function () {
  677. Em.tryInvoke(App.get, 'restore');
  678. });
  679. it('undefined component and security disabled', function () {
  680. var secureConfigs = [];
  681. this.stub.withArgs('isKerberosEnabled').returns(false);
  682. controller.set('secureConfigsMap', []);
  683. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  684. expect(secureConfigs).to.eql([]);
  685. });
  686. it('component exist and security disabled', function () {
  687. var secureConfigs = [];
  688. this.stub.withArgs('isKerberosEnabled').returns(false);
  689. controller.set('secureConfigsMap', [{
  690. componentName: 'COMP1'
  691. }]);
  692. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  693. expect(secureConfigs).to.eql([]);
  694. });
  695. it('undefined component and security enabled', function () {
  696. var secureConfigs = [];
  697. this.stub.withArgs('isKerberosEnabled').returns(true);
  698. controller.set('secureConfigsMap', []);
  699. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  700. expect(secureConfigs).to.eql([]);
  701. });
  702. it('component exist and security enabled', function () {
  703. var secureConfigs = [];
  704. this.stub.withArgs('isKerberosEnabled').returns(true);
  705. var configs = {'s1': {
  706. 'k1': 'kValue',
  707. 'p1': 'pValue'
  708. }};
  709. controller.set('secureConfigsMap', [{
  710. componentName: 'COMP1',
  711. configs: [{
  712. site: 's1',
  713. keytab: 'k1',
  714. principal: 'p1'
  715. }]
  716. }]);
  717. expect(controller.setSecureConfigs(secureConfigs, configs, 'COMP1')).to.be.true;
  718. expect(secureConfigs).to.eql([
  719. {
  720. "keytab": "kValue",
  721. "principal": "pValue"
  722. }
  723. ]);
  724. });
  725. });
  726. describe('#getComponentDir()', function () {
  727. var configs = {
  728. 'hdfs-site': {
  729. 'dfs.name.dir': 'case1',
  730. 'dfs.namenode.name.dir': 'case2',
  731. 'dfs.namenode.checkpoint.dir': 'case3'
  732. },
  733. 'core-site': {
  734. 'fs.checkpoint.dir': 'case4'
  735. }
  736. };
  737. it('unknown component name', function () {
  738. expect(controller.getComponentDir(configs, 'COMP1')).to.be.empty;
  739. });
  740. it('NAMENODE component', function () {
  741. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case2');
  742. });
  743. it('SECONDARY_NAMENODE component', function () {
  744. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case3');
  745. });
  746. });
  747. describe('#saveClusterStatus()', function () {
  748. var mock = {
  749. saveComponentDir: Em.K,
  750. saveSecureConfigs: Em.K
  751. };
  752. beforeEach(function () {
  753. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  754. sinon.stub(App.router, 'get', function() {
  755. return mock;
  756. });
  757. sinon.spy(mock, 'saveComponentDir');
  758. sinon.spy(mock, 'saveSecureConfigs');
  759. });
  760. afterEach(function () {
  761. App.clusterStatus.setClusterStatus.restore();
  762. App.router.get.restore();
  763. mock.saveSecureConfigs.restore();
  764. mock.saveComponentDir.restore();
  765. });
  766. it('componentDir undefined and secureConfigs is empty', function () {
  767. expect(controller.saveClusterStatus([], null)).to.be.false;
  768. });
  769. it('componentDir defined and secureConfigs is empty', function () {
  770. expect(controller.saveClusterStatus([], 'dir1')).to.be.true;
  771. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  772. expect(mock.saveSecureConfigs.calledWith([])).to.be.true;
  773. });
  774. it('componentDir undefined and secureConfigs has data', function () {
  775. expect(controller.saveClusterStatus([1], null)).to.be.true;
  776. expect(mock.saveComponentDir.calledWith(null)).to.be.true;
  777. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  778. });
  779. it('componentDir defined and secureConfigs has data', function () {
  780. expect(controller.saveClusterStatus([1], 'dir1')).to.be.true;
  781. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  782. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  783. });
  784. });
  785. describe('#onSaveConfigs()', function () {
  786. beforeEach(function () {
  787. sinon.stub(controller, 'onTaskCompleted', Em.K);
  788. });
  789. afterEach(function () {
  790. controller.onTaskCompleted.restore();
  791. });
  792. it('onTaskCompleted called once', function () {
  793. controller.onSaveConfigs();
  794. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  795. });
  796. });
  797. describe('#startZooKeeperServers()', function () {
  798. beforeEach(function () {
  799. sinon.stub(controller, 'updateComponent', Em.K);
  800. });
  801. afterEach(function () {
  802. controller.updateComponent.restore();
  803. });
  804. it('updateComponent called with valid arguments', function () {
  805. controller.set('content.masterComponentHosts', [{
  806. component: 'ZOOKEEPER_SERVER',
  807. hostName: 'host1'
  808. }]);
  809. controller.startZooKeeperServers();
  810. expect(controller.updateComponent.calledWith('ZOOKEEPER_SERVER', ['host1'], 'ZOOKEEPER', 'Start')).to.be.true;
  811. });
  812. });
  813. describe('#startNameNode()', function () {
  814. beforeEach(function () {
  815. sinon.stub(controller, 'updateComponent', Em.K);
  816. controller.set('content.masterComponentHosts', [{
  817. component: 'NAMENODE',
  818. hostName: 'host1'
  819. }]);
  820. });
  821. afterEach(function () {
  822. controller.updateComponent.restore();
  823. });
  824. it('reassign host does not match current', function () {
  825. controller.set('content.reassignHosts.source', 'host2');
  826. controller.startNameNode();
  827. expect(controller.updateComponent.getCall(0).args[0]).to.be.equal('NAMENODE');
  828. expect(controller.updateComponent.getCall(0).args[1][0]).to.be.equal('host1');
  829. expect(controller.updateComponent.getCall(0).args[2]).to.be.equal('HDFS');
  830. expect(controller.updateComponent.getCall(0).args[3]).to.be.equal('Start');
  831. });
  832. it('reassign host matches current', function () {
  833. controller.set('content.reassignHosts.source', 'host1');
  834. controller.startNameNode();
  835. expect(controller.updateComponent.calledWith('NAMENODE', [], 'HDFS', 'Start')).to.be.true;
  836. });
  837. });
  838. describe('#startServices()', function () {
  839. beforeEach(function () {
  840. sinon.stub(App.router, 'get').returns({"skip.service.checks": "false"});
  841. controller.startServices();
  842. this.args = testHelpers.findAjaxRequest('name', 'common.services.update');
  843. });
  844. afterEach(function () {
  845. App.router.get.restore();
  846. });
  847. it('request is sent', function () {
  848. expect(this.args).exists;
  849. });
  850. });
  851. describe('#deleteHostComponents()', function () {
  852. it('No host components', function () {
  853. controller.set('hostComponents', []);
  854. controller.set('content.reassignHosts.source', 'host1');
  855. controller.deleteHostComponents();
  856. var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
  857. expect(args).not.exists;
  858. });
  859. it('delete two components', function () {
  860. controller.set('hostComponents', [1, 2]);
  861. controller.set('content.reassignHosts.source', 'host1');
  862. controller.deleteHostComponents();
  863. var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
  864. expect(args).to.have.property('length').equal(2);
  865. expect(args[0][0].data).to.eql({
  866. "hostName": "host1",
  867. "componentName": 1
  868. });
  869. expect(args[1][0].data).to.eql({
  870. "hostName": "host1",
  871. "componentName": 2
  872. });
  873. });
  874. });
  875. describe('#onDeleteHostComponentsError()', function () {
  876. beforeEach(function () {
  877. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  878. sinon.stub(controller, 'onTaskError', Em.K);
  879. });
  880. afterEach(function () {
  881. controller.onComponentsTasksSuccess.restore();
  882. controller.onTaskError.restore();
  883. });
  884. it('task success', function () {
  885. var error = {
  886. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  887. };
  888. controller.onDeleteHostComponentsError(error);
  889. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  890. });
  891. it('unknown error', function () {
  892. var error = {
  893. responseText: ''
  894. };
  895. controller.onDeleteHostComponentsError(error);
  896. expect(controller.onTaskError.calledOnce).to.be.true;
  897. });
  898. });
  899. describe('#done()', function () {
  900. beforeEach(function () {
  901. sinon.stub(controller, 'removeObserver', Em.K);
  902. sinon.stub(App.router, 'send', Em.K);
  903. });
  904. afterEach(function () {
  905. controller.removeObserver.restore();
  906. App.router.send.restore();
  907. });
  908. it('submit disabled', function () {
  909. controller.set('isSubmitDisabled', true);
  910. controller.done();
  911. expect(App.router.send.called).to.be.false;
  912. });
  913. it('submit enabled and does not have manual steps', function () {
  914. controller.set('isSubmitDisabled', false);
  915. controller.set('content.hasManualSteps', false);
  916. controller.done();
  917. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  918. expect(App.router.send.calledWith('complete')).to.be.true;
  919. });
  920. it('submit enabled and has manual steps', function () {
  921. controller.set('isSubmitDisabled', false);
  922. controller.set('content.hasManualSteps', true);
  923. controller.done();
  924. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  925. expect(App.router.send.calledWith('next')).to.be.true;
  926. });
  927. });
  928. describe('#getServiceConfigData()', function () {
  929. var services = [];
  930. var stackServices = [];
  931. beforeEach(function () {
  932. sinon.stub(App.Service, 'find', function () {
  933. return services;
  934. });
  935. sinon.stub(App.StackService, 'find', function () {
  936. return stackServices;
  937. });
  938. });
  939. afterEach(function () {
  940. App.Service.find.restore();
  941. App.StackService.find.restore();
  942. });
  943. it('No services', function () {
  944. services = [];
  945. controller.set('content.reassign.component_name', 'COMP1');
  946. expect(controller.getServiceConfigData([])).to.eql([]);
  947. });
  948. it('No services in stackServices', function () {
  949. services = [Em.Object.create({serviceName: 'S1'})];
  950. stackServices = [];
  951. controller.set('content.reassign.component_name', 'COMP1');
  952. expect(controller.getServiceConfigData([])).to.eql([]);
  953. });
  954. it('Services in stackServices, but configTypesRendered is empty', function () {
  955. services = [Em.Object.create({serviceName: 'S1'})];
  956. stackServices = [Em.Object.create({
  957. serviceName: 'S1',
  958. configTypesRendered: {}
  959. })];
  960. controller.set('content.reassign.component_name', 'COMP1');
  961. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  962. });
  963. it('Services in stackServices, and configTypesRendered has data, but configs is empty', function () {
  964. services = [Em.Object.create({serviceName: 'S1'})];
  965. stackServices = [
  966. Em.Object.create({
  967. serviceName: 'S1',
  968. configTypesRendered: {'type1': {}}
  969. })
  970. ];
  971. controller.set('content.reassign.component_name', 'COMP1');
  972. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  973. });
  974. it('Services in stackServices, and configTypesRendered has data, and configs present', function () {
  975. services = [Em.Object.create({serviceName: 'S1'})];
  976. stackServices = [
  977. Em.Object.create({
  978. serviceName: 'S1',
  979. configTypesRendered: {'type1': {}}
  980. })
  981. ];
  982. var configs = {
  983. 'type1': {
  984. 'prop1': 'value1'
  985. }
  986. };
  987. controller.set('content.reassign.component_name', 'COMP1');
  988. expect(JSON.parse(controller.getServiceConfigData(configs)[0]).Clusters.desired_config.length).to.equal(1);
  989. });
  990. });
  991. describe('#cleanMySqlServer()', function () {
  992. beforeEach(function() {
  993. sinon.stub(App.HostComponent, 'find', function() {
  994. return Em.A([
  995. Em.Object.create({
  996. 'componentName': 'MYSQL_SERVER',
  997. 'hostName': 'host1'
  998. })
  999. ]);
  1000. });
  1001. });
  1002. afterEach(function() {
  1003. App.HostComponent.find.restore();
  1004. });
  1005. it('component_name is C1', function () {
  1006. controller.set('content.reassign.component_name', 'C1');
  1007. controller.cleanMySqlServer();
  1008. var args = testHelpers.findAjaxRequest('name', 'service.mysql.clean');
  1009. expect(args[0]).exists;
  1010. expect(args[0].sender).to.be.eql(controller);
  1011. expect(args[0].data).to.be.eql({
  1012. host: 'host1'
  1013. });
  1014. });
  1015. it('component_name is MYSQL_SERVER', function () {
  1016. controller.set('content.reassign.component_name', 'MYSQL_SERVER');
  1017. controller.set('content.reassignHosts.target', 'host2');
  1018. controller.cleanMySqlServer();
  1019. var args = testHelpers.findAjaxRequest('name', 'service.mysql.clean');
  1020. expect(args[0]).exists;
  1021. expect(args[0].sender).to.be.eql(controller);
  1022. expect(args[0].data).to.be.eql({
  1023. host: 'host2'
  1024. });
  1025. });
  1026. });
  1027. describe('#configureMySqlServer()', function () {
  1028. beforeEach(function() {
  1029. sinon.stub(App.HostComponent, 'find', function() {
  1030. return Em.A([
  1031. Em.Object.create({
  1032. 'componentName': 'MYSQL_SERVER',
  1033. 'hostName': 'host1'
  1034. })
  1035. ]);
  1036. });
  1037. });
  1038. afterEach(function() {
  1039. App.HostComponent.find.restore();
  1040. });
  1041. it('component_name is C1', function () {
  1042. controller.set('content.reassign.component_name', 'C1');
  1043. controller.configureMySqlServer();
  1044. var args = testHelpers.findAjaxRequest('name', 'service.mysql.configure');
  1045. expect(args[0]).exists;
  1046. expect(args[0].sender).to.be.eql(controller);
  1047. expect(args[0].data).to.be.eql({
  1048. host: 'host1'
  1049. });
  1050. });
  1051. it('component_name is MYSQL_SERVER', function () {
  1052. controller.set('content.reassign.component_name', 'MYSQL_SERVER');
  1053. controller.set('content.reassignHosts.target', 'host2');
  1054. controller.configureMySqlServer();
  1055. var args = testHelpers.findAjaxRequest('name', 'service.mysql.configure');
  1056. expect(args[0]).exists;
  1057. expect(args[0].sender).to.be.eql(controller);
  1058. expect(args[0].data).to.be.eql({
  1059. host: 'host2'
  1060. });
  1061. });
  1062. });
  1063. describe("#startRequiredServices()", function() {
  1064. beforeEach(function () {
  1065. sinon.stub(controller, 'startServices', Em.K);
  1066. });
  1067. afterEach(function () {
  1068. controller.startServices.restore();
  1069. });
  1070. it("component has related services", function() {
  1071. controller.set('content.reassign.component_name', 'JOBTRACKER');
  1072. controller.startRequiredServices();
  1073. expect(controller.startServices.calledWith(false, ['PIG', 'OOZIE'], true)).to.be.true;
  1074. });
  1075. it("component does not have related services", function() {
  1076. controller.set('content.reassign.component_name', 'C1');
  1077. controller.startRequiredServices();
  1078. expect(controller.startServices.calledWith(true)).to.be.true;
  1079. });
  1080. });
  1081. describe("#startMySqlServer()", function() {
  1082. beforeEach(function () {
  1083. sinon.stub(App.HostComponent, 'find').returns([
  1084. Em.Object.create({
  1085. componentName: 'MYSQL_SERVER',
  1086. hostName: 'host1'
  1087. })
  1088. ]);
  1089. });
  1090. afterEach(function () {
  1091. App.HostComponent.find.restore();
  1092. });
  1093. it("valid request is sent", function() {
  1094. controller.startMySqlServer();
  1095. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
  1096. expect(args[0]).exists;
  1097. expect(args[0].sender).to.be.eql(controller);
  1098. expect(args[0].data).to.be.eql({
  1099. context: "Start MySQL Server",
  1100. hostName: 'host1',
  1101. serviceName: "HIVE",
  1102. componentName: "MYSQL_SERVER",
  1103. HostRoles: {
  1104. state: "STARTED"
  1105. }
  1106. });
  1107. });
  1108. });
  1109. describe("#restartMySqlServer()", function() {
  1110. beforeEach(function () {
  1111. sinon.stub(App.HostComponent, 'find').returns([
  1112. Em.Object.create({
  1113. componentName: 'MYSQL_SERVER',
  1114. hostName: 'host1'
  1115. })
  1116. ]);
  1117. });
  1118. afterEach(function () {
  1119. App.HostComponent.find.restore();
  1120. });
  1121. it("valid request is sent", function() {
  1122. controller.set('content', Em.Object.create({
  1123. cluster: Em.Object.create({
  1124. name: 'cl1'
  1125. })
  1126. }));
  1127. controller.restartMySqlServer();
  1128. var args = testHelpers.findAjaxRequest('name', 'restart.hostComponents');
  1129. expect(args[0]).exists;
  1130. expect(args[0].sender).to.be.eql(controller);
  1131. expect(args[0].data).to.be.eql({
  1132. context: 'Restart MySql Server',
  1133. resource_filters: [{
  1134. component_name: "MYSQL_SERVER",
  1135. hosts: 'host1',
  1136. service_name: "HIVE"
  1137. }],
  1138. operation_level: {
  1139. level: "HOST_COMPONENT",
  1140. cluster_name: 'cl1',
  1141. service_name: "HIVE",
  1142. hostcomponent_name: "MYSQL_SERVER"
  1143. }
  1144. });
  1145. });
  1146. });
  1147. describe("#startNewMySqlServer()", function() {
  1148. beforeEach(function () {
  1149. controller.set('content', Em.Object.create({
  1150. reassignHosts: Em.Object.create({
  1151. target: 'host1'
  1152. })
  1153. }));
  1154. controller.startNewMySqlServer();
  1155. this.args = testHelpers.findAjaxRequest('name', 'common.host.host_component.update');
  1156. });
  1157. it('valid request is sent', function() {
  1158. expect(this.args[0]).exists;
  1159. expect(this.args[0].sender).to.be.eql(controller);
  1160. expect(this.args[0].data).to.be.eql({
  1161. context: "Start MySQL Server",
  1162. hostName: 'host1',
  1163. serviceName: "HIVE",
  1164. componentName: "MYSQL_SERVER",
  1165. HostRoles: {
  1166. state: "STARTED"
  1167. }
  1168. });
  1169. });
  1170. });
  1171. describe("#setDynamicConfigs HIVE", function() {
  1172. beforeEach(function () {
  1173. controller.set('content.masterComponentHosts', [
  1174. {component: 'HIVE_METASTORE', hostName: 'host1'},
  1175. {component: 'HIVE_METASTORE', hostName: 'host3'},
  1176. {component: 'HIVE_SERVER', hostName: 'host4'}
  1177. ]);
  1178. controller.set('content.reassignHosts.source', 'host1');
  1179. controller.set('content.reassignHosts.target', 'host2');
  1180. });
  1181. it("reassign component is HIVE_METASTORE", function() {
  1182. var configs = {
  1183. 'hive-env': {
  1184. 'hive_user': 'hive_user',
  1185. 'webhcat_user': 'webhcat_user'
  1186. },
  1187. 'hive-site': {
  1188. 'hive.metastore.uris': ''
  1189. },
  1190. 'webhcat-site': {
  1191. 'templeton.hive.properties': 'thrift'
  1192. },
  1193. 'core-site': {
  1194. 'hadoop.proxyuser.hive_user.hosts': '',
  1195. 'hadoop.proxyuser.webhcat_user.hosts': ''
  1196. }
  1197. };
  1198. App.MoveHmConfigInitializer.setup(controller._getHiveInitializerSettings(configs));
  1199. configs = controller.setDynamicConfigs(configs, App.MoveHmConfigInitializer);
  1200. expect(configs['hive-site']['hive.metastore.uris']).to.equal('thrift://host3:9083,thrift://host2:9083');
  1201. expect(configs['webhcat-site']['templeton.hive.properties']).to.equal('thrift');
  1202. expect(configs['core-site']['hadoop.proxyuser.hive_user.hosts']).to.equal('host2,host3,host4');
  1203. expect(configs['core-site']['hadoop.proxyuser.webhcat_user.hosts']).to.equal('host2,host3,host4');
  1204. });
  1205. it("reassign component is HIVE_SERVER", function() {
  1206. controller.get('content.masterComponentHosts').pushObject({component: 'HIVE_SERVER', hostName: 'host1'});
  1207. var configs = {
  1208. 'hive-env': {
  1209. 'hive_user': 'hive_user',
  1210. 'webhcat_user': 'webhcat_user'
  1211. },
  1212. 'hive-site': {
  1213. 'hive.metastore.uris': ''
  1214. },
  1215. 'webhcat-site': {
  1216. 'templeton.hive.properties': 'thrift'
  1217. },
  1218. 'core-site': {
  1219. 'hadoop.proxyuser.hive_user.hosts': '',
  1220. 'hadoop.proxyuser.webhcat_user.hosts': ''
  1221. }
  1222. };
  1223. App.MoveHsConfigInitializer.setup(controller._getHiveInitializerSettings(configs));
  1224. configs = controller.setDynamicConfigs(configs, App.MoveHsConfigInitializer);
  1225. expect(configs['core-site']['hadoop.proxyuser.hive_user.hosts']).to.equal('host1,host2,host3,host4');
  1226. expect(configs['core-site']['hadoop.proxyuser.webhcat_user.hosts']).to.equal('host1,host2,host3,host4');
  1227. });
  1228. });
  1229. describe('#setDynamicConfigs RESOURCEMANAGER', function () {
  1230. beforeEach(function () {
  1231. sinon.stub(App, 'get').withArgs('isRMHaEnabled').returns(true);
  1232. });
  1233. afterEach(function () {
  1234. App.get.restore();
  1235. App.MoveRmConfigInitializer.cleanup();
  1236. });
  1237. it('HA enabled and resource manager 1', function () {
  1238. controller.set('content.reassignHosts.source', 'host1');
  1239. controller.set('content.reassignHosts.target', 'host3');
  1240. var configs = {
  1241. 'yarn-site': {
  1242. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1243. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1244. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1245. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1246. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1247. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1248. }
  1249. };
  1250. var additionalDependencies = controller._getRmAdditionalDependencies(configs);
  1251. App.MoveRmConfigInitializer.setup(controller._getRmInitializerSettings(configs));
  1252. configs = controller.setDynamicConfigs(configs, App.MoveRmConfigInitializer, additionalDependencies);
  1253. expect(configs['yarn-site']).to.eql({
  1254. 'yarn.resourcemanager.hostname.rm1': 'host3',
  1255. 'yarn.resourcemanager.webapp.address.rm1': 'host3:8088',
  1256. 'yarn.resourcemanager.webapp.https.address.rm1': 'host3:8443',
  1257. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1258. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1259. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1260. });
  1261. });
  1262. it('HA enabled and resource manager 2', function () {
  1263. controller.set('content.reassignHosts.source', 'host2');
  1264. controller.set('content.reassignHosts.target', 'host3');
  1265. var configs = {
  1266. 'yarn-site': {
  1267. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1268. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1269. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1270. 'yarn.resourcemanager.hostname.rm2': 'host2',
  1271. 'yarn.resourcemanager.webapp.address.rm2': 'host2:8088',
  1272. 'yarn.resourcemanager.webapp.https.address.rm2': 'host2:8443'
  1273. }
  1274. };
  1275. var additionalDependencies = controller._getRmAdditionalDependencies(configs);
  1276. App.MoveRmConfigInitializer.setup(controller._getRmInitializerSettings(configs));
  1277. configs = controller.setDynamicConfigs(configs, App.MoveRmConfigInitializer, additionalDependencies);
  1278. expect(configs['yarn-site']).to.eql({
  1279. 'yarn.resourcemanager.hostname.rm1': 'host1',
  1280. 'yarn.resourcemanager.webapp.address.rm1': 'host1:8088',
  1281. 'yarn.resourcemanager.webapp.https.address.rm1': 'host1:8443',
  1282. 'yarn.resourcemanager.hostname.rm2': 'host3',
  1283. 'yarn.resourcemanager.webapp.address.rm2': 'host3:8088',
  1284. 'yarn.resourcemanager.webapp.https.address.rm2': 'host3:8443'
  1285. });
  1286. });
  1287. });
  1288. describe('#setDynamicConfigs NAMENODE', function () {
  1289. var isHaEnabled = false;
  1290. beforeEach(function () {
  1291. sinon.stub(App, 'get', function () {
  1292. return isHaEnabled;
  1293. });
  1294. sinon.stub(App.Service, 'find', function () {
  1295. return [
  1296. {serviceName: 'HDFS'},
  1297. {serviceName: 'ACCUMULO'},
  1298. {serviceName: 'HBASE'},
  1299. {serviceName: 'HAWQ'}
  1300. ];
  1301. });
  1302. controller.set('content.reassignHosts.source', 'host1');
  1303. });
  1304. afterEach(function () {
  1305. App.get.restore();
  1306. App.Service.find.restore();
  1307. App.MoveNameNodeConfigInitializer.cleanup();
  1308. });
  1309. it('HA isn\'t enabled and HBASE, HAWQ and ACCUMULO service', function () {
  1310. isHaEnabled = false;
  1311. var configs = {
  1312. 'hbase-site': {
  1313. 'hbase.rootdir': 'hdfs://localhost:8020/apps/hbase/data'
  1314. },
  1315. 'accumulo-site': {
  1316. 'instance.volumes': 'hdfs://localhost:8020/apps/accumulo/data',
  1317. 'instance.volumes.replacements': ''
  1318. },
  1319. 'hawq-site': {
  1320. 'hawq_dfs_url': 'localhost:8020/hawq/data'
  1321. }
  1322. };
  1323. controller.set('content.reassignHosts.target', 'host2');
  1324. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1325. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1326. expect(configs['hbase-site']['hbase.rootdir']).to.equal('hdfs://host2:8020/apps/hbase/data');
  1327. expect(configs['accumulo-site']['instance.volumes']).to.equal('hdfs://host2:8020/apps/accumulo/data');
  1328. expect(configs['accumulo-site']['instance.volumes.replacements']).to.equal('hdfs://host1:8020/apps/accumulo/data hdfs://host2:8020/apps/accumulo/data');
  1329. expect(configs['hawq-site']['hawq_dfs_url']).to.equal('host2:8020/hawq/data');
  1330. });
  1331. it('HA enabled and namenode 1', function () {
  1332. isHaEnabled = true;
  1333. var configs = {
  1334. 'hdfs-site': {
  1335. 'dfs.nameservices': 's',
  1336. 'dfs.namenode.http-address.s.nn1': 'host1:50070',
  1337. 'dfs.namenode.https-address.s.nn1': 'host1:50470',
  1338. 'dfs.namenode.rpc-address.s.nn1': 'host1:8020'
  1339. },
  1340. 'hdfs-client': {
  1341. 'dfs.namenode.rpc-address.s.nn1': '',
  1342. 'dfs.namenode.http-address.s.nn1': 'host1:50070'
  1343. }
  1344. };
  1345. controller.set('content.reassignHosts.target', 'host2');
  1346. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1347. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1348. expect(configs['hdfs-site']).to.eql({
  1349. "dfs.nameservices": "s",
  1350. "dfs.namenode.http-address.s.nn1": "host2:50070",
  1351. "dfs.namenode.https-address.s.nn1": "host2:50470",
  1352. "dfs.namenode.rpc-address.s.nn1": "host2:8020"
  1353. });
  1354. expect(configs['hdfs-client']).to.eql({
  1355. "dfs.namenode.http-address.s.nn1": "host2:50070",
  1356. "dfs.namenode.rpc-address.s.nn1": "host2:8020"
  1357. });
  1358. });
  1359. it('HA enabled and namenode 2', function () {
  1360. isHaEnabled = true;
  1361. var configs = {
  1362. 'hdfs-site': {
  1363. 'dfs.nameservices': 's',
  1364. "dfs.namenode.http-address.s.nn1": "host1:50070",
  1365. 'dfs.namenode.http-address.s.nn2': 'host2:50070',
  1366. 'dfs.namenode.https-address.s.nn2': 'host2:50470',
  1367. 'dfs.namenode.rpc-address.s.nn2': 'host2:8020'
  1368. },
  1369. 'hdfs-client': {
  1370. 'dfs.namenode.rpc-address.s.nn2': '',
  1371. 'dfs.namenode.http-address.s.nn2': 'host2:50070'
  1372. }
  1373. };
  1374. controller.set('content.reassignHosts.source', 'host2');
  1375. controller.set('content.reassignHosts.target', 'host3');
  1376. App.MoveNameNodeConfigInitializer.setup(controller._getNnInitializerSettings(configs));
  1377. configs = controller.setDynamicConfigs(configs, App.MoveNameNodeConfigInitializer);
  1378. expect(configs['hdfs-site']).to.eql({
  1379. "dfs.nameservices": "s",
  1380. "dfs.namenode.http-address.s.nn1": "host1:50070",
  1381. "dfs.namenode.http-address.s.nn2": "host3:50070",
  1382. "dfs.namenode.https-address.s.nn2": "host3:50470",
  1383. "dfs.namenode.rpc-address.s.nn2": "host3:8020"
  1384. });
  1385. expect(configs['hdfs-client']).to.eql({
  1386. "dfs.namenode.http-address.s.nn2": "host3:50070",
  1387. "dfs.namenode.rpc-address.s.nn2": "host3:8020"
  1388. });
  1389. });
  1390. });
  1391. describe('#setDynamicConfigs OOZIE_SERVER', function () {
  1392. it('should upodate hadoop.proxyuser.${oozie_user}.hosts', function () {
  1393. var configs = {
  1394. 'oozie-env': {
  1395. 'oozie_user': 'cool_dude'
  1396. },
  1397. 'core-site': {
  1398. 'hadoop.proxyuser.cool_dude.hosts': ''
  1399. }
  1400. };
  1401. controller.set('content.masterComponentHosts', [
  1402. {component: 'OOZIE_SERVER', hostName: 'host2'},
  1403. {component: 'OOZIE_SERVER', hostName: 'host3'},
  1404. {component: 'OOZIE_SERVER', hostName: 'host1'}
  1405. ]);
  1406. controller.set('content.reassignHosts.source', 'host1');
  1407. controller.set('content.reassignHosts.target', 'host4');
  1408. App.MoveOSConfigInitializer.setup(controller._getOsInitializerSettings(configs));
  1409. configs = controller.setDynamicConfigs(configs, App.MoveOSConfigInitializer);
  1410. App.MoveOSConfigInitializer.cleanup();
  1411. expect(configs['core-site']['hadoop.proxyuser.cool_dude.hosts']).to.equal('host2,host3,host4');
  1412. });
  1413. });
  1414. describe.skip("#prepareDBCheckAction()", function() {
  1415. beforeEach(function () {
  1416. sinon.stub(App.router, 'get').returns({
  1417. 'jdk_location': 'jdk_location',
  1418. 'jdk.name': 'jdk.name',
  1419. 'java.home': 'java.home'
  1420. });
  1421. sinon.stub(controller, 'getConnectionProperty').returns('prop1');
  1422. controller.set('content.reassignHosts', Em.Object.create({target: 'host1'}));
  1423. controller.reopen({
  1424. dbType: 'type1',
  1425. requiredProperties: [],
  1426. preparedDBProperties: {}
  1427. });
  1428. controller.prepareDBCheckAction();
  1429. this.args = testHelpers.findAjaxRequest('name', 'cluster.custom_action.create');
  1430. });
  1431. afterEach(function () {
  1432. App.router.get.restore();
  1433. controller.getConnectionProperty.restore();
  1434. });
  1435. it('valid request is sent', function () {
  1436. expect(this.args[0]).exists;
  1437. expect(this.args[0].data).to.eql({
  1438. requestInfo: {
  1439. "context": "Check host",
  1440. "action": "check_host",
  1441. "parameters": {
  1442. "db_name": "type1",
  1443. "jdk_location": "jdk_location",
  1444. "jdk_name": "jdk.name",
  1445. "java_home": "java.home",
  1446. "threshold": 60,
  1447. "ambari_server_host": "",
  1448. "check_execute_list": "db_connection_check"
  1449. }
  1450. },
  1451. filteredHosts: ['host1']
  1452. });
  1453. });
  1454. });
  1455. });