step4_controller_test.js 39 KB

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