step4_controller_test.js 54 KB

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