details_test.js 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474
  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. it('SLIDER is installed', function () {
  415. App.store.load(App.Service, {
  416. id: 'SLIDER',
  417. service_name: 'SLIDER'
  418. });
  419. var data = {Clusters: {desired_configs: {'slider-client': {tag: 1}}}};
  420. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=slider-client&tag=1)']);
  421. App.Service.find().clear();
  422. });
  423. });
  424. describe('#loadConfigsSuccessCallback()', function () {
  425. beforeEach(function () {
  426. sinon.stub(App.ajax, "send", Em.K);
  427. sinon.stub(controller, "constructConfigUrlParams", function () {
  428. return this.get('mockUrlParams');
  429. });
  430. });
  431. afterEach(function () {
  432. App.ajax.send.restore();
  433. controller.constructConfigUrlParams.restore();
  434. });
  435. it('url params is empty', function () {
  436. controller.set('mockUrlParams', []);
  437. expect(controller.loadConfigsSuccessCallback()).to.be.false;
  438. expect(App.ajax.send.called).to.be.false;
  439. });
  440. it('url params are correct', function () {
  441. controller.set('mockUrlParams', ['param1']);
  442. expect(controller.loadConfigsSuccessCallback()).to.be.true;
  443. expect(App.ajax.send.calledOnce).to.be.true;
  444. });
  445. });
  446. describe('#saveZkConfigs()', function () {
  447. beforeEach(function () {
  448. sinon.stub(controller, "getZkServerHosts", Em.K);
  449. sinon.stub(controller, "concatZkNames", Em.K);
  450. sinon.stub(controller, "setZKConfigs", Em.K);
  451. sinon.spy(App.ajax, "send");
  452. });
  453. afterEach(function () {
  454. controller.getZkServerHosts.restore();
  455. controller.concatZkNames.restore();
  456. controller.setZKConfigs.restore();
  457. App.ajax.send.restore();
  458. });
  459. it('data.items is empty', function () {
  460. var data = {items: []};
  461. controller.saveZkConfigs(data);
  462. expect(App.ajax.send.called).to.be.false;
  463. });
  464. it('data.items has one item', function () {
  465. var data = {items: [
  466. {
  467. type: 'type1',
  468. properties: {}
  469. }
  470. ]};
  471. controller.saveZkConfigs(data);
  472. expect(App.ajax.send.calledOnce).to.be.true;
  473. });
  474. it('data.items has two items', function () {
  475. var data = {items: [
  476. {
  477. type: 'type1',
  478. properties: {}
  479. },
  480. {
  481. type: 'type2',
  482. properties: {}
  483. }
  484. ]};
  485. controller.saveZkConfigs(data);
  486. expect(App.ajax.send.calledTwice).to.be.true;
  487. });
  488. });
  489. describe('#setZKConfigs()', function () {
  490. it('configs is null', function () {
  491. expect(controller.setZKConfigs(null)).to.be.false;
  492. });
  493. it('zks is null', function () {
  494. expect(controller.setZKConfigs({}, '', null)).to.be.false;
  495. });
  496. it('isHaEnabled = true', function () {
  497. var configs = {'core-site': {}};
  498. App.HostComponent.find().clear();
  499. App.store.load(App.Service, {
  500. id: 'HDFS',
  501. service_name: 'HDFS'
  502. });
  503. App.set('currentStackVersion', 'HDP-2.0.2');
  504. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  505. expect(configs).to.eql({"core-site": {
  506. "ha.zookeeper.quorum": "host1:2181"
  507. }});
  508. App.store.load(App.HostComponent, {
  509. id: 'SECONDARY_NAMENODE_host1',
  510. component_name: 'SECONDARY_NAMENODE'
  511. });
  512. App.set('currentStackVersion', 'HDP-2.0.1');
  513. });
  514. it('hbase-site is present', function () {
  515. var configs = {'hbase-site': {}};
  516. expect(controller.setZKConfigs(configs, '', ['host1', 'host2'])).to.be.true;
  517. expect(configs).to.eql({"hbase-site": {
  518. "hbase.zookeeper.quorum": "host1,host2"
  519. }});
  520. });
  521. it('webhcat-site is present', function () {
  522. var configs = {'webhcat-site': {}};
  523. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  524. expect(configs).to.eql({"webhcat-site": {
  525. "templeton.zookeeper.hosts": "host1:2181"
  526. }});
  527. });
  528. it('hive-site is present', function () {
  529. var configs = {'hive-site': {}};
  530. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  531. expect(configs).to.eql({"hive-site": {
  532. 'hive.cluster.delegation.token.store.zookeeper.connectString': "host1:2181",
  533. 'hive.zookeeper.quorum': "host1:2181"
  534. }});
  535. });
  536. it('storm-site is present', function () {
  537. var configs = {'storm-site': {}};
  538. expect(controller.setZKConfigs(configs, '', ["host1", 'host2'])).to.be.true;
  539. expect(configs).to.eql({"storm-site": {
  540. "storm.zookeeper.servers": "['host1','host2']"
  541. }});
  542. });
  543. it('slider-client is present', function () {
  544. var configs = {'slider-client': {}};
  545. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  546. expect(configs).to.eql({"slider-client": {
  547. "slider.zookeeper.quorum": "host1:2181"
  548. }});
  549. });
  550. });
  551. describe('#concatZkNames()', function () {
  552. it('No ZooKeeper hosts', function () {
  553. expect(controller.concatZkNames([])).to.equal('');
  554. });
  555. it('One ZooKeeper host', function () {
  556. expect(controller.concatZkNames(['host1'])).to.equal('host1:2181');
  557. });
  558. it('Two ZooKeeper hosts', function () {
  559. expect(controller.concatZkNames(['host1', 'host2'])).to.equal('host1:2181,host2:2181');
  560. });
  561. });
  562. describe('#getZkServerHosts()', function () {
  563. beforeEach(function() {
  564. controller.set('content', {});
  565. });
  566. afterEach(function() {
  567. App.HostComponent.find.restore();
  568. });
  569. it('No ZooKeeper hosts, fromDeleteHost = false', function () {
  570. sinon.stub(App.HostComponent, 'find', function() {return []});
  571. controller.set('fromDeleteHost', false);
  572. expect(controller.getZkServerHosts()).to.be.empty;
  573. });
  574. it('No ZooKeeper hosts, fromDeleteHost = true', function () {
  575. sinon.stub(App.HostComponent, 'find', function() {return []});
  576. controller.set('fromDeleteHost', true);
  577. expect(controller.getZkServerHosts()).to.be.empty;
  578. expect(controller.get('fromDeleteHost')).to.be.false;
  579. });
  580. it('One ZooKeeper host, fromDeleteHost = false', function () {
  581. controller.set('fromDeleteHost', false);
  582. sinon.stub(App.HostComponent, 'find', function() {return [{id: 'ZOOKEEPER_SERVER_host1',
  583. componentName: 'ZOOKEEPER_SERVER',
  584. hostName: 'host1'
  585. }]});
  586. expect(controller.getZkServerHosts()).to.eql(['host1']);
  587. });
  588. it('One ZooKeeper host match current host name, fromDeleteHost = true', function () {
  589. sinon.stub(App.HostComponent, 'find', function() {return [{id: 'ZOOKEEPER_SERVER_host1',
  590. componentName: 'ZOOKEEPER_SERVER',
  591. hostName: 'host1'
  592. }]});
  593. controller.set('fromDeleteHost', true);
  594. controller.set('content.hostName', 'host1');
  595. expect(controller.getZkServerHosts()).to.be.empty;
  596. expect(controller.get('fromDeleteHost')).to.be.false;
  597. });
  598. it('One ZooKeeper host does not match current host name, fromDeleteHost = true', function () {
  599. sinon.stub(App.HostComponent, 'find', function() {return [{id: 'ZOOKEEPER_SERVER_host1',
  600. componentName: 'ZOOKEEPER_SERVER',
  601. hostName: 'host1'
  602. }]});
  603. controller.set('fromDeleteHost', true);
  604. controller.set('content.hostName', 'host2');
  605. expect(controller.getZkServerHosts()[0]).to.equal("host1");
  606. expect(controller.get('fromDeleteHost')).to.be.false;
  607. });
  608. });
  609. describe('#installComponent()', function () {
  610. beforeEach(function () {
  611. sinon.spy(App.ModalPopup, "show");
  612. sinon.stub(App.ajax, "send", Em.K);
  613. });
  614. afterEach(function () {
  615. App.ModalPopup.show.restore();
  616. App.ajax.send.restore();
  617. });
  618. it('popup should be displayed', function () {
  619. var event = {context: Em.Object.create()};
  620. var popup = controller.installComponent(event);
  621. expect(App.ModalPopup.show.calledOnce).to.be.true;
  622. popup.onPrimary();
  623. expect(App.ajax.send.calledOnce).to.be.true;
  624. });
  625. });
  626. describe('#decommission()', function () {
  627. beforeEach(function () {
  628. sinon.spy(App, "showConfirmationPopup");
  629. sinon.stub(controller, "runDecommission", Em.K);
  630. });
  631. afterEach(function () {
  632. App.showConfirmationPopup.restore();
  633. controller.runDecommission.restore();
  634. });
  635. it('popup should be displayed', function () {
  636. var popup = controller.decommission(Em.Object.create({service: {}}));
  637. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  638. popup.onPrimary();
  639. expect(controller.runDecommission.calledOnce).to.be.true;
  640. });
  641. });
  642. describe('#runDecommission()', function () {
  643. beforeEach(function () {
  644. sinon.stub(controller, "doDecommission", Em.K);
  645. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  646. });
  647. afterEach(function () {
  648. controller.doDecommission.restore();
  649. controller.showBackgroundOperationsPopup.restore();
  650. });
  651. it('HDFS service', function () {
  652. controller.runDecommission('host1', 'HDFS');
  653. expect(controller.doDecommission.calledWith('host1', 'HDFS', "NAMENODE", "DATANODE")).to.be.true;
  654. });
  655. it('YARN service', function () {
  656. controller.runDecommission('host1', 'YARN');
  657. expect(controller.doDecommission.calledWith('host1', 'YARN', "RESOURCEMANAGER", "NODEMANAGER")).to.be.true;
  658. });
  659. it('MAPREDUCE service', function () {
  660. controller.runDecommission('host1', 'MAPREDUCE');
  661. expect(controller.doDecommission.calledWith('host1', 'MAPREDUCE', "JOBTRACKER", "TASKTRACKER")).to.be.true;
  662. });
  663. });
  664. describe('#runRecommission()', function () {
  665. beforeEach(function () {
  666. sinon.stub(controller, "doRecommissionAndStart", Em.K);
  667. sinon.stub(controller, "doRecommissionAndRestart", Em.K);
  668. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  669. });
  670. afterEach(function () {
  671. controller.doRecommissionAndStart.restore();
  672. controller.doRecommissionAndRestart.restore();
  673. controller.showBackgroundOperationsPopup.restore();
  674. });
  675. it('HDFS service', function () {
  676. controller.runRecommission('host1', 'HDFS');
  677. expect(controller.doRecommissionAndStart.calledWith('host1', 'HDFS', "NAMENODE", "DATANODE")).to.be.true;
  678. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  679. });
  680. it('YARN service', function () {
  681. controller.runRecommission('host1', 'YARN');
  682. expect(controller.doRecommissionAndStart.calledWith('host1', 'YARN', "RESOURCEMANAGER", "NODEMANAGER")).to.be.true;
  683. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  684. });
  685. it('MAPREDUCE service', function () {
  686. controller.runRecommission('host1', 'MAPREDUCE');
  687. expect(controller.doRecommissionAndRestart.calledWith('host1', 'MAPREDUCE', "JOBTRACKER", "TASKTRACKER")).to.be.true;
  688. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  689. });
  690. it('HBASE service', function () {
  691. controller.runRecommission('host1', 'HBASE');
  692. expect(controller.doRecommissionAndStart.calledWith('host1', 'HBASE', "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
  693. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  694. });
  695. });
  696. describe('#doDecommission()', function () {
  697. beforeEach(function () {
  698. sinon.stub(App.ajax, "send", Em.K);
  699. });
  700. afterEach(function () {
  701. App.ajax.send.restore();
  702. });
  703. it('Query should be sent', function () {
  704. controller.doDecommission('', '', '', '');
  705. expect(App.ajax.send.calledOnce).to.be.true;
  706. });
  707. });
  708. describe('#doDecommissionRegionServer()', function () {
  709. beforeEach(function () {
  710. sinon.stub(App.ajax, "send", Em.K);
  711. });
  712. afterEach(function () {
  713. App.ajax.send.restore();
  714. });
  715. it('Query should be sent', function () {
  716. controller.doDecommissionRegionServer('', '', '', '');
  717. expect(App.ajax.send.calledOnce).to.be.true;
  718. });
  719. });
  720. /**
  721. * TODO uncomment test when final rules will be implemented into warnBeforeDecommission function
  722. */
  723. /* describe('#warnBeforeDecommission()', function () {
  724. beforeEach(function () {
  725. sinon.stub(controller, "doDecommissionRegionServer", Em.K);
  726. sinon.stub(App.ModalPopup, "show", Em.K);
  727. });
  728. afterEach(function () {
  729. App.ModalPopup.show.restore();
  730. controller.doDecommissionRegionServer.restore();
  731. });
  732. it('Component in passive state', function () {
  733. controller.set('content.hostComponents', [Em.Object.create({
  734. componentName: 'HBASE_REGIONSERVER',
  735. passiveState: 'ON'
  736. })]);
  737. controller.warnBeforeDecommission('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE');
  738. expect(App.ModalPopup.show.called).to.be.false;
  739. expect(controller.doDecommissionRegionServer.calledWith('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE')).to.be.true;
  740. });
  741. it('Component is not in passive state', function () {
  742. controller.set('content.hostComponents', [Em.Object.create({
  743. componentName: 'HBASE_REGIONSERVER',
  744. passiveState: 'OFF'
  745. })]);
  746. controller.warnBeforeDecommission('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE');
  747. expect(App.ModalPopup.show.calledOnce).to.be.true;
  748. expect(controller.doDecommissionRegionServer.called).to.be.false;
  749. });
  750. });*/
  751. describe('#doRecommissionAndStart()', function () {
  752. beforeEach(function () {
  753. sinon.stub(App.ajax, "send", Em.K);
  754. });
  755. afterEach(function () {
  756. App.ajax.send.restore();
  757. });
  758. it('Query should be sent', function () {
  759. controller.doRecommissionAndStart('', '', '', '');
  760. expect(App.ajax.send.calledOnce).to.be.true;
  761. });
  762. });
  763. describe('#decommissionSuccessCallback()', function () {
  764. beforeEach(function () {
  765. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  766. });
  767. afterEach(function () {
  768. controller.showBackgroundOperationsPopup.restore();
  769. });
  770. it('data is null', function () {
  771. expect(controller.decommissionSuccessCallback(null)).to.be.false;
  772. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  773. });
  774. it('data has Requests', function () {
  775. var data = {Requests: []};
  776. expect(controller.decommissionSuccessCallback(data)).to.be.true;
  777. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  778. });
  779. it('data has resources', function () {
  780. var data = {resources: [{RequestSchedule: {}}]};
  781. expect(controller.decommissionSuccessCallback(data)).to.be.true;
  782. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  783. });
  784. });
  785. describe('#doRecommissionAndRestart()', function () {
  786. beforeEach(function () {
  787. sinon.stub(App.ajax, "send", Em.K);
  788. });
  789. afterEach(function () {
  790. App.ajax.send.restore();
  791. });
  792. it('Query should be sent', function () {
  793. controller.doRecommissionAndRestart('', '', '', '');
  794. expect(App.ajax.send.calledOnce).to.be.true;
  795. });
  796. });
  797. describe('#doAction()', function () {
  798. beforeEach(function () {
  799. sinon.stub(controller, "validateAndDeleteHost", Em.K);
  800. sinon.stub(controller, "doStartAllComponents", Em.K);
  801. sinon.stub(controller, "doStopAllComponents", Em.K);
  802. sinon.stub(controller, "doRestartAllComponents", Em.K);
  803. sinon.stub(controller, "onOffPassiveModeForHost", Em.K);
  804. });
  805. afterEach(function () {
  806. controller.validateAndDeleteHost.restore();
  807. controller.doStartAllComponents.restore();
  808. controller.doStopAllComponents.restore();
  809. controller.doRestartAllComponents.restore();
  810. controller.onOffPassiveModeForHost.restore();
  811. });
  812. it('"deleteHost" action', function () {
  813. var option = {context: {action: "deleteHost"}};
  814. controller.doAction(option);
  815. expect(controller.validateAndDeleteHost.calledOnce).to.be.true;
  816. });
  817. it('"startAllComponents" action, isNotHeartBeating = false', function () {
  818. var option = {context: {action: "startAllComponents"}};
  819. controller.set('content', {isNotHeartBeating: false});
  820. controller.doAction(option);
  821. expect(controller.doStartAllComponents.calledOnce).to.be.true;
  822. });
  823. it('"startAllComponents" action, isNotHeartBeating = true', function () {
  824. var option = {context: {action: "startAllComponents"}};
  825. controller.set('content', {isNotHeartBeating: true});
  826. controller.doAction(option);
  827. expect(controller.doStartAllComponents.called).to.be.false;
  828. });
  829. it('"stopAllComponents" action, isNotHeartBeating = false', function () {
  830. var option = {context: {action: "stopAllComponents"}};
  831. controller.set('content', {isNotHeartBeating: false});
  832. controller.doAction(option);
  833. expect(controller.doStopAllComponents.calledOnce).to.be.true;
  834. });
  835. it('"stopAllComponents" action, isNotHeartBeating = true', function () {
  836. var option = {context: {action: "stopAllComponents"}};
  837. controller.set('content', {isNotHeartBeating: true});
  838. controller.doAction(option);
  839. expect(controller.doStopAllComponents.called).to.be.false;
  840. });
  841. it('"restartAllComponents" action, isNotHeartBeating = false', function () {
  842. var option = {context: {action: "restartAllComponents"}};
  843. controller.set('content', {isNotHeartBeating: false});
  844. controller.doAction(option);
  845. expect(controller.doRestartAllComponents.calledOnce).to.be.true;
  846. });
  847. it('"restartAllComponents" action, isNotHeartBeating = true', function () {
  848. var option = {context: {action: "restartAllComponents"}};
  849. controller.set('content', {isNotHeartBeating: true});
  850. controller.doAction(option);
  851. expect(controller.doRestartAllComponents.called).to.be.false;
  852. });
  853. it('"onOffPassiveModeForHost" action', function () {
  854. var option = {context: {action: "onOffPassiveModeForHost"}};
  855. controller.doAction(option);
  856. expect(controller.onOffPassiveModeForHost.calledWith({action: "onOffPassiveModeForHost"})).to.be.true;
  857. });
  858. });
  859. describe('#onOffPassiveModeForHost()', function () {
  860. beforeEach(function () {
  861. sinon.spy(App, "showConfirmationPopup");
  862. sinon.stub(controller, "hostPassiveModeRequest", Em.K);
  863. });
  864. afterEach(function () {
  865. App.showConfirmationPopup.restore();
  866. controller.hostPassiveModeRequest.restore();
  867. });
  868. it('popup should be displayed, active = true', function () {
  869. var popup = controller.onOffPassiveModeForHost({active: true});
  870. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  871. popup.onPrimary();
  872. expect(controller.hostPassiveModeRequest.calledWith('ON')).to.be.true;
  873. });
  874. it('popup should be displayed, active = false', function () {
  875. var popup = controller.onOffPassiveModeForHost({active: false});
  876. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  877. popup.onPrimary();
  878. expect(controller.hostPassiveModeRequest.calledWith('OFF')).to.be.true;
  879. });
  880. });
  881. describe('#hostPassiveModeRequest()', function () {
  882. beforeEach(function () {
  883. sinon.stub(App.ajax, "send", Em.K);
  884. });
  885. afterEach(function () {
  886. App.ajax.send.restore();
  887. });
  888. it('Query should be sent', function () {
  889. controller.hostPassiveModeRequest('', '');
  890. expect(App.ajax.send.calledOnce).to.be.true;
  891. });
  892. });
  893. describe('#doStartAllComponents()', function () {
  894. beforeEach(function () {
  895. sinon.stub(App, "showConfirmationPopup", Em.K);
  896. controller.reopen({serviceActiveComponents: []});
  897. });
  898. afterEach(function () {
  899. App.showConfirmationPopup.restore();
  900. });
  901. it('serviceNonClientActiveComponents is empty', function () {
  902. controller.reopen({
  903. serviceNonClientActiveComponents: []
  904. });
  905. controller.doStartAllComponents();
  906. expect(App.showConfirmationPopup.called).to.be.false;
  907. });
  908. it('serviceNonClientActiveComponents is correct', function () {
  909. controller.reopen({
  910. serviceNonClientActiveComponents: [{}]
  911. });
  912. var popup = controller.doStartAllComponents();
  913. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  914. /*popup.onPrimary();
  915. expect(controller.sendStartComponentCommand.calledWith([{}])).to.be.true;*/
  916. });
  917. });
  918. describe('#doStopAllComponents()', function () {
  919. beforeEach(function () {
  920. sinon.stub(App, "showConfirmationPopup", Em.K);
  921. controller.reopen({serviceActiveComponents: []});
  922. });
  923. afterEach(function () {
  924. App.showConfirmationPopup.restore();
  925. });
  926. it('serviceNonClientActiveComponents is empty', function () {
  927. controller.reopen({
  928. serviceNonClientActiveComponents: []
  929. });
  930. controller.doStopAllComponents();
  931. expect(App.showConfirmationPopup.called).to.be.false;
  932. });
  933. it('serviceNonClientActiveComponents is correct', function () {
  934. controller.reopen({
  935. serviceNonClientActiveComponents: [{}]
  936. });
  937. var popup = controller.doStopAllComponents();
  938. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  939. /*popup.onPrimary();
  940. expect(controller.sendStopComponentCommand.calledWith([{}])).to.be.true;*/
  941. });
  942. });
  943. describe('#doRestartAllComponents()', function () {
  944. beforeEach(function () {
  945. sinon.stub(App, "showConfirmationPopup", Em.K);
  946. });
  947. afterEach(function () {
  948. App.showConfirmationPopup.restore();
  949. });
  950. it('serviceActiveComponents is empty', function () {
  951. controller.reopen({
  952. serviceActiveComponents: []
  953. });
  954. controller.doRestartAllComponents();
  955. expect(App.showConfirmationPopup.called).to.be.false;
  956. });
  957. it('serviceActiveComponents is correct', function () {
  958. controller.reopen({
  959. serviceActiveComponents: [{}]
  960. });
  961. var popup = controller.doRestartAllComponents();
  962. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  963. /*popup.onPrimary();
  964. expect(controller.restartHostComponents.calledWith([{}])).to.be.true;*/
  965. });
  966. });
  967. describe('#getHostComponentsInfo()', function () {
  968. var result = {
  969. zkServerInstalled: false,
  970. lastComponents: [],
  971. masterComponents: [],
  972. runningComponents: [],
  973. nonDeletableComponents: [],
  974. unknownComponents: []
  975. };
  976. it('content.hostComponents is null', function () {
  977. controller.set('content', {hostComponents: null});
  978. expect(controller.getHostComponentsInfo()).to.eql(result);
  979. });
  980. it('content.hostComponents is empty', function () {
  981. controller.set('content', {hostComponents :[]});
  982. expect(controller.getHostComponentsInfo()).to.eql(result);
  983. });
  984. it('content.hostComponents has ZOOKEEPER_SERVER', function () {
  985. App.HostComponent.find().clear();
  986. controller.set('content', {hostComponents: [Em.Object.create({
  987. componentName: 'ZOOKEEPER_SERVER',
  988. workStatus: 'INIT',
  989. isDeletable: true
  990. })]});
  991. expect(controller.getHostComponentsInfo().zkServerInstalled).to.be.true;
  992. });
  993. it('content.hostComponents has last component', function () {
  994. sinon.stub(App.HostComponent, 'find', function() {
  995. return [{
  996. id: 'TASKTRACKER_host1',
  997. componentName: 'TASKTRACKER'
  998. }];
  999. });
  1000. controller.set('content', {hostComponents: [Em.Object.create({
  1001. componentName: 'TASKTRACKER',
  1002. displayName: 'TaskTracker',
  1003. workStatus: 'INIT',
  1004. isDeletable: true
  1005. })]});
  1006. expect(controller.getHostComponentsInfo().lastComponents).to.eql(['TaskTracker']);
  1007. App.HostComponent.find.restore();
  1008. });
  1009. it('content.hostComponents has master non-deletable component', function () {
  1010. sinon.stub(App.HostComponent, 'find', function() {
  1011. return [{
  1012. id: 'TASKTRACKER_host1',
  1013. componentName: 'TASKTRACKER'
  1014. }];
  1015. });
  1016. controller.set('content', {hostComponents :[Em.Object.create({
  1017. componentName: 'TASKTRACKER',
  1018. workStatus: 'INIT',
  1019. isDeletable: false,
  1020. isMaster: true,
  1021. displayName: 'ZK1'
  1022. })]});
  1023. expect(controller.getHostComponentsInfo().masterComponents).to.eql(['ZK1']);
  1024. expect(controller.getHostComponentsInfo().nonDeletableComponents).to.eql(['ZK1']);
  1025. App.HostComponent.find.restore();
  1026. });
  1027. it('content.hostComponents has running component', function () {
  1028. sinon.stub(App.HostComponent, 'find', function() {
  1029. return [{
  1030. id: 'TASKTRACKER_host1',
  1031. componentName: 'TASKTRACKER'
  1032. }];
  1033. });
  1034. controller.set('content', {hostComponents: [Em.Object.create({
  1035. componentName: 'TASKTRACKER',
  1036. workStatus: 'STARTED',
  1037. isDeletable: true,
  1038. displayName: 'ZK1'
  1039. })]});
  1040. expect(controller.getHostComponentsInfo().runningComponents).to.eql(['ZK1']);
  1041. App.HostComponent.find.restore();
  1042. });
  1043. it('content.hostComponents has non-deletable component', function () {
  1044. sinon.stub(App.HostComponent, 'find', function() {
  1045. return [{
  1046. id: 'TASKTRACKER_host1',
  1047. componentName: 'TASKTRACKER'
  1048. }];
  1049. });
  1050. controller.set('content', {hostComponents: [Em.Object.create({
  1051. componentName: 'TASKTRACKER',
  1052. workStatus: 'INIT',
  1053. isDeletable: false,
  1054. displayName: 'ZK1'
  1055. })]});
  1056. expect(controller.getHostComponentsInfo().nonDeletableComponents).to.eql(['ZK1']);
  1057. App.HostComponent.find.restore();
  1058. });
  1059. it('content.hostComponents has component with UNKNOWN state', function () {
  1060. sinon.stub(App.HostComponent, 'find', function() {
  1061. return [{
  1062. id: 'TASKTRACKER_host1',
  1063. componentName: 'TASKTRACKER'
  1064. }];
  1065. });
  1066. controller.set('content', {hostComponents: [Em.Object.create({
  1067. componentName: 'TASKTRACKER',
  1068. workStatus: 'UNKNOWN',
  1069. isDeletable: false,
  1070. displayName: 'ZK1'
  1071. })]});
  1072. expect(controller.getHostComponentsInfo().unknownComponents).to.eql(['ZK1']);
  1073. App.HostComponent.find.restore();
  1074. });
  1075. });
  1076. describe('#validateAndDeleteHost()', function () {
  1077. beforeEach(function () {
  1078. sinon.stub(App, "showConfirmationPopup", Em.K);
  1079. sinon.stub(controller, "getHostComponentsInfo", function(){
  1080. return this.get('mockHostComponentsInfo');
  1081. });
  1082. sinon.stub(controller, "raiseDeleteComponentsError", Em.K);
  1083. sinon.stub(controller, "_doDeleteHost", Em.K);
  1084. });
  1085. afterEach(function () {
  1086. App.showConfirmationPopup.restore();
  1087. controller.getHostComponentsInfo.restore();
  1088. controller.raiseDeleteComponentsError.restore();
  1089. controller._doDeleteHost.restore();
  1090. });
  1091. it('App.supports.deleteHost = false', function () {
  1092. App.supports.deleteHost = false;
  1093. expect(controller.validateAndDeleteHost()).to.be.false;
  1094. App.supports.deleteHost = true;
  1095. });
  1096. it('masterComponents exist', function () {
  1097. controller.set('mockHostComponentsInfo', {masterComponents: [{}]});
  1098. controller.validateAndDeleteHost();
  1099. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'masterList')).to.be.true;
  1100. });
  1101. it('nonDeletableComponents exist', function () {
  1102. controller.set('mockHostComponentsInfo', {
  1103. masterComponents: [],
  1104. nonDeletableComponents: [{}]
  1105. });
  1106. controller.validateAndDeleteHost();
  1107. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'nonDeletableList')).to.be.true;
  1108. });
  1109. it('runningComponents exist', function () {
  1110. controller.set('mockHostComponentsInfo', {
  1111. masterComponents: [],
  1112. nonDeletableComponents: [],
  1113. runningComponents: [{}]
  1114. });
  1115. controller.validateAndDeleteHost();
  1116. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'runningList')).to.be.true;
  1117. });
  1118. it('zkServerInstalled = true', function () {
  1119. controller.set('mockHostComponentsInfo', {
  1120. masterComponents: [],
  1121. nonDeletableComponents: [],
  1122. runningComponents: [],
  1123. unknownComponents: [],
  1124. lastComponents: [],
  1125. zkServerInstalled: true
  1126. });
  1127. var popup = controller.validateAndDeleteHost();
  1128. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1129. /* popup.onPrimary();
  1130. expect(controller._doDeleteHost.calledWith([], [])).to.be.true;*/
  1131. });
  1132. it('zkServerInstalled = false', function () {
  1133. controller.set('mockHostComponentsInfo', {
  1134. masterComponents: [],
  1135. nonDeletableComponents: [],
  1136. runningComponents: [],
  1137. unknownComponents: [],
  1138. lastComponents: [],
  1139. zkServerInstalled: false
  1140. });
  1141. controller.validateAndDeleteHost();
  1142. expect(controller._doDeleteHost.calledWith([], [])).to.be.true;
  1143. });
  1144. });
  1145. describe('#raiseDeleteComponentsError()', function () {
  1146. beforeEach(function () {
  1147. sinon.stub(App.ModalPopup, "show", Em.K);
  1148. });
  1149. afterEach(function () {
  1150. App.ModalPopup.show.restore();
  1151. });
  1152. it('Popup should be displayed', function () {
  1153. controller.raiseDeleteComponentsError([], '');
  1154. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1155. });
  1156. });
  1157. describe('#_doDeleteHost()', function () {
  1158. beforeEach(function () {
  1159. sinon.stub(App.ModalPopup, "show", Em.K);
  1160. });
  1161. afterEach(function () {
  1162. App.ModalPopup.show.restore();
  1163. });
  1164. it('Popup should be displayed', function () {
  1165. controller._doDeleteHost([], []);
  1166. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1167. });
  1168. });
  1169. describe('#restartAllStaleConfigComponents()', function () {
  1170. beforeEach(function () {
  1171. sinon.spy(App, "showConfirmationPopup");
  1172. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  1173. });
  1174. afterEach(function () {
  1175. App.showConfirmationPopup.restore();
  1176. batchUtils.restartHostComponents.restore();
  1177. });
  1178. it('popup should be displayed', function () {
  1179. controller.set('content', {componentsWithStaleConfigs :[{}]});
  1180. var popup = controller.restartAllStaleConfigComponents();
  1181. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1182. popup.onPrimary();
  1183. expect(batchUtils.restartHostComponents.calledWith([{}])).to.be.true;
  1184. });
  1185. });
  1186. describe('#moveComponent()', function () {
  1187. beforeEach(function () {
  1188. sinon.spy(App, "showConfirmationPopup");
  1189. });
  1190. afterEach(function () {
  1191. App.showConfirmationPopup.restore();
  1192. });
  1193. it('popup should be displayed', function () {
  1194. var popup = controller.moveComponent();
  1195. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1196. });
  1197. });
  1198. describe('#refreshConfigs()', function () {
  1199. beforeEach(function () {
  1200. sinon.spy(App, "showConfirmationPopup");
  1201. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  1202. });
  1203. afterEach(function () {
  1204. App.showConfirmationPopup.restore();
  1205. batchUtils.restartHostComponents.restore();
  1206. });
  1207. it('No components', function () {
  1208. var event = {context: []};
  1209. controller.refreshConfigs(event);
  1210. expect(App.showConfirmationPopup.called).to.be.false;
  1211. });
  1212. it('No components with stale configs', function () {
  1213. var event = {context: [Em.Object.create({
  1214. staleConfigs: false
  1215. })]};
  1216. controller.refreshConfigs(event);
  1217. expect(App.showConfirmationPopup.called).to.be.false;
  1218. });
  1219. it('Components with stale configs', function () {
  1220. var event = {context: [Em.Object.create({
  1221. staleConfigs: true
  1222. })]};
  1223. var popup = controller.refreshConfigs(event);
  1224. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1225. popup.onPrimary();
  1226. expect(batchUtils.restartHostComponents.calledWith([Em.Object.create({
  1227. staleConfigs: true
  1228. })])).to.be.true;
  1229. });
  1230. });
  1231. describe('#getTotalComponent()', function () {
  1232. beforeEach(function () {
  1233. sinon.stub(App.SlaveComponent, 'find', function() {
  1234. return Em.Object.create({
  1235. componentName: "SLAVE",
  1236. totalCount: 1
  1237. });
  1238. });
  1239. sinon.stub(App.ClientComponent, 'find', function() {
  1240. return Em.Object.create({
  1241. componentName: "CLIENT",
  1242. totalCount: 1
  1243. });
  1244. });
  1245. sinon.stub(App.HostComponent, 'find', function() {
  1246. return [Em.Object.create({
  1247. componentName: "MASTER",
  1248. totalCount: 1
  1249. })]
  1250. });
  1251. });
  1252. afterEach(function () {
  1253. App.SlaveComponent.find.restore();
  1254. App.ClientComponent.find.restore();
  1255. App.HostComponent.find.restore();
  1256. });
  1257. it('component is slave', function () {
  1258. expect(controller.getTotalComponent(Em.Object.create({
  1259. componentName: "SLAVE",
  1260. isSlave: true
  1261. }))).to.equal(1);
  1262. });
  1263. it('component is client', function () {
  1264. expect(controller.getTotalComponent(Em.Object.create({
  1265. componentName: "CLIENT",
  1266. isClient: true
  1267. }))).to.equal(1);
  1268. });
  1269. it('component is master', function () {
  1270. expect(controller.getTotalComponent(Em.Object.create({
  1271. componentName: "MASTER"
  1272. }))).to.equal(1);
  1273. });
  1274. it('unknown component', function () {
  1275. expect(controller.getTotalComponent(Em.Object.create({
  1276. componentName: "UNKNOWN"
  1277. }))).to.equal(0);
  1278. });
  1279. });
  1280. describe('#downloadClientConfigs()', function () {
  1281. beforeEach(function () {
  1282. sinon.stub($, 'fileDownload', function() {
  1283. return {
  1284. fail: function() { return false; }
  1285. }
  1286. });
  1287. });
  1288. afterEach(function () {
  1289. $.fileDownload.restore();
  1290. });
  1291. it('should launch $.fileDownload method', function () {
  1292. controller.downloadClientConfigs({
  1293. context: Em.Object.create({
  1294. componentName: 'name'
  1295. })
  1296. });
  1297. expect($.fileDownload.calledOnce).to.be.true;
  1298. });
  1299. });
  1300. describe('#executeCustomCommands', function() {
  1301. beforeEach(function () {
  1302. sinon.spy(App, "showConfirmationPopup");
  1303. sinon.stub(App.ajax, "send", Em.K);
  1304. });
  1305. afterEach(function () {
  1306. App.showConfirmationPopup.restore();
  1307. App.ajax.send.restore();
  1308. });
  1309. it('confirm popup should be displayed', function () {
  1310. var popup = controller.executeCustomCommand({context: Em.Object.create()});
  1311. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1312. popup.onPrimary();
  1313. expect(App.ajax.send.calledOnce).to.be.true;
  1314. });
  1315. });
  1316. });