details_test.js 45 KB

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