step4_controller_test.js 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  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. var data = {
  424. Clusters: {
  425. desired_configs: {
  426. 'hdfs-site': {tag: 1},
  427. 'core-site': {tag: 2},
  428. 'hbase-site': {tag: 3},
  429. 'mapred-site': {tag: 4},
  430. 'yarn-site': {tag: 5}
  431. }
  432. }
  433. };
  434. var services = [];
  435. beforeEach(function () {
  436. sinon.stub(App.Service, 'find', function () {
  437. return services;
  438. })
  439. });
  440. afterEach(function () {
  441. App.Service.find.restore();
  442. });
  443. testCases.forEach(function (test) {
  444. it('get config of ' + test.componentName, function () {
  445. expect(controller.getConfigUrlParams(test.componentName, data)).to.eql(test.result);
  446. })
  447. });
  448. it('get config of NAMENODE when HBASE installed', function () {
  449. services = [
  450. {
  451. serviceName: 'HBASE'
  452. }
  453. ];
  454. expect(controller.getConfigUrlParams('NAMENODE', data)).to.eql([
  455. "(type=hdfs-site&tag=1)",
  456. "(type=core-site&tag=2)",
  457. "(type=hbase-site&tag=3)"
  458. ]);
  459. })
  460. });
  461. describe('#onLoadConfigsTags()', function () {
  462. it('', function () {
  463. sinon.stub(controller, 'getConfigUrlParams', function () {
  464. return [];
  465. });
  466. controller.set('content.reassign.component_name', 'COMP1');
  467. controller.onLoadConfigsTags({});
  468. expect(App.ajax.send.calledOnce).to.be.true;
  469. expect(controller.getConfigUrlParams.calledWith('COMP1', {})).to.be.true;
  470. controller.getConfigUrlParams.restore();
  471. });
  472. });
  473. describe('#onLoadConfigs()', function () {
  474. beforeEach(function () {
  475. sinon.stub(controller, 'setAdditionalConfigs', Em.K);
  476. sinon.stub(controller, 'setSecureConfigs', Em.K);
  477. sinon.stub(controller, 'setSpecificNamenodeConfigs', Em.K);
  478. sinon.stub(controller, 'setSpecificResourceMangerConfigs', Em.K);
  479. sinon.stub(controller, 'getComponentDir', Em.K);
  480. sinon.stub(controller, 'saveClusterStatus', Em.K);
  481. sinon.stub(controller, 'saveConfigsToServer', Em.K);
  482. controller.set('content.reassignHosts.target', 'host1');
  483. });
  484. afterEach(function () {
  485. controller.setAdditionalConfigs.restore();
  486. controller.setSecureConfigs.restore();
  487. controller.setSpecificNamenodeConfigs.restore();
  488. controller.setSpecificResourceMangerConfigs.restore();
  489. controller.getComponentDir.restore();
  490. controller.saveClusterStatus.restore();
  491. controller.saveConfigsToServer.restore();
  492. });
  493. it('component is not NAMENODE', function () {
  494. controller.set('content.reassign.component_name', 'COMP1');
  495. controller.onLoadConfigs({items: []});
  496. expect(controller.setAdditionalConfigs.calledWith({}, 'COMP1', 'host1')).to.be.true;
  497. expect(controller.setSecureConfigs.calledWith([], {}, 'COMP1')).to.be.true;
  498. expect(controller.setSpecificNamenodeConfigs.called).to.be.false;
  499. expect(controller.getComponentDir.calledWith({}, 'COMP1')).to.be.true;
  500. expect(controller.saveClusterStatus.calledWith([])).to.be.true;
  501. expect(controller.saveConfigsToServer.calledWith({})).to.be.true;
  502. });
  503. it('component is NAMENODE, has configs', function () {
  504. controller.set('content.reassign.component_name', 'NAMENODE');
  505. controller.onLoadConfigs({items: [
  506. {
  507. type: 'hdfs-site',
  508. properties: {}
  509. }
  510. ]});
  511. expect(controller.setAdditionalConfigs.calledWith({'hdfs-site': {}}, 'NAMENODE', 'host1')).to.be.true;
  512. expect(controller.setSecureConfigs.calledWith([], {'hdfs-site': {}}, 'NAMENODE')).to.be.true;
  513. expect(controller.setSpecificNamenodeConfigs.calledWith({'hdfs-site': {}}, 'host1')).to.be.true;
  514. expect(controller.getComponentDir.calledWith({'hdfs-site': {}}, 'NAMENODE')).to.be.true;
  515. expect(controller.saveClusterStatus.calledWith([])).to.be.true;
  516. expect(controller.saveConfigsToServer.calledWith({'hdfs-site': {}})).to.be.true;
  517. });
  518. it('component is RESOURCEMANAGER, has configs', function () {
  519. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  520. controller.onLoadConfigs({items: [
  521. {
  522. type: 'hdfs-site',
  523. properties: {}
  524. }
  525. ]});
  526. expect(controller.setAdditionalConfigs.calledWith({'hdfs-site': {}}, 'RESOURCEMANAGER', 'host1')).to.be.true;
  527. expect(controller.setSecureConfigs.calledWith([], {'hdfs-site': {}}, 'RESOURCEMANAGER')).to.be.true;
  528. expect(controller.setSpecificResourceMangerConfigs.calledWith({'hdfs-site': {}}, 'host1')).to.be.true;
  529. expect(controller.getComponentDir.calledWith({'hdfs-site': {}}, 'RESOURCEMANAGER')).to.be.true;
  530. expect(controller.saveClusterStatus.calledWith([])).to.be.true;
  531. expect(controller.saveConfigsToServer.calledWith({'hdfs-site': {}})).to.be.true;
  532. });
  533. });
  534. describe('#loadStep()', function () {
  535. var isHaEnabled = true;
  536. beforeEach(function () {
  537. controller.set('content.reassign.service_id', 'service1');
  538. sinon.stub(controller, 'onTaskStatusChange', Em.K);
  539. sinon.stub(controller, 'initializeTasks', Em.K);
  540. sinon.stub(App, 'get', function () {
  541. return isHaEnabled;
  542. });
  543. });
  544. afterEach(function () {
  545. controller.onTaskStatusChange.restore();
  546. controller.initializeTasks.restore();
  547. App.get.restore();
  548. });
  549. it('reassign component is NameNode and HA enabled', function () {
  550. isHaEnabled = true;
  551. controller.set('content.reassign.component_name', 'NAMENODE');
  552. controller.loadStep();
  553. expect(controller.get('hostComponents')).to.eql(['NAMENODE', 'ZKFC']);
  554. expect(controller.get('serviceName')).to.eql(['service1']);
  555. });
  556. it('reassign component is NameNode and HA disabled', function () {
  557. isHaEnabled = false;
  558. controller.set('content.reassign.component_name', 'NAMENODE');
  559. controller.loadStep();
  560. expect(controller.get('hostComponents')).to.eql(['NAMENODE']);
  561. expect(controller.get('serviceName')).to.eql(['service1']);
  562. });
  563. it('reassign component is JOBTRACKER and HA enabled', function () {
  564. isHaEnabled = true;
  565. controller.set('content.reassign.component_name', 'JOBTRACKER');
  566. controller.loadStep();
  567. expect(controller.get('hostComponents')).to.eql(['JOBTRACKER']);
  568. expect(controller.get('serviceName')).to.eql(['service1']);
  569. });
  570. it('reassign component is RESOURCEMANAGER and HA enabled', function () {
  571. isHaEnabled = true;
  572. controller.set('content.reassign.component_name', 'RESOURCEMANAGER');
  573. controller.loadStep();
  574. expect(controller.get('hostComponents')).to.eql(['RESOURCEMANAGER']);
  575. expect(controller.get('serviceName')).to.eql(['service1']);
  576. });
  577. });
  578. describe('#saveConfigsToServer()', function () {
  579. beforeEach(function () {
  580. sinon.stub(controller, 'getServiceConfigData', Em.K);
  581. });
  582. afterEach(function () {
  583. controller.getServiceConfigData.restore();
  584. });
  585. it('', function () {
  586. controller.saveConfigsToServer([1]);
  587. expect(controller.getServiceConfigData.calledWith([1])).to.be.true;
  588. expect(App.ajax.send.calledOnce).to.be.true;
  589. });
  590. });
  591. describe('#setSpecificNamenodeConfigs()', function () {
  592. var isHaEnabled = false;
  593. var service = Em.Object.create();
  594. beforeEach(function () {
  595. sinon.stub(App, 'get', function () {
  596. return isHaEnabled;
  597. });
  598. sinon.stub(App.Service, 'find', function () {
  599. return service;
  600. });
  601. controller.set('content.reassignHosts.source', 'host1');
  602. });
  603. afterEach(function () {
  604. App.get.restore();
  605. App.Service.find.restore();
  606. });
  607. it('HA isn\'t enabled and no HBASE service', function () {
  608. isHaEnabled = false;
  609. var configs = {};
  610. controller.setSpecificNamenodeConfigs(configs, 'host1');
  611. expect(configs).to.eql({});
  612. });
  613. it('HA isn\'t enabled and HBASE service', function () {
  614. isHaEnabled = false;
  615. service = Em.Object.create({
  616. isLoaded: true
  617. });
  618. var configs = {
  619. 'hbase-site': {
  620. 'hbase.rootdir': 'hdfs://localhost:8020/apps/hbase/data'
  621. }
  622. };
  623. controller.setSpecificNamenodeConfigs(configs, 'host1');
  624. expect(configs['hbase-site']['hbase.rootdir']).to.equal('hdfs://host1:8020/apps/hbase/data');
  625. });
  626. it('HA enabled and namenode 1', function () {
  627. isHaEnabled = true;
  628. var configs = {
  629. 'hdfs-site': {
  630. 'dfs.nameservices': 's',
  631. 'dfs.namenode.http-address.s.nn1': 'host1:50070',
  632. 'dfs.namenode.https-address.s.nn1': '',
  633. 'dfs.namenode.rpc-address.s.nn1': ''
  634. }
  635. };
  636. controller.setSpecificNamenodeConfigs(configs, 'host2');
  637. expect(configs['hdfs-site']).to.eql({
  638. "dfs.nameservices": "s",
  639. "dfs.namenode.http-address.s.nn1": "host2:50070",
  640. "dfs.namenode.https-address.s.nn1": "host2:50470",
  641. "dfs.namenode.rpc-address.s.nn1": "host2:8020"
  642. });
  643. });
  644. it('HA enabled and namenode 2', function () {
  645. isHaEnabled = true;
  646. var configs = {
  647. 'hdfs-site': {
  648. 'dfs.nameservices': 's',
  649. 'dfs.namenode.http-address.s.nn2': 'host2:50070',
  650. 'dfs.namenode.https-address.s.nn2': '',
  651. 'dfs.namenode.rpc-address.s.nn2': ''
  652. }
  653. };
  654. controller.setSpecificNamenodeConfigs(configs, 'host1');
  655. expect(configs['hdfs-site']).to.eql({
  656. "dfs.nameservices": "s",
  657. "dfs.namenode.http-address.s.nn2": "host1:50070",
  658. "dfs.namenode.https-address.s.nn2": "host1:50470",
  659. "dfs.namenode.rpc-address.s.nn2": "host1:8020"
  660. });
  661. });
  662. });
  663. describe('#setSpecificResourceMangerConfigs()', function () {
  664. var isRMHaEnabled = false;
  665. var service = Em.Object.create();
  666. beforeEach(function () {
  667. sinon.stub(App, 'get', function () {
  668. return isRMHaEnabled;
  669. });
  670. controller.set('content.reassignHosts.source', 'host1');
  671. });
  672. afterEach(function () {
  673. App.get.restore();
  674. });
  675. it('HA isn\'t enabled', function () {
  676. isRMHaEnabled = false;
  677. var configs = {};
  678. controller.setSpecificResourceMangerConfigs(configs, 'host1');
  679. expect(configs).to.eql({});
  680. });
  681. it('HA enabled and resource manager 1', function () {
  682. isRMHaEnabled = true;
  683. var configs = {
  684. 'yarn-site': {
  685. 'yarn.resourcemanager.hostname.rm1': 'host1'
  686. }
  687. };
  688. controller.setSpecificResourceMangerConfigs(configs, 'host2');
  689. expect(configs['yarn-site']).to.eql({
  690. 'yarn.resourcemanager.hostname.rm1': 'host2'
  691. });
  692. });
  693. it('HA enabled and resource manager 2', function () {
  694. isRMHaEnabled = true;
  695. var configs = {
  696. 'yarn-site': {
  697. 'yarn.resourcemanager.hostname.rm2': 'host2'
  698. }
  699. };
  700. controller.setSpecificResourceMangerConfigs(configs, 'host1');
  701. expect(configs['yarn-site']).to.eql({
  702. 'yarn.resourcemanager.hostname.rm2': 'host1'
  703. });
  704. });
  705. });
  706. describe('#setSecureConfigs()', function () {
  707. it('undefined component and security disabled', function () {
  708. var secureConfigs = [];
  709. controller.set('content.securityEnabled', false);
  710. controller.set('secureConfigsMap', []);
  711. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  712. expect(secureConfigs).to.eql([]);
  713. });
  714. it('undefined component and security enabled', function () {
  715. var secureConfigs = [];
  716. controller.set('content.securityEnabled', true);
  717. controller.set('secureConfigsMap', []);
  718. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  719. expect(secureConfigs).to.eql([]);
  720. });
  721. it('component exist and security disabled', function () {
  722. var secureConfigs = [];
  723. controller.set('content.securityEnabled', false);
  724. controller.set('secureConfigsMap', [{
  725. componentName: 'COMP1'
  726. }]);
  727. expect(controller.setSecureConfigs(secureConfigs, {}, 'COMP1')).to.be.false;
  728. expect(secureConfigs).to.eql([]);
  729. });
  730. it('component exist and security enabled', function () {
  731. var secureConfigs = [];
  732. var configs = {'s1': {
  733. 'k1': 'kValue',
  734. 'p1': 'pValue'
  735. }};
  736. controller.set('content.securityEnabled', true);
  737. controller.set('secureConfigsMap', [{
  738. componentName: 'COMP1',
  739. configs: [{
  740. site: 's1',
  741. keytab: 'k1',
  742. principal: 'p1'
  743. }]
  744. }]);
  745. expect(controller.setSecureConfigs(secureConfigs, configs, 'COMP1')).to.be.true;
  746. expect(secureConfigs).to.eql([
  747. {
  748. "keytab": "kValue",
  749. "principal": "pValue"
  750. }
  751. ]);
  752. });
  753. });
  754. describe('#getComponentDir()', function () {
  755. var isHadoop2Stack = false;
  756. beforeEach(function () {
  757. sinon.stub(App, 'get', function () {
  758. return isHadoop2Stack;
  759. });
  760. });
  761. afterEach(function () {
  762. App.get.restore();
  763. });
  764. var configs = {
  765. 'hdfs-site': {
  766. 'dfs.name.dir': 'case1',
  767. 'dfs.namenode.name.dir': 'case2',
  768. 'dfs.namenode.checkpoint.dir': 'case3'
  769. },
  770. 'core-site': {
  771. 'fs.checkpoint.dir': 'case4'
  772. }
  773. };
  774. it('unknown component name', function () {
  775. expect(controller.getComponentDir(configs, 'COMP1')).to.be.empty;
  776. });
  777. it('NAMENODE component and isHadoop2Stack is false', function () {
  778. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case1');
  779. });
  780. it('NAMENODE component and isHadoop2Stack is true', function () {
  781. isHadoop2Stack = true;
  782. expect(controller.getComponentDir(configs, 'NAMENODE')).to.equal('case2');
  783. });
  784. it('SECONDARY_NAMENODE component and isHadoop2Stack is true', function () {
  785. isHadoop2Stack = true;
  786. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case3');
  787. });
  788. it('SECONDARY_NAMENODE component and isHadoop2Stack is false', function () {
  789. isHadoop2Stack = false;
  790. expect(controller.getComponentDir(configs, 'SECONDARY_NAMENODE')).to.equal('case4');
  791. });
  792. });
  793. describe('#saveClusterStatus()', function () {
  794. var mock = {
  795. saveComponentDir: Em.K,
  796. saveSecureConfigs: Em.K
  797. };
  798. beforeEach(function () {
  799. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  800. sinon.stub(App.router, 'get', function() {
  801. return mock;
  802. });
  803. sinon.spy(mock, 'saveComponentDir');
  804. sinon.spy(mock, 'saveSecureConfigs');
  805. });
  806. afterEach(function () {
  807. App.clusterStatus.setClusterStatus.restore();
  808. App.router.get.restore();
  809. mock.saveSecureConfigs.restore();
  810. mock.saveComponentDir.restore();
  811. });
  812. it('componentDir undefined and secureConfigs is empty', function () {
  813. expect(controller.saveClusterStatus([], null)).to.be.false;
  814. });
  815. it('componentDir defined and secureConfigs is empty', function () {
  816. expect(controller.saveClusterStatus([], 'dir1')).to.be.true;
  817. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  818. expect(mock.saveSecureConfigs.calledWith([])).to.be.true;
  819. });
  820. it('componentDir undefined and secureConfigs has data', function () {
  821. expect(controller.saveClusterStatus([1], null)).to.be.true;
  822. expect(mock.saveComponentDir.calledWith(null)).to.be.true;
  823. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  824. });
  825. it('componentDir defined and secureConfigs has data', function () {
  826. expect(controller.saveClusterStatus([1], 'dir1')).to.be.true;
  827. expect(mock.saveComponentDir.calledWith('dir1')).to.be.true;
  828. expect(mock.saveSecureConfigs.calledWith([1])).to.be.true;
  829. });
  830. });
  831. describe('#onSaveConfigs()', function () {
  832. beforeEach(function () {
  833. sinon.stub(controller, 'onTaskCompleted', Em.K);
  834. });
  835. afterEach(function () {
  836. controller.onTaskCompleted.restore();
  837. });
  838. it('', function () {
  839. controller.onSaveConfigs();
  840. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  841. });
  842. });
  843. describe('#startZooKeeperServers()', function () {
  844. beforeEach(function () {
  845. sinon.stub(controller, 'updateComponent', Em.K);
  846. });
  847. afterEach(function () {
  848. controller.updateComponent.restore();
  849. });
  850. it('', function () {
  851. controller.set('content.masterComponentHosts', [{
  852. component: 'ZOOKEEPER_SERVER',
  853. hostName: 'host1'
  854. }]);
  855. controller.startZooKeeperServers();
  856. expect(controller.updateComponent.calledWith('ZOOKEEPER_SERVER', ['host1'], 'ZOOKEEPER', 'Start')).to.be.true;
  857. });
  858. });
  859. describe('#startNameNode()', function () {
  860. beforeEach(function () {
  861. sinon.stub(controller, 'updateComponent', Em.K);
  862. });
  863. afterEach(function () {
  864. controller.updateComponent.restore();
  865. });
  866. it('reassign host does not match current', function () {
  867. controller.set('content.masterComponentHosts', [{
  868. component: 'NAMENODE',
  869. hostName: 'host1'
  870. }]);
  871. controller.set('content.reassignHosts.source', 'host2');
  872. controller.startNameNode();
  873. expect(controller.updateComponent.calledWith('NAMENODE', ['host1'], 'HDFS', 'Start')).to.be.true;
  874. });
  875. it('reassign host matches current', function () {
  876. controller.set('content.masterComponentHosts', [{
  877. component: 'NAMENODE',
  878. hostName: 'host1'
  879. }]);
  880. controller.set('content.reassignHosts.source', 'host1');
  881. controller.startNameNode();
  882. expect(controller.updateComponent.calledWith('NAMENODE', [], 'HDFS', 'Start')).to.be.true;
  883. });
  884. });
  885. describe('#startServices()', function () {
  886. beforeEach(function () {
  887. sinon.stub(controller, 'getStartServicesData', Em.K);
  888. });
  889. afterEach(function () {
  890. controller.getStartServicesData.restore();
  891. });
  892. it('', function () {
  893. controller.startServices();
  894. expect(controller.getStartServicesData.calledOnce).to.be.true;
  895. expect(App.ajax.send.calledOnce).to.be.true;
  896. });
  897. });
  898. describe('#getStartServicesData()', function () {
  899. beforeEach(function () {
  900. sinon.stub(App.Service, 'find', function () {
  901. return [
  902. {serviceName: 'SERVICE1'},
  903. {serviceName: 'SERVICE2'}
  904. ]
  905. })
  906. });
  907. afterEach(function () {
  908. App.Service.find.restore();
  909. });
  910. it('No unrelated services', function () {
  911. controller.set('unrelatedServicesMap', {
  912. 'COMP1': ['SERVICE1']
  913. });
  914. controller.set('content.reassign.component_name', 'COMP2');
  915. expect(controller.getStartServicesData()).to.eql({
  916. "context": "Start all services",
  917. "ServiceInfo": {
  918. "state": "STARTED"
  919. },
  920. "urlParams": "params/run_smoke_test=true"
  921. });
  922. });
  923. it('Present unrelated services', function () {
  924. controller.set('unrelatedServicesMap', {
  925. 'COMP1': ['SERVICE1']
  926. });
  927. controller.set('content.reassign.component_name', 'COMP1');
  928. expect(controller.getStartServicesData()).to.eql({
  929. "context": "Start required services",
  930. "ServiceInfo": {
  931. "state": "STARTED"
  932. },
  933. "urlParams": "ServiceInfo/service_name.in(SERVICE2)"
  934. });
  935. });
  936. });
  937. describe('#deleteHostComponents()', function () {
  938. it('No host components', function () {
  939. controller.set('hostComponents', []);
  940. controller.set('content.reassignHosts.source', 'host1');
  941. controller.deleteHostComponents();
  942. expect(App.ajax.send.called).to.be.false;
  943. });
  944. it('delete two components', function () {
  945. controller.set('hostComponents', [1, 2]);
  946. controller.set('content.reassignHosts.source', 'host1');
  947. controller.deleteHostComponents();
  948. expect(App.ajax.send.getCall(0).args[0].data).to.eql({
  949. "hostName": "host1",
  950. "componentName": 1
  951. });
  952. expect(App.ajax.send.getCall(1).args[0].data).to.eql({
  953. "hostName": "host1",
  954. "componentName": 2
  955. });
  956. });
  957. });
  958. describe('#onDeleteHostComponentsError()', function () {
  959. beforeEach(function () {
  960. sinon.stub(controller, 'onComponentsTasksSuccess', Em.K);
  961. sinon.stub(controller, 'onTaskError', Em.K);
  962. });
  963. afterEach(function () {
  964. controller.onComponentsTasksSuccess.restore();
  965. controller.onTaskError.restore();
  966. });
  967. it('task success', function () {
  968. var error = {
  969. responseText: 'org.apache.ambari.server.controller.spi.NoSuchResourceException'
  970. }
  971. controller.onDeleteHostComponentsError(error);
  972. expect(controller.onComponentsTasksSuccess.calledOnce).to.be.true;
  973. });
  974. it('unknown error', function () {
  975. var error = {
  976. responseText: ''
  977. }
  978. controller.onDeleteHostComponentsError(error);
  979. expect(controller.onTaskError.calledOnce).to.be.true;
  980. });
  981. });
  982. describe('#done()', function () {
  983. beforeEach(function () {
  984. sinon.stub(controller, 'removeObserver', Em.K);
  985. sinon.stub(App.router, 'send', Em.K);
  986. });
  987. afterEach(function () {
  988. controller.removeObserver.restore();
  989. App.router.send.restore();
  990. });
  991. it('submit disabled', function () {
  992. controller.set('isSubmitDisabled', true);
  993. controller.done();
  994. expect(App.router.send.called).to.be.false;
  995. });
  996. it('submit enabled and does not have manual steps', function () {
  997. controller.set('isSubmitDisabled', false);
  998. controller.set('content.hasManualSteps', false);
  999. controller.done();
  1000. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  1001. expect(App.router.send.calledWith('complete')).to.be.true;
  1002. });
  1003. it('submit enabled and has manual steps', function () {
  1004. controller.set('isSubmitDisabled', false);
  1005. controller.set('content.hasManualSteps', true);
  1006. controller.done();
  1007. expect(controller.removeObserver.calledWith('tasks.@each.status', controller, 'onTaskStatusChange')).to.be.true;
  1008. expect(App.router.send.calledWith('next')).to.be.true;
  1009. });
  1010. });
  1011. describe('#getServiceConfigData()', function () {
  1012. var services = [];
  1013. var stackServices = [];
  1014. beforeEach(function () {
  1015. sinon.stub(App.Service, 'find', function () {
  1016. return services;
  1017. });
  1018. sinon.stub(App.StackService, 'find', function () {
  1019. return stackServices;
  1020. });
  1021. });
  1022. afterEach(function () {
  1023. App.Service.find.restore();
  1024. App.StackService.find.restore();
  1025. });
  1026. it('No services', function () {
  1027. services = [];
  1028. controller.set('content.reassign.component_name', 'COMP1');
  1029. expect(controller.getServiceConfigData([])).to.eql([]);
  1030. });
  1031. it('No services in stackServices', function () {
  1032. services = [Em.Object.create({serviceName: 'S1'})];
  1033. stackServices = [];
  1034. controller.set('content.reassign.component_name', 'COMP1');
  1035. expect(controller.getServiceConfigData([])).to.eql([]);
  1036. });
  1037. it('Services in stackServicesm but configTypesRendered is empty', function () {
  1038. services = [Em.Object.create({serviceName: 'S1'})];
  1039. stackServices = [Em.Object.create({
  1040. serviceName: 'S1',
  1041. configTypesRendered: {}
  1042. })];
  1043. controller.set('content.reassign.component_name', 'COMP1');
  1044. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  1045. });
  1046. it('Services in stackServicesm and configTypesRendered has data, but configs is empty', function () {
  1047. services = [Em.Object.create({serviceName: 'S1'})];
  1048. stackServices = [
  1049. Em.Object.create({
  1050. serviceName: 'S1',
  1051. configTypesRendered: {'type1': {}}
  1052. })
  1053. ];
  1054. controller.set('content.reassign.component_name', 'COMP1');
  1055. expect(controller.getServiceConfigData([])[0]).to.equal("{\"Clusters\":{\"desired_config\":[]}}");
  1056. });
  1057. it('Services in stackServicesm and configTypesRendered has data, and configs present', function () {
  1058. services = [Em.Object.create({serviceName: 'S1'})];
  1059. stackServices = [
  1060. Em.Object.create({
  1061. serviceName: 'S1',
  1062. configTypesRendered: {'type1': {}}
  1063. })
  1064. ];
  1065. var configs = {
  1066. 'type1': {
  1067. 'prop1': 'value1'
  1068. }
  1069. };
  1070. controller.set('content.reassign.component_name', 'COMP1');
  1071. expect(JSON.parse(controller.getServiceConfigData(configs)[0]).Clusters.desired_config.length).to.equal(1);
  1072. });
  1073. });
  1074. });