details_test.js 80 KB

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