details_test.js 111 KB

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