step4_controller_test.js 43 KB

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