details_test.js 86 KB

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