details_test.js 45 KB

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