details_test.js 82 KB

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