step4_controller_test.js 54 KB

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