details_test.js 91 KB

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