rollback_controller_test.js 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898
  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. var testHelpers = require('test/helpers');
  20. describe('App.HighAvailabilityRollbackController', function () {
  21. var controller;
  22. var masterComponentHosts = [
  23. {
  24. component: 'NAMENODE',
  25. isInstalled: true,
  26. hostName: 'host1'
  27. },
  28. {
  29. component: 'NAMENODE',
  30. isInstalled: false,
  31. hostName: 'host2'
  32. },
  33. {
  34. component: 'SECONDARY_NAMENODE',
  35. isInstalled: false,
  36. hostName: 'host2'
  37. },
  38. {
  39. component: 'JORNALNODE',
  40. isInstalled: false,
  41. hostName: 'host2'
  42. }
  43. ];
  44. beforeEach(function() {
  45. controller = App.HighAvailabilityRollbackController.create({
  46. popup: {
  47. proceedOnClose: Em.K
  48. },
  49. saveLogs: Em.K
  50. });
  51. });
  52. describe('#loadStep()', function() {
  53. var initData = false;
  54. var clearStep = false;
  55. var loadTasks = false;
  56. var addObserver = false;
  57. var onTaskStatusChange = false;
  58. var checker = {
  59. initData: function () {
  60. initData = true;
  61. return $.Deferred().resolve().promise();
  62. },
  63. clearStep: function () {
  64. clearStep = true;
  65. },
  66. loadTasks: function () {
  67. loadTasks = true;
  68. },
  69. addObserver: function () {
  70. addObserver = true;
  71. },
  72. onTaskStatusChange: function () {
  73. onTaskStatusChange = true;
  74. }
  75. };
  76. beforeEach(function () {
  77. controller.loadStep.call(checker);
  78. });
  79. it('data is initialized', function () {
  80. expect(initData).to.be.true;
  81. });
  82. it('step is cleared', function () {
  83. expect(clearStep).to.be.true;
  84. });
  85. it('tasks are loaded', function () {
  86. expect(loadTasks).to.be.true;
  87. });
  88. it('observer is added', function () {
  89. expect(addObserver).to.be.true;
  90. });
  91. it('status is changed', function () {
  92. expect(onTaskStatusChange).to.be.true;
  93. });
  94. });
  95. describe('#initData()', function() {
  96. var loadMasterComponentHosts = false;
  97. var loadFailedTask = false;
  98. var loadHdfsClientHosts = false;
  99. var checker = {
  100. loadMasterComponentHosts: function () {
  101. loadMasterComponentHosts = true;
  102. return $.Deferred().resolve().promise();
  103. },
  104. loadFailedTask: function () {
  105. loadFailedTask = true;
  106. },
  107. loadHdfsClientHosts: function () {
  108. loadHdfsClientHosts = true;
  109. }
  110. };
  111. beforeEach(function () {
  112. controller.initData.call(checker);
  113. });
  114. it('master component hosts are loaded', function () {
  115. expect(loadMasterComponentHosts).to.be.true;
  116. });
  117. it('failed tasks are loaded', function () {
  118. expect(loadFailedTask).to.be.true;
  119. });
  120. it('hdfs client hosts are loaded', function () {
  121. expect(loadHdfsClientHosts).to.be.true;
  122. });
  123. });
  124. describe('#skipTask()', function() {
  125. it('should skip task', function () {
  126. controller.set('tasks', [
  127. Em.Object.create({
  128. id: 'task1',
  129. status: 'FAILED',
  130. showRetry: true,
  131. showSkip: true
  132. })
  133. ]);
  134. controller.skipTask();
  135. expect(controller.get('tasks').findProperty('id', 'task1')).to.eql(Em.Object.create({
  136. id: 'task1',
  137. status: 'COMPLETED',
  138. showRetry: false,
  139. showSkip: false
  140. }));
  141. });
  142. });
  143. describe('#retryTask()', function() {
  144. it('should skip task', function () {
  145. controller.set('tasks', [
  146. Em.Object.create({
  147. id: 'task1',
  148. status: 'FAILED',
  149. showRetry: true,
  150. showSkip: true
  151. })
  152. ]);
  153. controller.retryTask();
  154. expect(controller.get('tasks').findProperty('id', 'task1')).to.eql(Em.Object.create({
  155. id: 'task1',
  156. status: 'PENDING',
  157. showRetry: false,
  158. showSkip: false
  159. }));
  160. });
  161. });
  162. describe('#onTaskCompleted()', function() {
  163. beforeEach(function () {
  164. sinon.stub(controller, 'getTaskStatus');
  165. sinon.stub(controller, 'setTaskStatus');
  166. });
  167. afterEach(function () {
  168. controller.getTaskStatus.restore();
  169. controller.setTaskStatus.restore();
  170. });
  171. it('should set task status', function () {
  172. controller.set('currentTaskId', 'task1');
  173. controller.onTaskCompleted();
  174. expect(controller.getTaskStatus.calledWith('task1')).to.be.true;
  175. expect(controller.setTaskStatus.calledWith('task1', 'COMPLETED')).to.be.true;
  176. });
  177. });
  178. describe('#getTaskStatus()', function() {
  179. it('should skip task', function () {
  180. controller.set('tasks', [
  181. Em.Object.create({
  182. id: 'task1',
  183. status: 'FAILED'
  184. })
  185. ]);
  186. controller.set('currentTaskId', 'task1');
  187. expect(controller.getTaskStatus('task1')).to.equal('FAILED');
  188. });
  189. });
  190. describe('#loadFailedTask()', function() {
  191. beforeEach(function () {
  192. sinon.stub(App.db, 'getHighAvailabilityWizardFailedTask').returns({id: 'task1'});
  193. });
  194. afterEach(function () {
  195. App.db.getHighAvailabilityWizardFailedTask.restore();
  196. });
  197. it('should load failed task', function () {
  198. controller.loadFailedTask();
  199. expect(controller.get('failedTask')).to.eql({id: 'task1'});
  200. });
  201. });
  202. describe('#loadFailedTask()', function() {
  203. beforeEach(function () {
  204. sinon.stub(controller, 'removeObserver');
  205. sinon.stub(controller.popup, 'proceedOnClose');
  206. });
  207. afterEach(function () {
  208. controller.removeObserver.restore();
  209. controller.popup.proceedOnClose.restore();
  210. });
  211. it('should remove observer and proceed', function () {
  212. controller.set('isSubmitDisabled', false);
  213. controller.done();
  214. expect(controller.removeObserver.calledOnce).to.be.true;
  215. expect(controller.popup.proceedOnClose.calledOnce).to.be.true;
  216. });
  217. });
  218. describe('#stopAllServices()', function() {
  219. it('should skip task', function () {
  220. controller.stopAllServices();
  221. var args = testHelpers.findAjaxRequest('name', 'common.services.update');
  222. expect(args).to.exists;
  223. });
  224. });
  225. describe('#restoreHBaseConfigs()', function() {
  226. beforeEach(function () {
  227. sinon.stub(controller, 'loadConfigTag');
  228. });
  229. afterEach(function () {
  230. controller.loadConfigTag.restore();
  231. });
  232. it('should restore hbase configs', function () {
  233. controller.set('content.hbaseSiteTag', 'v1');
  234. controller.restoreHBaseConfigs();
  235. var args = testHelpers.findAjaxRequest('name', 'admin.high_availability.load_hbase_configs');
  236. expect(args[0].data.hbaseSiteTag).to.equal('v1');
  237. });
  238. });
  239. describe('#restoreAccumuloConfigs()', function() {
  240. beforeEach(function () {
  241. sinon.stub(controller, 'loadConfigTag');
  242. });
  243. afterEach(function () {
  244. controller.loadConfigTag.restore();
  245. });
  246. it('should restore accumulo configs', function () {
  247. controller.set('content.accumuloSiteTag', 'v1');
  248. controller.restoreAccumuloConfigs();
  249. var args = testHelpers.findAjaxRequest('name', 'admin.high_availability.load_accumulo_configs');
  250. expect(args[0].data.accumuloSiteTag).to.equal('v1');
  251. });
  252. });
  253. describe('#restoreHawqConfigs()', function() {
  254. beforeEach(function () {
  255. sinon.stub(controller, 'loadConfigTag');
  256. });
  257. afterEach(function () {
  258. controller.loadConfigTag.restore();
  259. });
  260. it('should restore hawq configs', function () {
  261. controller.set('content.hawqSiteTag', 'v1');
  262. controller.set('content.hdfsClientTag', 'v2');
  263. controller.restoreHawqConfigs();
  264. var args = testHelpers.filterAjaxRequests('name', 'admin.high_availability.load_hawq_configs');
  265. expect(args[0][0].data.tagName).to.equal('v1');
  266. expect(args[1][0].data.tagName).to.equal('v2');
  267. });
  268. });
  269. describe('#stopFailoverControllers()', function() {
  270. beforeEach(function () {
  271. sinon.stub(controller, 'updateComponent');
  272. });
  273. afterEach(function () {
  274. controller.updateComponent.restore();
  275. });
  276. it('should execute stopFailoverControllers function', function () {
  277. controller.set('content.masterComponentHosts', masterComponentHosts);
  278. controller.stopFailoverControllers();
  279. expect(controller.updateComponent.calledOnce).to.be.true;
  280. });
  281. });
  282. describe('#deleteFailoverControllers()', function() {
  283. beforeEach(function () {
  284. sinon.stub(controller, 'checkBeforeDelete');
  285. });
  286. afterEach(function () {
  287. controller.checkBeforeDelete.restore();
  288. });
  289. it('should execute checkBeforeDelete function', function () {
  290. controller.set('content.masterComponentHosts', masterComponentHosts);
  291. controller.deleteFailoverControllers();
  292. expect(controller.checkBeforeDelete.calledOnce).to.be.true;
  293. });
  294. });
  295. describe('#stopStandbyNameNode()', function() {
  296. beforeEach(function () {
  297. sinon.stub(controller, 'updateComponent');
  298. });
  299. afterEach(function () {
  300. controller.updateComponent.restore();
  301. });
  302. it('should execute updateComponent function', function () {
  303. controller.set('content.masterComponentHosts', masterComponentHosts);
  304. controller.stopStandbyNameNode();
  305. expect(controller.updateComponent.calledOnce).to.be.true;
  306. });
  307. });
  308. describe('#stopNameNode()', function() {
  309. beforeEach(function () {
  310. sinon.stub(controller, 'updateComponent');
  311. });
  312. afterEach(function () {
  313. controller.updateComponent.restore();
  314. });
  315. it('should execute updateComponent function', function () {
  316. controller.set('content.masterComponentHosts', masterComponentHosts);
  317. controller.stopNameNode();
  318. expect(controller.updateComponent.calledOnce).to.be.true;
  319. });
  320. });
  321. describe('#restoreHDFSConfigs()', function() {
  322. beforeEach(function () {
  323. sinon.stub(controller, 'unInstallHDFSClients');
  324. });
  325. afterEach(function () {
  326. controller.unInstallHDFSClients.restore();
  327. });
  328. it('should execute restoreHDFSConfigs function', function () {
  329. controller.restoreHDFSConfigs();
  330. expect(controller.unInstallHDFSClients.calledOnce).to.be.true;
  331. });
  332. });
  333. describe('#enableSecondaryNameNode()', function() {
  334. beforeEach(function () {
  335. sinon.stub(controller, 'updateComponent');
  336. });
  337. afterEach(function () {
  338. controller.updateComponent.restore();
  339. });
  340. it('should execute updateComponent function', function () {
  341. controller.set('content.masterComponentHosts', masterComponentHosts);
  342. controller.enableSecondaryNameNode();
  343. expect(controller.updateComponent.calledOnce).to.be.true;
  344. });
  345. });
  346. describe('#stopJournalNodes()', function() {
  347. beforeEach(function () {
  348. sinon.stub(controller, 'updateComponent');
  349. });
  350. afterEach(function () {
  351. controller.updateComponent.restore();
  352. });
  353. it('should execute updateComponent function', function () {
  354. controller.set('content.masterComponentHosts', masterComponentHosts);
  355. controller.stopJournalNodes();
  356. expect(controller.updateComponent.calledOnce).to.be.true;
  357. });
  358. });
  359. describe('#deleteJournalNodes()', function() {
  360. beforeEach(function () {
  361. sinon.stub(controller, 'unInstallComponent');
  362. });
  363. afterEach(function () {
  364. controller.unInstallComponent.restore();
  365. });
  366. it('should execute unInstallComponent function', function () {
  367. controller.set('content.masterComponentHosts', masterComponentHosts);
  368. controller.deleteJournalNodes();
  369. expect(controller.unInstallComponent.calledOnce).to.be.true;
  370. });
  371. });
  372. describe.skip('#deleteAdditionalNameNode()', function() {
  373. beforeEach(function () {
  374. sinon.stub(controller, 'unInstallComponent');
  375. });
  376. afterEach(function () {
  377. controller.unInstallComponent.restore();
  378. });
  379. it('should execute unInstallComponent function', function () {
  380. controller.set('content.masterComponentHosts', masterComponentHosts);
  381. controller.deleteAdditionalNameNode();
  382. expect(controller.unInstallComponent.calledOnce).to.be.true;
  383. });
  384. });
  385. describe('#startAllServices()', function() {
  386. it('should start all services', function () {
  387. controller.startAllServices();
  388. var args = testHelpers.findAjaxRequest('name', 'common.services.update');
  389. expect(args).to.exists;
  390. });
  391. });
  392. describe('#onLoadHbaseConfigs()', function() {
  393. it('should make ajax send request', function () {
  394. var data = {
  395. items: [
  396. {
  397. type: 'hbase-site',
  398. properties: {}
  399. }
  400. ]
  401. };
  402. controller.onLoadHbaseConfigs(data);
  403. var args = testHelpers.findAjaxRequest('name', 'admin.save_configs');
  404. expect(args).to.exists;
  405. });
  406. });
  407. describe('#onLoadAccumuloConfigs()', function() {
  408. it('should make ajax send request', function () {
  409. var data = {items: [
  410. {
  411. type: 'accumulo-site',
  412. properties: {}
  413. }
  414. ]};
  415. controller.onLoadAccumuloConfigs(data);
  416. var args = testHelpers.findAjaxRequest('name', 'admin.save_configs');
  417. expect(args).to.exists;
  418. });
  419. });
  420. describe('#onLoadHawqConfigs()', function() {
  421. it('should make ajax send request', function () {
  422. var data = {items: [
  423. {
  424. type: 'hawq-site',
  425. properties: {}
  426. }
  427. ]};
  428. controller.onLoadHawqConfigs(data);
  429. var args = testHelpers.findAjaxRequest('name', 'admin.save_configs');
  430. expect(args).to.exists;
  431. });
  432. });
  433. describe('#onDeletedHDFSClient()', function() {
  434. beforeEach(function () {
  435. sinon.stub(controller, 'loadConfigTag');
  436. });
  437. afterEach(function () {
  438. controller.loadConfigTag.restore();
  439. });
  440. it('should make ajax send request', function () {
  441. controller.set('deletedHdfsClients', 1);
  442. controller.set('content.hdfsClientHostNames', ['host1', 'host2']);
  443. controller.set('content.hdfsSiteTag', 'v1');
  444. controller.set('content.coreSiteTag', 'v2');
  445. controller.onDeletedHDFSClient();
  446. var args = testHelpers.findAjaxRequest('name', 'admin.high_availability.load_configs');
  447. expect(args[0].data).to.eql({
  448. hdfsSiteTag: 'v1',
  449. coreSiteTag: 'v2'
  450. });
  451. });
  452. it('should set deletedHdfsClients property', function () {
  453. controller.set('deletedHdfsClients', 0);
  454. controller.set('content.hdfsClientHostNames', ['host1', 'host2']);
  455. controller.onDeletedHDFSClient();
  456. expect(controller.get('deletedHdfsClients')).to.equal(1);
  457. });
  458. });
  459. describe('#onLoadConfigs()', function() {
  460. beforeEach(function () {
  461. sinon.stub(controller, 'loadConfigTag');
  462. });
  463. afterEach(function () {
  464. controller.loadConfigTag.restore();
  465. });
  466. it('should make 2 ajax send requests', function () {
  467. var data = {
  468. items: [
  469. {
  470. type: 'hdfs-site',
  471. properties: {}
  472. },
  473. {
  474. type: 'core-site',
  475. properties: {}
  476. }
  477. ]
  478. };
  479. controller.onLoadConfigs(data);
  480. var args = testHelpers.filterAjaxRequests('name', 'admin.save_configs');
  481. expect(args[0][0].data.siteName).to.equal('hdfs-site');
  482. expect(args[1][0].data.siteName).to.equal('core-site');
  483. });
  484. });
  485. describe('#onHdfsConfigsSaved()', function() {
  486. beforeEach(function () {
  487. sinon.stub(controller, 'onTaskCompleted');
  488. });
  489. afterEach(function () {
  490. controller.onTaskCompleted.restore();
  491. });
  492. it('should execute onTaskCompleted function', function () {
  493. controller.set('configsSaved', true);
  494. controller.onHdfsConfigsSaved();
  495. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  496. });
  497. it('should set configsSaved property to true', function () {
  498. controller.set('configsSaved', false);
  499. controller.onHdfsConfigsSaved();
  500. expect(controller.get('configsSaved')).to.be.true;
  501. });
  502. });
  503. describe('#unInstallHDFSClients()', function() {
  504. it('should make ajax send requests', function () {
  505. controller.set('content.hdfsClientHostNames', ['host1', 'host2']);
  506. controller.unInstallHDFSClients();
  507. var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
  508. expect(args.length).to.equal(2);
  509. });
  510. });
  511. describe('#unInstallComponent()', function() {
  512. it('should make ajax send request', function () {
  513. controller.unInstallComponent('comp1', 'host1');
  514. var args = testHelpers.findAjaxRequest('name', 'common.host.host_component.passive');
  515. expect(args[0].data).to.eql({
  516. hostName: 'host1',
  517. componentName: 'comp1',
  518. passive_state: "ON",
  519. taskNum: 1,
  520. callback: 'checkBeforeDelete'
  521. });
  522. });
  523. it('should make ajax send requests', function () {
  524. controller.unInstallComponent('comp1', ['host1', 'host2']);
  525. var args = testHelpers.filterAjaxRequests('name', 'common.host.host_component.passive');
  526. expect(args.length).to.equal(2);
  527. });
  528. });
  529. describe('#checkBeforeDelete()', function() {
  530. it('should make ajax send request', function () {
  531. controller.checkBeforeDelete('comp1', 'host1');
  532. var args = testHelpers.findAjaxRequest('name', 'admin.high_availability.getHostComponent');
  533. expect(controller.get('hostsToPerformDel')).to.eql([]);
  534. expect(args[0].data).to.eql({
  535. componentName: 'comp1',
  536. hostName: 'host1',
  537. taskNum: 1,
  538. callback: 'deleteComponent'
  539. });
  540. });
  541. it('should make ajax send requests', function () {
  542. controller.checkBeforeDelete('comp1', ['host1', 'host2']);
  543. var args = testHelpers.filterAjaxRequests('name', 'admin.high_availability.getHostComponent');
  544. expect(controller.get('hostsToPerformDel')).to.eql([]);
  545. expect(args.length).to.equal(2);
  546. });
  547. });
  548. describe('#checkResult()', function() {
  549. beforeEach(function () {
  550. sinon.stub(controller, 'deleteComponent');
  551. sinon.stub(controller, 'onTaskCompleted');
  552. });
  553. afterEach(function () {
  554. controller.deleteComponent.restore();
  555. controller.onTaskCompleted.restore();
  556. });
  557. it('should execute deleteComponent function', function () {
  558. controller.set('hostsToPerformDel', []);
  559. controller.checkResult({}, 'success', {
  560. componentName: 'comp1',
  561. hostName: 'host1',
  562. taskNum: 1,
  563. callback: 'deleteComponent'
  564. });
  565. expect(controller.deleteComponent.calledWith('comp1', ['host1'])).to.be.true;
  566. });
  567. it('should execute onTaskCompleted function', function () {
  568. controller.set('hostsToPerformDel', []);
  569. controller.checkResult({}, 'error', {
  570. componentName: 'comp1',
  571. hostName: 'host1',
  572. taskNum: 1,
  573. callback: 'deleteComponent'
  574. });
  575. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  576. });
  577. });
  578. describe('#deleteComponent()', function() {
  579. it('should make ajax send request', function () {
  580. controller.deleteComponent('comp1', 'host1');
  581. var args = testHelpers.findAjaxRequest('name', 'common.delete.host_component');
  582. expect(controller.get('numOfDelOperations')).to.equal(1);
  583. expect(args[0].data).to.eql({
  584. componentName: 'comp1',
  585. hostName: 'host1'
  586. });
  587. });
  588. it('should make ajax send requests', function () {
  589. controller.deleteComponent('comp1', ['host1', 'host2']);
  590. var args = testHelpers.filterAjaxRequests('name', 'common.delete.host_component');
  591. expect(controller.get('numOfDelOperations')).to.equal(2);
  592. expect(args.length).to.equal(2);
  593. });
  594. });
  595. describe('#onDeleteComplete()', function() {
  596. beforeEach(function () {
  597. sinon.stub(controller, 'onTaskCompleted');
  598. });
  599. afterEach(function () {
  600. controller.onTaskCompleted.restore();
  601. });
  602. it('should execute onTaskCompleted function', function () {
  603. controller.set('numOfDelOperations', 1);
  604. controller.onDeleteComplete();
  605. expect(controller.onTaskCompleted.calledOnce).to.be.true;
  606. });
  607. it('should set numOfDelOperations property', function () {
  608. controller.set('numOfDelOperations', 2);
  609. controller.onDeleteComplete();
  610. expect(controller.get('numOfDelOperations')).to.equal(1);
  611. });
  612. });
  613. describe.skip('#deletePXF()', function() {
  614. beforeEach(function () {
  615. this.mock = sinon.stub(controller, 'getSlaveComponentHosts');
  616. sinon.stub(controller, 'updateComponent');
  617. sinon.stub(controller, 'checkBeforeDelete');
  618. });
  619. afterEach(function () {
  620. this.mock.restore();
  621. controller.updateComponent.restore();
  622. controller.checkBeforeDelete.restore();
  623. });
  624. it('should remove PXF', function () {
  625. this.mock.returns([
  626. {
  627. componentName: 'PXF',
  628. hosts: [{hostName: 'host2'}]
  629. },
  630. {
  631. componentName: 'DATANODE',
  632. hosts: [{hostName: 'host1'}]
  633. }
  634. ]);
  635. controller.set('content.masterComponentHosts', masterComponentHosts);
  636. controller.deletePXF();
  637. expect(controller.updateComponent.calledOnce).to.be.true;
  638. expect(controller.checkBeforeDelete.calledOnce).to.be.true;
  639. });
  640. it('should not remove PXF', function () {
  641. this.mock.returns([
  642. {
  643. componentName: 'PXF',
  644. hosts: [{hostName: 'host1'}]
  645. },
  646. {
  647. componentName: 'DATANODE',
  648. hosts: [{hostName: 'host2'}]
  649. }
  650. ]);
  651. controller.set('content.masterComponentHosts', masterComponentHosts);
  652. controller.deletePXF();
  653. expect(controller.updateComponent.calledOnce).to.be.false;
  654. expect(controller.checkBeforeDelete.calledOnce).to.be.false;
  655. });
  656. });
  657. describe('#setCommandsAndTasks()', function() {
  658. beforeEach(function () {
  659. sinon.stub(App.Service, 'find').returns([]);
  660. });
  661. afterEach(function () {
  662. App.Service.find.restore();
  663. });
  664. it('should set tasks property', function () {
  665. var tmpTasks = [
  666. Em.Object.create({command: 'deleteSNameNode'}),
  667. Em.Object.create({command: 'startAllServices'}),
  668. Em.Object.create({command: 'reconfigureHBase'}),
  669. Em.Object.create({command: 'reconfigureAMS'}),
  670. Em.Object.create({command: 'reconfigureAccumulo'}),
  671. Em.Object.create({command: 'reconfigureHawq'}),
  672. Em.Object.create({command: 'installPXF'}),
  673. Em.Object.create({command: 'startZKFC'}),
  674. Em.Object.create({command: 'installZKFC'}),
  675. Em.Object.create({command: 'startSecondNameNode'}),
  676. Em.Object.create({command: 'startNameNode'}),
  677. Em.Object.create({command: 'startZooKeeperServers'}),
  678. Em.Object.create({command: 'reconfigureHDFS'}),
  679. Em.Object.create({command: 'disableSNameNode'}),
  680. Em.Object.create({command: 'startJournalNodes'}),
  681. Em.Object.create({command: 'installJournalNodes'}),
  682. Em.Object.create({command: 'installNameNode'}),
  683. Em.Object.create({command: 'stopAllServices'}),
  684. Em.Object.create({command: 'restoreHawqConfigs'}),
  685. Em.Object.create({command: 'restoreAccumuloConfigs'}),
  686. Em.Object.create({command: 'restoreHBaseConfigs'}),
  687. Em.Object.create({command: 'deletePXF'})
  688. ];
  689. controller.set('failedTask', {command: 'reconfigureHDFS'});
  690. controller.set('commands', []);
  691. controller.setCommandsAndTasks(tmpTasks);
  692. expect(controller.get('tasks').mapProperty('command').join(', ')).to.equal('startZooKeeperServers, reconfigureHDFS, disableSNameNode, startJournalNodes, installJournalNodes, installNameNode, stopAllServices');
  693. });
  694. });
  695. describe('#clearStep()', function() {
  696. beforeEach(function () {
  697. sinon.stub(controller, 'setCommandsAndTasks').returns([]);
  698. });
  699. afterEach(function () {
  700. controller.setCommandsAndTasks.restore();
  701. });
  702. it('should clear step', function () {
  703. controller.set('commands', ['deletePXF']);
  704. controller.clearStep();
  705. expect(controller.get('isSubmitDisabled')).to.be.true;
  706. expect(controller.get('tasks')).to.eql([]);
  707. expect(controller.get('logs')).to.eql([]);
  708. expect(controller.get('currentRequestIds')).to.eql([]);
  709. expect(controller.setCommandsAndTasks.calledOnce).to.be.true;
  710. });
  711. });
  712. describe('#onTaskStatusChange()', function() {
  713. beforeEach(function () {
  714. sinon.stub(controller, 'setTaskStatus');
  715. sinon.stub(controller, 'runTask');
  716. sinon.stub(controller, 'saveTasksStatuses');
  717. sinon.stub(controller, 'saveRequestIds');
  718. sinon.stub(controller, 'saveLogs');
  719. sinon.stub(App.clusterStatus, 'setClusterStatus');
  720. });
  721. afterEach(function () {
  722. controller.setTaskStatus.restore();
  723. controller.runTask.restore();
  724. controller.saveTasksStatuses.restore();
  725. controller.saveRequestIds.restore();
  726. controller.saveLogs.restore();
  727. App.clusterStatus.setClusterStatus.restore();
  728. });
  729. it('should set cluster status{1}', function () {
  730. controller.set('tasks', [
  731. Em.Object.create({status: 'FAILED'})
  732. ]);
  733. controller.onTaskStatusChange();
  734. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  735. });
  736. it('should set cluster status{2}', function () {
  737. controller.onTaskStatusChange();
  738. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  739. });
  740. it('should set cluster status{3}', function () {
  741. controller.set('tasks', [
  742. Em.Object.create({status: 'PENDING'})
  743. ]);
  744. controller.onTaskStatusChange();
  745. expect(App.clusterStatus.setClusterStatus.calledOnce).to.be.true;
  746. });
  747. });
  748. });