details_test.js 83 KB

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