details_test.js 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566
  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. require('models/host_stack_version');
  23. var batchUtils = require('utils/batch_scheduled_requests');
  24. var componentsUtils = require('utils/components');
  25. var hostsManagement = require('utils/hosts');
  26. var controller;
  27. describe('App.MainHostDetailsController', function () {
  28. beforeEach(function () {
  29. sinon.stub(App.ajax, 'send').returns({
  30. then: Em.K
  31. });
  32. controller = App.MainHostDetailsController.create({
  33. content: Em.Object.create()
  34. });
  35. });
  36. afterEach(function () {
  37. App.ajax.send.restore();
  38. });
  39. describe('#routeHome()', function () {
  40. it('transiotion to dashboard', function () {
  41. sinon.stub(App.router, 'transitionTo', Em.K);
  42. controller.routeHome();
  43. expect(App.router.transitionTo.calledWith('main.dashboard.index')).to.be.true;
  44. App.router.transitionTo.restore();
  45. });
  46. });
  47. describe('#startComponent()', function () {
  48. it('call sendComponentCommand', function () {
  49. var event = {
  50. context: Em.Object.create({
  51. displayName: 'comp'
  52. })
  53. };
  54. sinon.stub(App, 'showConfirmationPopup', function (callback) {
  55. callback();
  56. });
  57. sinon.stub(controller, 'sendComponentCommand');
  58. controller.startComponent(event);
  59. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  60. expect(controller.sendComponentCommand.calledWith(Em.Object.create({
  61. displayName: 'comp'
  62. })), Em.I18n.t('requestInfo.startHostComponent') + " comp", App.HostComponentStatus.started).to.be.true;
  63. App.showConfirmationPopup.restore();
  64. controller.sendComponentCommand.restore();
  65. });
  66. });
  67. describe('#stopComponent()', function () {
  68. it('call sendComponentCommand', function () {
  69. var event = {
  70. context: Em.Object.create({
  71. displayName: 'comp'
  72. })
  73. };
  74. sinon.stub(App, 'showConfirmationPopup', function (callback) {
  75. callback();
  76. });
  77. sinon.stub(controller, 'sendComponentCommand');
  78. controller.stopComponent(event);
  79. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  80. expect(controller.sendComponentCommand.calledWith(Em.Object.create({
  81. displayName: 'comp'
  82. })), Em.I18n.t('requestInfo.stopHostComponent') + " comp", App.HostComponentStatus.started).to.be.true;
  83. App.showConfirmationPopup.restore();
  84. controller.sendComponentCommand.restore();
  85. });
  86. });
  87. describe('#sendComponentCommand()', function () {
  88. it('single component', function () {
  89. controller.set('content.hostName', 'host1');
  90. var component = Em.Object.create({
  91. service: {serviceName: 'S1'},
  92. componentName: 'COMP1'
  93. });
  94. controller.sendComponentCommand(component, {}, 'state');
  95. expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.host.host_component.update');
  96. expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
  97. "hostName": "host1",
  98. "context": {},
  99. "component": Em.Object.create({
  100. service: {serviceName: 'S1'},
  101. componentName: 'COMP1'
  102. }),
  103. "HostRoles": {
  104. "state": "state"
  105. },
  106. "componentName": "COMP1",
  107. "serviceName": "S1"
  108. });
  109. });
  110. it('multiple component', function () {
  111. controller.set('content.hostName', 'host1');
  112. var component = [
  113. Em.Object.create({
  114. service: {serviceName: 'S1'},
  115. componentName: 'COMP1'
  116. }),
  117. Em.Object.create({
  118. service: {serviceName: 'S1'},
  119. componentName: 'COMP2'
  120. })
  121. ];
  122. controller.sendComponentCommand(component, {}, 'state');
  123. expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.host.host_components.update');
  124. expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
  125. "hostName": "host1",
  126. "context": {},
  127. "component": [
  128. Em.Object.create({
  129. service: {serviceName: 'S1'},
  130. componentName: 'COMP1'
  131. }),
  132. Em.Object.create({
  133. service: {serviceName: 'S1'},
  134. componentName: 'COMP2'
  135. })
  136. ],
  137. "HostRoles": {
  138. "state": "state"
  139. },
  140. "query": "HostRoles/component_name.in(COMP1,COMP2)"
  141. });
  142. });
  143. });
  144. describe('#sendComponentCommandSuccessCallback()', function () {
  145. beforeEach(function () {
  146. sinon.stub(controller, 'mimicWorkStatusChange', Em.K);
  147. sinon.stub(controller, 'showBackgroundOperationsPopup', Em.K);
  148. });
  149. afterEach(function () {
  150. controller.showBackgroundOperationsPopup.restore();
  151. controller.mimicWorkStatusChange.restore();
  152. });
  153. it('testMode, starting component', function () {
  154. var params = {
  155. component: Em.Object.create({}),
  156. HostRoles: {
  157. state: App.HostComponentStatus.started
  158. }
  159. };
  160. App.set('testMode', true);
  161. controller.sendComponentCommandSuccessCallback({}, {}, params);
  162. expect(controller.mimicWorkStatusChange.calledWith(Em.Object.create({
  163. workStatus: App.HostComponentStatus.starting
  164. }), App.HostComponentStatus.starting, App.HostComponentStatus.started)).to.be.true;
  165. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  166. });
  167. it('testMode, stopping component', function () {
  168. var params = {
  169. component: Em.Object.create({}),
  170. HostRoles: {
  171. state: App.HostComponentStatus.stopped
  172. }
  173. };
  174. App.set('testMode', true);
  175. controller.sendComponentCommandSuccessCallback({}, {}, params);
  176. expect(controller.mimicWorkStatusChange.calledWith(Em.Object.create({
  177. workStatus: App.HostComponentStatus.stopping
  178. }), App.HostComponentStatus.stopping, App.HostComponentStatus.stopped)).to.be.true;
  179. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  180. });
  181. it('testMode, stopping component', function () {
  182. var params = {
  183. component: Em.Object.create({}),
  184. HostRoles: {
  185. state: App.HostComponentStatus.stopped
  186. }
  187. };
  188. App.set('testMode', false);
  189. controller.sendComponentCommandSuccessCallback({}, {}, params);
  190. expect(controller.mimicWorkStatusChange.called).to.be.false;
  191. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  192. });
  193. });
  194. describe('#ajaxErrorCallback()', function () {
  195. it('call componentsUtils.ajaxErrorCallback', function () {
  196. sinon.stub(componentsUtils, 'ajaxErrorCallback', Em.K);
  197. controller.ajaxErrorCallback('request', 'ajaxOptions', 'error', 'opt', 'params');
  198. expect(componentsUtils.ajaxErrorCallback.calledWith('request', 'ajaxOptions', 'error', 'opt', 'params')).to.be.true;
  199. componentsUtils.ajaxErrorCallback.restore();
  200. });
  201. });
  202. describe('#showBackgroundOperationsPopup()', function () {
  203. var mock = {
  204. done: function (callback) {
  205. callback(this.initValue);
  206. }
  207. };
  208. var bgController = {
  209. showPopup: Em.K
  210. };
  211. beforeEach(function () {
  212. var stub = sinon.stub(App.router, 'get');
  213. stub.withArgs('applicationController').returns({
  214. dataLoading: function () {
  215. return mock;
  216. }
  217. });
  218. stub.withArgs('backgroundOperationsController').returns(bgController);
  219. sinon.spy(bgController, 'showPopup');
  220. sinon.spy(mock, 'done');
  221. });
  222. afterEach(function () {
  223. bgController.showPopup.restore();
  224. mock.done.restore();
  225. App.router.get.restore();
  226. });
  227. it('initValue is true, callback is undefined', function () {
  228. mock.initValue = true;
  229. controller.showBackgroundOperationsPopup();
  230. expect(mock.done.calledOnce).to.be.true;
  231. expect(bgController.showPopup.calledOnce).to.be.true;
  232. });
  233. it('initValue is false, callback is defined', function () {
  234. mock.initValue = false;
  235. var callback = sinon.stub();
  236. controller.showBackgroundOperationsPopup(callback);
  237. expect(mock.done.calledOnce).to.be.true;
  238. expect(bgController.showPopup.calledOnce).to.be.false;
  239. expect(callback.calledOnce).to.be.true;
  240. });
  241. });
  242. describe('#serviceActiveComponents', function () {
  243. it('No host-components', function () {
  244. controller.set('content', {hostComponents: []});
  245. expect(controller.get('serviceActiveComponents')).to.be.empty;
  246. });
  247. it('No host-components in active state', function () {
  248. controller.set('content', {hostComponents: [Em.Object.create({
  249. service: {
  250. isInPassive: true
  251. }
  252. })]});
  253. expect(controller.get('serviceActiveComponents')).to.be.empty;
  254. });
  255. it('Host-components in active state', function () {
  256. controller.set('content', {hostComponents: [Em.Object.create({
  257. service: {
  258. isInPassive: false
  259. }
  260. })]});
  261. expect(controller.get('serviceActiveComponents')).to.eql([Em.Object.create({
  262. service: {
  263. isInPassive: false
  264. }
  265. })]);
  266. });
  267. });
  268. describe('#serviceNonClientActiveComponents', function () {
  269. it('No active host-components', function () {
  270. controller.reopen({
  271. serviceActiveComponents: []
  272. });
  273. controller.set('serviceActiveComponents', []);
  274. expect(controller.get('serviceNonClientActiveComponents')).to.be.empty;
  275. });
  276. it('Active host-component is client', function () {
  277. controller.reopen({serviceActiveComponents: [Em.Object.create({
  278. isClient: true
  279. })]});
  280. expect(controller.get('serviceNonClientActiveComponents')).to.be.empty;
  281. });
  282. it('Active host-component is not client', function () {
  283. controller.reopen({serviceActiveComponents: [Em.Object.create({
  284. isClient: false
  285. })]});
  286. expect(controller.get('serviceNonClientActiveComponents')).to.eql([Em.Object.create({
  287. isClient: false
  288. })]);
  289. });
  290. });
  291. describe('#deleteComponent()', function () {
  292. it('confirm popup should be displayed', function () {
  293. var event = {
  294. context: Em.Object.create({})
  295. };
  296. sinon.spy(App.ModalPopup, "show");
  297. sinon.stub(controller, '_doDeleteHostComponent', Em.K);
  298. var popup = controller.deleteComponent(event);
  299. expect(App.ModalPopup.show.calledOnce).to.be.true;
  300. popup.onPrimary();
  301. expect(controller._doDeleteHostComponent.calledWith(Em.Object.create({}))).to.be.true;
  302. App.ModalPopup.show.restore();
  303. controller._doDeleteHostComponent.restore();
  304. });
  305. });
  306. describe('#mimicWorkStatusChange()', function () {
  307. var clock;
  308. beforeEach(function () {
  309. clock = sinon.useFakeTimers();
  310. });
  311. afterEach(function () {
  312. clock.restore();
  313. });
  314. it('change status of object', function () {
  315. var entity = Em.Object.create({
  316. workStatus: ''
  317. });
  318. controller.mimicWorkStatusChange(entity, 'STATE1', 'STATE2');
  319. expect(entity.get('workStatus')).to.equal('STATE1');
  320. clock.tick(App.testModeDelayForActions);
  321. expect(entity.get('workStatus')).to.equal('STATE2');
  322. });
  323. it('change status of objects in array', function () {
  324. var entity = [Em.Object.create({
  325. workStatus: ''
  326. })];
  327. controller.mimicWorkStatusChange(entity, 'STATE1', 'STATE2');
  328. expect(entity[0].get('workStatus')).to.equal('STATE1');
  329. clock.tick(App.testModeDelayForActions);
  330. expect(entity[0].get('workStatus')).to.equal('STATE2');
  331. });
  332. });
  333. describe('#upgradeComponent()', function () {
  334. beforeEach(function () {
  335. sinon.spy(App, "showConfirmationPopup");
  336. });
  337. afterEach(function () {
  338. App.showConfirmationPopup.restore();
  339. });
  340. it('confirm popup should be displayed', function () {
  341. var popup = controller.upgradeComponent({context: Em.Object.create()});
  342. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  343. popup.onPrimary();
  344. expect(App.ajax.send.calledOnce).to.be.true;
  345. });
  346. });
  347. describe('#restartComponent()', function () {
  348. beforeEach(function () {
  349. sinon.spy(App, "showConfirmationPopup");
  350. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  351. });
  352. afterEach(function () {
  353. App.showConfirmationPopup.restore();
  354. batchUtils.restartHostComponents.restore();
  355. });
  356. it('popup should be displayed', function () {
  357. var popup = controller.restartComponent({context: Em.Object.create({'displayName': 'Comp1'})});
  358. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  359. popup.onPrimary();
  360. expect(batchUtils.restartHostComponents.calledOnce).to.be.true;
  361. });
  362. });
  363. describe('#securityEnabled', function () {
  364. it('', function () {
  365. sinon.stub(App.router, 'get').withArgs('mainAdminSecurityController.securityEnabled').returns(true);
  366. controller.propertyDidChange('securityEnabled');
  367. expect(controller.get('securityEnabled')).to.be.true;
  368. App.router.get.restore();
  369. });
  370. });
  371. describe('#addComponent()', function () {
  372. beforeEach(function () {
  373. sinon.spy(App, "showConfirmationPopup");
  374. sinon.stub(controller, "addClientComponent", Em.K);
  375. sinon.stub(controller, "primary", Em.K);
  376. controller.set('content', {hostComponents: [Em.Object.create({
  377. componentName: "HDFS_CLIENT"
  378. })]});
  379. controller.reopen({
  380. securityEnabled: false
  381. });
  382. });
  383. afterEach(function () {
  384. App.showConfirmationPopup.restore();
  385. controller.addClientComponent.restore();
  386. controller.primary.restore();
  387. });
  388. it('add ZOOKEEPER_SERVER', function () {
  389. var event = {context: Em.Object.create({
  390. componentName: 'ZOOKEEPER_SERVER'
  391. })};
  392. var popup = controller.addComponent(event);
  393. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  394. popup.onPrimary();
  395. expect(controller.primary.calledWith(Em.Object.create({
  396. componentName: 'ZOOKEEPER_SERVER'
  397. }))).to.be.true;
  398. });
  399. it('add slave component', function () {
  400. var event = {context: Em.Object.create({
  401. componentName: 'HIVE_CLIENT'
  402. })};
  403. controller.set('securityEnabled', false);
  404. controller.addComponent(event);
  405. expect(controller.addClientComponent.calledWith(Em.Object.create({
  406. componentName: 'HIVE_CLIENT'
  407. }))).to.be.true;
  408. });
  409. });
  410. describe('#formatClientsMessage()', function () {
  411. var testCases = [
  412. {
  413. title: 'subComponentNames is null',
  414. client: Em.Object.create({
  415. subComponentNames: null,
  416. displayName: 'CLIENTS'
  417. }),
  418. result: 'CLIENTS'
  419. },
  420. {
  421. title: 'subComponentNames is empty',
  422. client: Em.Object.create({
  423. subComponentNames: [],
  424. displayName: 'CLIENTS'
  425. }),
  426. result: 'CLIENTS'
  427. },
  428. {
  429. title: 'displayName is null',
  430. client: Em.Object.create({
  431. subComponentNames: ['DATANODE'],
  432. displayName: null
  433. }),
  434. result: ' (DataNode)'
  435. },
  436. {
  437. title: 'displayName is CLIENTS',
  438. client: Em.Object.create({
  439. subComponentNames: ['DATANODE'],
  440. displayName: 'CLIENTS'
  441. }),
  442. result: 'CLIENTS (DataNode)'
  443. }
  444. ];
  445. testCases.forEach(function (test) {
  446. it(test.title, function () {
  447. expect(controller.formatClientsMessage(test.client)).to.equal(test.result);
  448. });
  449. });
  450. });
  451. describe('#addClientComponent()', function () {
  452. var component = Em.Object.create({
  453. componentName: ' Comp1'
  454. });
  455. beforeEach(function () {
  456. sinon.stub(controller, 'showAddComponentPopup', Em.K);
  457. });
  458. afterEach(function () {
  459. controller.showAddComponentPopup.restore();
  460. });
  461. it('any CLIENT component', function () {
  462. var popup = controller.addClientComponent(component);
  463. expect(controller.showAddComponentPopup.calledOnce).to.be.true;
  464. });
  465. });
  466. describe('#showAddComponentPopup()', function () {
  467. var message = 'Comp1',
  468. component = Em.Object.create({
  469. componentName: ' Comp1'
  470. });
  471. beforeEach(function () {
  472. sinon.spy(App.ModalPopup, 'show');
  473. sinon.stub(controller, 'primary', Em.K);
  474. });
  475. afterEach(function () {
  476. App.ModalPopup.show.restore();
  477. controller.primary.restore();
  478. });
  479. it('should display add component confirmation', function () {
  480. var popup = controller.showAddComponentPopup(message, false, function () {
  481. controller.primary(component);
  482. });
  483. expect(App.ModalPopup.show.calledOnce).to.be.true;
  484. expect(popup.get('addComponentMsg')).to.eql(Em.I18n.t('hosts.host.addComponent.msg').format(message));
  485. popup.onPrimary();
  486. expect(controller.primary.calledWith(component)).to.be.true;
  487. });
  488. });
  489. describe('#primary()', function () {
  490. it('Query should be sent', function () {
  491. var component = Em.Object.create({
  492. componentName: 'COMP1',
  493. displayName: 'comp1'
  494. });
  495. controller.primary(component);
  496. expect(App.ajax.send.calledOnce).to.be.true;
  497. });
  498. });
  499. describe('#installNewComponentSuccessCallback()', function () {
  500. beforeEach(function () {
  501. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  502. });
  503. afterEach(function () {
  504. controller.showBackgroundOperationsPopup.restore();
  505. });
  506. it('data is null', function () {
  507. var data = {Requests: null};
  508. expect(controller.installNewComponentSuccessCallback(null, {}, {})).to.be.false;
  509. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  510. });
  511. it('data.Requests is null', function () {
  512. var data = {Requests: null};
  513. expect(controller.installNewComponentSuccessCallback(data, {}, {})).to.be.false;
  514. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  515. });
  516. it('data.Requests.id is null', function () {
  517. var data = {Requests: {id: null}};
  518. expect(controller.installNewComponentSuccessCallback(data, {}, {})).to.be.false;
  519. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  520. });
  521. it('data.Requests.id is correct', function () {
  522. var data = {Requests: {id: 1}};
  523. expect(controller.installNewComponentSuccessCallback(data, {}, {component: []})).to.be.true;
  524. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  525. });
  526. });
  527. describe('#refreshComponentConfigs()', function () {
  528. beforeEach(function () {
  529. sinon.spy(App, "showConfirmationPopup");
  530. sinon.stub(controller, "sendRefreshComponentConfigsCommand", Em.K);
  531. });
  532. afterEach(function () {
  533. App.showConfirmationPopup.restore();
  534. controller.sendRefreshComponentConfigsCommand.restore();
  535. });
  536. it('popup should be displayed', function () {
  537. var popup = controller.refreshComponentConfigs({context: Em.Object.create({'displayName': 'Comp1'})});
  538. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  539. popup.onPrimary();
  540. expect(controller.sendRefreshComponentConfigsCommand.calledOnce).to.be.true;
  541. });
  542. });
  543. describe('#sendRefreshComponentConfigsCommand()', function () {
  544. it('Query should be sent', function () {
  545. var component = Em.Object.create({
  546. service: {},
  547. componentName: 'COMP1',
  548. host: {}
  549. });
  550. controller.sendRefreshComponentConfigsCommand(component, {});
  551. expect(App.ajax.send.calledOnce).to.be.true;
  552. });
  553. });
  554. describe('#loadConfigs()', function () {
  555. it('Query should be sent', function () {
  556. controller.loadConfigs();
  557. expect(App.ajax.send.calledOnce).to.be.true;
  558. });
  559. });
  560. describe('#constructConfigUrlParams()', function () {
  561. it('URL params should be empty', function () {
  562. var data = {};
  563. App.Service.find().clear();
  564. expect(controller.constructConfigUrlParams(data)).to.eql([]);
  565. });
  566. it('isHaEnabled = true', function () {
  567. App.store.load(App.Service, {
  568. id: 'HDFS',
  569. service_name: 'HDFS'
  570. });
  571. var data = {Clusters: {desired_configs: {'core-site': {tag: 1}}}};
  572. App.HostComponent.find().clear();
  573. App.propertyDidChange('isHaEnabled');
  574. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=core-site&tag=1)']);
  575. App.store.load(App.HostComponent, {
  576. id: 'SECONDARY_NAMENODE_host1',
  577. component_name: 'SECONDARY_NAMENODE'
  578. });
  579. App.set('currentStackVersion', 'HDP-2.0.1');
  580. });
  581. it('HBASE is installed', function () {
  582. App.store.load(App.Service, {
  583. id: 'HBASE',
  584. service_name: 'HBASE'
  585. });
  586. App.propertyDidChange('isHaEnabled');
  587. var data = {Clusters: {desired_configs: {'hbase-site': {tag: 1}}}};
  588. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=hbase-site&tag=1)']);
  589. App.Service.find().clear();
  590. });
  591. it('HIVE is installed', function () {
  592. App.store.load(App.Service, {
  593. id: 'HIVE',
  594. service_name: 'HIVE'
  595. });
  596. var data = {Clusters: {desired_configs: {'webhcat-site': {tag: 1}, 'hive-site': {tag: 1}}}};
  597. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=webhcat-site&tag=1)', '(type=hive-site&tag=1)']);
  598. App.Service.find().clear();
  599. });
  600. it('STORM is installed', function () {
  601. App.store.load(App.Service, {
  602. id: 'STORM',
  603. service_name: 'STORM'
  604. });
  605. var data = {Clusters: {desired_configs: {'storm-site': {tag: 1}}}};
  606. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=storm-site&tag=1)']);
  607. App.Service.find().clear();
  608. });
  609. it('YARN for 2.2 stack is installed', function () {
  610. App.set('currentStackVersion', 'HDP-2.2.0');
  611. App.store.load(App.Service, {
  612. id: 'YARN',
  613. service_name: 'YARN'
  614. });
  615. var data = {Clusters: {desired_configs: {'yarn-site': {tag: 1}, 'zoo.cfg': {tag: 1}}}};
  616. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=yarn-site&tag=1)', '(type=zoo.cfg&tag=1)']);
  617. App.set('currentStackVersion', 'HDP-2.0.1');
  618. App.Service.find().clear();
  619. });
  620. it('isRMHaEnabled true', function () {
  621. sinon.stub(App, 'get').withArgs('isRMHaEnabled').returns(true);
  622. var data = {Clusters: {desired_configs: {'yarn-site': {tag: 1}, 'zoo.cfg': {tag: 1}}}};
  623. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=yarn-site&tag=1)', '(type=zoo.cfg&tag=1)']);
  624. App.get.restore();
  625. });
  626. });
  627. describe('#loadConfigsSuccessCallback()', function () {
  628. beforeEach(function () {
  629. sinon.stub(controller, "constructConfigUrlParams", function () {
  630. return this.get('mockUrlParams');
  631. });
  632. });
  633. afterEach(function () {
  634. controller.constructConfigUrlParams.restore();
  635. });
  636. it('url params is empty', function () {
  637. controller.set('mockUrlParams', []);
  638. expect(controller.loadConfigsSuccessCallback()).to.be.false;
  639. expect(App.ajax.send.called).to.be.false;
  640. });
  641. it('url params are correct', function () {
  642. controller.set('mockUrlParams', ['param1']);
  643. expect(controller.loadConfigsSuccessCallback()).to.be.true;
  644. expect(App.ajax.send.calledOnce).to.be.true;
  645. });
  646. });
  647. describe('#saveZkConfigs()', function () {
  648. var yarnCases = [
  649. {
  650. isYARNInstalled: true,
  651. isHadoop22Stack: true,
  652. isRMHaEnabled: true,
  653. shouldYarnSiteBeModified: true,
  654. title: 'HDP 2.2, YARN installed, RM HA enabled'
  655. },
  656. {
  657. isYARNInstalled: true,
  658. isHadoop22Stack: false,
  659. isRMHaEnabled: true,
  660. shouldYarnSiteBeModified: true,
  661. title: 'HDP < 2.2, YARN installed, RM HA enabled'
  662. },
  663. {
  664. isYARNInstalled: true,
  665. isHadoop22Stack: true,
  666. isRMHaEnabled: false,
  667. shouldYarnSiteBeModified: true,
  668. title: 'HDP 2.2, YARN installed, RM HA disabled'
  669. },
  670. {
  671. isYARNInstalled: false,
  672. isHadoop22Stack: true,
  673. isRMHaEnabled: false,
  674. shouldYarnSiteBeModified: false,
  675. title: 'HDP 2.2, YARN not installed'
  676. },
  677. {
  678. isYARNInstalled: true,
  679. isHadoop22Stack: false,
  680. isRMHaEnabled: false,
  681. shouldYarnSiteBeModified: false,
  682. title: 'HDP < 2.2, YARN installed, RM HA disabled'
  683. },
  684. {
  685. isYARNInstalled: false,
  686. isHadoop22Stack: false,
  687. isRMHaEnabled: false,
  688. shouldYarnSiteBeModified: false,
  689. title: 'HDP < 2.2, YARN not installed'
  690. }
  691. ],
  692. yarnData = {
  693. items: [
  694. {
  695. type: 'yarn-site',
  696. properties: {
  697. p: 'v'
  698. }
  699. }
  700. ]
  701. };
  702. beforeEach(function () {
  703. sinon.stub(controller, "getZkServerHosts", Em.K);
  704. sinon.stub(controller, "concatZkNames", Em.K);
  705. sinon.stub(controller, "setZKConfigs", Em.K);
  706. sinon.stub(controller, 'saveConfigsBatch', Em.K);
  707. });
  708. afterEach(function () {
  709. controller.getZkServerHosts.restore();
  710. controller.concatZkNames.restore();
  711. controller.setZKConfigs.restore();
  712. controller.saveConfigsBatch.restore();
  713. });
  714. it('call saveConfigsBatch()', function () {
  715. var data = {items: []};
  716. controller.saveZkConfigs(data);
  717. expect(controller.saveConfigsBatch.calledOnce).to.be.true;
  718. });
  719. yarnCases.forEach(function (item) {
  720. it(item.title, function () {
  721. var servicesMock = item.isYARNInstalled ? [
  722. {
  723. serviceName: 'YARN'
  724. }
  725. ] : [];
  726. sinon.stub(App, 'get').withArgs('isHadoop22Stack').returns(item.isHadoop22Stack).
  727. withArgs('isRMHaEnabled').returns(item.isRMHaEnabled);
  728. sinon.stub(App.Service, 'find').returns(servicesMock);
  729. controller.saveZkConfigs(yarnData);
  730. expect(controller.saveConfigsBatch.firstCall.args[0].someProperty('properties.yarn-site')).to.equal(item.shouldYarnSiteBeModified);
  731. expect(controller.saveConfigsBatch.firstCall.args[0].someProperty('properties_attributes.yarn-site')).to.equal(item.shouldYarnSiteBeModified);
  732. App.get.restore();
  733. App.Service.find.restore();
  734. });
  735. });
  736. });
  737. describe("#saveConfigsBatch()", function() {
  738. it("no groups", function() {
  739. controller.saveConfigsBatch([]);
  740. expect(App.ajax.send.called).to.be.false;
  741. });
  742. it("configs is empty", function() {
  743. controller.saveConfigsBatch([{}]);
  744. expect(App.ajax.send.called).to.be.false;
  745. });
  746. it("configs is correct", function() {
  747. controller.saveConfigsBatch([{'properties' : {'site': {}}, 'properties_attributes': {'site': {}}}]);
  748. expect(App.ajax.send.calledOnce).to.be.true;
  749. });
  750. });
  751. describe('#setZKConfigs()', function () {
  752. it('configs is null', function () {
  753. expect(controller.setZKConfigs(null)).to.be.false;
  754. });
  755. it('zks is null', function () {
  756. expect(controller.setZKConfigs({}, '', null)).to.be.false;
  757. });
  758. it('isHaEnabled = true', function () {
  759. var configs = {'core-site': {}};
  760. App.HostComponent.find().clear();
  761. App.store.load(App.Service, {
  762. id: 'HDFS',
  763. service_name: 'HDFS'
  764. });
  765. App.propertyDidChange('isHaEnabled');
  766. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  767. expect(configs).to.eql({"core-site": {
  768. "ha.zookeeper.quorum": "host1:2181"
  769. }});
  770. App.store.load(App.HostComponent, {
  771. id: 'SECONDARY_NAMENODE_host1',
  772. component_name: 'SECONDARY_NAMENODE'
  773. });
  774. App.propertyDidChange('isHaEnabled');
  775. });
  776. it('hbase-site is present', function () {
  777. var configs = {'hbase-site': {}};
  778. expect(controller.setZKConfigs(configs, '', ['host1', 'host2'])).to.be.true;
  779. expect(configs).to.eql({"hbase-site": {
  780. "hbase.zookeeper.quorum": "host1,host2"
  781. }});
  782. });
  783. it('webhcat-site is present', function () {
  784. var configs = {'webhcat-site': {}};
  785. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  786. expect(configs).to.eql({"webhcat-site": {
  787. "templeton.zookeeper.hosts": "host1:2181"
  788. }});
  789. });
  790. it('hive-site is present and stack < 2.2', function () {
  791. var version = App.get('currentStackVersion');
  792. var configs = {'hive-site': {}};
  793. App.set('currentStackVersion', 'HDP-2.1.0');
  794. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  795. expect(configs).to.eql({"hive-site": {
  796. 'hive.cluster.delegation.token.store.zookeeper.connectString': "host1:2181"
  797. }});
  798. App.set('currentStackVersion', version);
  799. });
  800. it('hive-site is present and stack > 2.2', function () {
  801. var version = App.get('currentStackVersion');
  802. var configs = {'hive-site': {}};
  803. App.set('currentStackVersion', 'HDP-2.2.0');
  804. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  805. expect(configs).to.eql({"hive-site": {
  806. 'hive.cluster.delegation.token.store.zookeeper.connectString': "host1:2181",
  807. 'hive.zookeeper.quorum': "host1:2181"
  808. }});
  809. App.set('currentStackVersion', version);
  810. });
  811. it('yarn-site is present and stack > 2.2', function () {
  812. var version = App.get('currentStackVersion');
  813. var configs = {'yarn-site': {}};
  814. App.set('currentStackVersion', 'HDP-2.2.0');
  815. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  816. expect(configs).to.eql({"yarn-site": {
  817. 'hadoop.registry.zk.quorum': "host1:2181",
  818. 'yarn.resourcemanager.zk-address': "host1:2181"
  819. }});
  820. App.set('currentStackVersion', version);
  821. });
  822. it('storm-site is present', function () {
  823. var configs = {'storm-site': {}};
  824. expect(controller.setZKConfigs(configs, '', ["host1", 'host2'])).to.be.true;
  825. expect(configs).to.eql({"storm-site": {
  826. "storm.zookeeper.servers": "['host1','host2']"
  827. }});
  828. });
  829. it('isRMHaEnabled true', function () {
  830. var configs = {'yarn-site': {}};
  831. sinon.stub(App, 'get').withArgs('isRMHaEnabled').returns(true);
  832. expect(controller.setZKConfigs(configs, 'host1:2181', ['host1', 'host2'])).to.be.true;
  833. expect(configs).to.eql({"yarn-site": {
  834. "yarn.resourcemanager.zk-address": "host1:2181"
  835. }});
  836. App.get.restore();
  837. });
  838. });
  839. describe('#concatZkNames()', function () {
  840. it('No ZooKeeper hosts', function () {
  841. expect(controller.concatZkNames([])).to.equal('');
  842. });
  843. it('One ZooKeeper host', function () {
  844. expect(controller.concatZkNames(['host1'], '2181')).to.equal('host1:2181');
  845. });
  846. it('Two ZooKeeper hosts', function () {
  847. expect(controller.concatZkNames(['host1', 'host2'], '2181')).to.equal('host1:2181,host2:2181');
  848. });
  849. });
  850. describe('#getZkServerHosts()', function () {
  851. beforeEach(function () {
  852. controller.set('content', {});
  853. });
  854. afterEach(function () {
  855. App.HostComponent.find.restore();
  856. });
  857. it('No ZooKeeper hosts, fromDeleteHost = false', function () {
  858. sinon.stub(App.HostComponent, 'find', function () {
  859. return []
  860. });
  861. controller.set('fromDeleteHost', false);
  862. expect(controller.getZkServerHosts()).to.be.empty;
  863. });
  864. it('No ZooKeeper hosts, fromDeleteHost = true', function () {
  865. sinon.stub(App.HostComponent, 'find', function () {
  866. return []
  867. });
  868. controller.set('fromDeleteHost', true);
  869. expect(controller.getZkServerHosts()).to.be.empty;
  870. expect(controller.get('fromDeleteHost')).to.be.false;
  871. });
  872. it('One ZooKeeper host, fromDeleteHost = false', function () {
  873. controller.set('fromDeleteHost', false);
  874. sinon.stub(App.HostComponent, 'find', function () {
  875. return [
  876. {id: 'ZOOKEEPER_SERVER_host1',
  877. componentName: 'ZOOKEEPER_SERVER',
  878. hostName: 'host1'
  879. }
  880. ]
  881. });
  882. expect(controller.getZkServerHosts()).to.eql(['host1']);
  883. });
  884. it('One ZooKeeper host match current host name, fromDeleteHost = true', function () {
  885. sinon.stub(App.HostComponent, 'find', function () {
  886. return [
  887. {id: 'ZOOKEEPER_SERVER_host1',
  888. componentName: 'ZOOKEEPER_SERVER',
  889. hostName: 'host1'
  890. }
  891. ]
  892. });
  893. controller.set('fromDeleteHost', true);
  894. controller.set('content.hostName', 'host1');
  895. expect(controller.getZkServerHosts()).to.be.empty;
  896. expect(controller.get('fromDeleteHost')).to.be.false;
  897. });
  898. it('One ZooKeeper host does not match current host name, fromDeleteHost = true', function () {
  899. sinon.stub(App.HostComponent, 'find', function () {
  900. return [
  901. {id: 'ZOOKEEPER_SERVER_host1',
  902. componentName: 'ZOOKEEPER_SERVER',
  903. hostName: 'host1'
  904. }
  905. ]
  906. });
  907. controller.set('fromDeleteHost', true);
  908. controller.set('content.hostName', 'host2');
  909. expect(controller.getZkServerHosts()[0]).to.equal("host1");
  910. expect(controller.get('fromDeleteHost')).to.be.false;
  911. });
  912. });
  913. describe('#installComponent()', function () {
  914. beforeEach(function () {
  915. sinon.spy(App.ModalPopup, "show");
  916. });
  917. afterEach(function () {
  918. App.ModalPopup.show.restore();
  919. });
  920. it('popup should be displayed', function () {
  921. var event = {context: Em.Object.create()};
  922. var popup = controller.installComponent(event);
  923. expect(App.ModalPopup.show.calledOnce).to.be.true;
  924. popup.onPrimary();
  925. expect(App.ajax.send.calledOnce).to.be.true;
  926. });
  927. });
  928. describe('#decommission()', function () {
  929. beforeEach(function () {
  930. sinon.spy(App, "showConfirmationPopup");
  931. sinon.stub(controller, "runDecommission", Em.K);
  932. });
  933. afterEach(function () {
  934. App.showConfirmationPopup.restore();
  935. controller.runDecommission.restore();
  936. });
  937. it('popup should be displayed', function () {
  938. var popup = controller.decommission(Em.Object.create({service: {}}));
  939. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  940. popup.onPrimary();
  941. expect(controller.runDecommission.calledOnce).to.be.true;
  942. });
  943. });
  944. describe('#recommission()', function () {
  945. beforeEach(function () {
  946. sinon.spy(App, "showConfirmationPopup");
  947. sinon.stub(controller, "runRecommission", Em.K);
  948. });
  949. afterEach(function () {
  950. App.showConfirmationPopup.restore();
  951. controller.runRecommission.restore();
  952. });
  953. it('popup should be displayed', function () {
  954. var popup = controller.recommission(Em.Object.create({service: {}}));
  955. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  956. popup.onPrimary();
  957. expect(controller.runRecommission.calledOnce).to.be.true;
  958. });
  959. });
  960. describe('#runDecommission()', function () {
  961. beforeEach(function () {
  962. sinon.stub(controller, "doDecommission", Em.K);
  963. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  964. });
  965. afterEach(function () {
  966. controller.doDecommission.restore();
  967. controller.showBackgroundOperationsPopup.restore();
  968. });
  969. it('HDFS service', function () {
  970. controller.runDecommission('host1', 'HDFS');
  971. expect(controller.doDecommission.calledWith('host1', 'HDFS', "NAMENODE", "DATANODE")).to.be.true;
  972. });
  973. it('YARN service', function () {
  974. controller.runDecommission('host1', 'YARN');
  975. expect(controller.doDecommission.calledWith('host1', 'YARN', "RESOURCEMANAGER", "NODEMANAGER")).to.be.true;
  976. });
  977. it('HBASE service', function () {
  978. sinon.stub(controller, 'warnBeforeDecommission', Em.K);
  979. controller.runDecommission('host1', 'HBASE');
  980. expect(controller.warnBeforeDecommission.calledWith('host1')).to.be.true;
  981. controller.warnBeforeDecommission.restore();
  982. });
  983. });
  984. describe('#runRecommission()', function () {
  985. beforeEach(function () {
  986. sinon.stub(controller, "doRecommissionAndStart", Em.K);
  987. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  988. });
  989. afterEach(function () {
  990. controller.doRecommissionAndStart.restore();
  991. controller.showBackgroundOperationsPopup.restore();
  992. });
  993. it('HDFS service', function () {
  994. controller.runRecommission('host1', 'HDFS');
  995. expect(controller.doRecommissionAndStart.calledWith('host1', 'HDFS', "NAMENODE", "DATANODE")).to.be.true;
  996. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  997. });
  998. it('YARN service', function () {
  999. controller.runRecommission('host1', 'YARN');
  1000. expect(controller.doRecommissionAndStart.calledWith('host1', 'YARN', "RESOURCEMANAGER", "NODEMANAGER")).to.be.true;
  1001. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  1002. });
  1003. it('HBASE service', function () {
  1004. controller.runRecommission('host1', 'HBASE');
  1005. expect(controller.doRecommissionAndStart.calledWith('host1', 'HBASE', "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
  1006. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  1007. });
  1008. });
  1009. describe('#doDecommission()', function () {
  1010. it('Query should be sent', function () {
  1011. controller.doDecommission('', '', '', '');
  1012. expect(App.ajax.send.calledOnce).to.be.true;
  1013. });
  1014. });
  1015. describe('#doDecommissionRegionServer()', function () {
  1016. it('Query should be sent', function () {
  1017. controller.doDecommissionRegionServer('', '', '', '');
  1018. expect(App.ajax.send.calledOnce).to.be.true;
  1019. });
  1020. });
  1021. describe('#warnBeforeDecommission()', function () {
  1022. beforeEach(function () {
  1023. sinon.stub(controller, "showHbaseActiveWarning", Em.K);
  1024. sinon.stub(controller, "checkRegionServerState", Em.K);
  1025. });
  1026. afterEach(function () {
  1027. controller.checkRegionServerState.restore();
  1028. controller.showHbaseActiveWarning.restore();
  1029. });
  1030. it('Component in passive state', function () {
  1031. controller.set('content.hostComponents', [Em.Object.create({
  1032. componentName: 'HBASE_REGIONSERVER',
  1033. passiveState: 'ON'
  1034. })]);
  1035. controller.warnBeforeDecommission('host1');
  1036. expect(controller.checkRegionServerState.calledOnce).to.be.true;
  1037. });
  1038. it('Component is not in passive state', function () {
  1039. controller.set('content.hostComponents', [Em.Object.create({
  1040. componentName: 'HBASE_REGIONSERVER',
  1041. passiveState: 'OFF'
  1042. })]);
  1043. controller.warnBeforeDecommission('host1');
  1044. expect(controller.showHbaseActiveWarning.calledOnce).to.be.true;
  1045. });
  1046. });
  1047. describe('#checkRegionServerState()', function () {
  1048. it('', function () {
  1049. expect(controller.checkRegionServerState('host1')).to.be.an('object');
  1050. expect(App.ajax.send.getCall(0).args[0].data.hostNames).to.equal('host1');
  1051. });
  1052. });
  1053. describe('#checkRegionServerStateSuccessCallback()', function () {
  1054. beforeEach(function () {
  1055. sinon.stub(controller, "doDecommissionRegionServer", Em.K);
  1056. sinon.stub(controller, "showRegionServerWarning", Em.K);
  1057. });
  1058. afterEach(function () {
  1059. controller.doDecommissionRegionServer.restore();
  1060. controller.showRegionServerWarning.restore();
  1061. });
  1062. it('Decommission all regionservers', function () {
  1063. var data = {
  1064. items: [
  1065. {
  1066. HostRoles: {
  1067. host_name: 'host1'
  1068. }
  1069. },
  1070. {
  1071. HostRoles: {
  1072. host_name: 'host2'
  1073. }
  1074. }
  1075. ]
  1076. };
  1077. controller.checkRegionServerStateSuccessCallback(data, {}, {hostNames: 'host1,host2'});
  1078. expect(controller.showRegionServerWarning.calledOnce).to.be.true;
  1079. });
  1080. it('Decommission one of two regionservers', function () {
  1081. var data = {
  1082. items: [
  1083. {
  1084. HostRoles: {
  1085. host_name: 'host1'
  1086. }
  1087. },
  1088. {
  1089. HostRoles: {
  1090. host_name: 'host2'
  1091. }
  1092. }
  1093. ]
  1094. };
  1095. controller.checkRegionServerStateSuccessCallback(data, {}, {hostNames: 'host1'});
  1096. expect(controller.doDecommissionRegionServer.calledWith('host1', "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
  1097. });
  1098. it('Decommission one of three regionservers', function () {
  1099. var data = {
  1100. items: [
  1101. {
  1102. HostRoles: {
  1103. host_name: 'host1'
  1104. }
  1105. },
  1106. {
  1107. HostRoles: {
  1108. host_name: 'host2'
  1109. }
  1110. },
  1111. {
  1112. HostRoles: {
  1113. host_name: 'host3'
  1114. }
  1115. }
  1116. ]
  1117. };
  1118. controller.checkRegionServerStateSuccessCallback(data, {}, {hostNames: 'host1'});
  1119. expect(controller.doDecommissionRegionServer.calledWith('host1', "HBASE", "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
  1120. });
  1121. });
  1122. describe('#showRegionServerWarning()', function () {
  1123. beforeEach(function () {
  1124. sinon.stub(App.ModalPopup, 'show', Em.K);
  1125. });
  1126. afterEach(function () {
  1127. App.ModalPopup.show.restore();
  1128. });
  1129. it('', function () {
  1130. controller.showRegionServerWarning();
  1131. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1132. });
  1133. });
  1134. describe('#doRecommissionAndStart()', function () {
  1135. it('Query should be sent', function () {
  1136. controller.doRecommissionAndStart('', '', '', '');
  1137. expect(App.ajax.send.calledOnce).to.be.true;
  1138. });
  1139. });
  1140. describe('#decommissionSuccessCallback()', function () {
  1141. beforeEach(function () {
  1142. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  1143. });
  1144. afterEach(function () {
  1145. controller.showBackgroundOperationsPopup.restore();
  1146. });
  1147. it('data is null', function () {
  1148. expect(controller.decommissionSuccessCallback(null)).to.be.false;
  1149. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  1150. });
  1151. it('data has Requests', function () {
  1152. var data = {Requests: []};
  1153. expect(controller.decommissionSuccessCallback(data)).to.be.true;
  1154. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  1155. });
  1156. it('data has resources', function () {
  1157. var data = {resources: [
  1158. {RequestSchedule: {}}
  1159. ]};
  1160. expect(controller.decommissionSuccessCallback(data)).to.be.true;
  1161. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  1162. });
  1163. });
  1164. describe('#doAction()', function () {
  1165. beforeEach(function () {
  1166. sinon.stub(controller, "validateAndDeleteHost", Em.K);
  1167. sinon.stub(controller, "doStartAllComponents", Em.K);
  1168. sinon.stub(controller, "doStopAllComponents", Em.K);
  1169. sinon.stub(controller, "doRestartAllComponents", Em.K);
  1170. sinon.stub(controller, "onOffPassiveModeForHost", Em.K);
  1171. });
  1172. afterEach(function () {
  1173. controller.validateAndDeleteHost.restore();
  1174. controller.doStartAllComponents.restore();
  1175. controller.doStopAllComponents.restore();
  1176. controller.doRestartAllComponents.restore();
  1177. controller.onOffPassiveModeForHost.restore();
  1178. });
  1179. it('"deleteHost" action', function () {
  1180. var option = {context: {action: "deleteHost"}};
  1181. controller.doAction(option);
  1182. expect(controller.validateAndDeleteHost.calledOnce).to.be.true;
  1183. });
  1184. it('"startAllComponents" action, isNotHeartBeating = false', function () {
  1185. var option = {context: {action: "startAllComponents"}};
  1186. controller.set('content', {isNotHeartBeating: false});
  1187. controller.doAction(option);
  1188. expect(controller.doStartAllComponents.calledOnce).to.be.true;
  1189. });
  1190. it('"startAllComponents" action, isNotHeartBeating = true', function () {
  1191. var option = {context: {action: "startAllComponents"}};
  1192. controller.set('content', {isNotHeartBeating: true});
  1193. controller.doAction(option);
  1194. expect(controller.doStartAllComponents.called).to.be.false;
  1195. });
  1196. it('"stopAllComponents" action, isNotHeartBeating = false', function () {
  1197. var option = {context: {action: "stopAllComponents"}};
  1198. controller.set('content', {isNotHeartBeating: false});
  1199. controller.doAction(option);
  1200. expect(controller.doStopAllComponents.calledOnce).to.be.true;
  1201. });
  1202. it('"stopAllComponents" action, isNotHeartBeating = true', function () {
  1203. var option = {context: {action: "stopAllComponents"}};
  1204. controller.set('content', {isNotHeartBeating: true});
  1205. controller.doAction(option);
  1206. expect(controller.doStopAllComponents.called).to.be.false;
  1207. });
  1208. it('"restartAllComponents" action, isNotHeartBeating = false', function () {
  1209. var option = {context: {action: "restartAllComponents"}};
  1210. controller.set('content', {isNotHeartBeating: false});
  1211. controller.doAction(option);
  1212. expect(controller.doRestartAllComponents.calledOnce).to.be.true;
  1213. });
  1214. it('"restartAllComponents" action, isNotHeartBeating = true', function () {
  1215. var option = {context: {action: "restartAllComponents"}};
  1216. controller.set('content', {isNotHeartBeating: true});
  1217. controller.doAction(option);
  1218. expect(controller.doRestartAllComponents.called).to.be.false;
  1219. });
  1220. it('"onOffPassiveModeForHost" action', function () {
  1221. var option = {context: {action: "onOffPassiveModeForHost"}};
  1222. controller.doAction(option);
  1223. expect(controller.onOffPassiveModeForHost.calledWith({action: "onOffPassiveModeForHost"})).to.be.true;
  1224. });
  1225. });
  1226. describe('#onOffPassiveModeForHost()', function () {
  1227. beforeEach(function () {
  1228. sinon.spy(App, "showConfirmationPopup");
  1229. sinon.stub(controller, "hostPassiveModeRequest", Em.K);
  1230. });
  1231. afterEach(function () {
  1232. App.showConfirmationPopup.restore();
  1233. controller.hostPassiveModeRequest.restore();
  1234. });
  1235. it('popup should be displayed, active = true', function () {
  1236. var popup = controller.onOffPassiveModeForHost({active: true});
  1237. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1238. popup.onPrimary();
  1239. expect(controller.hostPassiveModeRequest.calledWith('ON')).to.be.true;
  1240. });
  1241. it('popup should be displayed, active = false', function () {
  1242. var popup = controller.onOffPassiveModeForHost({active: false});
  1243. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1244. popup.onPrimary();
  1245. expect(controller.hostPassiveModeRequest.calledWith('OFF')).to.be.true;
  1246. });
  1247. });
  1248. describe('#hostPassiveModeRequest()', function () {
  1249. it('Query should be sent', function () {
  1250. controller.hostPassiveModeRequest('', '');
  1251. expect(App.ajax.send.calledOnce).to.be.true;
  1252. });
  1253. });
  1254. describe('#doStartAllComponents()', function () {
  1255. beforeEach(function () {
  1256. sinon.spy(App, "showConfirmationPopup");
  1257. controller.reopen({serviceActiveComponents: []});
  1258. });
  1259. afterEach(function () {
  1260. App.showConfirmationPopup.restore();
  1261. });
  1262. it('serviceNonClientActiveComponents is empty', function () {
  1263. controller.reopen({
  1264. serviceNonClientActiveComponents: []
  1265. });
  1266. controller.doStartAllComponents();
  1267. expect(App.showConfirmationPopup.called).to.be.false;
  1268. });
  1269. it('serviceNonClientActiveComponents is correct', function () {
  1270. controller.reopen({
  1271. serviceNonClientActiveComponents: [
  1272. {}
  1273. ]
  1274. });
  1275. sinon.stub(controller, 'sendComponentCommand', Em.K);
  1276. var popup = controller.doStartAllComponents();
  1277. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1278. popup.onPrimary();
  1279. expect(controller.sendComponentCommand.calledWith(
  1280. [
  1281. {}
  1282. ],
  1283. Em.I18n.t('hosts.host.maintainance.startAllComponents.context'),
  1284. App.HostComponentStatus.started)
  1285. ).to.be.true;
  1286. controller.sendComponentCommand.restore();
  1287. });
  1288. });
  1289. describe('#doStopAllComponents()', function () {
  1290. beforeEach(function () {
  1291. sinon.spy(App, "showConfirmationPopup");
  1292. controller.reopen({serviceActiveComponents: []});
  1293. });
  1294. afterEach(function () {
  1295. App.showConfirmationPopup.restore();
  1296. });
  1297. it('serviceNonClientActiveComponents is empty', function () {
  1298. controller.reopen({
  1299. serviceNonClientActiveComponents: []
  1300. });
  1301. controller.doStopAllComponents();
  1302. expect(App.showConfirmationPopup.called).to.be.false;
  1303. });
  1304. it('serviceNonClientActiveComponents is correct', function () {
  1305. controller.reopen({
  1306. serviceNonClientActiveComponents: [
  1307. {}
  1308. ]
  1309. });
  1310. sinon.stub(controller, 'sendComponentCommand', Em.K);
  1311. var popup = controller.doStopAllComponents();
  1312. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1313. popup.onPrimary();
  1314. expect(controller.sendComponentCommand.calledWith(
  1315. [
  1316. {}
  1317. ],
  1318. Em.I18n.t('hosts.host.maintainance.stopAllComponents.context'),
  1319. App.HostComponentStatus.stopped)
  1320. ).to.be.true;
  1321. controller.sendComponentCommand.restore();
  1322. });
  1323. });
  1324. describe('#doRestartAllComponents()', function () {
  1325. beforeEach(function () {
  1326. sinon.spy(App, "showConfirmationPopup");
  1327. });
  1328. afterEach(function () {
  1329. App.showConfirmationPopup.restore();
  1330. });
  1331. it('serviceActiveComponents is empty', function () {
  1332. controller.reopen({
  1333. serviceActiveComponents: []
  1334. });
  1335. controller.doRestartAllComponents();
  1336. expect(App.showConfirmationPopup.called).to.be.false;
  1337. });
  1338. it('serviceActiveComponents is correct', function () {
  1339. controller.reopen({
  1340. serviceActiveComponents: [
  1341. {}
  1342. ]
  1343. });
  1344. sinon.stub(batchUtils, 'restartHostComponents', Em.K);
  1345. var popup = controller.doRestartAllComponents();
  1346. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1347. popup.onPrimary();
  1348. expect(batchUtils.restartHostComponents.calledWith(
  1349. [
  1350. {}
  1351. ])
  1352. ).to.be.true;
  1353. batchUtils.restartHostComponents.restore();
  1354. });
  1355. });
  1356. describe('#getHostComponentsInfo()', function () {
  1357. var result = {
  1358. zkServerInstalled: false,
  1359. lastComponents: [],
  1360. masterComponents: [],
  1361. runningComponents: [],
  1362. nonDeletableComponents: [],
  1363. unknownComponents: []
  1364. };
  1365. it('content.hostComponents is null', function () {
  1366. controller.set('content', {hostComponents: null});
  1367. expect(controller.getHostComponentsInfo()).to.eql(result);
  1368. });
  1369. it('content.hostComponents is empty', function () {
  1370. controller.set('content', {hostComponents: []});
  1371. expect(controller.getHostComponentsInfo()).to.eql(result);
  1372. });
  1373. it('content.hostComponents has ZOOKEEPER_SERVER', function () {
  1374. App.HostComponent.find().clear();
  1375. controller.set('content', {hostComponents: [Em.Object.create({
  1376. componentName: 'ZOOKEEPER_SERVER',
  1377. workStatus: 'INIT',
  1378. isDeletable: true
  1379. })]});
  1380. expect(controller.getHostComponentsInfo().zkServerInstalled).to.be.true;
  1381. });
  1382. it('content.hostComponents has last component', function () {
  1383. sinon.stub(App.HostComponent, 'find', function () {
  1384. return [
  1385. {
  1386. id: 'TASKTRACKER_host1',
  1387. componentName: 'TASKTRACKER'
  1388. }
  1389. ];
  1390. });
  1391. controller.set('content', {hostComponents: [Em.Object.create({
  1392. componentName: 'TASKTRACKER',
  1393. displayName: 'TaskTracker',
  1394. workStatus: 'INIT',
  1395. isDeletable: true
  1396. })]});
  1397. expect(controller.getHostComponentsInfo().lastComponents).to.eql(['TaskTracker']);
  1398. App.HostComponent.find.restore();
  1399. });
  1400. it('content.hostComponents has master non-deletable component', function () {
  1401. sinon.stub(App.HostComponent, 'find', function () {
  1402. return [
  1403. {
  1404. id: 'TASKTRACKER_host1',
  1405. componentName: 'TASKTRACKER'
  1406. }
  1407. ];
  1408. });
  1409. controller.set('content', {hostComponents: [Em.Object.create({
  1410. componentName: 'TASKTRACKER',
  1411. workStatus: 'INIT',
  1412. isDeletable: false,
  1413. isMaster: true,
  1414. displayName: 'ZK1'
  1415. })]});
  1416. expect(controller.getHostComponentsInfo().masterComponents).to.eql(['ZK1']);
  1417. expect(controller.getHostComponentsInfo().nonDeletableComponents).to.eql(['ZK1']);
  1418. App.HostComponent.find.restore();
  1419. });
  1420. it('content.hostComponents has running component', function () {
  1421. sinon.stub(App.HostComponent, 'find', function () {
  1422. return [
  1423. {
  1424. id: 'TASKTRACKER_host1',
  1425. componentName: 'TASKTRACKER'
  1426. }
  1427. ];
  1428. });
  1429. controller.set('content', {hostComponents: [Em.Object.create({
  1430. componentName: 'TASKTRACKER',
  1431. workStatus: 'STARTED',
  1432. isDeletable: true,
  1433. displayName: 'ZK1'
  1434. })]});
  1435. expect(controller.getHostComponentsInfo().runningComponents).to.eql(['ZK1']);
  1436. App.HostComponent.find.restore();
  1437. });
  1438. it('content.hostComponents has non-deletable component', function () {
  1439. sinon.stub(App.HostComponent, 'find', function () {
  1440. return [
  1441. {
  1442. id: 'TASKTRACKER_host1',
  1443. componentName: 'TASKTRACKER'
  1444. }
  1445. ];
  1446. });
  1447. controller.set('content', {hostComponents: [Em.Object.create({
  1448. componentName: 'TASKTRACKER',
  1449. workStatus: 'INIT',
  1450. isDeletable: false,
  1451. displayName: 'ZK1'
  1452. })]});
  1453. expect(controller.getHostComponentsInfo().nonDeletableComponents).to.eql(['ZK1']);
  1454. App.HostComponent.find.restore();
  1455. });
  1456. it('content.hostComponents has component with UNKNOWN state', function () {
  1457. sinon.stub(App.HostComponent, 'find', function () {
  1458. return [
  1459. {
  1460. id: 'TASKTRACKER_host1',
  1461. componentName: 'TASKTRACKER'
  1462. }
  1463. ];
  1464. });
  1465. controller.set('content', {hostComponents: [Em.Object.create({
  1466. componentName: 'TASKTRACKER',
  1467. workStatus: 'UNKNOWN',
  1468. isDeletable: false,
  1469. displayName: 'ZK1'
  1470. })]});
  1471. expect(controller.getHostComponentsInfo().unknownComponents).to.eql(['ZK1']);
  1472. App.HostComponent.find.restore();
  1473. });
  1474. });
  1475. describe('#validateAndDeleteHost()', function () {
  1476. beforeEach(function () {
  1477. sinon.spy(App, "showConfirmationPopup");
  1478. sinon.stub(controller, "getHostComponentsInfo", function () {
  1479. return this.get('mockHostComponentsInfo');
  1480. });
  1481. sinon.stub(controller, "raiseDeleteComponentsError", Em.K);
  1482. sinon.stub(controller, "confirmDeleteHost", Em.K);
  1483. });
  1484. afterEach(function () {
  1485. App.showConfirmationPopup.restore();
  1486. controller.getHostComponentsInfo.restore();
  1487. controller.raiseDeleteComponentsError.restore();
  1488. controller.confirmDeleteHost.restore();
  1489. });
  1490. it('masterComponents exist', function () {
  1491. controller.set('mockHostComponentsInfo', {masterComponents: [
  1492. {}
  1493. ]});
  1494. controller.validateAndDeleteHost();
  1495. expect(controller.raiseDeleteComponentsError.calledWith([
  1496. {}
  1497. ], 'masterList')).to.be.true;
  1498. });
  1499. it('nonDeletableComponents exist', function () {
  1500. controller.set('mockHostComponentsInfo', {
  1501. masterComponents: [],
  1502. nonDeletableComponents: [
  1503. {}
  1504. ]
  1505. });
  1506. controller.validateAndDeleteHost();
  1507. expect(controller.raiseDeleteComponentsError.calledWith([
  1508. {}
  1509. ], 'nonDeletableList')).to.be.true;
  1510. });
  1511. it('runningComponents exist', function () {
  1512. controller.set('mockHostComponentsInfo', {
  1513. masterComponents: [],
  1514. nonDeletableComponents: [],
  1515. runningComponents: [{}]
  1516. });
  1517. controller.validateAndDeleteHost();
  1518. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'runningList')).to.be.true;
  1519. });
  1520. it('zkServerInstalled = true', function () {
  1521. controller.set('mockHostComponentsInfo', {
  1522. masterComponents: [],
  1523. nonDeletableComponents: [],
  1524. runningComponents: [],
  1525. unknownComponents: [],
  1526. lastComponents: [],
  1527. zkServerInstalled: true
  1528. });
  1529. var popup = controller.validateAndDeleteHost();
  1530. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1531. popup.onPrimary();
  1532. expect(controller.confirmDeleteHost.calledWith([], [])).to.be.true;
  1533. });
  1534. it('zkServerInstalled = false', function () {
  1535. controller.set('mockHostComponentsInfo', {
  1536. masterComponents: [],
  1537. nonDeletableComponents: [],
  1538. runningComponents: [],
  1539. unknownComponents: [],
  1540. lastComponents: [],
  1541. zkServerInstalled: false
  1542. });
  1543. controller.validateAndDeleteHost();
  1544. expect(controller.confirmDeleteHost.calledWith([], [])).to.be.true;
  1545. });
  1546. });
  1547. describe('#raiseDeleteComponentsError()', function () {
  1548. beforeEach(function () {
  1549. sinon.stub(App.ModalPopup, "show", Em.K);
  1550. });
  1551. afterEach(function () {
  1552. App.ModalPopup.show.restore();
  1553. });
  1554. it('Popup should be displayed', function () {
  1555. controller.raiseDeleteComponentsError([], '');
  1556. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1557. });
  1558. });
  1559. describe('#confirmDeleteHost()', function () {
  1560. it('Popup should be displayed', function () {
  1561. sinon.spy(App.ModalPopup, "show");
  1562. sinon.stub(controller, 'doDeleteHost');
  1563. var popup = controller.confirmDeleteHost([], []);
  1564. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1565. popup.onPrimary();
  1566. expect(controller.doDeleteHost.calledOnce).to.be.true;
  1567. App.ModalPopup.show.restore();
  1568. controller.doDeleteHost.restore();
  1569. });
  1570. });
  1571. describe('#setRackId', function () {
  1572. beforeEach(function () {
  1573. sinon.stub(hostsManagement, 'setRackInfo', Em.K);
  1574. });
  1575. afterEach(function () {
  1576. hostsManagement.setRackInfo.restore();
  1577. });
  1578. it('should call setRackInfo with appropriate arguments', function () {
  1579. var mockedHost = Em.Object.create({
  1580. rack: 'rackId'
  1581. });
  1582. controller.setRackId({
  1583. context: mockedHost
  1584. });
  1585. expect(hostsManagement.setRackInfo.calledWith({message: Em.I18n.t('hosts.host.details.setRackId')}, [mockedHost], 'rackId')).to.be.true;
  1586. });
  1587. });
  1588. describe('#restartAllStaleConfigComponents()', function () {
  1589. beforeEach(function () {
  1590. sinon.spy(App, "showConfirmationPopup");
  1591. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  1592. });
  1593. afterEach(function () {
  1594. App.showConfirmationPopup.restore();
  1595. batchUtils.restartHostComponents.restore();
  1596. });
  1597. it('popup should be displayed', function () {
  1598. controller.set('content', {componentsWithStaleConfigs: [
  1599. {}
  1600. ]});
  1601. var popup = controller.restartAllStaleConfigComponents();
  1602. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1603. popup.onPrimary();
  1604. expect(batchUtils.restartHostComponents.calledWith([
  1605. {}
  1606. ])).to.be.true;
  1607. });
  1608. });
  1609. describe('#moveComponent()', function () {
  1610. it('popup should be displayed', function () {
  1611. var mock = {
  1612. saveComponentToReassign: Em.K,
  1613. getSecurityStatus: Em.K,
  1614. setCurrentStep: Em.K
  1615. };
  1616. sinon.spy(App, "showConfirmationPopup");
  1617. sinon.stub(App.router, 'get').withArgs('reassignMasterController').returns(mock);
  1618. sinon.stub(App.router, 'transitionTo', Em.K);
  1619. sinon.spy(mock, "saveComponentToReassign");
  1620. sinon.spy(mock, "getSecurityStatus");
  1621. sinon.spy(mock, "setCurrentStep");
  1622. var popup = controller.moveComponent({context: {}});
  1623. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1624. popup.onPrimary();
  1625. expect(App.router.get.calledWith('reassignMasterController')).to.be.true;
  1626. expect(mock.saveComponentToReassign.calledWith({})).to.be.true;
  1627. expect(mock.getSecurityStatus.calledOnce).to.be.true;
  1628. expect(mock.setCurrentStep.calledWith('1')).to.be.true;
  1629. expect(App.router.transitionTo.calledWith('reassign')).to.be.true;
  1630. App.showConfirmationPopup.restore();
  1631. App.router.get.restore();
  1632. App.router.transitionTo.restore();
  1633. mock.saveComponentToReassign.restore();
  1634. mock.getSecurityStatus.restore();
  1635. mock.setCurrentStep.restore();
  1636. });
  1637. });
  1638. describe('#refreshConfigs()', function () {
  1639. beforeEach(function () {
  1640. sinon.spy(App, "showConfirmationPopup");
  1641. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  1642. });
  1643. afterEach(function () {
  1644. App.showConfirmationPopup.restore();
  1645. batchUtils.restartHostComponents.restore();
  1646. });
  1647. it('No components', function () {
  1648. var event = {context: []};
  1649. controller.refreshConfigs(event);
  1650. expect(App.showConfirmationPopup.called).to.be.false;
  1651. });
  1652. it('Some components present', function () {
  1653. var event = {context: [Em.Object.create()]};
  1654. var popup = controller.refreshConfigs(event);
  1655. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1656. popup.onPrimary();
  1657. expect(batchUtils.restartHostComponents.calledWith([Em.Object.create()])).to.be.true;
  1658. });
  1659. });
  1660. describe('#getTotalComponent()', function () {
  1661. beforeEach(function () {
  1662. sinon.stub(App.SlaveComponent, 'find', function () {
  1663. return Em.Object.create({
  1664. componentName: "SLAVE",
  1665. totalCount: 1
  1666. });
  1667. });
  1668. sinon.stub(App.ClientComponent, 'find', function () {
  1669. return Em.Object.create({
  1670. componentName: "CLIENT",
  1671. totalCount: 1
  1672. });
  1673. });
  1674. sinon.stub(App.HostComponent, 'find', function () {
  1675. return [Em.Object.create({
  1676. componentName: "MASTER",
  1677. totalCount: 1
  1678. })]
  1679. });
  1680. });
  1681. afterEach(function () {
  1682. App.SlaveComponent.find.restore();
  1683. App.ClientComponent.find.restore();
  1684. App.HostComponent.find.restore();
  1685. });
  1686. it('component is slave', function () {
  1687. expect(controller.getTotalComponent(Em.Object.create({
  1688. componentName: "SLAVE",
  1689. isSlave: true
  1690. }))).to.equal(1);
  1691. });
  1692. it('component is client', function () {
  1693. expect(controller.getTotalComponent(Em.Object.create({
  1694. componentName: "CLIENT",
  1695. isClient: true
  1696. }))).to.equal(1);
  1697. });
  1698. it('component is master', function () {
  1699. expect(controller.getTotalComponent(Em.Object.create({
  1700. componentName: "MASTER"
  1701. }))).to.equal(1);
  1702. });
  1703. it('unknown component', function () {
  1704. expect(controller.getTotalComponent(Em.Object.create({
  1705. componentName: "UNKNOWN"
  1706. }))).to.equal(0);
  1707. });
  1708. });
  1709. describe('#downloadClientConfigs()', function () {
  1710. beforeEach(function () {
  1711. sinon.stub(componentsUtils, 'downloadClientConfigs', Em.K);
  1712. });
  1713. afterEach(function () {
  1714. componentsUtils.downloadClientConfigs.restore();
  1715. });
  1716. it('should launch componentsUtils.downloadClientConfigs method', function () {
  1717. controller.downloadClientConfigs({
  1718. context: Em.Object.create({
  1719. componentName: 'name',
  1720. hostName: 'host1',
  1721. displayName: 'dName'
  1722. })
  1723. });
  1724. expect(componentsUtils.downloadClientConfigs.calledWith({
  1725. componentName: 'name',
  1726. hostName: 'host1',
  1727. displayName: 'dName'
  1728. })).to.be.true;
  1729. });
  1730. });
  1731. describe('#executeCustomCommands', function () {
  1732. beforeEach(function () {
  1733. sinon.spy(App, "showConfirmationPopup");
  1734. });
  1735. afterEach(function () {
  1736. App.showConfirmationPopup.restore();
  1737. });
  1738. it('confirm popup should be displayed', function () {
  1739. var popup = controller.executeCustomCommand({context: Em.Object.create()});
  1740. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1741. popup.onPrimary();
  1742. expect(App.ajax.send.calledOnce).to.be.true;
  1743. });
  1744. });
  1745. describe('#_doDeleteHostComponent()', function () {
  1746. it('single component', function () {
  1747. controller.set('content.hostName', 'host1');
  1748. var component = Em.Object.create({componentName: 'COMP'});
  1749. controller._doDeleteHostComponent(component);
  1750. expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.delete.host_component');
  1751. expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
  1752. componentName: 'COMP',
  1753. hostName: 'host1'
  1754. });
  1755. });
  1756. it('all components', function () {
  1757. controller.set('content.hostName', 'host1');
  1758. controller._doDeleteHostComponent(null);
  1759. expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.delete.host');
  1760. expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
  1761. componentName: '',
  1762. hostName: 'host1'
  1763. });
  1764. });
  1765. });
  1766. describe('#_doDeleteHostComponentSuccessCallback()', function () {
  1767. beforeEach(function() {
  1768. sinon.stub(controller, 'removeHostComponentModel', Em.K);
  1769. });
  1770. afterEach(function() {
  1771. controller.removeHostComponentModel.restore();
  1772. });
  1773. it('ZOOKEEPER_SERVER component', function () {
  1774. var data = {
  1775. componentName: 'ZOOKEEPER_SERVER'
  1776. }
  1777. sinon.stub(controller, 'loadConfigs', Em.K);
  1778. controller._doDeleteHostComponentSuccessCallback({}, {}, data);
  1779. expect(controller.get('_deletedHostComponentResult')).to.be.null;
  1780. expect(controller.get('fromDeleteZkServer')).to.be.true;
  1781. expect(controller.loadConfigs.calledOnce).to.be.true;
  1782. controller.loadConfigs.restore();
  1783. });
  1784. it('Not ZOOKEEPER_SERVER component', function () {
  1785. var data = {
  1786. componentName: 'COMP'
  1787. }
  1788. controller.set('fromDeleteZkServer', false);
  1789. controller._doDeleteHostComponentSuccessCallback({}, {}, data);
  1790. expect(controller.get('_deletedHostComponentResult')).to.be.null;
  1791. expect(controller.get('fromDeleteZkServer')).to.be.false;
  1792. });
  1793. it('should call `removeHostComponentModel` with correct params', function() {
  1794. var data = {
  1795. componentName: 'COMPONENT',
  1796. hostName: 'h1'
  1797. };
  1798. controller._doDeleteHostComponentSuccessCallback({}, {}, data);
  1799. expect(controller.removeHostComponentModel.calledWith('COMPONENT', 'h1')).to.be.true;
  1800. });
  1801. });
  1802. describe('#upgradeComponentSuccessCallback()', function () {
  1803. beforeEach(function () {
  1804. sinon.stub(controller, 'showBackgroundOperationsPopup', Em.K);
  1805. sinon.stub(controller, 'mimicWorkStatusChange', Em.K);
  1806. });
  1807. afterEach(function () {
  1808. controller.mimicWorkStatusChange.restore();
  1809. controller.showBackgroundOperationsPopup.restore();
  1810. });
  1811. it('testMode is true', function () {
  1812. App.set('testMode', true);
  1813. controller.upgradeComponentSuccessCallback({}, {}, {component: "COMP"});
  1814. expect(controller.mimicWorkStatusChange.calledWith("COMP", App.HostComponentStatus.starting, App.HostComponentStatus.started)).to.be.true;
  1815. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  1816. });
  1817. it('testMode is false', function () {
  1818. App.set('testMode', false);
  1819. controller.upgradeComponentSuccessCallback({}, {}, {component: "COMP"});
  1820. expect(controller.mimicWorkStatusChange.called).to.be.false;
  1821. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  1822. });
  1823. });
  1824. describe('#refreshComponentConfigsSuccessCallback()', function () {
  1825. it('call showBackgroundOperationsPopup', function () {
  1826. sinon.stub(controller, 'showBackgroundOperationsPopup', Em.K);
  1827. controller.refreshComponentConfigsSuccessCallback();
  1828. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  1829. controller.showBackgroundOperationsPopup.restore();
  1830. });
  1831. });
  1832. describe('#checkZkConfigs()', function () {
  1833. beforeEach(function () {
  1834. sinon.stub(controller, 'removeObserver');
  1835. sinon.stub(controller, 'loadConfigs');
  1836. });
  1837. afterEach(function () {
  1838. controller.loadConfigs.restore();
  1839. controller.removeObserver.restore();
  1840. App.router.get.restore();
  1841. });
  1842. it('No operations of ZOOKEEPER_SERVER', function () {
  1843. sinon.stub(App.router, 'get').withArgs('backgroundOperationsController.services').returns([]);
  1844. controller.checkZkConfigs();
  1845. expect(controller.removeObserver.called).to.be.false;
  1846. expect(controller.loadConfigs.called).to.be.false;
  1847. });
  1848. it('Operation of ZOOKEEPER_SERVER running', function () {
  1849. sinon.stub(App.router, 'get').withArgs('backgroundOperationsController.services').returns([Em.Object.create({
  1850. id: 1,
  1851. isRunning: true
  1852. })]);
  1853. controller.set('zkRequestId', 1);
  1854. controller.checkZkConfigs();
  1855. expect(controller.removeObserver.called).to.be.false;
  1856. expect(controller.loadConfigs.called).to.be.false;
  1857. });
  1858. it('Operation of ZOOKEEPER_SERVER finished', function () {
  1859. sinon.stub(App.router, 'get').withArgs('backgroundOperationsController.services').returns([Em.Object.create({
  1860. id: 1
  1861. })]);
  1862. var clock = sinon.useFakeTimers();
  1863. controller.set('zkRequestId', 1);
  1864. controller.checkZkConfigs();
  1865. expect(controller.removeObserver.calledWith('App.router.backgroundOperationsController.serviceTimestamp', controller, controller.checkZkConfigs)).to.be.true;
  1866. clock.tick(App.get('componentsUpdateInterval'));
  1867. expect(controller.loadConfigs.calledOnce).to.be.true;
  1868. clock.restore();
  1869. });
  1870. });
  1871. describe('#_doDeleteHostComponentErrorCallback()', function () {
  1872. it('call showBackgroundOperationsPopup', function () {
  1873. controller._doDeleteHostComponentErrorCallback({}, 'textStatus', {}, {url: 'url'});
  1874. expect(controller.get('_deletedHostComponentResult')).to.be.eql({xhr: {}, url: 'url', method: 'DELETE'});
  1875. });
  1876. });
  1877. describe('#installComponentSuccessCallback()', function () {
  1878. beforeEach(function () {
  1879. sinon.stub(controller, 'showBackgroundOperationsPopup', Em.K);
  1880. sinon.stub(controller, 'mimicWorkStatusChange', Em.K);
  1881. });
  1882. afterEach(function () {
  1883. controller.mimicWorkStatusChange.restore();
  1884. controller.showBackgroundOperationsPopup.restore();
  1885. });
  1886. it('testMode is true', function () {
  1887. App.set('testMode', true);
  1888. controller.installComponentSuccessCallback({}, {}, {component: "COMP"});
  1889. expect(controller.mimicWorkStatusChange.calledWith("COMP", App.HostComponentStatus.installing, App.HostComponentStatus.stopped)).to.be.true;
  1890. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  1891. });
  1892. it('testMode is false', function () {
  1893. App.set('testMode', false);
  1894. controller.installComponentSuccessCallback({}, {}, {component: "COMP"});
  1895. expect(controller.mimicWorkStatusChange.called).to.be.false;
  1896. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  1897. });
  1898. });
  1899. describe('#showHbaseActiveWarning()', function () {
  1900. it('popup should be displayed', function () {
  1901. sinon.spy(App.ModalPopup, "show");
  1902. var popup = controller.showHbaseActiveWarning(Em.Object.create({service: {}}));
  1903. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1904. App.ModalPopup.show.restore();
  1905. });
  1906. });
  1907. describe('#updateHost()', function () {
  1908. it('popup should be displayed', function () {
  1909. sinon.stub(batchUtils, "infoPassiveState", Em.K);
  1910. controller.updateHost({}, {}, {passive_state: 'state'});
  1911. expect(controller.get('content.passiveState')).to.equal('state');
  1912. expect(batchUtils.infoPassiveState.calledWith('state')).to.be.true;
  1913. batchUtils.infoPassiveState.restore();
  1914. });
  1915. });
  1916. describe('#updateComponentPassiveState()', function () {
  1917. it('popup should be displayed', function () {
  1918. controller.set('content.hostName', 'host1');
  1919. var component = Em.Object.create({
  1920. componentName: 'COMP1'
  1921. });
  1922. controller.updateComponentPassiveState(component, 'state', 'message');
  1923. expect(App.ajax.send.getCall(0).args[0].data).to.be.eql({
  1924. "hostName": "host1",
  1925. "componentName": "COMP1",
  1926. "component": component,
  1927. "passive_state": "state",
  1928. "context": "message"
  1929. });
  1930. });
  1931. });
  1932. describe('#updateHostComponent()', function () {
  1933. it('popup should be displayed', function () {
  1934. sinon.stub(batchUtils, "infoPassiveState", Em.K);
  1935. var params = {
  1936. component: Em.Object.create(),
  1937. passive_state: 'state'
  1938. }
  1939. controller.updateHostComponent({}, {}, params);
  1940. expect(params.component.get('passiveState')).to.equal('state');
  1941. expect(batchUtils.infoPassiveState.calledWith('state')).to.be.true;
  1942. batchUtils.infoPassiveState.restore();
  1943. });
  1944. });
  1945. describe('#toggleMaintenanceMode()', function () {
  1946. beforeEach(function () {
  1947. sinon.spy(App, "showConfirmationPopup");
  1948. sinon.stub(controller, 'updateComponentPassiveState');
  1949. });
  1950. afterEach(function () {
  1951. App.showConfirmationPopup.restore();
  1952. controller.updateComponentPassiveState.restore();
  1953. });
  1954. it('passive state is ON', function () {
  1955. var event = {context: Em.Object.create({
  1956. passiveState: 'ON'
  1957. })};
  1958. var popup = controller.toggleMaintenanceMode(event);
  1959. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1960. popup.onPrimary();
  1961. expect(controller.updateComponentPassiveState.calledWith(Em.Object.create({
  1962. passiveState: 'ON'
  1963. }), 'OFF')).to.be.true;
  1964. });
  1965. it('passive state is OFF', function () {
  1966. var event = {context: Em.Object.create({
  1967. passiveState: 'OFF'
  1968. })};
  1969. var popup = controller.toggleMaintenanceMode(event);
  1970. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1971. popup.onPrimary();
  1972. expect(controller.updateComponentPassiveState.calledWith(Em.Object.create({
  1973. passiveState: 'OFF'
  1974. }), 'ON')).to.be.true;
  1975. });
  1976. });
  1977. describe('#installClients()', function () {
  1978. var cases = [
  1979. {
  1980. context: [
  1981. Em.Object.create({
  1982. componentName: 'c0',
  1983. workStatus: 'INSTALLED'
  1984. }),
  1985. Em.Object.create({
  1986. componentName: 'c1',
  1987. workStatus: 'INIT'
  1988. }),
  1989. Em.Object.create({
  1990. componentName: 'c2',
  1991. workStatus: 'INSTALL_FAILED'
  1992. })
  1993. ],
  1994. dependencies: {
  1995. c0: [],
  1996. c1: [],
  1997. c2: []
  1998. },
  1999. getSecurityTypeCalled: null, //should have same value as getKDCSessionStateCalled, always
  2000. getKDCSessionStateCalled: true,
  2001. sendComponentCommandCalled: true,
  2002. showAlertPopupCalled: false,
  2003. title: 'No clients to add, some clients to install'
  2004. },
  2005. {
  2006. context: [
  2007. Em.Object.create({
  2008. componentName: 'c3',
  2009. displayName: 'c3'
  2010. })
  2011. ],
  2012. dependencies: {
  2013. c3: []
  2014. },
  2015. getSecurityTypeCalled: null, //should have same value as getKDCSessionStateCalled, always
  2016. getKDCSessionStateCalled: true,
  2017. sendComponentCommandCalled: false,
  2018. showAlertPopupCalled: false,
  2019. title: 'No clients to install, some clients to add'
  2020. },
  2021. {
  2022. context: [
  2023. Em.Object.create({
  2024. componentName: 'c4',
  2025. displayName: 'c4'
  2026. })
  2027. ],
  2028. dependencies: {
  2029. c4: ['c5']
  2030. },
  2031. getSecurityTypeCalled: null, //should have same value as getKDCSessionStateCalled, always
  2032. getKDCSessionStateCalled: false,
  2033. sendComponentCommandCalled: false,
  2034. showAlertPopupCalled: true,
  2035. title: 'Clients to add have unresolved dependencies'
  2036. },
  2037. {
  2038. context: [
  2039. Em.Object.create({
  2040. componentName: 'c5',
  2041. displayName: 'c5'
  2042. }),
  2043. Em.Object.create({
  2044. componentName: 'c6',
  2045. displayName: 'c6'
  2046. })
  2047. ],
  2048. dependencies: {
  2049. c5: ['c6'],
  2050. c6: ['c5']
  2051. },
  2052. getSecurityTypeCalled: null, //should have same value as getKDCSessionStateCalled, always
  2053. getKDCSessionStateCalled: true,
  2054. sendComponentCommandCalled: false,
  2055. showAlertPopupCalled: false,
  2056. title: 'Clients to add have mutual dependencies'
  2057. }
  2058. ],
  2059. componentsUtils = require('utils/components');
  2060. beforeEach(function () {
  2061. sinon.stub(controller, 'sendComponentCommand', Em.K);
  2062. sinon.stub(controller, 'showAddComponentPopup', Em.K);
  2063. sinon.stub(App.get('router.mainAdminKerberosController'), 'getKDCSessionState', function (arg) {
  2064. return arg();
  2065. });
  2066. sinon.stub(App.get('router.mainAdminKerberosController'), 'getSecurityType', function (arg) {
  2067. return arg();
  2068. });
  2069. sinon.stub(App, 'showAlertPopup', Em.K);
  2070. sinon.stub(App.StackServiceComponent, 'find', function (componentName) {
  2071. return Em.Object.create({
  2072. displayName: componentName
  2073. });
  2074. });
  2075. controller.set('content.hostComponents', []);
  2076. });
  2077. afterEach(function () {
  2078. controller.sendComponentCommand.restore();
  2079. controller.showAddComponentPopup.restore();
  2080. App.get('router.mainAdminKerberosController').getKDCSessionState.restore();
  2081. App.get('router.mainAdminKerberosController').getSecurityType.restore();
  2082. App.showAlertPopup.restore();
  2083. App.StackServiceComponent.find.restore();
  2084. componentsUtils.checkComponentDependencies.restore();
  2085. });
  2086. cases.forEach(function (item) {
  2087. it(item.title, function () {
  2088. sinon.stub(componentsUtils, 'checkComponentDependencies', function (componentName, params) {
  2089. return item.dependencies[componentName];
  2090. });
  2091. controller.installClients({
  2092. context: item.context
  2093. });
  2094. expect(App.get('router.mainAdminKerberosController').getSecurityType.calledOnce).to.equal(item.getKDCSessionStateCalled);
  2095. expect(App.get('router.mainAdminKerberosController').getKDCSessionState.calledOnce).to.equal(item.getKDCSessionStateCalled);
  2096. expect(controller.sendComponentCommand.calledOnce).to.equal(item.sendComponentCommandCalled);
  2097. expect(App.showAlertPopup.calledOnce).to.equal(item.showAlertPopupCalled);
  2098. });
  2099. });
  2100. });
  2101. describe("#executeCustomCommandSuccessCallback()", function () {
  2102. it("BO popup should be shown", function () {
  2103. var mock = {
  2104. showPopup: Em.K
  2105. };
  2106. sinon.stub(App.router, 'get').returns(mock);
  2107. sinon.spy(mock, 'showPopup');
  2108. var data = {
  2109. Requests: {
  2110. id: 1
  2111. }
  2112. };
  2113. controller.executeCustomCommandSuccessCallback(data, {}, {});
  2114. expect(App.router.get.calledWith('backgroundOperationsController')).to.be.true;
  2115. expect(mock.showPopup.calledOnce).to.be.true;
  2116. App.router.get.restore();
  2117. mock.showPopup.restore();
  2118. });
  2119. });
  2120. describe("#executeCustomCommandErrorCallback()", function () {
  2121. beforeEach(function () {
  2122. sinon.stub($, 'parseJSON');
  2123. sinon.spy(App, 'showAlertPopup');
  2124. });
  2125. afterEach(function () {
  2126. App.showAlertPopup.restore();
  2127. $.parseJSON.restore();
  2128. });
  2129. it("data empty", function () {
  2130. controller.executeCustomCommandErrorCallback(null);
  2131. expect(App.showAlertPopup.calledWith(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), Em.I18n.t('services.service.actions.run.executeCustomCommand.error'))).to.be.true;
  2132. expect($.parseJSON.called).to.be.false;
  2133. });
  2134. it("responseText empty", function () {
  2135. var data = {
  2136. responseText: null
  2137. };
  2138. controller.executeCustomCommandErrorCallback(data);
  2139. expect(App.showAlertPopup.calledWith(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), Em.I18n.t('services.service.actions.run.executeCustomCommand.error'))).to.be.true;
  2140. expect($.parseJSON.called).to.be.false;
  2141. });
  2142. it("data empty", function () {
  2143. var data = {
  2144. responseText: "test"
  2145. };
  2146. controller.executeCustomCommandErrorCallback(data);
  2147. expect(App.showAlertPopup.calledWith(Em.I18n.t('services.service.actions.run.executeCustomCommand.error'), Em.I18n.t('services.service.actions.run.executeCustomCommand.error'))).to.be.true;
  2148. expect($.parseJSON.calledWith('test')).to.be.true;
  2149. });
  2150. });
  2151. describe("#doDeleteHost()", function() {
  2152. beforeEach(function(){
  2153. controller.set('fromDeleteHost', false);
  2154. controller.set('content.hostName', 'host1');
  2155. sinon.stub(controller, '_doDeleteHostComponent', function (comp, callback) {
  2156. callback();
  2157. });
  2158. });
  2159. afterEach(function(){
  2160. controller._doDeleteHostComponent.restore();
  2161. });
  2162. it("Host has no components", function() {
  2163. controller.set('content.hostComponents', Em.A([]));
  2164. controller.doDeleteHost(Em.K);
  2165. expect(controller.get('fromDeleteHost')).to.be.true;
  2166. expect(App.ajax.send.getCall(0).args[0].data.hostName).to.be.equal('host1');
  2167. expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.delete.host');
  2168. });
  2169. it("Host has components", function() {
  2170. controller.set('content.hostComponents', Em.A([Em.Object.create({
  2171. componentName: 'COMP1'
  2172. })]));
  2173. controller.doDeleteHost(Em.K);
  2174. expect(controller._doDeleteHostComponent.calledWith(Em.Object.create({
  2175. componentName: 'COMP1'
  2176. }))).to.be.true;
  2177. expect(controller.get('fromDeleteHost')).to.be.true;
  2178. expect(App.ajax.send.getCall(0).args[0].data.hostName).to.be.equal('host1');
  2179. expect(App.ajax.send.getCall(0).args[0].name).to.be.equal('common.delete.host');
  2180. });
  2181. });
  2182. describe("#deleteHostSuccessCallback", function() {
  2183. it("call updateHost", function() {
  2184. var mock = {
  2185. updateHost: function(callback){
  2186. callback();
  2187. },
  2188. getAllHostNames: Em.K
  2189. };
  2190. sinon.stub(App.router, 'get').withArgs('updateController').returns(mock).withArgs('clusterController').returns(mock);
  2191. sinon.spy(mock, 'updateHost');
  2192. sinon.spy(mock, 'getAllHostNames');
  2193. sinon.stub(controller, 'loadConfigs', Em.K);
  2194. sinon.stub(App.router, 'transitionTo', Em.K);
  2195. controller.deleteHostSuccessCallback();
  2196. expect(App.router.get.calledWith('updateController')).to.be.true;
  2197. expect(mock.updateHost.calledOnce).to.be.true;
  2198. expect(controller.loadConfigs.called).to.be.true;
  2199. expect(App.router.transitionTo.calledWith('hosts.index')).to.be.true;
  2200. expect(App.router.get.calledWith('clusterController')).to.be.true;
  2201. expect(mock.getAllHostNames.calledOnce).to.be.true;
  2202. App.router.get.restore();
  2203. mock.updateHost.restore();
  2204. mock.getAllHostNames.restore();
  2205. controller.loadConfigs.restore();
  2206. App.router.transitionTo.restore();
  2207. });
  2208. });
  2209. describe("#deleteHostErrorCallback", function() {
  2210. it("call defaultErrorHandler", function() {
  2211. sinon.stub(controller, 'loadConfigs', Em.K);
  2212. sinon.stub(App.ajax, 'defaultErrorHandler', Em.K);
  2213. controller.deleteHostErrorCallback({status: 'status', statusText: "statusText"}, 'textStatus', 'errorThrown', {url: 'url'});
  2214. expect(controller.loadConfigs.calledOnce).to.be.true;
  2215. expect(App.ajax.defaultErrorHandler.calledOnce).to.be.true;
  2216. App.ajax.defaultErrorHandler.restore();
  2217. controller.loadConfigs.restore();
  2218. });
  2219. });
  2220. describe('#installVersionConfirmation()', function () {
  2221. beforeEach(function () {
  2222. sinon.spy(App, "showConfirmationPopup");
  2223. sinon.stub(controller, 'installVersion', Em.K);
  2224. });
  2225. afterEach(function () {
  2226. App.showConfirmationPopup.restore();
  2227. controller.installVersion.restore();
  2228. });
  2229. it('confirm popup should be displayed', function () {
  2230. var event = {context: Em.Object.create({displayName: 'displayName'})};
  2231. var popup = controller.installVersionConfirmation(event);
  2232. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  2233. popup.onPrimary();
  2234. expect(controller.installVersion.calledWith(event)).to.be.true;
  2235. });
  2236. });
  2237. describe("#installVersion()", function() {
  2238. it("call App.ajax.send", function() {
  2239. controller.set('content.hostName', 'host1');
  2240. controller.installVersion({context: {}});
  2241. expect(App.ajax.send.getCall(0).args[0]).to.eql({
  2242. name: 'host.stack_versions.install',
  2243. sender: controller,
  2244. data: {
  2245. hostName: 'host1',
  2246. version: {}
  2247. },
  2248. success: 'installVersionSuccessCallback'
  2249. });
  2250. });
  2251. });
  2252. describe("#installVersionSuccessCallback()", function () {
  2253. before(function () {
  2254. this.mock = sinon.stub(App.HostStackVersion, 'find');
  2255. sinon.stub(App.db, 'set', Em.K);
  2256. sinon.stub(App.clusterStatus, 'setClusterStatus', Em.K);
  2257. });
  2258. after(function () {
  2259. this.mock.restore();
  2260. App.db.set.restore();
  2261. App.clusterStatus.setClusterStatus.restore();
  2262. });
  2263. it("", function () {
  2264. var version = Em.Object.create({
  2265. id: 1,
  2266. status: 'INIT'
  2267. });
  2268. this.mock.returns(version);
  2269. controller.installVersionSuccessCallback({Requests:{id: 1}}, {}, {version: version});
  2270. expect(version.get('status')).to.equal('INSTALLING');
  2271. expect(App.db.set.calledWith('repoVersionInstall', 'id', [1])).to.be.true;
  2272. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  2273. });
  2274. });
  2275. describe('#getHiveHosts()', function () {
  2276. var cases = [
  2277. {
  2278. 'input': {
  2279. 'hiveMetastoreHost': '',
  2280. 'fromDeleteHost': false,
  2281. 'deleteHiveMetaStore': false
  2282. },
  2283. 'hiveHosts': ['h1', 'h2'],
  2284. 'title': 'adding HiveServer2'
  2285. },
  2286. {
  2287. 'input': {
  2288. 'hiveMetastoreHost': 'h0',
  2289. 'fromDeleteHost': false,
  2290. 'deleteHiveMetaStore': false
  2291. },
  2292. 'hiveHosts': ['h0', 'h1', 'h2'],
  2293. 'title': 'adding Hive Metastore'
  2294. },
  2295. {
  2296. 'input': {
  2297. 'hiveMetastoreHost': '',
  2298. 'content.hostName': 'h1',
  2299. 'fromDeleteHost': false,
  2300. 'deleteHiveMetaStore': true
  2301. },
  2302. 'hiveHosts': ['h2'],
  2303. 'title': 'deleting Hive component'
  2304. },
  2305. {
  2306. 'input': {
  2307. 'hiveMetastoreHost': '',
  2308. 'content.hostName': 'h2',
  2309. 'fromDeleteHost': true,
  2310. 'deleteHiveMetaStore': false
  2311. },
  2312. 'hiveHosts': ['h1'],
  2313. 'title': 'deleting host with Hive component'
  2314. }
  2315. ];
  2316. before(function () {
  2317. sinon.stub(App.HostComponent, 'find').returns([
  2318. {
  2319. componentName: 'HIVE_METASTORE',
  2320. hostName: 'h2'
  2321. },
  2322. {
  2323. componentName: 'HIVE_METASTORE',
  2324. hostName: 'h1'
  2325. },
  2326. {
  2327. componentName: 'HIVE_SERVER',
  2328. hostName: 'h3'
  2329. }
  2330. ]);
  2331. });
  2332. after(function () {
  2333. App.HostComponent.find.restore();
  2334. });
  2335. cases.forEach(function (item) {
  2336. it(item.title, function () {
  2337. Em.keys(item.input).forEach(function (key) {
  2338. controller.set(key, item.input[key]);
  2339. });
  2340. expect(controller.getHiveHosts()).to.eql(item.hiveHosts);
  2341. expect(controller.get('hiveMetastoreHost')).to.be.empty;
  2342. expect(controller.get('fromDeleteHost')).to.be.false;
  2343. expect(controller.get('deleteHiveMetaStore')).to.be.false;
  2344. });
  2345. });
  2346. });
  2347. });