step4_controller_test.js 53 KB

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