step4_controller_test.js 38 KB

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