step4_controller_test.js 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187
  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. 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. var isHadoop2Stack = false;
  35. beforeEach(function () {
  36. sinon.stub(App, 'get', function () {
  37. return isHadoop2Stack;
  38. });
  39. });
  40. afterEach(function () {
  41. App.get.restore();
  42. });
  43. it('Component is absent', function () {
  44. controller.set('additionalConfigsMap', []);
  45. var configs = {};
  46. expect(controller.setAdditionalConfigs(configs, 'COMP1', '')).to.be.false;
  47. expect(configs).to.eql({});
  48. });
  49. it('Component is present', function () {
  50. controller.set('additionalConfigsMap', [
  51. {
  52. componentName: 'COMP1',
  53. configs: {
  54. 'test-site': {
  55. 'property1': '<replace-value>:1111'
  56. }
  57. }
  58. }
  59. ]);
  60. var configs = {
  61. 'test-site': {}
  62. };
  63. expect(controller.setAdditionalConfigs(configs, 'COMP1', 'host1')).to.be.true;
  64. expect(configs).to.eql({
  65. 'test-site': {
  66. 'property1': 'host1:1111'
  67. }
  68. });
  69. });
  70. it('configs_Hadoop2 is present but isHadoop2Stack = false', function () {
  71. isHadoop2Stack = false;
  72. controller.set('additionalConfigsMap', [
  73. {
  74. componentName: 'COMP1',
  75. configs: {
  76. 'test-site': {
  77. 'property1': '<replace-value>:1111'
  78. }
  79. },
  80. configs_Hadoop2: {
  81. 'test-site': {
  82. 'property2': '<replace-value>:2222'
  83. }
  84. }
  85. }
  86. ]);
  87. var configs = {
  88. 'test-site': {}
  89. };
  90. expect(controller.setAdditionalConfigs(configs, 'COMP1', 'host1')).to.be.true;
  91. expect(configs).to.eql({
  92. 'test-site': {
  93. 'property1': 'host1:1111'
  94. }
  95. });
  96. });
  97. it('configs_Hadoop2 is present but isHadoop2Stack = true', function () {
  98. isHadoop2Stack = true;
  99. controller.set('additionalConfigsMap', [
  100. {
  101. componentName: 'COMP1',
  102. configs: {
  103. 'test-site': {
  104. 'property1': '<replace-value>:1111'
  105. }
  106. },
  107. configs_Hadoop2: {
  108. 'test-site': {
  109. 'property2': '<replace-value>:2222'
  110. }
  111. }
  112. }
  113. ]);
  114. var configs = {
  115. 'test-site': {}
  116. };
  117. expect(controller.setAdditionalConfigs(configs, 'COMP1', 'host1')).to.be.true;
  118. expect(configs).to.eql({
  119. 'test-site': {
  120. 'property2': 'host1:2222'
  121. }
  122. });
  123. });
  124. });
  125. describe('#getHostComponentsNames()', function () {
  126. it('No host-components', function () {
  127. controller.set('hostComponents', []);
  128. expect(controller.getHostComponentsNames()).to.be.empty;
  129. });
  130. it('one host-components', function () {
  131. controller.set('hostComponents', ['COMP1']);
  132. expect(controller.getHostComponentsNames()).to.equal('Comp1');
  133. });
  134. it('ZKFC host-components', function () {
  135. controller.set('hostComponents', ['COMP1', 'ZKFC']);
  136. expect(controller.getHostComponentsNames()).to.equal('Comp1+ZKFC');
  137. });
  138. });
  139. describe('#removeUnneededTasks()', function () {
  140. var isHaEnabled = false;
  141. beforeEach(function () {
  142. sinon.stub(App, 'get', function () {
  143. return isHaEnabled;
  144. });
  145. controller.set('tasks', [
  146. {id: 1},
  147. {id: 2},
  148. {id: 3},
  149. {id: 4},
  150. {id: 5},
  151. {id: 6},
  152. {id: 7},
  153. {id: 8},
  154. {id: 9}
  155. ]);
  156. });
  157. afterEach(function () {
  158. App.get.restore();
  159. });
  160. it('hasManualSteps is false', function () {
  161. controller.set('content.hasManualSteps', false);
  162. controller.removeUnneededTasks();
  163. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5, 8, 9]);
  164. });
  165. it('reassign component is not NameNode and HA disabled', function () {
  166. controller.set('content.hasManualSteps', true);
  167. controller.set('content.reassign.component_name', 'COMP1');
  168. isHaEnabled = false;
  169. controller.removeUnneededTasks();
  170. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5]);
  171. });
  172. it('reassign component is not NameNode and HA enabled', function () {
  173. controller.set('content.hasManualSteps', true);
  174. controller.set('content.reassign.component_name', 'COMP1');
  175. isHaEnabled = true;
  176. controller.removeUnneededTasks();
  177. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5]);
  178. });
  179. it('reassign component is NameNode and HA disabled', function () {
  180. controller.set('content.hasManualSteps', true);
  181. controller.set('content.reassign.component_name', 'NAMENODE');
  182. isHaEnabled = false;
  183. controller.removeUnneededTasks();
  184. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5]);
  185. });
  186. it('reassign component is NameNode and HA enabled', function () {
  187. controller.set('content.hasManualSteps', true);
  188. controller.set('content.reassign.component_name', 'NAMENODE');
  189. isHaEnabled = true;
  190. controller.removeUnneededTasks();
  191. expect(controller.get('tasks').mapProperty('id')).to.eql([1, 2, 3, 4, 5, 6, 7]);
  192. });
  193. });
  194. describe('#initializeTasks()', function () {
  195. beforeEach(function () {
  196. controller.set('tasks', []);
  197. sinon.stub(controller, 'getHostComponentsNames', Em.K);
  198. sinon.stub(controller, 'removeUnneededTasks', Em.K);
  199. });
  200. afterEach(function () {
  201. controller.removeUnneededTasks.restore();
  202. controller.getHostComponentsNames.restore();
  203. });
  204. it('No commands', function () {
  205. controller.set('commands', []);
  206. controller.initializeTasks();
  207. expect(controller.get('tasks')).to.be.empty;
  208. });
  209. it('One command', function () {
  210. controller.set('commands', ['COMMAND1']);
  211. controller.initializeTasks();
  212. expect(controller.get('tasks')[0].get('id')).to.equal(0);
  213. expect(controller.get('tasks')[0].get('command')).to.equal('COMMAND1');
  214. });
  215. });
  216. describe('#hideRollbackButton()', function () {
  217. it('No showRollback command', function () {
  218. controller.set('tasks', [Em.Object.create({
  219. showRollback: false
  220. })]);
  221. controller.hideRollbackButton();
  222. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  223. });
  224. it('showRollback command is present', function () {
  225. controller.set('tasks', [Em.Object.create({
  226. showRollback: true
  227. })]);
  228. controller.hideRollbackButton();
  229. expect(controller.get('tasks')[0].get('showRollback')).to.be.false;
  230. });
  231. });
  232. describe('#onComponentsTasksSuccess()', function () {
  233. beforeEach(function () {
  234. sinon.stub(controller, 'onTaskCompleted', Em.K);
  235. });
  236. afterEach(function () {
  237. controller.onTaskCompleted.restore();
  238. });
  239. it('No host-components', function () {
  240. controller.set('multiTaskCounter', 0);
  241. controller.set('hostComponents', []);
  242. controller.onComponentsTasksSuccess();
  243. expect(controller.get('multiTaskCounter')).to.equal(1);
  244. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  245. });
  246. it('One host-component', function () {
  247. controller.set('multiTaskCounter', 0);
  248. controller.set('hostComponents', [
  249. {}
  250. ]);
  251. controller.onComponentsTasksSuccess();
  252. expect(controller.get('multiTaskCounter')).to.equal(1);
  253. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  254. });
  255. it('two host-components', function () {
  256. controller.set('multiTaskCounter', 0);
  257. controller.set('hostComponents', [
  258. {},
  259. {}
  260. ]);
  261. controller.onComponentsTasksSuccess();
  262. expect(controller.get('multiTaskCounter')).to.equal(1);
  263. expect(controller.onTaskCompleted.called).to.be.false;
  264. });
  265. });
  266. describe('#getStopServicesData()', function () {
  267. it('restarting YARN component', function () {
  268. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  269. sinon.stub(App.Service, 'find', function () {
  270. return [
  271. {
  272. serviceName: 'HDFS'
  273. },
  274. {
  275. serviceName: 'SERVICE1'
  276. }
  277. ];
  278. });
  279. expect(controller.getStopServicesData()).to.eql({
  280. "ServiceInfo": {
  281. "state": "INSTALLED"
  282. },
  283. "context": "Stop required services",
  284. "urlParams": "ServiceInfo/service_name.in(SERVICE1)"
  285. });
  286. App.Service.find.restore();
  287. });
  288. it('restarting non-YARN component', function () {
  289. controller.set('content.reassign.component_name', 'NAMENODE');
  290. expect(controller.getStopServicesData()).to.eql({
  291. "ServiceInfo": {
  292. "state": "INSTALLED"
  293. },
  294. "context": "Stop all services"
  295. });
  296. });
  297. });
  298. describe('#stopServices()', function () {
  299. it('', function () {
  300. sinon.stub(controller, 'getStopServicesData', Em.K);
  301. controller.stopServices();
  302. expect(App.ajax.send.calledOnce).to.be.true;
  303. expect(controller.getStopServicesData.calledOnce).to.be.true;
  304. controller.getStopServicesData.restore();
  305. });
  306. });
  307. describe('#createHostComponents()', function () {
  308. beforeEach(function () {
  309. sinon.stub(controller, 'createComponent', Em.K);
  310. });
  311. afterEach(function () {
  312. controller.createComponent.restore();
  313. });
  314. it('No host-components', function () {
  315. controller.set('hostComponents', []);
  316. controller.createHostComponents();
  317. expect(controller.get('multiTaskCounter')).to.equal(0);
  318. expect(controller.createComponent.called).to.be.false;
  319. });
  320. it('One host-component', function () {
  321. controller.set('hostComponents', ['COMP1']);
  322. controller.set('content.reassignHosts.target', 'host1');
  323. controller.set('content.reassign.service_id', 'SERVICE1');
  324. controller.createHostComponents();
  325. expect(controller.get('multiTaskCounter')).to.equal(0);
  326. expect(controller.createComponent.calledWith('COMP1', 'host1', 'SERVICE1')).to.be.true;
  327. });
  328. });
  329. describe('#onCreateComponent()', function () {
  330. it('', function () {
  331. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  332. controller.onCreateComponent();
  333. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  334. controller.onComponentsTasksSuccess.restore();
  335. });
  336. });
  337. describe('#putHostComponentsInMaintenanceMode()', function () {
  338. beforeEach(function(){
  339. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  340. controller.set('content.reassignHosts.source', 'source');
  341. });
  342. afterEach(function(){
  343. controller.onComponentsTasksSuccess.restore();
  344. });
  345. it('No host-components', function () {
  346. controller.set('hostComponents', []);
  347. controller.putHostComponentsInMaintenanceMode();
  348. expect(App.ajax.send.called).to.be.false;
  349. expect(controller.get('multiTaskCounter')).to.equal(0);
  350. });
  351. it('One host-components', function () {
  352. controller.set('hostComponents', [{}]);
  353. controller.putHostComponentsInMaintenanceMode();
  354. expect(App.ajax.send.calledOnce).to.be.true;
  355. expect(controller.get('multiTaskCounter')).to.equal(0);
  356. });
  357. });
  358. describe('#installHostComponents()', function () {
  359. beforeEach(function () {
  360. sinon.stub(controller, 'updateComponent', Em.K);
  361. });
  362. afterEach(function () {
  363. controller.updateComponent.restore();
  364. });
  365. it('No host-components', function () {
  366. controller.set('hostComponents', []);
  367. controller.installHostComponents();
  368. expect(controller.get('multiTaskCounter')).to.equal(0);
  369. expect(controller.updateComponent.called).to.be.false;
  370. });
  371. it('One host-component', function () {
  372. controller.set('hostComponents', ['COMP1']);
  373. controller.set('content.reassignHosts.target', 'host1');
  374. controller.set('content.reassign.service_id', 'SERVICE1');
  375. controller.installHostComponents();
  376. expect(controller.get('multiTaskCounter')).to.equal(0);
  377. expect(controller.updateComponent.calledWith('COMP1', 'host1', 'SERVICE1', 'Install', 1)).to.be.true;
  378. });
  379. });
  380. describe('#reconfigure()', function () {
  381. it('', function () {
  382. sinon.stub(controller, 'loadConfigsTags', Em.K);
  383. controller.reconfigure();
  384. expect(controller.loadConfigsTags.calledOnce).to.be.true;
  385. controller.loadConfigsTags.restore();
  386. });
  387. });
  388. describe('#loadConfigsTags()', function () {
  389. it('', function () {
  390. controller.loadConfigsTags();
  391. expect(App.ajax.send.calledOnce).to.be.true;
  392. });
  393. });
  394. describe('#getConfigUrlParams()', function () {
  395. var testCases = [
  396. {
  397. componentName: 'NAMENODE',
  398. result: [
  399. "(type=hdfs-site&tag=1)",
  400. "(type=core-site&tag=2)"
  401. ]
  402. },
  403. {
  404. componentName: 'SECONDARY_NAMENODE',
  405. result: [
  406. "(type=hdfs-site&tag=1)",
  407. "(type=core-site&tag=2)"
  408. ]
  409. },
  410. {
  411. componentName: 'JOBTRACKER',
  412. result: [
  413. "(type=mapred-site&tag=4)"
  414. ]
  415. },
  416. {
  417. componentName: 'RESOURCEMANAGER',
  418. result: [
  419. "(type=yarn-site&tag=5)"
  420. ]
  421. },
  422. {
  423. componentName: 'APP_TIMELINE_SERVER',
  424. result: [
  425. "(type=yarn-site&tag=5)"
  426. ]
  427. },
  428. {
  429. componentName: 'OOZIE_SERVER',
  430. result: [
  431. "(type=oozie-site&tag=6)"
  432. ]
  433. }
  434. ];
  435. var data = {
  436. Clusters: {
  437. desired_configs: {
  438. 'hdfs-site': {tag: 1},
  439. 'core-site': {tag: 2},
  440. 'hbase-site': {tag: 3},
  441. 'mapred-site': {tag: 4},
  442. 'yarn-site': {tag: 5},
  443. 'oozie-site': {tag: 6}
  444. }
  445. }
  446. };
  447. var services = [];
  448. beforeEach(function () {
  449. sinon.stub(App.Service, 'find', function () {
  450. return services;
  451. })
  452. });
  453. afterEach(function () {
  454. App.Service.find.restore();
  455. });
  456. testCases.forEach(function (test) {
  457. it('get config of ' + test.componentName, function () {
  458. expect(controller.getConfigUrlParams(test.componentName, data)).to.eql(test.result);
  459. })
  460. });
  461. it('get config of NAMENODE when HBASE installed', function () {
  462. services = [
  463. {
  464. serviceName: 'HBASE'
  465. }
  466. ];
  467. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  468. "(type=hdfs-site&tag=1)",
  469. "(type=core-site&tag=2)",
  470. "(type=hbase-site&tag=3)"
  471. ]);
  472. })
  473. });
  474. describe('#onLoadConfigsTags()', function () {
  475. it('', function () {
  476. sinon.stub(controller, 'getConfigUrlParams', function () {
  477. return [];
  478. });
  479. controller.set('content.reassign.component_name', 'COMP1');
  480. controller.onLoadConfigsTags({});
  481. expect(App.ajax.send.calledOnce).to.be.true;
  482. expect(controller.getConfigUrlParams.calledWith('COMP1', {})).to.be.true;
  483. controller.getConfigUrlParams.restore();
  484. });
  485. });
  486. describe('#onLoadConfigs()', function () {
  487. beforeEach(function () {
  488. sinon.stub(controller, 'setAdditionalConfigs', Em.K);
  489. sinon.stub(controller, 'setSecureConfigs', Em.K);
  490. sinon.stub(controller, 'setSpecificNamenodeConfigs', Em.K);
  491. sinon.stub(controller, 'setSpecificResourceMangerConfigs', Em.K);
  492. sinon.stub(controller, 'getComponentDir', Em.K);
  493. sinon.stub(controller, 'saveClusterStatus', Em.K);
  494. sinon.stub(controller, 'saveConfigsToServer', Em.K);
  495. controller.set('content.reassignHosts.target', 'host1');
  496. });
  497. afterEach(function () {
  498. controller.setAdditionalConfigs.restore();
  499. controller.setSecureConfigs.restore();
  500. controller.setSpecificNamenodeConfigs.restore();
  501. controller.setSpecificResourceMangerConfigs.restore();
  502. controller.getComponentDir.restore();
  503. controller.saveClusterStatus.restore();
  504. controller.saveConfigsToServer.restore();
  505. });
  506. it('component is not NAMENODE', function () {
  507. controller.set('content.reassign.component_name', 'COMP1');
  508. controller.onLoadConfigs({items: []});
  509. expect(controller.setAdditionalConfigs.calledWith({}, 'COMP1', 'host1')).to.be.true;
  510. expect(controller.setSecureConfigs.calledWith([], {}, 'COMP1')).to.be.true;
  511. expect(controller.setSpecificNamenodeConfigs.called).to.be.false;
  512. expect(controller.getComponentDir.calledWith({}, 'COMP1')).to.be.true;
  513. expect(controller.saveClusterStatus.calledWith([])).to.be.true;
  514. expect(controller.saveConfigsToServer.calledWith({})).to.be.true;
  515. });
  516. it('component is NAMENODE, has configs', function () {
  517. controller.set('content.reassign.component_name', 'NAMENODE');
  518. controller.onLoadConfigs({items: [
  519. {
  520. type: 'hdfs-site',
  521. properties: {}
  522. }
  523. ]});
  524. expect(controller.setAdditionalConfigs.calledWith({'hdfs-site': {}}, 'NAMENODE', 'host1')).to.be.true;
  525. expect(controller.setSecureConfigs.calledWith([], {'hdfs-site': {}}, 'NAMENODE')).to.be.true;
  526. expect(controller.setSpecificNamenodeConfigs.calledWith({'hdfs-site': {}}, 'host1')).to.be.true;
  527. expect(controller.getComponentDir.calledWith({'hdfs-site': {}}, 'NAMENODE')).to.be.true;
  528. expect(controller.saveClusterStatus.calledWith([])).to.be.true;
  529. expect(controller.saveConfigsToServer.calledWith({'hdfs-site': {}})).to.be.true;
  530. });
  531. it('component is RESOURCEMANAGER, has configs', function () {
  532. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  533. controller.onLoadConfigs({items: [
  534. {
  535. type: 'hdfs-site',
  536. properties: {}
  537. }
  538. ]});
  539. expect(controller.setAdditionalConfigs.calledWith({'hdfs-site': {}}, 'RESOURCEMANAGER', 'host1')).to.be.true;
  540. expect(controller.setSecureConfigs.calledWith([], {'hdfs-site': {}}, 'RESOURCEMANAGER')).to.be.true;
  541. expect(controller.setSpecificResourceMangerConfigs.calledWith({'hdfs-site': {}}, 'host1')).to.be.true;
  542. expect(controller.getComponentDir.calledWith({'hdfs-site': {}}, 'RESOURCEMANAGER')).to.be.true;
  543. expect(controller.saveClusterStatus.calledWith([])).to.be.true;
  544. expect(controller.saveConfigsToServer.calledWith({'hdfs-site': {}})).to.be.true;
  545. });
  546. });
  547. describe('#loadStep()', function () {
  548. var isHaEnabled = true;
  549. beforeEach(function () {
  550. controller.set('content.reassign.service_id', 'service1');
  551. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  552. sinon.stub(controller, 'initializeTasks', Em.K);
  553. sinon.stub(App, 'get', function () {
  554. return isHaEnabled;
  555. });
  556. });
  557. afterEach(function () {
  558. controller.onTaskStatusChange.restore();
  559. controller.initializeTasks.restore();
  560. App.get.restore();
  561. });
  562. it('reassign component is NameNode and HA enabled', function () {
  563. isHaEnabled = true;
  564. controller.set('content.reassign.component_name', 'NAMENODE');
  565. controller.loadStep();
  566. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  567. expect(controller.get('serviceName')).to.eql(['service1']);
  568. });
  569. it('reassign component is NameNode and HA disabled', function () {
  570. isHaEnabled = false;
  571. controller.set('content.reassign.component_name', 'NAMENODE');
  572. controller.loadStep();
  573. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  574. expect(controller.get('serviceName')).to.eql(['service1']);
  575. });
  576. it('reassign component is JOBTRACKER and HA enabled', function () {
  577. isHaEnabled = true;
  578. controller.set('content.reassign.component_name', 'JOBTRACKER');
  579. controller.loadStep();
  580. expect(controller.get('hostComponents')).to.eql(['JOBTRACKER']);
  581. expect(controller.get('serviceName')).to.eql(['service1']);
  582. });
  583. it('reassign component is RESOURCEMANAGER and HA enabled', function () {
  584. isHaEnabled = true;
  585. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  586. controller.loadStep();
  587. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  588. expect(controller.get('serviceName')).to.eql(['service1']);
  589. });
  590. });
  591. describe('#saveConfigsToServer()', function () {
  592. beforeEach(function () {
  593. sinon.stub(controller, 'getServiceConfigData', Em.K);
  594. });
  595. afterEach(function () {
  596. controller.getServiceConfigData.restore();
  597. });
  598. it('', function () {
  599. controller.saveConfigsToServer([1]);
  600. expect(controller.getServiceConfigData.calledWith([1])).to.be.true;
  601. expect(App.ajax.send.calledOnce).to.be.true;
  602. });
  603. });
  604. describe('#setSpecificNamenodeConfigs()', function () {
  605. var isHaEnabled = false;
  606. var service = Em.Object.create();
  607. beforeEach(function () {
  608. sinon.stub(App, 'get', function () {
  609. return isHaEnabled;
  610. });
  611. sinon.stub(App.Service, 'find', function () {
  612. return service;
  613. });
  614. controller.set('content.reassignHosts.source', 'host1');
  615. });
  616. afterEach(function () {
  617. App.get.restore();
  618. App.Service.find.restore();
  619. });
  620. it('HA isn\'t enabled and no HBASE service', function () {
  621. isHaEnabled = false;
  622. var configs = {};
  623. controller.setSpecificNamenodeConfigs(configs, 'host1');
  624. expect(configs).to.eql({});
  625. });
  626. it('HA isn\'t enabled and HBASE service', function () {
  627. isHaEnabled = false;
  628. service = Em.Object.create({
  629. isLoaded: true
  630. });
  631. var configs = {
  632. 'hbase-site': {
  633. 'hbase.rootdir': 'hdfs://localhost:8020/apps/hbase/data'
  634. }
  635. };
  636. controller.setSpecificNamenodeConfigs(configs, 'host1');
  637. expect(configs['hbase-site']['hbase.rootdir']).to.equal('hdfs://host1:8020/apps/hbase/data');
  638. });
  639. it('HA enabled and namenode 1', function () {
  640. isHaEnabled = true;
  641. var configs = {
  642. 'hdfs-site': {
  643. 'dfs.nameservices': 's',
  644. 'dfs.namenode.http-address.s.nn1': 'host1:50070',
  645. 'dfs.namenode.https-address.s.nn1': '',
  646. 'dfs.namenode.rpc-address.s.nn1': ''
  647. }
  648. };
  649. controller.setSpecificNamenodeConfigs(configs, 'host2');
  650. expect(configs['hdfs-site']).to.eql({
  651. "dfs.nameservices": "s",
  652. "dfs.namenode.http-address.s.nn1": "host2:50070",
  653. "dfs.namenode.https-address.s.nn1": "host2:50470",
  654. "dfs.namenode.rpc-address.s.nn1": "host2:8020"
  655. });
  656. });
  657. it('HA enabled and namenode 2', function () {
  658. isHaEnabled = true;
  659. var configs = {
  660. 'hdfs-site': {
  661. 'dfs.nameservices': 's',
  662. 'dfs.namenode.http-address.s.nn2': 'host2:50070',
  663. 'dfs.namenode.https-address.s.nn2': '',
  664. 'dfs.namenode.rpc-address.s.nn2': ''
  665. }
  666. };
  667. controller.setSpecificNamenodeConfigs(configs, 'host1');
  668. expect(configs['hdfs-site']).to.eql({
  669. "dfs.nameservices": "s",
  670. "dfs.namenode.http-address.s.nn2": "host1:50070",
  671. "dfs.namenode.https-address.s.nn2": "host1:50470",
  672. "dfs.namenode.rpc-address.s.nn2": "host1:8020"
  673. });
  674. });
  675. });
  676. describe('#setSpecificResourceMangerConfigs()', function () {
  677. var isRMHaEnabled = false;
  678. var service = Em.Object.create();
  679. beforeEach(function () {
  680. sinon.stub(App, 'get', function () {
  681. return isRMHaEnabled;
  682. });
  683. controller.set('content.reassignHosts.source', 'host1');
  684. });
  685. afterEach(function () {
  686. App.get.restore();
  687. });
  688. it('HA isn\'t enabled', function () {
  689. isRMHaEnabled = false;
  690. var configs = {};
  691. controller.setSpecificResourceMangerConfigs(configs, 'host1');
  692. expect(configs).to.eql({});
  693. });
  694. it('HA enabled and resource manager 1', function () {
  695. isRMHaEnabled = true;
  696. var configs = {
  697. 'yarn-site': {
  698. 'yarn.resourcemanager.hostname.rm1': 'host1'
  699. }
  700. };
  701. controller.setSpecificResourceMangerConfigs(configs, 'host2');
  702. expect(configs['yarn-site']).to.eql({
  703. 'yarn.resourcemanager.hostname.rm1': 'host2'
  704. });
  705. });
  706. it('HA enabled and resource manager 2', function () {
  707. isRMHaEnabled = true;
  708. var configs = {
  709. 'yarn-site': {
  710. 'yarn.resourcemanager.hostname.rm2': 'host2'
  711. }
  712. };
  713. controller.setSpecificResourceMangerConfigs(configs, 'host1');
  714. expect(configs['yarn-site']).to.eql({
  715. 'yarn.resourcemanager.hostname.rm2': 'host1'
  716. });
  717. });
  718. });
  719. describe('#setSecureConfigs()', function () {
  720. it('undefined component and security disabled', function () {
  721. var secureConfigs = [];
  722. controller.set('content.securityEnabled', false);
  723. controller.set('secureConfigsMap', []);
  724. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  725. expect(secureConfigs).to.eql([]);
  726. });
  727. it('undefined component and security enabled', function () {
  728. var secureConfigs = [];
  729. controller.set('content.securityEnabled', true);
  730. controller.set('secureConfigsMap', []);
  731. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  732. expect(secureConfigs).to.eql([]);
  733. });
  734. it('component exist and security disabled', function () {
  735. var secureConfigs = [];
  736. controller.set('content.securityEnabled', false);
  737. controller.set('secureConfigsMap', [{
  738. componentName: 'COMP1'
  739. }]);
  740. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  741. expect(secureConfigs).to.eql([]);
  742. });
  743. it('component exist and security enabled', function () {
  744. var secureConfigs = [];
  745. var configs = {'s1': {
  746. 'k1': 'kValue',
  747. 'p1': 'pValue'
  748. }};
  749. controller.set('content.securityEnabled', true);
  750. controller.set('secureConfigsMap', [{
  751. componentName: 'COMP1',
  752. configs: [{
  753. site: 's1',
  754. keytab: 'k1',
  755. principal: 'p1'
  756. }]
  757. }]);
  758. expect(controller.setSecureConfigs(secureConfigs, configs, 'COMP1')).to.be.true;
  759. expect(secureConfigs).to.eql([
  760. {
  761. "keytab": "kValue",
  762. "principal": "pValue"
  763. }
  764. ]);
  765. });
  766. });
  767. describe('#getComponentDir()', function () {
  768. var isHadoop2Stack = false;
  769. beforeEach(function () {
  770. sinon.stub(App, 'get', function () {
  771. return isHadoop2Stack;
  772. });
  773. });
  774. afterEach(function () {
  775. App.get.restore();
  776. });
  777. var configs = {
  778. 'hdfs-site': {
  779. 'dfs.name.dir': 'case1',
  780. 'dfs.namenode.name.dir': 'case2',
  781. 'dfs.namenode.checkpoint.dir': 'case3'
  782. },
  783. 'core-site': {
  784. 'fs.checkpoint.dir': 'case4'
  785. }
  786. };
  787. it('unknown component name', function () {
  788. expect(controller.getComponentDir(configs, 'COMP1')).to.be.empty;
  789. });
  790. it('NAMENODE component and isHadoop2Stack is false', function () {
  791. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case1');
  792. });
  793. it('NAMENODE component and isHadoop2Stack is true', function () {
  794. isHadoop2Stack = true;
  795. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case2');
  796. });
  797. it('SECONDARY_NAMENODE component and isHadoop2Stack is true', function () {
  798. isHadoop2Stack = true;
  799. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case3');
  800. });
  801. it('SECONDARY_NAMENODE component and isHadoop2Stack is false', function () {
  802. isHadoop2Stack = false;
  803. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case4');
  804. });
  805. });
  806. describe('#saveClusterStatus()', function () {
  807. var mock = {
  808. saveComponentDir: Em.K,
  809. saveSecureConfigs: Em.K
  810. };
  811. beforeEach(function () {
  812. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  813. sinon.stub(App.router, 'get', function() {
  814. return mock;
  815. });
  816. sinon.spy(mock, 'saveComponentDir');
  817. sinon.spy(mock, 'saveSecureConfigs');
  818. });
  819. afterEach(function () {
  820. App.clusterStatus.setClusterStatus.restore();
  821. App.router.get.restore();
  822. mock.saveSecureConfigs.restore();
  823. mock.saveComponentDir.restore();
  824. });
  825. it('componentDir undefined and secureConfigs is empty', function () {
  826. expect(controller.saveClusterStatus([], null)).to.be.false;
  827. });
  828. it('componentDir defined and secureConfigs is empty', function () {
  829. expect(controller.saveClusterStatus([], 'dir1')).to.be.true;
  830. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  831. expect(mock.saveSecureConfigs.calledWith([])).to.be.true;
  832. });
  833. it('componentDir undefined and secureConfigs has data', function () {
  834. expect(controller.saveClusterStatus([1], null)).to.be.true;
  835. expect(mock.saveComponentDir.calledWith(null)).to.be.true;
  836. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  837. });
  838. it('componentDir defined and secureConfigs has data', function () {
  839. expect(controller.saveClusterStatus([1], 'dir1')).to.be.true;
  840. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  841. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  842. });
  843. });
  844. describe('#onSaveConfigs()', function () {
  845. beforeEach(function () {
  846. sinon.stub(controller, 'onTaskCompleted', Em.K);
  847. });
  848. afterEach(function () {
  849. controller.onTaskCompleted.restore();
  850. });
  851. it('', function () {
  852. controller.onSaveConfigs();
  853. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  854. });
  855. });
  856. describe('#startZooKeeperServers()', function () {
  857. beforeEach(function () {
  858. sinon.stub(controller, 'updateComponent', Em.K);
  859. });
  860. afterEach(function () {
  861. controller.updateComponent.restore();
  862. });
  863. it('', function () {
  864. controller.set('content.masterComponentHosts', [{
  865. component: 'ZOOKEEPER_SERVER',
  866. hostName: 'host1'
  867. }]);
  868. controller.startZooKeeperServers();
  869. expect(controller.updateComponent.calledWith('ZOOKEEPER_SERVER', ['host1'], 'ZOOKEEPER', 'Start')).to.be.true;
  870. });
  871. });
  872. describe('#startNameNode()', function () {
  873. beforeEach(function () {
  874. sinon.stub(controller, 'updateComponent', Em.K);
  875. });
  876. afterEach(function () {
  877. controller.updateComponent.restore();
  878. });
  879. it('reassign host does not match current', function () {
  880. controller.set('content.masterComponentHosts', [{
  881. component: 'NAMENODE',
  882. hostName: 'host1'
  883. }]);
  884. controller.set('content.reassignHosts.source', 'host2');
  885. controller.startNameNode();
  886. expect(controller.updateComponent.calledWith('NAMENODE', ['host1'], 'HDFS', 'Start')).to.be.true;
  887. });
  888. it('reassign host matches current', function () {
  889. controller.set('content.masterComponentHosts', [{
  890. component: 'NAMENODE',
  891. hostName: 'host1'
  892. }]);
  893. controller.set('content.reassignHosts.source', 'host1');
  894. controller.startNameNode();
  895. expect(controller.updateComponent.calledWith('NAMENODE', [], 'HDFS', 'Start')).to.be.true;
  896. });
  897. });
  898. describe('#startServices()', function () {
  899. beforeEach(function () {
  900. sinon.stub(controller, 'getStartServicesData', Em.K);
  901. });
  902. afterEach(function () {
  903. controller.getStartServicesData.restore();
  904. });
  905. it('', function () {
  906. controller.startServices();
  907. expect(controller.getStartServicesData.calledOnce).to.be.true;
  908. expect(App.ajax.send.calledOnce).to.be.true;
  909. });
  910. });
  911. describe('#getStartServicesData()', function () {
  912. beforeEach(function () {
  913. sinon.stub(App.Service, 'find', function () {
  914. return [
  915. {serviceName: 'SERVICE1'},
  916. {serviceName: 'SERVICE2'}
  917. ]
  918. })
  919. });
  920. afterEach(function () {
  921. App.Service.find.restore();
  922. });
  923. it('No unrelated services', function () {
  924. controller.set('unrelatedServicesMap', {
  925. 'COMP1': ['SERVICE1']
  926. });
  927. controller.set('content.reassign.component_name', 'COMP2');
  928. expect(controller.getStartServicesData()).to.eql({
  929. "context": "Start all services",
  930. "ServiceInfo": {
  931. "state": "STARTED"
  932. },
  933. "urlParams": "params/run_smoke_test=true"
  934. });
  935. });
  936. it('Present unrelated services', function () {
  937. controller.set('unrelatedServicesMap', {
  938. 'COMP1': ['SERVICE1']
  939. });
  940. controller.set('content.reassign.component_name', 'COMP1');
  941. expect(controller.getStartServicesData()).to.eql({
  942. "context": "Start required services",
  943. "ServiceInfo": {
  944. "state": "STARTED"
  945. },
  946. "urlParams": "ServiceInfo/service_name.in(SERVICE2)"
  947. });
  948. });
  949. });
  950. describe('#deleteHostComponents()', function () {
  951. it('No host components', function () {
  952. controller.set('hostComponents', []);
  953. controller.set('content.reassignHosts.source', 'host1');
  954. controller.deleteHostComponents();
  955. expect(App.ajax.send.called).to.be.false;
  956. });
  957. it('delete two components', function () {
  958. controller.set('hostComponents', [1, 2]);
  959. controller.set('content.reassignHosts.source', 'host1');
  960. controller.deleteHostComponents();
  961. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  962. "hostName": "host1",
  963. "componentName": 1
  964. });
  965. expect(App.ajax.send.getCall(1).args[0].data).to.eql({
  966. "hostName": "host1",
  967. "componentName": 2
  968. });
  969. });
  970. });
  971. describe('#onDeleteHostComponentsError()', function () {
  972. beforeEach(function () {
  973. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  974. sinon.stub(controller, 'onTaskError', Em.K);
  975. });
  976. afterEach(function () {
  977. controller.onComponentsTasksSuccess.restore();
  978. controller.onTaskError.restore();
  979. });
  980. it('task success', function () {
  981. var error = {
  982. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  983. }
  984. controller.onDeleteHostComponentsError(error);
  985. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  986. });
  987. it('unknown error', function () {
  988. var error = {
  989. responseText: ''
  990. }
  991. controller.onDeleteHostComponentsError(error);
  992. expect(controller.onTaskError.calledOnce).to.be.true;
  993. });
  994. });
  995. describe('#done()', function () {
  996. beforeEach(function () {
  997. sinon.stub(controller, 'removeObserver', Em.K);
  998. sinon.stub(App.router, 'send', Em.K);
  999. });
  1000. afterEach(function () {
  1001. controller.removeObserver.restore();
  1002. App.router.send.restore();
  1003. });
  1004. it('submit disabled', function () {
  1005. controller.set('isSubmitDisabled', true);
  1006. controller.done();
  1007. expect(App.router.send.called).to.be.false;
  1008. });
  1009. it('submit enabled and does not have manual steps', function () {
  1010. controller.set('isSubmitDisabled', false);
  1011. controller.set('content.hasManualSteps', false);
  1012. controller.done();
  1013. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  1014. expect(App.router.send.calledWith('complete')).to.be.true;
  1015. });
  1016. it('submit enabled and has manual steps', function () {
  1017. controller.set('isSubmitDisabled', false);
  1018. controller.set('content.hasManualSteps', true);
  1019. controller.done();
  1020. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  1021. expect(App.router.send.calledWith('next')).to.be.true;
  1022. });
  1023. });
  1024. describe('#getServiceConfigData()', function () {
  1025. var services = [];
  1026. var stackServices = [];
  1027. beforeEach(function () {
  1028. sinon.stub(App.Service, 'find', function () {
  1029. return services;
  1030. });
  1031. sinon.stub(App.StackService, 'find', function () {
  1032. return stackServices;
  1033. });
  1034. });
  1035. afterEach(function () {
  1036. App.Service.find.restore();
  1037. App.StackService.find.restore();
  1038. });
  1039. it('No services', function () {
  1040. services = [];
  1041. controller.set('content.reassign.component_name', 'COMP1');
  1042. expect(controller.getServiceConfigData([])).to.eql([]);
  1043. });
  1044. it('No services in stackServices', function () {
  1045. services = [Em.Object.create({serviceName: 'S1'})];
  1046. stackServices = [];
  1047. controller.set('content.reassign.component_name', 'COMP1');
  1048. expect(controller.getServiceConfigData([])).to.eql([]);
  1049. });
  1050. it('Services in stackServicesm but configTypesRendered is empty', function () {
  1051. services = [Em.Object.create({serviceName: 'S1'})];
  1052. stackServices = [Em.Object.create({
  1053. serviceName: 'S1',
  1054. configTypesRendered: {}
  1055. })];
  1056. controller.set('content.reassign.component_name', 'COMP1');
  1057. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  1058. });
  1059. it('Services in stackServicesm and configTypesRendered has data, but configs is empty', function () {
  1060. services = [Em.Object.create({serviceName: 'S1'})];
  1061. stackServices = [
  1062. Em.Object.create({
  1063. serviceName: 'S1',
  1064. configTypesRendered: {'type1': {}}
  1065. })
  1066. ];
  1067. controller.set('content.reassign.component_name', 'COMP1');
  1068. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  1069. });
  1070. it('Services in stackServicesm and configTypesRendered has data, and configs present', function () {
  1071. services = [Em.Object.create({serviceName: 'S1'})];
  1072. stackServices = [
  1073. Em.Object.create({
  1074. serviceName: 'S1',
  1075. configTypesRendered: {'type1': {}}
  1076. })
  1077. ];
  1078. var configs = {
  1079. 'type1': {
  1080. 'prop1': 'value1'
  1081. }
  1082. };
  1083. controller.set('content.reassign.component_name', 'COMP1');
  1084. expect(JSON.parse(controller.getServiceConfigData(configs)[0]).Clusters.desired_config.length).to.equal(1);
  1085. });
  1086. });
  1087. });