details_test.js 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516
  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. var App = require('app');
  19. require('controllers/main/host/details');
  20. require('models/service');
  21. require('models/host_component');
  22. var batchUtils = require('utils/batch_scheduled_requests');
  23. describe('App.MainHostDetailsController', function () {
  24. var controller = App.MainHostDetailsController.create({
  25. getSecurityStatus: function () {
  26. return this.get('mockSecurityStatus');
  27. },
  28. mockSecurityStatus: false
  29. });
  30. describe('#serviceActiveComponents', function () {
  31. it('No host-components', function () {
  32. controller.set('content.hostComponents', []);
  33. expect(controller.get('serviceActiveComponents')).to.be.empty;
  34. });
  35. it('No host-components in active state', function () {
  36. controller.set('content.hostComponents', [Em.Object.create({
  37. service: {
  38. isInPassive: true
  39. }
  40. })]);
  41. expect(controller.get('serviceActiveComponents')).to.be.empty;
  42. });
  43. it('Host-components in active state', function () {
  44. controller.set('content.hostComponents', [Em.Object.create({
  45. service: {
  46. isInPassive: false
  47. }
  48. })]);
  49. expect(controller.get('serviceActiveComponents')).to.eql([Em.Object.create({
  50. service: {
  51. isInPassive: false
  52. }
  53. })]);
  54. });
  55. });
  56. describe('#serviceNonClientActiveComponents', function () {
  57. it('No active host-components', function () {
  58. controller.reopen({
  59. serviceActiveComponents: []
  60. });
  61. controller.set('serviceActiveComponents', []);
  62. expect(controller.get('serviceNonClientActiveComponents')).to.be.empty;
  63. });
  64. it('Active host-component is client', function () {
  65. controller.set('serviceActiveComponents', [Em.Object.create({
  66. isClient: true
  67. })]);
  68. expect(controller.get('serviceNonClientActiveComponents')).to.be.empty;
  69. });
  70. it('Active host-component is not client', function () {
  71. controller.set('serviceActiveComponents', [Em.Object.create({
  72. isClient: false
  73. })]);
  74. expect(controller.get('serviceNonClientActiveComponents')).to.eql( [Em.Object.create({
  75. isClient: false
  76. })]);
  77. });
  78. });
  79. describe('#startComponent()', function () {
  80. beforeEach(function () {
  81. sinon.spy(App, "showConfirmationPopup");
  82. sinon.stub(controller, "sendStartComponentCommand", Em.K);
  83. });
  84. afterEach(function () {
  85. App.showConfirmationPopup.restore();
  86. controller.sendStartComponentCommand.restore();
  87. });
  88. it('popup should be displayed', function () {
  89. var popup = controller.startComponent({context: Em.Object.create({'displayName': 'Comp1'})});
  90. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  91. popup.onPrimary();
  92. expect(controller.sendStartComponentCommand.calledOnce).to.be.true;
  93. });
  94. });
  95. describe('#sendStartComponentCommand()', function () {
  96. beforeEach(function () {
  97. sinon.stub(App.ajax, "send", Em.K);
  98. });
  99. afterEach(function () {
  100. App.ajax.send.restore();
  101. });
  102. it('Query should be sent', function () {
  103. var component = Em.Object.create({
  104. componentName: 'comp1'
  105. });
  106. controller.sendStartComponentCommand(component, '');
  107. expect(App.ajax.send.calledOnce).to.be.true;
  108. });
  109. });
  110. describe('#getDataToSend()', function () {
  111. it('should return correct query info', function () {
  112. expect(controller.getDataToSend('STATE1', 'context')).to.eql({
  113. RequestInfo: {
  114. "context": 'context'
  115. },
  116. Body: {
  117. HostRoles: {
  118. state: 'STATE1'
  119. }
  120. }
  121. });
  122. });
  123. });
  124. describe('#setComponentToData()', function () {
  125. var testCases = [
  126. {
  127. title: 'dataToSend is null',
  128. content: {
  129. data: {},
  130. dataToSend: null,
  131. component: {}
  132. },
  133. result: {
  134. output: false,
  135. data: {}
  136. }
  137. },
  138. {
  139. title: 'component is null',
  140. content: {
  141. data: {},
  142. dataToSend: {},
  143. component: null
  144. },
  145. result: {
  146. output: false,
  147. data: {}
  148. }
  149. },
  150. {
  151. title: 'data is null',
  152. content: {
  153. data: null,
  154. dataToSend: {},
  155. component: {}
  156. },
  157. result: {
  158. output: false,
  159. data: null
  160. }
  161. },
  162. {
  163. title: 'component is object',
  164. content: {
  165. data: {},
  166. dataToSend: {},
  167. component: Em.Object.create({componentName: 'comp1'})
  168. },
  169. result: {
  170. output: true,
  171. data: {
  172. componentName: 'comp1',
  173. data: '{}'
  174. }
  175. }
  176. },
  177. {
  178. title: 'component is array',
  179. content: {
  180. data: {},
  181. dataToSend: {RequestInfo: {}},
  182. component: [Em.Object.create({componentName: 'comp1'})]
  183. },
  184. result: {
  185. output: true,
  186. data: {
  187. data: '{\"RequestInfo\":{\"query\":\"HostRoles/component_name.in(comp1)\"}}'
  188. }
  189. }
  190. }
  191. ];
  192. testCases.forEach(function (test) {
  193. it(test.title, function () {
  194. expect(controller.setComponentToData(test.content.data, test.content.dataToSend, test.content.component)).to.equal(test.result.output);
  195. expect(test.content.data).to.eql(test.result.data);
  196. });
  197. });
  198. });
  199. describe('#deleteComponent()', function () {
  200. beforeEach(function () {
  201. sinon.spy(App.ModalPopup, "show");
  202. });
  203. afterEach(function () {
  204. App.ModalPopup.show.restore();
  205. });
  206. it('confirm popup should be displayed', function () {
  207. var event = {
  208. context: Em.Object.create({})
  209. };
  210. controller.deleteComponent(event);
  211. expect(App.ModalPopup.show.calledOnce).to.be.true;
  212. });
  213. });
  214. describe('#_doDeleteHostComponent()', function () {
  215. beforeEach(function () {
  216. sinon.stub(App.ajax, "send", Em.K);
  217. });
  218. afterEach(function () {
  219. App.ajax.send.restore();
  220. });
  221. it('delete request should be sent, component is null', function () {
  222. controller.set('_deletedHostComponentResult', null);
  223. expect(controller._doDeleteHostComponent()).to.equal(null);
  224. expect(App.ajax.send.calledOnce).to.be.true;
  225. });
  226. it('delete request should be sent, component is correct', function () {
  227. controller.set('_deletedHostComponentResult', {});
  228. expect(controller._doDeleteHostComponent(Em.Object.create({componentName: 'COMP1'}))).to.eql({});
  229. expect(App.ajax.send.calledOnce).to.be.true;
  230. });
  231. });
  232. describe('#mimicWorkStatusChange()', function () {
  233. var clock;
  234. beforeEach(function () {
  235. clock = sinon.useFakeTimers();
  236. });
  237. afterEach(function () {
  238. clock.restore()
  239. });
  240. it('change status of object', function () {
  241. var entity = Em.Object.create({
  242. workStatus: ''
  243. });
  244. controller.mimicWorkStatusChange(entity, 'STATE1', 'STATE2');
  245. expect(entity.get('workStatus')).to.equal('STATE1');
  246. clock.tick(App.testModeDelayForActions);
  247. expect(entity.get('workStatus')).to.equal('STATE2');
  248. });
  249. it('change status of objects in array', function () {
  250. var entity = [Em.Object.create({
  251. workStatus: ''
  252. })];
  253. controller.mimicWorkStatusChange(entity, 'STATE1', 'STATE2');
  254. expect(entity[0].get('workStatus')).to.equal('STATE1');
  255. clock.tick(App.testModeDelayForActions);
  256. expect(entity[0].get('workStatus')).to.equal('STATE2');
  257. });
  258. });
  259. describe('#upgradeComponent()', function () {
  260. beforeEach(function () {
  261. sinon.spy(App, "showConfirmationPopup");
  262. sinon.stub(App.ajax, "send", Em.K);
  263. });
  264. afterEach(function () {
  265. App.showConfirmationPopup.restore();
  266. App.ajax.send.restore();
  267. });
  268. it('confirm popup should be displayed', function () {
  269. var popup = controller.upgradeComponent({context: Em.Object.create()});
  270. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  271. popup.onPrimary();
  272. expect(App.ajax.send.calledOnce).to.be.true;
  273. });
  274. });
  275. describe('#stopComponent()', function () {
  276. beforeEach(function () {
  277. sinon.spy(App, "showConfirmationPopup");
  278. sinon.stub(controller, "sendStopComponentCommand", Em.K);
  279. });
  280. afterEach(function () {
  281. App.showConfirmationPopup.restore();
  282. controller.sendStopComponentCommand.restore();
  283. });
  284. it('popup should be displayed', function () {
  285. var popup = controller.stopComponent({context: Em.Object.create({'displayName': 'Comp1'})});
  286. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  287. popup.onPrimary();
  288. expect(controller.sendStopComponentCommand.calledOnce).to.be.true;
  289. });
  290. });
  291. describe('#sendStopComponentCommand()', function () {
  292. beforeEach(function () {
  293. sinon.stub(App.ajax, "send", Em.K);
  294. });
  295. afterEach(function () {
  296. App.ajax.send.restore();
  297. });
  298. it('Query should be sent', function () {
  299. var component = Em.Object.create({
  300. componentName: 'comp1'
  301. });
  302. controller.sendStopComponentCommand(component, '');
  303. expect(App.ajax.send.calledOnce).to.be.true;
  304. });
  305. });
  306. describe('#restartComponent()', function () {
  307. beforeEach(function () {
  308. sinon.spy(App, "showConfirmationPopup");
  309. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  310. });
  311. afterEach(function () {
  312. App.showConfirmationPopup.restore();
  313. batchUtils.restartHostComponents.restore();
  314. });
  315. it('popup should be displayed', function () {
  316. var popup = controller.restartComponent({context: Em.Object.create({'displayName': 'Comp1'})});
  317. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  318. popup.onPrimary();
  319. expect(batchUtils.restartHostComponents.calledOnce).to.be.true;
  320. });
  321. });
  322. describe('#addComponent()', function () {
  323. beforeEach(function () {
  324. sinon.spy(App, "showConfirmationPopup");
  325. sinon.stub(controller, "addClientComponent", Em.K);
  326. sinon.stub(controller, "primary", Em.K);
  327. });
  328. afterEach(function () {
  329. App.showConfirmationPopup.restore();
  330. controller.addClientComponent.restore();
  331. controller.primary.restore();
  332. });
  333. it('add ZOOKEEPER_SERVER', function () {
  334. var event = {context: Em.Object.create({
  335. componentName: 'ZOOKEEPER_SERVER'
  336. })};
  337. var popup = controller.addComponent(event);
  338. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  339. popup.onPrimary();
  340. expect(controller.primary.calledWith(Em.Object.create({
  341. componentName: 'ZOOKEEPER_SERVER'
  342. }))).to.be.true;
  343. });
  344. it('add slave component, securityEnabled = true', function () {
  345. var event = {context: Em.Object.create({
  346. componentName: 'COMP1'
  347. })};
  348. controller.set('mockSecurityStatus', true);
  349. var popup = controller.addComponent(event);
  350. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  351. popup.onPrimary();
  352. expect(controller.primary.calledWith(Em.Object.create({
  353. componentName: 'COMP1'
  354. }))).to.be.true;
  355. });
  356. it('add slave component, securityEnabled = false', function () {
  357. var event = {context: Em.Object.create({
  358. componentName: 'COMP1'
  359. })};
  360. controller.set('mockSecurityStatus', false);
  361. controller.addComponent(event);
  362. expect(controller.addClientComponent.calledWith(Em.Object.create({
  363. componentName: 'COMP1'
  364. }))).to.be.true;
  365. });
  366. it('add CLIENTS', function () {
  367. var event = {context: Em.Object.create({
  368. componentName: 'CLIENTS'
  369. })};
  370. controller.set('mockSecurityStatus', true);
  371. controller.addComponent(event);
  372. expect(controller.addClientComponent.calledWith(Em.Object.create({
  373. componentName: 'CLIENTS'
  374. }))).to.be.true;
  375. });
  376. });
  377. describe('#formatClientsMessage()', function () {
  378. var testCases = [
  379. {
  380. title: 'subComponentNames is null',
  381. client: Em.Object.create({
  382. subComponentNames: null,
  383. displayName: 'CLIENTS'
  384. }),
  385. result: 'CLIENTS'
  386. },
  387. {
  388. title: 'subComponentNames is empty',
  389. client: Em.Object.create({
  390. subComponentNames: [],
  391. displayName: 'CLIENTS'
  392. }),
  393. result: 'CLIENTS'
  394. },
  395. {
  396. title: 'displayName is null',
  397. client: Em.Object.create({
  398. subComponentNames: ['DATANODE'],
  399. displayName: null
  400. }),
  401. result: ' (DataNode)'
  402. },
  403. {
  404. title: 'displayName is CLIENTS',
  405. client: Em.Object.create({
  406. subComponentNames: ['DATANODE'],
  407. displayName: 'CLIENTS'
  408. }),
  409. result: 'CLIENTS (DataNode)'
  410. }
  411. ];
  412. testCases.forEach(function (test) {
  413. it(test.title, function () {
  414. expect(controller.formatClientsMessage(test.client)).to.equal(test.result);
  415. });
  416. });
  417. });
  418. describe('#addClientComponent()', function () {
  419. beforeEach(function () {
  420. sinon.spy(App.ModalPopup, "show");
  421. sinon.stub(controller, "primary", Em.K);
  422. });
  423. afterEach(function () {
  424. App.ModalPopup.show.restore();
  425. controller.primary.restore();
  426. });
  427. it('not CLIENT component', function () {
  428. var component = Em.Object.create({'componentName': 'Comp1'});
  429. var popup = controller.addClientComponent(component);
  430. expect(App.ModalPopup.show.calledOnce).to.be.true;
  431. popup.onPrimary();
  432. expect(controller.primary.calledWith(Em.Object.create({'componentName': 'Comp1'}))).to.be.true;
  433. });
  434. it('CLIENT components, with empty subComponentNames', function () {
  435. var component = Em.Object.create({
  436. componentName: 'CLIENTS',
  437. subComponentNames: []
  438. });
  439. var popup = controller.addClientComponent(component);
  440. expect(App.ModalPopup.show.calledOnce).to.be.true;
  441. popup.onPrimary();
  442. expect(controller.primary.calledOnce).to.be.false;
  443. });
  444. it('CLIENT components, with two sub-component', function () {
  445. var component = Em.Object.create({
  446. componentName: 'CLIENTS',
  447. subComponentNames: ['DATANODE', 'TASKTRACKER']
  448. });
  449. var popup = controller.addClientComponent(component);
  450. expect(App.ModalPopup.show.calledOnce).to.be.true;
  451. popup.onPrimary();
  452. expect(controller.primary.calledTwice).to.be.true;
  453. });
  454. });
  455. describe('#primary()', function () {
  456. beforeEach(function () {
  457. sinon.stub(App.ajax, "send", Em.K);
  458. });
  459. afterEach(function () {
  460. App.ajax.send.restore();
  461. });
  462. it('Query should be sent', function () {
  463. var component = Em.Object.create({
  464. componentName: 'COMP1',
  465. displayName: 'comp1'
  466. });
  467. controller.primary(component);
  468. expect(App.ajax.send.calledOnce).to.be.true;
  469. });
  470. });
  471. describe('#addNewComponentSuccessCallback()', function () {
  472. beforeEach(function () {
  473. sinon.stub(App.ajax, "send", Em.K);
  474. });
  475. afterEach(function () {
  476. App.ajax.send.restore();
  477. });
  478. it('Query should be sent', function () {
  479. controller.addNewComponentSuccessCallback({}, {}, {component: Em.Object.create()});
  480. expect(App.ajax.send.calledOnce).to.be.true;
  481. });
  482. });
  483. describe('#installNewComponentSuccessCallback()', function () {
  484. beforeEach(function () {
  485. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  486. });
  487. afterEach(function () {
  488. controller.showBackgroundOperationsPopup.restore();
  489. });
  490. it('data.Requests is null', function () {
  491. var data = {Requests: null};
  492. expect(controller.installNewComponentSuccessCallback(data, {}, {})).to.be.false;
  493. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  494. });
  495. it('data.Requests.id is null', function () {
  496. var data = {Requests: {id: null}};
  497. expect(controller.installNewComponentSuccessCallback(data, {}, {})).to.be.false;
  498. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  499. });
  500. it('data.Requests.id is correct', function () {
  501. var data = {Requests: {id: 1}};
  502. expect(controller.installNewComponentSuccessCallback(data, {}, {component: []})).to.be.true;
  503. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  504. });
  505. });
  506. describe('#refreshComponentConfigs()', function () {
  507. beforeEach(function () {
  508. sinon.spy(App, "showConfirmationPopup");
  509. sinon.stub(controller, "sendRefreshComponentConfigsCommand", Em.K);
  510. });
  511. afterEach(function () {
  512. App.showConfirmationPopup.restore();
  513. controller.sendRefreshComponentConfigsCommand.restore();
  514. });
  515. it('popup should be displayed', function () {
  516. var popup = controller.refreshComponentConfigs({context: Em.Object.create({'displayName': 'Comp1'})});
  517. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  518. popup.onPrimary();
  519. expect(controller.sendRefreshComponentConfigsCommand.calledOnce).to.be.true;
  520. });
  521. });
  522. describe('#sendRefreshComponentConfigsCommand()', function () {
  523. beforeEach(function () {
  524. sinon.stub(App.ajax, "send", Em.K);
  525. });
  526. afterEach(function () {
  527. App.ajax.send.restore();
  528. });
  529. it('Query should be sent', function () {
  530. var component = Em.Object.create({
  531. service: {},
  532. componentName: 'COMP1',
  533. host: {}
  534. });
  535. controller.sendRefreshComponentConfigsCommand(component, {});
  536. expect(App.ajax.send.calledOnce).to.be.true;
  537. });
  538. });
  539. describe('#loadConfigs()', function () {
  540. beforeEach(function () {
  541. sinon.stub(App.ajax, "send", Em.K);
  542. });
  543. afterEach(function () {
  544. App.ajax.send.restore();
  545. });
  546. it('Query should be sent', function () {
  547. controller.loadConfigs();
  548. expect(App.ajax.send.calledOnce).to.be.true;
  549. });
  550. });
  551. describe('#constructConfigUrlParams()', function () {
  552. it('URL params should be empty', function () {
  553. var data = {};
  554. App.Service.find().clear();
  555. expect(controller.constructConfigUrlParams(data)).to.eql([]);
  556. });
  557. it('isHaEnabled = true', function () {
  558. var data = {Clusters: {desired_configs: {'core-site': {tag: 1}}}};
  559. App.HostComponent.find().clear();
  560. App.set('currentStackVersion', 'HDP-2.0.2');
  561. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=core-site&tag=1)']);
  562. App.store.load(App.HostComponent, {
  563. id: 'SECONDARY_NAMENODE_host1',
  564. component_name: 'SECONDARY_NAMENODE'
  565. });
  566. App.set('currentStackVersion', 'HDP-2.0.1');
  567. });
  568. it('HBASE is installed', function () {
  569. App.store.load(App.Service, {
  570. id: 'HBASE',
  571. service_name: 'HBASE'
  572. });
  573. var data = {Clusters: {desired_configs: {'hbase-site': {tag: 1}}}};
  574. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=hbase-site&tag=1)']);
  575. App.Service.find().clear();
  576. });
  577. it('HIVE is installed', function () {
  578. App.store.load(App.Service, {
  579. id: 'HIVE',
  580. service_name: 'HIVE'
  581. });
  582. var data = {Clusters: {desired_configs: {'webhcat-site': {tag: 1}}}};
  583. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=webhcat-site&tag=1)']);
  584. App.Service.find().clear();
  585. });
  586. it('STORM is installed', function () {
  587. App.store.load(App.Service, {
  588. id: 'STORM',
  589. service_name: 'STORM'
  590. });
  591. var data = {Clusters: {desired_configs: {'storm-site': {tag: 1}}}};
  592. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=storm-site&tag=1)']);
  593. App.Service.find().clear();
  594. });
  595. });
  596. describe('#loadConfigsSuccessCallback()', function () {
  597. beforeEach(function () {
  598. sinon.stub(App.ajax, "send", Em.K);
  599. sinon.stub(controller, "constructConfigUrlParams", function () {
  600. return this.get('mockUrlParams');
  601. });
  602. });
  603. afterEach(function () {
  604. App.ajax.send.restore();
  605. controller.constructConfigUrlParams.restore();
  606. });
  607. it('url params is empty', function () {
  608. controller.set('mockUrlParams', []);
  609. expect(controller.loadConfigsSuccessCallback()).to.be.false;
  610. expect(App.ajax.send.called).to.be.false;
  611. });
  612. it('url params are correct', function () {
  613. controller.set('mockUrlParams', ['param1']);
  614. expect(controller.loadConfigsSuccessCallback()).to.be.true;
  615. expect(App.ajax.send.calledOnce).to.be.true;
  616. });
  617. });
  618. describe('#saveZkConfigs()', function () {
  619. beforeEach(function () {
  620. sinon.stub(controller, "getZkServerHosts", Em.K);
  621. sinon.stub(controller, "concatZkNames", Em.K);
  622. sinon.stub(controller, "setZKConfigs", Em.K);
  623. sinon.spy(App.ajax, "send");
  624. });
  625. afterEach(function () {
  626. controller.getZkServerHosts.restore();
  627. controller.concatZkNames.restore();
  628. controller.setZKConfigs.restore();
  629. App.ajax.send.restore();
  630. });
  631. it('data.items is empty', function () {
  632. var data = {items: []};
  633. controller.saveZkConfigs(data);
  634. expect(App.ajax.send.called).to.be.false;
  635. });
  636. it('data.items has one item', function () {
  637. var data = {items: [
  638. {
  639. type: 'type1',
  640. properties: {}
  641. }
  642. ]};
  643. controller.saveZkConfigs(data);
  644. expect(App.ajax.send.calledOnce).to.be.true;
  645. });
  646. it('data.items has two items', function () {
  647. var data = {items: [
  648. {
  649. type: 'type1',
  650. properties: {}
  651. },
  652. {
  653. type: 'type2',
  654. properties: {}
  655. }
  656. ]};
  657. controller.saveZkConfigs(data);
  658. expect(App.ajax.send.calledTwice).to.be.true;
  659. });
  660. });
  661. describe('#setZKConfigs()', function () {
  662. it('configs is null', function () {
  663. expect(controller.setZKConfigs(null)).to.be.false;
  664. });
  665. it('zks is null', function () {
  666. expect(controller.setZKConfigs({}, '', null)).to.be.false;
  667. });
  668. it('isHaEnabled = true', function () {
  669. var configs = {'core-site': {}};
  670. App.HostComponent.find().clear();
  671. App.set('currentStackVersion', 'HDP-2.0.2');
  672. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  673. expect(configs).to.eql({"core-site": {
  674. "ha.zookeeper.quorum": "host1:2181"
  675. }});
  676. App.store.load(App.HostComponent, {
  677. id: 'SECONDARY_NAMENODE_host1',
  678. component_name: 'SECONDARY_NAMENODE'
  679. });
  680. App.set('currentStackVersion', 'HDP-2.0.1');
  681. });
  682. it('hbase-site is present', function () {
  683. var configs = {'hbase-site': {}};
  684. expect(controller.setZKConfigs(configs, '', ['host1', 'host2'])).to.be.true;
  685. expect(configs).to.eql({"hbase-site": {
  686. "hbase.zookeeper.quorum": "host1,host2"
  687. }});
  688. });
  689. it('webhcat-site is present', function () {
  690. var configs = {'webhcat-site': {}};
  691. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  692. expect(configs).to.eql({"webhcat-site": {
  693. "templeton.zookeeper.hosts": "host1:2181"
  694. }});
  695. });
  696. it('storm-site is present', function () {
  697. var configs = {'storm-site': {}};
  698. expect(controller.setZKConfigs(configs, '', ["host1", 'host2'])).to.be.true;
  699. expect(configs).to.eql({"storm-site": {
  700. "storm.zookeeper.servers": "['host1','host2']"
  701. }});
  702. });
  703. });
  704. describe('#concatZkNames()', function () {
  705. it('No ZooKeeper hosts', function () {
  706. expect(controller.concatZkNames([])).to.equal('');
  707. });
  708. it('One ZooKeeper host', function () {
  709. expect(controller.concatZkNames(['host1'])).to.equal('host1:2181');
  710. });
  711. it('Two ZooKeeper hosts', function () {
  712. expect(controller.concatZkNames(['host1', 'host2'])).to.equal('host1:2181,host2:2181');
  713. });
  714. });
  715. describe('#getZkServerHosts()', function () {
  716. controller.set('content', {});
  717. it('No ZooKeeper hosts, fromDeleteHost = false', function () {
  718. App.HostComponent.find().clear();
  719. controller.set('fromDeleteHost', false);
  720. expect(controller.getZkServerHosts()).to.be.empty;
  721. });
  722. it('No ZooKeeper hosts, fromDeleteHost = true', function () {
  723. controller.set('fromDeleteHost', true);
  724. expect(controller.getZkServerHosts()).to.be.empty;
  725. expect(controller.get('fromDeleteHost')).to.be.false;
  726. });
  727. it('One ZooKeeper host, fromDeleteHost = false', function () {
  728. controller.set('fromDeleteHost', false);
  729. App.store.load(App.HostComponent, {
  730. id: 'ZOOKEEPER_SERVER_host1',
  731. component_name: 'ZOOKEEPER_SERVER',
  732. host_id: 'host1'
  733. });
  734. expect(controller.getZkServerHosts()).to.eql(['host1']);
  735. });
  736. it('One ZooKeeper host match current host name, fromDeleteHost = true', function () {
  737. controller.set('fromDeleteHost', true);
  738. controller.set('content.hostName', 'host1');
  739. expect(controller.getZkServerHosts()).to.be.empty;
  740. expect(controller.get('fromDeleteHost')).to.be.false;
  741. });
  742. it('One ZooKeeper host does not match current host name, fromDeleteHost = true', function () {
  743. controller.set('fromDeleteHost', true);
  744. controller.set('content.hostName', 'host2');
  745. expect(controller.getZkServerHosts()[0]).to.equal("host1");
  746. expect(controller.get('fromDeleteHost')).to.be.false;
  747. });
  748. });
  749. describe('#installComponent()', function () {
  750. beforeEach(function () {
  751. sinon.spy(App.ModalPopup, "show");
  752. sinon.stub(App.ajax, "send", Em.K);
  753. });
  754. afterEach(function () {
  755. App.ModalPopup.show.restore();
  756. App.ajax.send.restore();
  757. });
  758. it('popup should be displayed', function () {
  759. var event = {context: Em.Object.create()};
  760. var popup = controller.installComponent(event);
  761. expect(App.ModalPopup.show.calledOnce).to.be.true;
  762. popup.onPrimary();
  763. expect(App.ajax.send.calledOnce).to.be.true;
  764. });
  765. });
  766. describe('#decommission()', function () {
  767. beforeEach(function () {
  768. sinon.spy(App, "showConfirmationPopup");
  769. sinon.stub(controller, "runDecommission", Em.K);
  770. });
  771. afterEach(function () {
  772. App.showConfirmationPopup.restore();
  773. controller.runDecommission.restore();
  774. });
  775. it('popup should be displayed', function () {
  776. var popup = controller.decommission(Em.Object.create({service: {}}));
  777. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  778. popup.onPrimary();
  779. expect(controller.runDecommission.calledOnce).to.be.true;
  780. });
  781. });
  782. describe('#runDecommission()', function () {
  783. beforeEach(function () {
  784. sinon.stub(controller, "doDecommission", Em.K);
  785. sinon.stub(controller, "warnBeforeDecommission", Em.K);
  786. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  787. });
  788. afterEach(function () {
  789. controller.doDecommission.restore();
  790. controller.warnBeforeDecommission.restore();
  791. controller.showBackgroundOperationsPopup.restore();
  792. });
  793. it('HDFS service', function () {
  794. controller.runDecommission('host1', 'HDFS');
  795. expect(controller.doDecommission.calledWith('host1', 'HDFS', "NAMENODE", "DATANODE")).to.be.true;
  796. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  797. });
  798. it('YARN service', function () {
  799. controller.runDecommission('host1', 'YARN');
  800. expect(controller.doDecommission.calledWith('host1', 'YARN', "RESOURCEMANAGER", "NODEMANAGER")).to.be.true;
  801. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  802. });
  803. it('MAPREDUCE service', function () {
  804. controller.runDecommission('host1', 'MAPREDUCE');
  805. expect(controller.doDecommission.calledWith('host1', 'MAPREDUCE', "JOBTRACKER", "TASKTRACKER")).to.be.true;
  806. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  807. });
  808. it('HBASE service', function () {
  809. controller.runDecommission('host1', 'HBASE');
  810. expect(controller.warnBeforeDecommission.calledWith('host1', 'HBASE', "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
  811. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  812. });
  813. });
  814. describe('#runRecommission()', function () {
  815. beforeEach(function () {
  816. sinon.stub(controller, "doRecommissionAndStart", Em.K);
  817. sinon.stub(controller, "doRecommissionAndRestart", Em.K);
  818. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  819. });
  820. afterEach(function () {
  821. controller.doRecommissionAndStart.restore();
  822. controller.doRecommissionAndRestart.restore();
  823. controller.showBackgroundOperationsPopup.restore();
  824. });
  825. it('HDFS service', function () {
  826. controller.runRecommission('host1', 'HDFS');
  827. expect(controller.doRecommissionAndStart.calledWith('host1', 'HDFS', "NAMENODE", "DATANODE")).to.be.true;
  828. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  829. });
  830. it('YARN service', function () {
  831. controller.runRecommission('host1', 'YARN');
  832. expect(controller.doRecommissionAndStart.calledWith('host1', 'YARN', "RESOURCEMANAGER", "NODEMANAGER")).to.be.true;
  833. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  834. });
  835. it('MAPREDUCE service', function () {
  836. controller.runRecommission('host1', 'MAPREDUCE');
  837. expect(controller.doRecommissionAndRestart.calledWith('host1', 'MAPREDUCE', "JOBTRACKER", "TASKTRACKER")).to.be.true;
  838. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  839. });
  840. it('HBASE service', function () {
  841. controller.runRecommission('host1', 'HBASE');
  842. expect(controller.doRecommissionAndStart.calledWith('host1', 'HBASE', "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
  843. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  844. });
  845. });
  846. describe('#doDecommission()', function () {
  847. beforeEach(function () {
  848. sinon.stub(App.ajax, "send", Em.K);
  849. });
  850. afterEach(function () {
  851. App.ajax.send.restore();
  852. });
  853. it('Query should be sent', function () {
  854. controller.doDecommission('', '', '', '');
  855. expect(App.ajax.send.calledOnce).to.be.true;
  856. });
  857. });
  858. describe('#doDecommissionRegionServer()', function () {
  859. beforeEach(function () {
  860. sinon.stub(App.ajax, "send", Em.K);
  861. });
  862. afterEach(function () {
  863. App.ajax.send.restore();
  864. });
  865. it('Query should be sent', function () {
  866. controller.doDecommissionRegionServer('', '', '', '');
  867. expect(App.ajax.send.calledOnce).to.be.true;
  868. });
  869. });
  870. /**
  871. * TODO uncomment test when final rules will be implemented into warnBeforeDecommission function
  872. */
  873. /* describe('#warnBeforeDecommission()', function () {
  874. beforeEach(function () {
  875. sinon.stub(controller, "doDecommissionRegionServer", Em.K);
  876. sinon.stub(App.ModalPopup, "show", Em.K);
  877. });
  878. afterEach(function () {
  879. App.ModalPopup.show.restore();
  880. controller.doDecommissionRegionServer.restore();
  881. });
  882. it('Component in passive state', function () {
  883. controller.set('content.hostComponents', [Em.Object.create({
  884. componentName: 'HBASE_REGIONSERVER',
  885. passiveState: 'ON'
  886. })]);
  887. controller.warnBeforeDecommission('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE');
  888. expect(App.ModalPopup.show.called).to.be.false;
  889. expect(controller.doDecommissionRegionServer.calledWith('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE')).to.be.true;
  890. });
  891. it('Component is not in passive state', function () {
  892. controller.set('content.hostComponents', [Em.Object.create({
  893. componentName: 'HBASE_REGIONSERVER',
  894. passiveState: 'OFF'
  895. })]);
  896. controller.warnBeforeDecommission('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE');
  897. expect(App.ModalPopup.show.calledOnce).to.be.true;
  898. expect(controller.doDecommissionRegionServer.called).to.be.false;
  899. });
  900. });*/
  901. describe('#doRecommissionAndStart()', function () {
  902. beforeEach(function () {
  903. sinon.stub(App.ajax, "send", Em.K);
  904. });
  905. afterEach(function () {
  906. App.ajax.send.restore();
  907. });
  908. it('Query should be sent', function () {
  909. controller.doRecommissionAndStart('', '', '', '');
  910. expect(App.ajax.send.calledOnce).to.be.true;
  911. });
  912. });
  913. describe('#decommissionSuccessCallback()', function () {
  914. beforeEach(function () {
  915. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  916. });
  917. afterEach(function () {
  918. controller.showBackgroundOperationsPopup.restore();
  919. });
  920. it('data is null', function () {
  921. expect(controller.decommissionSuccessCallback(null)).to.be.false;
  922. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  923. });
  924. it('data has Requests', function () {
  925. var data = {Requests: []};
  926. expect(controller.decommissionSuccessCallback(data)).to.be.true;
  927. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  928. });
  929. it('data has resources', function () {
  930. var data = {resources: [{RequestSchedule: {}}]};
  931. expect(controller.decommissionSuccessCallback(data)).to.be.true;
  932. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  933. });
  934. });
  935. describe('#doRecommissionAndRestart()', function () {
  936. beforeEach(function () {
  937. sinon.stub(App.ajax, "send", Em.K);
  938. });
  939. afterEach(function () {
  940. App.ajax.send.restore();
  941. });
  942. it('Query should be sent', function () {
  943. controller.doRecommissionAndRestart('', '', '', '');
  944. expect(App.ajax.send.calledOnce).to.be.true;
  945. });
  946. });
  947. describe('#doAction()', function () {
  948. beforeEach(function () {
  949. sinon.stub(controller, "validateAndDeleteHost", Em.K);
  950. sinon.stub(controller, "doStartAllComponents", Em.K);
  951. sinon.stub(controller, "doStopAllComponents", Em.K);
  952. sinon.stub(controller, "doRestartAllComponents", Em.K);
  953. sinon.stub(controller, "onOffPassiveModeForHost", Em.K);
  954. });
  955. afterEach(function () {
  956. controller.validateAndDeleteHost.restore();
  957. controller.doStartAllComponents.restore();
  958. controller.doStopAllComponents.restore();
  959. controller.doRestartAllComponents.restore();
  960. controller.onOffPassiveModeForHost.restore();
  961. });
  962. it('"deleteHost" action', function () {
  963. var option = {context: {action: "deleteHost"}};
  964. controller.doAction(option);
  965. expect(controller.validateAndDeleteHost.calledOnce).to.be.true;
  966. });
  967. it('"startAllComponents" action, isNotHeartBeating = false', function () {
  968. var option = {context: {action: "startAllComponents"}};
  969. controller.set('content.isNotHeartBeating', false);
  970. controller.doAction(option);
  971. expect(controller.doStartAllComponents.calledOnce).to.be.true;
  972. });
  973. it('"startAllComponents" action, isNotHeartBeating = true', function () {
  974. var option = {context: {action: "startAllComponents"}};
  975. controller.set('content.isNotHeartBeating', true);
  976. controller.doAction(option);
  977. expect(controller.doStartAllComponents.called).to.be.false;
  978. });
  979. it('"stopAllComponents" action, isNotHeartBeating = false', function () {
  980. var option = {context: {action: "stopAllComponents"}};
  981. controller.set('content.isNotHeartBeating', false);
  982. controller.doAction(option);
  983. expect(controller.doStopAllComponents.calledOnce).to.be.true;
  984. });
  985. it('"stopAllComponents" action, isNotHeartBeating = true', function () {
  986. var option = {context: {action: "stopAllComponents"}};
  987. controller.set('content.isNotHeartBeating', true);
  988. controller.doAction(option);
  989. expect(controller.doStopAllComponents.called).to.be.false;
  990. });
  991. it('"restartAllComponents" action, isNotHeartBeating = false', function () {
  992. var option = {context: {action: "restartAllComponents"}};
  993. controller.set('content.isNotHeartBeating', false);
  994. controller.doAction(option);
  995. expect(controller.doRestartAllComponents.calledOnce).to.be.true;
  996. });
  997. it('"restartAllComponents" action, isNotHeartBeating = true', function () {
  998. var option = {context: {action: "restartAllComponents"}};
  999. controller.set('content.isNotHeartBeating', true);
  1000. controller.doAction(option);
  1001. expect(controller.doRestartAllComponents.called).to.be.false;
  1002. });
  1003. it('"onOffPassiveModeForHost" action', function () {
  1004. var option = {context: {action: "onOffPassiveModeForHost"}};
  1005. controller.doAction(option);
  1006. expect(controller.onOffPassiveModeForHost.calledWith({action: "onOffPassiveModeForHost"})).to.be.true;
  1007. });
  1008. });
  1009. describe('#onOffPassiveModeForHost()', function () {
  1010. beforeEach(function () {
  1011. sinon.spy(App, "showConfirmationPopup");
  1012. sinon.stub(controller, "hostPassiveModeRequest", Em.K);
  1013. });
  1014. afterEach(function () {
  1015. App.showConfirmationPopup.restore();
  1016. controller.hostPassiveModeRequest.restore();
  1017. });
  1018. it('popup should be displayed, active = true', function () {
  1019. var popup = controller.onOffPassiveModeForHost({active: true});
  1020. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1021. popup.onPrimary();
  1022. expect(controller.hostPassiveModeRequest.calledWith('ON')).to.be.true;
  1023. });
  1024. it('popup should be displayed, active = false', function () {
  1025. var popup = controller.onOffPassiveModeForHost({active: false});
  1026. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1027. popup.onPrimary();
  1028. expect(controller.hostPassiveModeRequest.calledWith('OFF')).to.be.true;
  1029. });
  1030. });
  1031. describe('#hostPassiveModeRequest()', function () {
  1032. beforeEach(function () {
  1033. sinon.stub(App.ajax, "send", Em.K);
  1034. });
  1035. afterEach(function () {
  1036. App.ajax.send.restore();
  1037. });
  1038. it('Query should be sent', function () {
  1039. controller.hostPassiveModeRequest('', '');
  1040. expect(App.ajax.send.calledOnce).to.be.true;
  1041. });
  1042. });
  1043. describe('#doStartAllComponents()', function () {
  1044. beforeEach(function () {
  1045. sinon.stub(App, "showConfirmationPopup", Em.K);
  1046. sinon.stub(controller, "sendStartComponentCommand", Em.K);
  1047. });
  1048. afterEach(function () {
  1049. App.showConfirmationPopup.restore();
  1050. controller.sendStartComponentCommand.restore();
  1051. });
  1052. it('serviceNonClientActiveComponents is null', function () {
  1053. controller.reopen({
  1054. serviceNonClientActiveComponents: []
  1055. });
  1056. controller.set('serviceNonClientActiveComponents', null);
  1057. controller.doStartAllComponents();
  1058. expect(App.showConfirmationPopup.called).to.be.false;
  1059. });
  1060. it('serviceNonClientActiveComponents is empty', function () {
  1061. controller.set('serviceNonClientActiveComponents', []);
  1062. controller.doStartAllComponents();
  1063. expect(App.showConfirmationPopup.called).to.be.false;
  1064. });
  1065. it('serviceNonClientActiveComponents is correct', function () {
  1066. controller.set('serviceNonClientActiveComponents', [{}]);
  1067. var popup = controller.doStartAllComponents();
  1068. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1069. /*popup.onPrimary();
  1070. expect(controller.sendStartComponentCommand.calledWith([{}])).to.be.true;*/
  1071. });
  1072. });
  1073. describe('#doStopAllComponents()', function () {
  1074. beforeEach(function () {
  1075. sinon.stub(App, "showConfirmationPopup", Em.K);
  1076. sinon.stub(controller, "sendStartComponentCommand", Em.K);
  1077. });
  1078. afterEach(function () {
  1079. App.showConfirmationPopup.restore();
  1080. controller.sendStartComponentCommand.restore();
  1081. });
  1082. it('serviceNonClientActiveComponents is null', function () {
  1083. controller.set('serviceNonClientActiveComponents', null);
  1084. controller.doStopAllComponents();
  1085. expect(App.showConfirmationPopup.called).to.be.false;
  1086. });
  1087. it('serviceNonClientActiveComponents is empty', function () {
  1088. controller.set('serviceNonClientActiveComponents', []);
  1089. controller.doStopAllComponents();
  1090. expect(App.showConfirmationPopup.called).to.be.false;
  1091. });
  1092. it('serviceNonClientActiveComponents is correct', function () {
  1093. controller.set('serviceNonClientActiveComponents', [{}]);
  1094. var popup = controller.doStopAllComponents();
  1095. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1096. /*popup.onPrimary();
  1097. expect(controller.sendStopComponentCommand.calledWith([{}])).to.be.true;*/
  1098. });
  1099. });
  1100. describe('#doRestartAllComponents()', function () {
  1101. beforeEach(function () {
  1102. sinon.stub(App, "showConfirmationPopup", Em.K);
  1103. sinon.stub(controller, "sendStartComponentCommand", Em.K);
  1104. });
  1105. afterEach(function () {
  1106. App.showConfirmationPopup.restore();
  1107. controller.sendStartComponentCommand.restore();
  1108. });
  1109. it('serviceActiveComponents is null', function () {
  1110. controller.set('serviceActiveComponents', null);
  1111. controller.doRestartAllComponents();
  1112. expect(App.showConfirmationPopup.called).to.be.false;
  1113. });
  1114. it('serviceActiveComponents is empty', function () {
  1115. controller.set('serviceActiveComponents', []);
  1116. controller.doRestartAllComponents();
  1117. expect(App.showConfirmationPopup.called).to.be.false;
  1118. });
  1119. it('serviceActiveComponents is correct', function () {
  1120. controller.set('serviceActiveComponents', [{}]);
  1121. var popup = controller.doRestartAllComponents();
  1122. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1123. /*popup.onPrimary();
  1124. expect(controller.restartHostComponents.calledWith([{}])).to.be.true;*/
  1125. });
  1126. });
  1127. describe('#getHostComponentsInfo()', function () {
  1128. var result = {
  1129. zkServerInstalled: false,
  1130. lastComponents: [],
  1131. masterComponents: [],
  1132. runningComponents: [],
  1133. nonDeletableComponents: [],
  1134. unknownComponents: []
  1135. };
  1136. it('content.hostComponents is null', function () {
  1137. controller.set('content.hostComponents', null);
  1138. expect(controller.getHostComponentsInfo()).to.eql(result);
  1139. });
  1140. it('content.hostComponents is empty', function () {
  1141. controller.set('content.hostComponents', []);
  1142. expect(controller.getHostComponentsInfo()).to.eql(result);
  1143. });
  1144. it('content.hostComponents has ZOOKEEPER_SERVER', function () {
  1145. App.HostComponent.find().clear();
  1146. controller.set('content.hostComponents', [Em.Object.create({
  1147. componentName: 'ZOOKEEPER_SERVER',
  1148. workStatus: 'INIT',
  1149. isDeletable: true
  1150. })]);
  1151. expect(controller.getHostComponentsInfo().zkServerInstalled).to.be.true;
  1152. });
  1153. it('content.hostComponents has last component', function () {
  1154. App.store.load(App.HostComponent, {
  1155. id: 'TASKTRACKER_host1',
  1156. component_name: 'TASKTRACKER'
  1157. });
  1158. controller.set('content.hostComponents', [Em.Object.create({
  1159. componentName: 'TASKTRACKER',
  1160. displayName: 'TaskTracker',
  1161. workStatus: 'INIT',
  1162. isDeletable: true
  1163. })]);
  1164. expect(controller.getHostComponentsInfo().lastComponents).to.eql(['TaskTracker']);
  1165. App.HostComponent.find().clear();
  1166. });
  1167. it('content.hostComponents has master non-deletable component', function () {
  1168. controller.set('content.hostComponents', [Em.Object.create({
  1169. componentName: 'TASKTRACKER',
  1170. workStatus: 'INIT',
  1171. isDeletable: false,
  1172. isMaster: true,
  1173. displayName: 'ZK1'
  1174. })]);
  1175. expect(controller.getHostComponentsInfo().masterComponents).to.eql(['ZK1']);
  1176. expect(controller.getHostComponentsInfo().nonDeletableComponents).to.eql(['ZK1']);
  1177. });
  1178. it('content.hostComponents has running component', function () {
  1179. controller.set('content.hostComponents', [Em.Object.create({
  1180. componentName: 'TASKTRACKER',
  1181. workStatus: 'STARTED',
  1182. isDeletable: true,
  1183. displayName: 'ZK1'
  1184. })]);
  1185. expect(controller.getHostComponentsInfo().runningComponents).to.eql(['ZK1']);
  1186. });
  1187. it('content.hostComponents has non-deletable component', function () {
  1188. controller.set('content.hostComponents', [Em.Object.create({
  1189. componentName: 'TASKTRACKER',
  1190. workStatus: 'INIT',
  1191. isDeletable: false,
  1192. displayName: 'ZK1'
  1193. })]);
  1194. expect(controller.getHostComponentsInfo().nonDeletableComponents).to.eql(['ZK1']);
  1195. });
  1196. it('content.hostComponents has component with UNKNOWN state', function () {
  1197. controller.set('content.hostComponents', [Em.Object.create({
  1198. componentName: 'TASKTRACKER',
  1199. workStatus: 'UNKNOWN',
  1200. isDeletable: false,
  1201. displayName: 'ZK1'
  1202. })]);
  1203. expect(controller.getHostComponentsInfo().unknownComponents).to.eql(['ZK1']);
  1204. });
  1205. });
  1206. describe('#validateAndDeleteHost()', function () {
  1207. beforeEach(function () {
  1208. sinon.stub(App, "showConfirmationPopup", Em.K);
  1209. sinon.stub(controller, "getHostComponentsInfo", function(){
  1210. return this.get('mockHostComponentsInfo');
  1211. });
  1212. sinon.stub(controller, "raiseDeleteComponentsError", Em.K);
  1213. sinon.stub(controller, "_doDeleteHost", Em.K);
  1214. });
  1215. afterEach(function () {
  1216. App.showConfirmationPopup.restore();
  1217. controller.getHostComponentsInfo.restore();
  1218. controller.raiseDeleteComponentsError.restore();
  1219. controller._doDeleteHost.restore();
  1220. });
  1221. it('App.supports.deleteHost = false', function () {
  1222. App.supports.deleteHost = false;
  1223. expect(controller.validateAndDeleteHost()).to.be.false;
  1224. App.supports.deleteHost = true;
  1225. });
  1226. it('masterComponents exist', function () {
  1227. controller.set('mockHostComponentsInfo', {masterComponents: [{}]});
  1228. controller.validateAndDeleteHost();
  1229. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'masterList')).to.be.true;
  1230. });
  1231. it('nonDeletableComponents exist', function () {
  1232. controller.set('mockHostComponentsInfo', {
  1233. masterComponents: [],
  1234. nonDeletableComponents: [{}]
  1235. });
  1236. controller.validateAndDeleteHost();
  1237. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'nonDeletableList')).to.be.true;
  1238. });
  1239. it('runningComponents exist', function () {
  1240. controller.set('mockHostComponentsInfo', {
  1241. masterComponents: [],
  1242. nonDeletableComponents: [],
  1243. runningComponents: [{}]
  1244. });
  1245. controller.validateAndDeleteHost();
  1246. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'runningList')).to.be.true;
  1247. });
  1248. it('zkServerInstalled = true', function () {
  1249. controller.set('mockHostComponentsInfo', {
  1250. masterComponents: [],
  1251. nonDeletableComponents: [],
  1252. runningComponents: [],
  1253. unknownComponents: [],
  1254. lastComponents: [],
  1255. zkServerInstalled: true
  1256. });
  1257. var popup = controller.validateAndDeleteHost();
  1258. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1259. /* popup.onPrimary();
  1260. expect(controller._doDeleteHost.calledWith([], [])).to.be.true;*/
  1261. });
  1262. it('zkServerInstalled = false', function () {
  1263. controller.set('mockHostComponentsInfo', {
  1264. masterComponents: [],
  1265. nonDeletableComponents: [],
  1266. runningComponents: [],
  1267. unknownComponents: [],
  1268. lastComponents: [],
  1269. zkServerInstalled: false
  1270. });
  1271. controller.validateAndDeleteHost();
  1272. expect(controller._doDeleteHost.calledWith([], [])).to.be.true;
  1273. });
  1274. });
  1275. describe('#raiseDeleteComponentsError()', function () {
  1276. beforeEach(function () {
  1277. sinon.stub(App.ModalPopup, "show", Em.K);
  1278. });
  1279. afterEach(function () {
  1280. App.ModalPopup.show.restore();
  1281. });
  1282. it('Popup should be displayed', function () {
  1283. controller.raiseDeleteComponentsError([], '');
  1284. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1285. });
  1286. });
  1287. describe('#_doDeleteHost()', function () {
  1288. beforeEach(function () {
  1289. sinon.stub(App.ModalPopup, "show", Em.K);
  1290. });
  1291. afterEach(function () {
  1292. App.ModalPopup.show.restore();
  1293. });
  1294. it('Popup should be displayed', function () {
  1295. controller._doDeleteHost([], []);
  1296. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1297. });
  1298. });
  1299. describe('#restartAllStaleConfigComponents()', function () {
  1300. beforeEach(function () {
  1301. sinon.spy(App, "showConfirmationPopup");
  1302. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  1303. });
  1304. afterEach(function () {
  1305. App.showConfirmationPopup.restore();
  1306. batchUtils.restartHostComponents.restore();
  1307. });
  1308. it('popup should be displayed', function () {
  1309. controller.set('content.componentsWithStaleConfigs', [{}]);
  1310. var popup = controller.restartAllStaleConfigComponents();
  1311. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1312. popup.onPrimary();
  1313. expect(batchUtils.restartHostComponents.calledWith([{}])).to.be.true;
  1314. });
  1315. });
  1316. describe('#moveComponent()', function () {
  1317. beforeEach(function () {
  1318. sinon.spy(App, "showConfirmationPopup");
  1319. });
  1320. afterEach(function () {
  1321. App.showConfirmationPopup.restore();
  1322. });
  1323. it('popup should be displayed', function () {
  1324. var popup = controller.moveComponent();
  1325. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1326. });
  1327. });
  1328. describe('#refreshConfigs()', function () {
  1329. beforeEach(function () {
  1330. sinon.spy(App, "showConfirmationPopup");
  1331. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  1332. });
  1333. afterEach(function () {
  1334. App.showConfirmationPopup.restore();
  1335. batchUtils.restartHostComponents.restore();
  1336. });
  1337. it('No components', function () {
  1338. var event = {context: []};
  1339. controller.refreshConfigs(event);
  1340. expect(App.showConfirmationPopup.called).to.be.false;
  1341. });
  1342. it('No components with stale configs', function () {
  1343. var event = {context: [Em.Object.create({
  1344. staleConfigs: false
  1345. })]};
  1346. controller.refreshConfigs(event);
  1347. expect(App.showConfirmationPopup.called).to.be.false;
  1348. });
  1349. it('Components with stale configs', function () {
  1350. var event = {context: [Em.Object.create({
  1351. staleConfigs: true
  1352. })]};
  1353. var popup = controller.refreshConfigs(event);
  1354. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1355. popup.onPrimary();
  1356. expect(batchUtils.restartHostComponents.calledWith([Em.Object.create({
  1357. staleConfigs: true
  1358. })])).to.be.true;
  1359. });
  1360. });
  1361. });