step4_controller_test.js 43 KB

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