details_test.js 111 KB

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