details_test.js 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. var App = require('app');
  19. require('controllers/main/host/details');
  20. require('models/service');
  21. require('models/host_component');
  22. var batchUtils = require('utils/batch_scheduled_requests');
  23. describe('App.MainHostDetailsController', function () {
  24. var controller = App.MainHostDetailsController.create({
  25. getSecurityStatus: function () {
  26. return this.get('mockSecurityStatus');
  27. },
  28. mockSecurityStatus: false
  29. });
  30. describe('#serviceActiveComponents', function () {
  31. it('No host-components', function () {
  32. controller.set('content.hostComponents', []);
  33. expect(controller.get('serviceActiveComponents')).to.be.empty;
  34. });
  35. it('No host-components in active state', function () {
  36. controller.set('content.hostComponents', [Em.Object.create({
  37. service: {
  38. isInPassive: true
  39. }
  40. })]);
  41. expect(controller.get('serviceActiveComponents')).to.be.empty;
  42. });
  43. it('Host-components in active state', function () {
  44. controller.set('content.hostComponents', [Em.Object.create({
  45. service: {
  46. isInPassive: false
  47. }
  48. })]);
  49. expect(controller.get('serviceActiveComponents')).to.eql([Em.Object.create({
  50. service: {
  51. isInPassive: false
  52. }
  53. })]);
  54. });
  55. });
  56. describe('#serviceNonClientActiveComponents', function () {
  57. it('No active host-components', function () {
  58. controller.reopen({
  59. serviceActiveComponents: []
  60. });
  61. controller.set('serviceActiveComponents', []);
  62. expect(controller.get('serviceNonClientActiveComponents')).to.be.empty;
  63. });
  64. it('Active host-component is client', function () {
  65. controller.set('serviceActiveComponents', [Em.Object.create({
  66. isClient: true
  67. })]);
  68. expect(controller.get('serviceNonClientActiveComponents')).to.be.empty;
  69. });
  70. it('Active host-component is not client', function () {
  71. controller.set('serviceActiveComponents', [Em.Object.create({
  72. isClient: false
  73. })]);
  74. expect(controller.get('serviceNonClientActiveComponents')).to.eql( [Em.Object.create({
  75. isClient: false
  76. })]);
  77. });
  78. });
  79. describe('#startComponent()', function () {
  80. beforeEach(function () {
  81. sinon.spy(App, "showConfirmationPopup");
  82. sinon.stub(controller, "sendStartComponentCommand", Em.K);
  83. });
  84. afterEach(function () {
  85. App.showConfirmationPopup.restore();
  86. controller.sendStartComponentCommand.restore();
  87. });
  88. it('popup should be displayed', function () {
  89. var popup = controller.startComponent({context: Em.Object.create({'displayName': 'Comp1'})});
  90. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  91. popup.onPrimary();
  92. expect(controller.sendStartComponentCommand.calledOnce).to.be.true;
  93. });
  94. });
  95. describe('#sendStartComponentCommand()', function () {
  96. beforeEach(function () {
  97. sinon.stub(App.ajax, "send", Em.K);
  98. });
  99. afterEach(function () {
  100. App.ajax.send.restore();
  101. });
  102. it('Query should be sent', function () {
  103. var component = Em.Object.create({
  104. componentName: 'comp1'
  105. });
  106. controller.sendStartComponentCommand(component, '');
  107. expect(App.ajax.send.calledOnce).to.be.true;
  108. });
  109. });
  110. describe('#getDataToSend()', function () {
  111. var component = Em.Object.create({
  112. componentName: 'comp1',
  113. host: {
  114. hostName: 'host1'
  115. },
  116. service: {
  117. serviceName: 'serv1'
  118. }
  119. });
  120. it('should return correct query info', function () {
  121. controller.set("content.hostName", "host1");
  122. expect(controller.getDataToSend('STATE1', 'context', component)).to.deep.eql({
  123. RequestInfo: {
  124. "context": 'context',
  125. "operation_level": {
  126. "cluster_name": "tdk",
  127. "host_name": "host1",
  128. "hostcomponent_name": "comp1",
  129. "service_name": "serv1",
  130. "level": "HOST_COMPONENT"
  131. }
  132. },
  133. Body: {
  134. HostRoles: {
  135. state: 'STATE1'
  136. }
  137. }
  138. });
  139. expect(controller.getDataToSend('STATE1', 'context', [component])).to.deep.eql({
  140. RequestInfo: {
  141. "context": 'context',
  142. "operation_level": {
  143. "cluster_name": "tdk",
  144. "host_name": "host1",
  145. "level": "HOST"
  146. }
  147. },
  148. Body: {
  149. HostRoles: {
  150. state: 'STATE1'
  151. }
  152. }
  153. });
  154. });
  155. });
  156. describe('#setComponentToData()', function () {
  157. var testCases = [
  158. {
  159. title: 'dataToSend is null',
  160. content: {
  161. data: {},
  162. dataToSend: null,
  163. component: {}
  164. },
  165. result: {
  166. output: false,
  167. data: {}
  168. }
  169. },
  170. {
  171. title: 'component is null',
  172. content: {
  173. data: {},
  174. dataToSend: {},
  175. component: null
  176. },
  177. result: {
  178. output: false,
  179. data: {}
  180. }
  181. },
  182. {
  183. title: 'data is null',
  184. content: {
  185. data: null,
  186. dataToSend: {},
  187. component: {}
  188. },
  189. result: {
  190. output: false,
  191. data: null
  192. }
  193. },
  194. {
  195. title: 'component is object',
  196. content: {
  197. data: {},
  198. dataToSend: {},
  199. component: Em.Object.create({componentName: 'comp1'})
  200. },
  201. result: {
  202. output: true,
  203. data: {
  204. componentName: 'comp1',
  205. data: '{}'
  206. }
  207. }
  208. },
  209. {
  210. title: 'component is array',
  211. content: {
  212. data: {},
  213. dataToSend: {RequestInfo: {}},
  214. component: [Em.Object.create({componentName: 'comp1'})]
  215. },
  216. result: {
  217. output: true,
  218. data: {
  219. data: '{\"RequestInfo\":{\"query\":\"HostRoles/component_name.in(comp1)\"}}'
  220. }
  221. }
  222. }
  223. ];
  224. testCases.forEach(function (test) {
  225. it(test.title, function () {
  226. expect(controller.setComponentToData(test.content.data, test.content.dataToSend, test.content.component)).to.equal(test.result.output);
  227. expect(test.content.data).to.eql(test.result.data);
  228. });
  229. });
  230. });
  231. describe('#deleteComponent()', function () {
  232. beforeEach(function () {
  233. sinon.spy(App.ModalPopup, "show");
  234. });
  235. afterEach(function () {
  236. App.ModalPopup.show.restore();
  237. });
  238. it('confirm popup should be displayed', function () {
  239. var event = {
  240. context: Em.Object.create({})
  241. };
  242. controller.deleteComponent(event);
  243. expect(App.ModalPopup.show.calledOnce).to.be.true;
  244. });
  245. });
  246. describe('#_doDeleteHostComponent()', function () {
  247. beforeEach(function () {
  248. sinon.stub(App.ajax, "send", Em.K);
  249. });
  250. afterEach(function () {
  251. App.ajax.send.restore();
  252. });
  253. it('delete request should be sent, component is null', function () {
  254. controller.set('_deletedHostComponentResult', null);
  255. expect(controller._doDeleteHostComponent()).to.equal(null);
  256. expect(App.ajax.send.calledOnce).to.be.true;
  257. });
  258. it('delete request should be sent, component is correct', function () {
  259. controller.set('_deletedHostComponentResult', {});
  260. expect(controller._doDeleteHostComponent(Em.Object.create({componentName: 'COMP1'}))).to.eql({});
  261. expect(App.ajax.send.calledOnce).to.be.true;
  262. });
  263. });
  264. describe('#mimicWorkStatusChange()', function () {
  265. var clock;
  266. beforeEach(function () {
  267. clock = sinon.useFakeTimers();
  268. });
  269. afterEach(function () {
  270. clock.restore()
  271. });
  272. it('change status of object', function () {
  273. var entity = Em.Object.create({
  274. workStatus: ''
  275. });
  276. controller.mimicWorkStatusChange(entity, 'STATE1', 'STATE2');
  277. expect(entity.get('workStatus')).to.equal('STATE1');
  278. clock.tick(App.testModeDelayForActions);
  279. expect(entity.get('workStatus')).to.equal('STATE2');
  280. });
  281. it('change status of objects in array', function () {
  282. var entity = [Em.Object.create({
  283. workStatus: ''
  284. })];
  285. controller.mimicWorkStatusChange(entity, 'STATE1', 'STATE2');
  286. expect(entity[0].get('workStatus')).to.equal('STATE1');
  287. clock.tick(App.testModeDelayForActions);
  288. expect(entity[0].get('workStatus')).to.equal('STATE2');
  289. });
  290. });
  291. describe('#upgradeComponent()', function () {
  292. beforeEach(function () {
  293. sinon.spy(App, "showConfirmationPopup");
  294. sinon.stub(App.ajax, "send", Em.K);
  295. });
  296. afterEach(function () {
  297. App.showConfirmationPopup.restore();
  298. App.ajax.send.restore();
  299. });
  300. it('confirm popup should be displayed', function () {
  301. var popup = controller.upgradeComponent({context: Em.Object.create()});
  302. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  303. popup.onPrimary();
  304. expect(App.ajax.send.calledOnce).to.be.true;
  305. });
  306. });
  307. describe('#stopComponent()', function () {
  308. beforeEach(function () {
  309. sinon.spy(App, "showConfirmationPopup");
  310. sinon.stub(controller, "sendStopComponentCommand", Em.K);
  311. });
  312. afterEach(function () {
  313. App.showConfirmationPopup.restore();
  314. controller.sendStopComponentCommand.restore();
  315. });
  316. it('popup should be displayed', function () {
  317. var popup = controller.stopComponent({context: Em.Object.create({'displayName': 'Comp1'})});
  318. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  319. popup.onPrimary();
  320. expect(controller.sendStopComponentCommand.calledOnce).to.be.true;
  321. });
  322. });
  323. describe('#sendStopComponentCommand()', function () {
  324. beforeEach(function () {
  325. sinon.stub(App.ajax, "send", Em.K);
  326. });
  327. afterEach(function () {
  328. App.ajax.send.restore();
  329. });
  330. it('Query should be sent', function () {
  331. var component = Em.Object.create({
  332. componentName: 'comp1'
  333. });
  334. controller.sendStopComponentCommand(component, '');
  335. expect(App.ajax.send.calledOnce).to.be.true;
  336. });
  337. });
  338. describe('#restartComponent()', function () {
  339. beforeEach(function () {
  340. sinon.spy(App, "showConfirmationPopup");
  341. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  342. });
  343. afterEach(function () {
  344. App.showConfirmationPopup.restore();
  345. batchUtils.restartHostComponents.restore();
  346. });
  347. it('popup should be displayed', function () {
  348. var popup = controller.restartComponent({context: Em.Object.create({'displayName': 'Comp1'})});
  349. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  350. popup.onPrimary();
  351. expect(batchUtils.restartHostComponents.calledOnce).to.be.true;
  352. });
  353. });
  354. describe('#addComponent()', function () {
  355. beforeEach(function () {
  356. sinon.spy(App, "showConfirmationPopup");
  357. sinon.stub(controller, "addClientComponent", Em.K);
  358. sinon.stub(controller, "primary", Em.K);
  359. });
  360. afterEach(function () {
  361. App.showConfirmationPopup.restore();
  362. controller.addClientComponent.restore();
  363. controller.primary.restore();
  364. });
  365. it('add ZOOKEEPER_SERVER', function () {
  366. var event = {context: Em.Object.create({
  367. componentName: 'ZOOKEEPER_SERVER'
  368. })};
  369. var popup = controller.addComponent(event);
  370. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  371. popup.onPrimary();
  372. expect(controller.primary.calledWith(Em.Object.create({
  373. componentName: 'ZOOKEEPER_SERVER'
  374. }))).to.be.true;
  375. });
  376. it('add slave component, securityEnabled = true', function () {
  377. var event = {context: Em.Object.create({
  378. componentName: 'COMP1'
  379. })};
  380. controller.set('mockSecurityStatus', true);
  381. var popup = controller.addComponent(event);
  382. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  383. popup.onPrimary();
  384. expect(controller.primary.calledWith(Em.Object.create({
  385. componentName: 'COMP1'
  386. }))).to.be.true;
  387. });
  388. it('add slave component, securityEnabled = false', function () {
  389. var event = {context: Em.Object.create({
  390. componentName: 'COMP1'
  391. })};
  392. controller.set('mockSecurityStatus', false);
  393. controller.addComponent(event);
  394. expect(controller.addClientComponent.calledWith(Em.Object.create({
  395. componentName: 'COMP1'
  396. }))).to.be.true;
  397. });
  398. it('add CLIENTS', function () {
  399. var event = {context: Em.Object.create({
  400. componentName: 'CLIENTS'
  401. })};
  402. controller.set('mockSecurityStatus', true);
  403. controller.addComponent(event);
  404. expect(controller.addClientComponent.calledWith(Em.Object.create({
  405. componentName: 'CLIENTS'
  406. }))).to.be.true;
  407. });
  408. });
  409. describe('#formatClientsMessage()', function () {
  410. var testCases = [
  411. {
  412. title: 'subComponentNames is null',
  413. client: Em.Object.create({
  414. subComponentNames: null,
  415. displayName: 'CLIENTS'
  416. }),
  417. result: 'CLIENTS'
  418. },
  419. {
  420. title: 'subComponentNames is empty',
  421. client: Em.Object.create({
  422. subComponentNames: [],
  423. displayName: 'CLIENTS'
  424. }),
  425. result: 'CLIENTS'
  426. },
  427. {
  428. title: 'displayName is null',
  429. client: Em.Object.create({
  430. subComponentNames: ['DATANODE'],
  431. displayName: null
  432. }),
  433. result: ' (DataNode)'
  434. },
  435. {
  436. title: 'displayName is CLIENTS',
  437. client: Em.Object.create({
  438. subComponentNames: ['DATANODE'],
  439. displayName: 'CLIENTS'
  440. }),
  441. result: 'CLIENTS (DataNode)'
  442. }
  443. ];
  444. testCases.forEach(function (test) {
  445. it(test.title, function () {
  446. expect(controller.formatClientsMessage(test.client)).to.equal(test.result);
  447. });
  448. });
  449. });
  450. describe('#addClientComponent()', function () {
  451. beforeEach(function () {
  452. sinon.spy(App.ModalPopup, "show");
  453. sinon.stub(controller, "primary", Em.K);
  454. });
  455. afterEach(function () {
  456. App.ModalPopup.show.restore();
  457. controller.primary.restore();
  458. });
  459. it('not CLIENT component', function () {
  460. var component = Em.Object.create({'componentName': 'Comp1'});
  461. var popup = controller.addClientComponent(component);
  462. expect(App.ModalPopup.show.calledOnce).to.be.true;
  463. popup.onPrimary();
  464. expect(controller.primary.calledWith(Em.Object.create({'componentName': 'Comp1'}))).to.be.true;
  465. });
  466. it('CLIENT components, with empty subComponentNames', function () {
  467. var component = Em.Object.create({
  468. componentName: 'CLIENTS',
  469. subComponentNames: []
  470. });
  471. var popup = controller.addClientComponent(component);
  472. expect(App.ModalPopup.show.calledOnce).to.be.true;
  473. popup.onPrimary();
  474. expect(controller.primary.calledOnce).to.be.false;
  475. });
  476. it('CLIENT components, with two sub-component', function () {
  477. var component = Em.Object.create({
  478. componentName: 'CLIENTS',
  479. subComponentNames: ['DATANODE', 'TASKTRACKER']
  480. });
  481. var popup = controller.addClientComponent(component);
  482. expect(App.ModalPopup.show.calledOnce).to.be.true;
  483. popup.onPrimary();
  484. expect(controller.primary.calledTwice).to.be.true;
  485. });
  486. });
  487. describe('#primary()', function () {
  488. beforeEach(function () {
  489. sinon.stub(App.ajax, "send", Em.K);
  490. });
  491. afterEach(function () {
  492. App.ajax.send.restore();
  493. });
  494. it('Query should be sent', function () {
  495. var component = Em.Object.create({
  496. componentName: 'COMP1',
  497. displayName: 'comp1'
  498. });
  499. controller.primary(component);
  500. expect(App.ajax.send.calledOnce).to.be.true;
  501. });
  502. });
  503. describe('#addNewComponentSuccessCallback()', function () {
  504. beforeEach(function () {
  505. sinon.stub(App.ajax, "send", Em.K);
  506. });
  507. afterEach(function () {
  508. App.ajax.send.restore();
  509. });
  510. it('Query should be sent', function () {
  511. controller.addNewComponentSuccessCallback({}, {}, {component: Em.Object.create()});
  512. expect(App.ajax.send.calledOnce).to.be.true;
  513. });
  514. });
  515. describe('#installNewComponentSuccessCallback()', function () {
  516. beforeEach(function () {
  517. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  518. });
  519. afterEach(function () {
  520. controller.showBackgroundOperationsPopup.restore();
  521. });
  522. it('data.Requests is null', function () {
  523. var data = {Requests: null};
  524. expect(controller.installNewComponentSuccessCallback(data, {}, {})).to.be.false;
  525. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  526. });
  527. it('data.Requests.id is null', function () {
  528. var data = {Requests: {id: null}};
  529. expect(controller.installNewComponentSuccessCallback(data, {}, {})).to.be.false;
  530. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  531. });
  532. it('data.Requests.id is correct', function () {
  533. var data = {Requests: {id: 1}};
  534. expect(controller.installNewComponentSuccessCallback(data, {}, {component: []})).to.be.true;
  535. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  536. });
  537. });
  538. describe('#refreshComponentConfigs()', function () {
  539. beforeEach(function () {
  540. sinon.spy(App, "showConfirmationPopup");
  541. sinon.stub(controller, "sendRefreshComponentConfigsCommand", Em.K);
  542. });
  543. afterEach(function () {
  544. App.showConfirmationPopup.restore();
  545. controller.sendRefreshComponentConfigsCommand.restore();
  546. });
  547. it('popup should be displayed', function () {
  548. var popup = controller.refreshComponentConfigs({context: Em.Object.create({'displayName': 'Comp1'})});
  549. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  550. popup.onPrimary();
  551. expect(controller.sendRefreshComponentConfigsCommand.calledOnce).to.be.true;
  552. });
  553. });
  554. describe('#sendRefreshComponentConfigsCommand()', function () {
  555. beforeEach(function () {
  556. sinon.stub(App.ajax, "send", Em.K);
  557. });
  558. afterEach(function () {
  559. App.ajax.send.restore();
  560. });
  561. it('Query should be sent', function () {
  562. var component = Em.Object.create({
  563. service: {},
  564. componentName: 'COMP1',
  565. host: {}
  566. });
  567. controller.sendRefreshComponentConfigsCommand(component, {});
  568. expect(App.ajax.send.calledOnce).to.be.true;
  569. });
  570. });
  571. describe('#loadConfigs()', function () {
  572. beforeEach(function () {
  573. sinon.stub(App.ajax, "send", Em.K);
  574. });
  575. afterEach(function () {
  576. App.ajax.send.restore();
  577. });
  578. it('Query should be sent', function () {
  579. controller.loadConfigs();
  580. expect(App.ajax.send.calledOnce).to.be.true;
  581. });
  582. });
  583. describe('#constructConfigUrlParams()', function () {
  584. it('URL params should be empty', function () {
  585. var data = {};
  586. App.Service.find().clear();
  587. expect(controller.constructConfigUrlParams(data)).to.eql([]);
  588. });
  589. it('isHaEnabled = true', function () {
  590. var data = {Clusters: {desired_configs: {'core-site': {tag: 1}}}};
  591. App.HostComponent.find().clear();
  592. App.set('currentStackVersion', 'HDP-2.0.2');
  593. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=core-site&tag=1)']);
  594. App.store.load(App.HostComponent, {
  595. id: 'SECONDARY_NAMENODE_host1',
  596. component_name: 'SECONDARY_NAMENODE'
  597. });
  598. App.set('currentStackVersion', 'HDP-2.0.1');
  599. });
  600. it('HBASE is installed', function () {
  601. App.store.load(App.Service, {
  602. id: 'HBASE',
  603. service_name: 'HBASE'
  604. });
  605. var data = {Clusters: {desired_configs: {'hbase-site': {tag: 1}}}};
  606. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=hbase-site&tag=1)']);
  607. App.Service.find().clear();
  608. });
  609. it('HIVE is installed', function () {
  610. App.store.load(App.Service, {
  611. id: 'HIVE',
  612. service_name: 'HIVE'
  613. });
  614. var data = {Clusters: {desired_configs: {'webhcat-site': {tag: 1}}}};
  615. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=webhcat-site&tag=1)']);
  616. App.Service.find().clear();
  617. });
  618. it('STORM is installed', function () {
  619. App.store.load(App.Service, {
  620. id: 'STORM',
  621. service_name: 'STORM'
  622. });
  623. var data = {Clusters: {desired_configs: {'storm-site': {tag: 1}}}};
  624. expect(controller.constructConfigUrlParams(data)).to.eql(['(type=storm-site&tag=1)']);
  625. App.Service.find().clear();
  626. });
  627. });
  628. describe('#loadConfigsSuccessCallback()', function () {
  629. beforeEach(function () {
  630. sinon.stub(App.ajax, "send", Em.K);
  631. sinon.stub(controller, "constructConfigUrlParams", function () {
  632. return this.get('mockUrlParams');
  633. });
  634. });
  635. afterEach(function () {
  636. App.ajax.send.restore();
  637. controller.constructConfigUrlParams.restore();
  638. });
  639. it('url params is empty', function () {
  640. controller.set('mockUrlParams', []);
  641. expect(controller.loadConfigsSuccessCallback()).to.be.false;
  642. expect(App.ajax.send.called).to.be.false;
  643. });
  644. it('url params are correct', function () {
  645. controller.set('mockUrlParams', ['param1']);
  646. expect(controller.loadConfigsSuccessCallback()).to.be.true;
  647. expect(App.ajax.send.calledOnce).to.be.true;
  648. });
  649. });
  650. describe('#saveZkConfigs()', function () {
  651. beforeEach(function () {
  652. sinon.stub(controller, "getZkServerHosts", Em.K);
  653. sinon.stub(controller, "concatZkNames", Em.K);
  654. sinon.stub(controller, "setZKConfigs", Em.K);
  655. sinon.spy(App.ajax, "send");
  656. });
  657. afterEach(function () {
  658. controller.getZkServerHosts.restore();
  659. controller.concatZkNames.restore();
  660. controller.setZKConfigs.restore();
  661. App.ajax.send.restore();
  662. });
  663. it('data.items is empty', function () {
  664. var data = {items: []};
  665. controller.saveZkConfigs(data);
  666. expect(App.ajax.send.called).to.be.false;
  667. });
  668. it('data.items has one item', function () {
  669. var data = {items: [
  670. {
  671. type: 'type1',
  672. properties: {}
  673. }
  674. ]};
  675. controller.saveZkConfigs(data);
  676. expect(App.ajax.send.calledOnce).to.be.true;
  677. });
  678. it('data.items has two items', function () {
  679. var data = {items: [
  680. {
  681. type: 'type1',
  682. properties: {}
  683. },
  684. {
  685. type: 'type2',
  686. properties: {}
  687. }
  688. ]};
  689. controller.saveZkConfigs(data);
  690. expect(App.ajax.send.calledTwice).to.be.true;
  691. });
  692. });
  693. describe('#setZKConfigs()', function () {
  694. it('configs is null', function () {
  695. expect(controller.setZKConfigs(null)).to.be.false;
  696. });
  697. it('zks is null', function () {
  698. expect(controller.setZKConfigs({}, '', null)).to.be.false;
  699. });
  700. it('isHaEnabled = true', function () {
  701. var configs = {'core-site': {}};
  702. App.HostComponent.find().clear();
  703. App.set('currentStackVersion', 'HDP-2.0.2');
  704. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  705. expect(configs).to.eql({"core-site": {
  706. "ha.zookeeper.quorum": "host1:2181"
  707. }});
  708. App.store.load(App.HostComponent, {
  709. id: 'SECONDARY_NAMENODE_host1',
  710. component_name: 'SECONDARY_NAMENODE'
  711. });
  712. App.set('currentStackVersion', 'HDP-2.0.1');
  713. });
  714. it('hbase-site is present', function () {
  715. var configs = {'hbase-site': {}};
  716. expect(controller.setZKConfigs(configs, '', ['host1', 'host2'])).to.be.true;
  717. expect(configs).to.eql({"hbase-site": {
  718. "hbase.zookeeper.quorum": "host1,host2"
  719. }});
  720. });
  721. it('webhcat-site is present', function () {
  722. var configs = {'webhcat-site': {}};
  723. expect(controller.setZKConfigs(configs, 'host1:2181', [])).to.be.true;
  724. expect(configs).to.eql({"webhcat-site": {
  725. "templeton.zookeeper.hosts": "host1:2181"
  726. }});
  727. });
  728. it('storm-site is present', function () {
  729. var configs = {'storm-site': {}};
  730. expect(controller.setZKConfigs(configs, '', ["host1", 'host2'])).to.be.true;
  731. expect(configs).to.eql({"storm-site": {
  732. "storm.zookeeper.servers": "['host1','host2']"
  733. }});
  734. });
  735. });
  736. describe('#concatZkNames()', function () {
  737. it('No ZooKeeper hosts', function () {
  738. expect(controller.concatZkNames([])).to.equal('');
  739. });
  740. it('One ZooKeeper host', function () {
  741. expect(controller.concatZkNames(['host1'])).to.equal('host1:2181');
  742. });
  743. it('Two ZooKeeper hosts', function () {
  744. expect(controller.concatZkNames(['host1', 'host2'])).to.equal('host1:2181,host2:2181');
  745. });
  746. });
  747. describe('#getZkServerHosts()', function () {
  748. controller.set('content', {});
  749. it('No ZooKeeper hosts, fromDeleteHost = false', function () {
  750. App.HostComponent.find().clear();
  751. controller.set('fromDeleteHost', false);
  752. expect(controller.getZkServerHosts()).to.be.empty;
  753. });
  754. it('No ZooKeeper hosts, fromDeleteHost = true', function () {
  755. controller.set('fromDeleteHost', true);
  756. expect(controller.getZkServerHosts()).to.be.empty;
  757. expect(controller.get('fromDeleteHost')).to.be.false;
  758. });
  759. it('One ZooKeeper host, fromDeleteHost = false', function () {
  760. controller.set('fromDeleteHost', false);
  761. App.store.load(App.HostComponent, {
  762. id: 'ZOOKEEPER_SERVER_host1',
  763. component_name: 'ZOOKEEPER_SERVER',
  764. host_id: 'host1'
  765. });
  766. expect(controller.getZkServerHosts()).to.eql(['host1']);
  767. });
  768. it('One ZooKeeper host match current host name, fromDeleteHost = true', function () {
  769. controller.set('fromDeleteHost', true);
  770. controller.set('content.hostName', 'host1');
  771. expect(controller.getZkServerHosts()).to.be.empty;
  772. expect(controller.get('fromDeleteHost')).to.be.false;
  773. });
  774. it('One ZooKeeper host does not match current host name, fromDeleteHost = true', function () {
  775. controller.set('fromDeleteHost', true);
  776. controller.set('content.hostName', 'host2');
  777. expect(controller.getZkServerHosts()[0]).to.equal("host1");
  778. expect(controller.get('fromDeleteHost')).to.be.false;
  779. });
  780. });
  781. describe('#installComponent()', function () {
  782. beforeEach(function () {
  783. sinon.spy(App.ModalPopup, "show");
  784. sinon.stub(App.ajax, "send", Em.K);
  785. });
  786. afterEach(function () {
  787. App.ModalPopup.show.restore();
  788. App.ajax.send.restore();
  789. });
  790. it('popup should be displayed', function () {
  791. var event = {context: Em.Object.create()};
  792. var popup = controller.installComponent(event);
  793. expect(App.ModalPopup.show.calledOnce).to.be.true;
  794. popup.onPrimary();
  795. expect(App.ajax.send.calledOnce).to.be.true;
  796. });
  797. });
  798. describe('#decommission()', function () {
  799. beforeEach(function () {
  800. sinon.spy(App, "showConfirmationPopup");
  801. sinon.stub(controller, "runDecommission", Em.K);
  802. });
  803. afterEach(function () {
  804. App.showConfirmationPopup.restore();
  805. controller.runDecommission.restore();
  806. });
  807. it('popup should be displayed', function () {
  808. var popup = controller.decommission(Em.Object.create({service: {}}));
  809. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  810. popup.onPrimary();
  811. expect(controller.runDecommission.calledOnce).to.be.true;
  812. });
  813. });
  814. describe('#runDecommission()', function () {
  815. beforeEach(function () {
  816. sinon.stub(controller, "doDecommission", Em.K);
  817. sinon.stub(controller, "warnBeforeDecommission", Em.K);
  818. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  819. });
  820. afterEach(function () {
  821. controller.doDecommission.restore();
  822. controller.warnBeforeDecommission.restore();
  823. controller.showBackgroundOperationsPopup.restore();
  824. });
  825. it('HDFS service', function () {
  826. controller.runDecommission('host1', 'HDFS');
  827. expect(controller.doDecommission.calledWith('host1', 'HDFS', "NAMENODE", "DATANODE")).to.be.true;
  828. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  829. });
  830. it('YARN service', function () {
  831. controller.runDecommission('host1', 'YARN');
  832. expect(controller.doDecommission.calledWith('host1', 'YARN', "RESOURCEMANAGER", "NODEMANAGER")).to.be.true;
  833. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  834. });
  835. it('MAPREDUCE service', function () {
  836. controller.runDecommission('host1', 'MAPREDUCE');
  837. expect(controller.doDecommission.calledWith('host1', 'MAPREDUCE', "JOBTRACKER", "TASKTRACKER")).to.be.true;
  838. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  839. });
  840. it('HBASE service', function () {
  841. controller.runDecommission('host1', 'HBASE');
  842. expect(controller.warnBeforeDecommission.calledWith('host1', 'HBASE', "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
  843. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  844. });
  845. });
  846. describe('#runRecommission()', function () {
  847. beforeEach(function () {
  848. sinon.stub(controller, "doRecommissionAndStart", Em.K);
  849. sinon.stub(controller, "doRecommissionAndRestart", Em.K);
  850. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  851. });
  852. afterEach(function () {
  853. controller.doRecommissionAndStart.restore();
  854. controller.doRecommissionAndRestart.restore();
  855. controller.showBackgroundOperationsPopup.restore();
  856. });
  857. it('HDFS service', function () {
  858. controller.runRecommission('host1', 'HDFS');
  859. expect(controller.doRecommissionAndStart.calledWith('host1', 'HDFS', "NAMENODE", "DATANODE")).to.be.true;
  860. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  861. });
  862. it('YARN service', function () {
  863. controller.runRecommission('host1', 'YARN');
  864. expect(controller.doRecommissionAndStart.calledWith('host1', 'YARN', "RESOURCEMANAGER", "NODEMANAGER")).to.be.true;
  865. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  866. });
  867. it('MAPREDUCE service', function () {
  868. controller.runRecommission('host1', 'MAPREDUCE');
  869. expect(controller.doRecommissionAndRestart.calledWith('host1', 'MAPREDUCE', "JOBTRACKER", "TASKTRACKER")).to.be.true;
  870. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  871. });
  872. it('HBASE service', function () {
  873. controller.runRecommission('host1', 'HBASE');
  874. expect(controller.doRecommissionAndStart.calledWith('host1', 'HBASE', "HBASE_MASTER", "HBASE_REGIONSERVER")).to.be.true;
  875. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  876. });
  877. });
  878. describe('#doDecommission()', function () {
  879. beforeEach(function () {
  880. sinon.stub(App.ajax, "send", Em.K);
  881. });
  882. afterEach(function () {
  883. App.ajax.send.restore();
  884. });
  885. it('Query should be sent', function () {
  886. controller.doDecommission('', '', '', '');
  887. expect(App.ajax.send.calledOnce).to.be.true;
  888. });
  889. });
  890. describe('#doDecommissionRegionServer()', function () {
  891. beforeEach(function () {
  892. sinon.stub(App.ajax, "send", Em.K);
  893. });
  894. afterEach(function () {
  895. App.ajax.send.restore();
  896. });
  897. it('Query should be sent', function () {
  898. controller.doDecommissionRegionServer('', '', '', '');
  899. expect(App.ajax.send.calledOnce).to.be.true;
  900. });
  901. });
  902. /**
  903. * TODO uncomment test when final rules will be implemented into warnBeforeDecommission function
  904. */
  905. /* describe('#warnBeforeDecommission()', function () {
  906. beforeEach(function () {
  907. sinon.stub(controller, "doDecommissionRegionServer", Em.K);
  908. sinon.stub(App.ModalPopup, "show", Em.K);
  909. });
  910. afterEach(function () {
  911. App.ModalPopup.show.restore();
  912. controller.doDecommissionRegionServer.restore();
  913. });
  914. it('Component in passive state', function () {
  915. controller.set('content.hostComponents', [Em.Object.create({
  916. componentName: 'HBASE_REGIONSERVER',
  917. passiveState: 'ON'
  918. })]);
  919. controller.warnBeforeDecommission('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE');
  920. expect(App.ModalPopup.show.called).to.be.false;
  921. expect(controller.doDecommissionRegionServer.calledWith('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE')).to.be.true;
  922. });
  923. it('Component is not in passive state', function () {
  924. controller.set('content.hostComponents', [Em.Object.create({
  925. componentName: 'HBASE_REGIONSERVER',
  926. passiveState: 'OFF'
  927. })]);
  928. controller.warnBeforeDecommission('host1', 'HBASE', 'HBASE_REGIONSERVER', 'SLAVE');
  929. expect(App.ModalPopup.show.calledOnce).to.be.true;
  930. expect(controller.doDecommissionRegionServer.called).to.be.false;
  931. });
  932. });*/
  933. describe('#doRecommissionAndStart()', function () {
  934. beforeEach(function () {
  935. sinon.stub(App.ajax, "send", Em.K);
  936. });
  937. afterEach(function () {
  938. App.ajax.send.restore();
  939. });
  940. it('Query should be sent', function () {
  941. controller.doRecommissionAndStart('', '', '', '');
  942. expect(App.ajax.send.calledOnce).to.be.true;
  943. });
  944. });
  945. describe('#decommissionSuccessCallback()', function () {
  946. beforeEach(function () {
  947. sinon.stub(controller, "showBackgroundOperationsPopup", Em.K);
  948. });
  949. afterEach(function () {
  950. controller.showBackgroundOperationsPopup.restore();
  951. });
  952. it('data is null', function () {
  953. expect(controller.decommissionSuccessCallback(null)).to.be.false;
  954. expect(controller.showBackgroundOperationsPopup.called).to.be.false;
  955. });
  956. it('data has Requests', function () {
  957. var data = {Requests: []};
  958. expect(controller.decommissionSuccessCallback(data)).to.be.true;
  959. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  960. });
  961. it('data has resources', function () {
  962. var data = {resources: [{RequestSchedule: {}}]};
  963. expect(controller.decommissionSuccessCallback(data)).to.be.true;
  964. expect(controller.showBackgroundOperationsPopup.calledOnce).to.be.true;
  965. });
  966. });
  967. describe('#doRecommissionAndRestart()', function () {
  968. beforeEach(function () {
  969. sinon.stub(App.ajax, "send", Em.K);
  970. });
  971. afterEach(function () {
  972. App.ajax.send.restore();
  973. });
  974. it('Query should be sent', function () {
  975. controller.doRecommissionAndRestart('', '', '', '');
  976. expect(App.ajax.send.calledOnce).to.be.true;
  977. });
  978. });
  979. describe('#doAction()', function () {
  980. beforeEach(function () {
  981. sinon.stub(controller, "validateAndDeleteHost", Em.K);
  982. sinon.stub(controller, "doStartAllComponents", Em.K);
  983. sinon.stub(controller, "doStopAllComponents", Em.K);
  984. sinon.stub(controller, "doRestartAllComponents", Em.K);
  985. sinon.stub(controller, "onOffPassiveModeForHost", Em.K);
  986. });
  987. afterEach(function () {
  988. controller.validateAndDeleteHost.restore();
  989. controller.doStartAllComponents.restore();
  990. controller.doStopAllComponents.restore();
  991. controller.doRestartAllComponents.restore();
  992. controller.onOffPassiveModeForHost.restore();
  993. });
  994. it('"deleteHost" action', function () {
  995. var option = {context: {action: "deleteHost"}};
  996. controller.doAction(option);
  997. expect(controller.validateAndDeleteHost.calledOnce).to.be.true;
  998. });
  999. it('"startAllComponents" action, isNotHeartBeating = false', function () {
  1000. var option = {context: {action: "startAllComponents"}};
  1001. controller.set('content.isNotHeartBeating', false);
  1002. controller.doAction(option);
  1003. expect(controller.doStartAllComponents.calledOnce).to.be.true;
  1004. });
  1005. it('"startAllComponents" action, isNotHeartBeating = true', function () {
  1006. var option = {context: {action: "startAllComponents"}};
  1007. controller.set('content.isNotHeartBeating', true);
  1008. controller.doAction(option);
  1009. expect(controller.doStartAllComponents.called).to.be.false;
  1010. });
  1011. it('"stopAllComponents" action, isNotHeartBeating = false', function () {
  1012. var option = {context: {action: "stopAllComponents"}};
  1013. controller.set('content.isNotHeartBeating', false);
  1014. controller.doAction(option);
  1015. expect(controller.doStopAllComponents.calledOnce).to.be.true;
  1016. });
  1017. it('"stopAllComponents" action, isNotHeartBeating = true', function () {
  1018. var option = {context: {action: "stopAllComponents"}};
  1019. controller.set('content.isNotHeartBeating', true);
  1020. controller.doAction(option);
  1021. expect(controller.doStopAllComponents.called).to.be.false;
  1022. });
  1023. it('"restartAllComponents" action, isNotHeartBeating = false', function () {
  1024. var option = {context: {action: "restartAllComponents"}};
  1025. controller.set('content.isNotHeartBeating', false);
  1026. controller.doAction(option);
  1027. expect(controller.doRestartAllComponents.calledOnce).to.be.true;
  1028. });
  1029. it('"restartAllComponents" action, isNotHeartBeating = true', function () {
  1030. var option = {context: {action: "restartAllComponents"}};
  1031. controller.set('content.isNotHeartBeating', true);
  1032. controller.doAction(option);
  1033. expect(controller.doRestartAllComponents.called).to.be.false;
  1034. });
  1035. it('"onOffPassiveModeForHost" action', function () {
  1036. var option = {context: {action: "onOffPassiveModeForHost"}};
  1037. controller.doAction(option);
  1038. expect(controller.onOffPassiveModeForHost.calledWith({action: "onOffPassiveModeForHost"})).to.be.true;
  1039. });
  1040. });
  1041. describe('#onOffPassiveModeForHost()', function () {
  1042. beforeEach(function () {
  1043. sinon.spy(App, "showConfirmationPopup");
  1044. sinon.stub(controller, "hostPassiveModeRequest", Em.K);
  1045. });
  1046. afterEach(function () {
  1047. App.showConfirmationPopup.restore();
  1048. controller.hostPassiveModeRequest.restore();
  1049. });
  1050. it('popup should be displayed, active = true', function () {
  1051. var popup = controller.onOffPassiveModeForHost({active: true});
  1052. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1053. popup.onPrimary();
  1054. expect(controller.hostPassiveModeRequest.calledWith('ON')).to.be.true;
  1055. });
  1056. it('popup should be displayed, active = false', function () {
  1057. var popup = controller.onOffPassiveModeForHost({active: false});
  1058. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1059. popup.onPrimary();
  1060. expect(controller.hostPassiveModeRequest.calledWith('OFF')).to.be.true;
  1061. });
  1062. });
  1063. describe('#hostPassiveModeRequest()', function () {
  1064. beforeEach(function () {
  1065. sinon.stub(App.ajax, "send", Em.K);
  1066. });
  1067. afterEach(function () {
  1068. App.ajax.send.restore();
  1069. });
  1070. it('Query should be sent', function () {
  1071. controller.hostPassiveModeRequest('', '');
  1072. expect(App.ajax.send.calledOnce).to.be.true;
  1073. });
  1074. });
  1075. describe('#doStartAllComponents()', function () {
  1076. beforeEach(function () {
  1077. sinon.stub(App, "showConfirmationPopup", Em.K);
  1078. sinon.stub(controller, "sendStartComponentCommand", Em.K);
  1079. });
  1080. afterEach(function () {
  1081. App.showConfirmationPopup.restore();
  1082. controller.sendStartComponentCommand.restore();
  1083. });
  1084. it('serviceNonClientActiveComponents is null', function () {
  1085. controller.reopen({
  1086. serviceNonClientActiveComponents: []
  1087. });
  1088. controller.set('serviceNonClientActiveComponents', null);
  1089. controller.doStartAllComponents();
  1090. expect(App.showConfirmationPopup.called).to.be.false;
  1091. });
  1092. it('serviceNonClientActiveComponents is empty', function () {
  1093. controller.set('serviceNonClientActiveComponents', []);
  1094. controller.doStartAllComponents();
  1095. expect(App.showConfirmationPopup.called).to.be.false;
  1096. });
  1097. it('serviceNonClientActiveComponents is correct', function () {
  1098. controller.set('serviceNonClientActiveComponents', [{}]);
  1099. var popup = controller.doStartAllComponents();
  1100. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1101. /*popup.onPrimary();
  1102. expect(controller.sendStartComponentCommand.calledWith([{}])).to.be.true;*/
  1103. });
  1104. });
  1105. describe('#doStopAllComponents()', function () {
  1106. beforeEach(function () {
  1107. sinon.stub(App, "showConfirmationPopup", Em.K);
  1108. sinon.stub(controller, "sendStartComponentCommand", Em.K);
  1109. });
  1110. afterEach(function () {
  1111. App.showConfirmationPopup.restore();
  1112. controller.sendStartComponentCommand.restore();
  1113. });
  1114. it('serviceNonClientActiveComponents is null', function () {
  1115. controller.set('serviceNonClientActiveComponents', null);
  1116. controller.doStopAllComponents();
  1117. expect(App.showConfirmationPopup.called).to.be.false;
  1118. });
  1119. it('serviceNonClientActiveComponents is empty', function () {
  1120. controller.set('serviceNonClientActiveComponents', []);
  1121. controller.doStopAllComponents();
  1122. expect(App.showConfirmationPopup.called).to.be.false;
  1123. });
  1124. it('serviceNonClientActiveComponents is correct', function () {
  1125. controller.set('serviceNonClientActiveComponents', [{}]);
  1126. var popup = controller.doStopAllComponents();
  1127. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1128. /*popup.onPrimary();
  1129. expect(controller.sendStopComponentCommand.calledWith([{}])).to.be.true;*/
  1130. });
  1131. });
  1132. describe('#doRestartAllComponents()', function () {
  1133. beforeEach(function () {
  1134. sinon.stub(App, "showConfirmationPopup", Em.K);
  1135. sinon.stub(controller, "sendStartComponentCommand", Em.K);
  1136. });
  1137. afterEach(function () {
  1138. App.showConfirmationPopup.restore();
  1139. controller.sendStartComponentCommand.restore();
  1140. });
  1141. it('serviceActiveComponents is null', function () {
  1142. controller.set('serviceActiveComponents', null);
  1143. controller.doRestartAllComponents();
  1144. expect(App.showConfirmationPopup.called).to.be.false;
  1145. });
  1146. it('serviceActiveComponents is empty', function () {
  1147. controller.set('serviceActiveComponents', []);
  1148. controller.doRestartAllComponents();
  1149. expect(App.showConfirmationPopup.called).to.be.false;
  1150. });
  1151. it('serviceActiveComponents is correct', function () {
  1152. controller.set('serviceActiveComponents', [{}]);
  1153. var popup = controller.doRestartAllComponents();
  1154. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1155. /*popup.onPrimary();
  1156. expect(controller.restartHostComponents.calledWith([{}])).to.be.true;*/
  1157. });
  1158. });
  1159. describe('#getHostComponentsInfo()', function () {
  1160. var result = {
  1161. zkServerInstalled: false,
  1162. lastComponents: [],
  1163. masterComponents: [],
  1164. runningComponents: [],
  1165. nonDeletableComponents: [],
  1166. unknownComponents: []
  1167. };
  1168. it('content.hostComponents is null', function () {
  1169. controller.set('content.hostComponents', null);
  1170. expect(controller.getHostComponentsInfo()).to.eql(result);
  1171. });
  1172. it('content.hostComponents is empty', function () {
  1173. controller.set('content.hostComponents', []);
  1174. expect(controller.getHostComponentsInfo()).to.eql(result);
  1175. });
  1176. it('content.hostComponents has ZOOKEEPER_SERVER', function () {
  1177. App.HostComponent.find().clear();
  1178. controller.set('content.hostComponents', [Em.Object.create({
  1179. componentName: 'ZOOKEEPER_SERVER',
  1180. workStatus: 'INIT',
  1181. isDeletable: true
  1182. })]);
  1183. expect(controller.getHostComponentsInfo().zkServerInstalled).to.be.true;
  1184. });
  1185. it('content.hostComponents has last component', function () {
  1186. App.store.load(App.HostComponent, {
  1187. id: 'TASKTRACKER_host1',
  1188. component_name: 'TASKTRACKER'
  1189. });
  1190. controller.set('content.hostComponents', [Em.Object.create({
  1191. componentName: 'TASKTRACKER',
  1192. displayName: 'TaskTracker',
  1193. workStatus: 'INIT',
  1194. isDeletable: true
  1195. })]);
  1196. expect(controller.getHostComponentsInfo().lastComponents).to.eql(['TaskTracker']);
  1197. App.HostComponent.find().clear();
  1198. });
  1199. it('content.hostComponents has master non-deletable component', function () {
  1200. controller.set('content.hostComponents', [Em.Object.create({
  1201. componentName: 'TASKTRACKER',
  1202. workStatus: 'INIT',
  1203. isDeletable: false,
  1204. isMaster: true,
  1205. displayName: 'ZK1'
  1206. })]);
  1207. expect(controller.getHostComponentsInfo().masterComponents).to.eql(['ZK1']);
  1208. expect(controller.getHostComponentsInfo().nonDeletableComponents).to.eql(['ZK1']);
  1209. });
  1210. it('content.hostComponents has running component', function () {
  1211. controller.set('content.hostComponents', [Em.Object.create({
  1212. componentName: 'TASKTRACKER',
  1213. workStatus: 'STARTED',
  1214. isDeletable: true,
  1215. displayName: 'ZK1'
  1216. })]);
  1217. expect(controller.getHostComponentsInfo().runningComponents).to.eql(['ZK1']);
  1218. });
  1219. it('content.hostComponents has non-deletable component', function () {
  1220. controller.set('content.hostComponents', [Em.Object.create({
  1221. componentName: 'TASKTRACKER',
  1222. workStatus: 'INIT',
  1223. isDeletable: false,
  1224. displayName: 'ZK1'
  1225. })]);
  1226. expect(controller.getHostComponentsInfo().nonDeletableComponents).to.eql(['ZK1']);
  1227. });
  1228. it('content.hostComponents has component with UNKNOWN state', function () {
  1229. controller.set('content.hostComponents', [Em.Object.create({
  1230. componentName: 'TASKTRACKER',
  1231. workStatus: 'UNKNOWN',
  1232. isDeletable: false,
  1233. displayName: 'ZK1'
  1234. })]);
  1235. expect(controller.getHostComponentsInfo().unknownComponents).to.eql(['ZK1']);
  1236. });
  1237. });
  1238. describe('#validateAndDeleteHost()', function () {
  1239. beforeEach(function () {
  1240. sinon.stub(App, "showConfirmationPopup", Em.K);
  1241. sinon.stub(controller, "getHostComponentsInfo", function(){
  1242. return this.get('mockHostComponentsInfo');
  1243. });
  1244. sinon.stub(controller, "raiseDeleteComponentsError", Em.K);
  1245. sinon.stub(controller, "_doDeleteHost", Em.K);
  1246. });
  1247. afterEach(function () {
  1248. App.showConfirmationPopup.restore();
  1249. controller.getHostComponentsInfo.restore();
  1250. controller.raiseDeleteComponentsError.restore();
  1251. controller._doDeleteHost.restore();
  1252. });
  1253. it('App.supports.deleteHost = false', function () {
  1254. App.supports.deleteHost = false;
  1255. expect(controller.validateAndDeleteHost()).to.be.false;
  1256. App.supports.deleteHost = true;
  1257. });
  1258. it('masterComponents exist', function () {
  1259. controller.set('mockHostComponentsInfo', {masterComponents: [{}]});
  1260. controller.validateAndDeleteHost();
  1261. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'masterList')).to.be.true;
  1262. });
  1263. it('nonDeletableComponents exist', function () {
  1264. controller.set('mockHostComponentsInfo', {
  1265. masterComponents: [],
  1266. nonDeletableComponents: [{}]
  1267. });
  1268. controller.validateAndDeleteHost();
  1269. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'nonDeletableList')).to.be.true;
  1270. });
  1271. it('runningComponents exist', function () {
  1272. controller.set('mockHostComponentsInfo', {
  1273. masterComponents: [],
  1274. nonDeletableComponents: [],
  1275. runningComponents: [{}]
  1276. });
  1277. controller.validateAndDeleteHost();
  1278. expect(controller.raiseDeleteComponentsError.calledWith([{}], 'runningList')).to.be.true;
  1279. });
  1280. it('zkServerInstalled = true', function () {
  1281. controller.set('mockHostComponentsInfo', {
  1282. masterComponents: [],
  1283. nonDeletableComponents: [],
  1284. runningComponents: [],
  1285. unknownComponents: [],
  1286. lastComponents: [],
  1287. zkServerInstalled: true
  1288. });
  1289. var popup = controller.validateAndDeleteHost();
  1290. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1291. /* popup.onPrimary();
  1292. expect(controller._doDeleteHost.calledWith([], [])).to.be.true;*/
  1293. });
  1294. it('zkServerInstalled = false', function () {
  1295. controller.set('mockHostComponentsInfo', {
  1296. masterComponents: [],
  1297. nonDeletableComponents: [],
  1298. runningComponents: [],
  1299. unknownComponents: [],
  1300. lastComponents: [],
  1301. zkServerInstalled: false
  1302. });
  1303. controller.validateAndDeleteHost();
  1304. expect(controller._doDeleteHost.calledWith([], [])).to.be.true;
  1305. });
  1306. });
  1307. describe('#raiseDeleteComponentsError()', function () {
  1308. beforeEach(function () {
  1309. sinon.stub(App.ModalPopup, "show", Em.K);
  1310. });
  1311. afterEach(function () {
  1312. App.ModalPopup.show.restore();
  1313. });
  1314. it('Popup should be displayed', function () {
  1315. controller.raiseDeleteComponentsError([], '');
  1316. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1317. });
  1318. });
  1319. describe('#_doDeleteHost()', function () {
  1320. beforeEach(function () {
  1321. sinon.stub(App.ModalPopup, "show", Em.K);
  1322. });
  1323. afterEach(function () {
  1324. App.ModalPopup.show.restore();
  1325. });
  1326. it('Popup should be displayed', function () {
  1327. controller._doDeleteHost([], []);
  1328. expect(App.ModalPopup.show.calledOnce).to.be.true;
  1329. });
  1330. });
  1331. describe('#restartAllStaleConfigComponents()', function () {
  1332. beforeEach(function () {
  1333. sinon.spy(App, "showConfirmationPopup");
  1334. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  1335. });
  1336. afterEach(function () {
  1337. App.showConfirmationPopup.restore();
  1338. batchUtils.restartHostComponents.restore();
  1339. });
  1340. it('popup should be displayed', function () {
  1341. controller.set('content.componentsWithStaleConfigs', [{}]);
  1342. var popup = controller.restartAllStaleConfigComponents();
  1343. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1344. popup.onPrimary();
  1345. expect(batchUtils.restartHostComponents.calledWith([{}])).to.be.true;
  1346. });
  1347. });
  1348. describe('#moveComponent()', function () {
  1349. beforeEach(function () {
  1350. sinon.spy(App, "showConfirmationPopup");
  1351. });
  1352. afterEach(function () {
  1353. App.showConfirmationPopup.restore();
  1354. });
  1355. it('popup should be displayed', function () {
  1356. var popup = controller.moveComponent();
  1357. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1358. });
  1359. });
  1360. describe('#refreshConfigs()', function () {
  1361. beforeEach(function () {
  1362. sinon.spy(App, "showConfirmationPopup");
  1363. sinon.stub(batchUtils, "restartHostComponents", Em.K);
  1364. });
  1365. afterEach(function () {
  1366. App.showConfirmationPopup.restore();
  1367. batchUtils.restartHostComponents.restore();
  1368. });
  1369. it('No components', function () {
  1370. var event = {context: []};
  1371. controller.refreshConfigs(event);
  1372. expect(App.showConfirmationPopup.called).to.be.false;
  1373. });
  1374. it('No components with stale configs', function () {
  1375. var event = {context: [Em.Object.create({
  1376. staleConfigs: false
  1377. })]};
  1378. controller.refreshConfigs(event);
  1379. expect(App.showConfirmationPopup.called).to.be.false;
  1380. });
  1381. it('Components with stale configs', function () {
  1382. var event = {context: [Em.Object.create({
  1383. staleConfigs: true
  1384. })]};
  1385. var popup = controller.refreshConfigs(event);
  1386. expect(App.showConfirmationPopup.calledOnce).to.be.true;
  1387. popup.onPrimary();
  1388. expect(batchUtils.restartHostComponents.calledWith([Em.Object.create({
  1389. staleConfigs: true
  1390. })])).to.be.true;
  1391. });
  1392. });
  1393. });