details_test.js 94 KB

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