details_test.js 127 KB

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