details_test.js 47 KB

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