details_test.js 79 KB

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