app_test.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  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('views/common/quick_view_link_view');
  20. require('models/host_component');
  21. require('models/stack_service_component');
  22. var modelSetup = require('test/init_model_test');
  23. describe('App', function () {
  24. describe('#stackVersionURL', function () {
  25. App.set('defaultStackVersion', "HDP-1.2.2");
  26. App.set('currentStackVersion', "HDP-1.2.2");
  27. var testCases = [
  28. {
  29. title: 'if currentStackVersion and defaultStackVersion are empty then stackVersionURL should contain prefix',
  30. currentStackVersion: '',
  31. defaultStackVersion: '',
  32. result: '/stacks/HDP/versions/'
  33. },
  34. {
  35. title: 'if currentStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/versions/1.3.1"',
  36. currentStackVersion: 'HDP-1.3.1',
  37. defaultStackVersion: '',
  38. result: '/stacks/HDP/versions/1.3.1'
  39. },
  40. {
  41. title: 'if defaultStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/versions/1.3.1"',
  42. currentStackVersion: '',
  43. defaultStackVersion: 'HDP-1.3.1',
  44. result: '/stacks/HDP/versions/1.3.1'
  45. },
  46. {
  47. title: 'if defaultStackVersion and currentStackVersion are different then stackVersionURL should have currentStackVersion value',
  48. currentStackVersion: 'HDP-1.3.2',
  49. defaultStackVersion: 'HDP-1.3.1',
  50. result: '/stacks/HDP/versions/1.3.2'
  51. }
  52. ];
  53. testCases.forEach(function (test) {
  54. it(test.title, function () {
  55. App.set('defaultStackVersion', test.defaultStackVersion);
  56. App.set('currentStackVersion', test.currentStackVersion);
  57. expect(App.get('stackVersionURL')).to.equal(test.result);
  58. App.set('defaultStackVersion', "HDP-1.2.2");
  59. App.set('currentStackVersion', "HDP-1.2.2");
  60. });
  61. });
  62. });
  63. describe('#falconServerURL', function () {
  64. var testCases = [
  65. {
  66. title: 'No services installed, url should be empty',
  67. service: Em.A([]),
  68. result: ''
  69. },
  70. {
  71. title: 'FALCON is not installed, url should be empty',
  72. service: Em.A([
  73. {
  74. serviceName: 'HDFS'
  75. }
  76. ]),
  77. result: ''
  78. },
  79. {
  80. title: 'FALCON is installed, url should be "host1"',
  81. service: Em.A([
  82. Em.Object.create({
  83. serviceName: 'FALCON',
  84. hostComponents: [
  85. Em.Object.create({
  86. componentName: 'FALCON_SERVER',
  87. hostName: 'host1'
  88. })
  89. ]
  90. })
  91. ]),
  92. result: 'host1'
  93. }
  94. ];
  95. testCases.forEach(function (test) {
  96. it(test.title, function () {
  97. sinon.stub(App.Service, 'find', function () {
  98. return test.service;
  99. });
  100. expect(App.get('falconServerURL')).to.equal(test.result);
  101. App.Service.find.restore();
  102. });
  103. });
  104. });
  105. describe('#currentStackVersionNumber', function () {
  106. var testCases = [
  107. {
  108. title: 'if currentStackVersion is empty then currentStackVersionNumber should be empty',
  109. currentStackVersion: '',
  110. result: ''
  111. },
  112. {
  113. title: 'if currentStackVersion is "HDP-1.3.1" then currentStackVersionNumber should be "1.3.1',
  114. currentStackVersion: 'HDP-1.3.1',
  115. result: '1.3.1'
  116. },
  117. {
  118. title: 'if currentStackVersion is "HDPLocal-1.3.1" then currentStackVersionNumber should be "1.3.1',
  119. currentStackVersion: 'HDPLocal-1.3.1',
  120. result: '1.3.1'
  121. }
  122. ];
  123. before(function () {
  124. App.set('defaultStackVersion', '');
  125. });
  126. after(function () {
  127. App.set('defaultStackVersion', 'HDP-2.0.5');
  128. });
  129. testCases.forEach(function (test) {
  130. it(test.title, function () {
  131. App.set('currentStackVersion', test.currentStackVersion);
  132. expect(App.get('currentStackVersionNumber')).to.equal(test.result);
  133. App.set('currentStackVersion', "HDP-1.2.2");
  134. });
  135. });
  136. });
  137. describe('#isHaEnabled when HDFS is installed:', function () {
  138. beforeEach(function () {
  139. sinon.stub(App.Service, 'find').returns(Em.Object.create({'isLoaded': true}));
  140. this.mock = sinon.stub(App.HostComponent, 'find');
  141. });
  142. afterEach(function () {
  143. App.Service.find.restore();
  144. this.mock.restore();
  145. });
  146. it('if hadoop stack version higher than 2 then isHaEnabled should be true', function () {
  147. this.mock.returns([]);
  148. App.propertyDidChange('isHaEnabled');
  149. expect(App.get('isHaEnabled')).to.equal(true);
  150. });
  151. it('if cluster has SECONDARY_NAMENODE then isHaEnabled should be false', function () {
  152. this.mock.returns([Em.Object.create({componentName: 'SECONDARY_NAMENODE'})]);
  153. App.propertyDidChange('isHaEnabled');
  154. expect(App.get('isHaEnabled')).to.equal(false);
  155. });
  156. });
  157. describe('#isHaEnabled when HDFS is not installed:', function () {
  158. beforeEach(function () {
  159. sinon.stub(App.Service, 'find').returns(Em.Object.create({'isLoaded': false}));
  160. });
  161. afterEach(function () {
  162. App.Service.find.restore();
  163. });
  164. it('if hadoop stack version higher than 2 but HDFS not installed then isHaEnabled should be false', function () {
  165. App.set('currentStackVersion', 'HDP-2.1');
  166. expect(App.get('isHaEnabled')).to.equal(false);
  167. App.set('currentStackVersion', "HDP-1.2.2");
  168. });
  169. });
  170. describe('#services', function () {
  171. var stackServices = [
  172. Em.Object.create({
  173. serviceName: 'S1',
  174. isClientOnlyService: true
  175. }),
  176. Em.Object.create({
  177. serviceName: 'S2',
  178. hasClient: true
  179. }),
  180. Em.Object.create({
  181. serviceName: 'S3',
  182. hasMaster: true
  183. }),
  184. Em.Object.create({
  185. serviceName: 'S4',
  186. hasSlave: true
  187. }),
  188. Em.Object.create({
  189. serviceName: 'S5',
  190. isNoConfigTypes: true
  191. }),
  192. Em.Object.create({
  193. serviceName: 'S6',
  194. isMonitoringService: true
  195. }),
  196. Em.Object.create({
  197. serviceName: 'S7'
  198. })
  199. ];
  200. it('distribute services by categories', function () {
  201. sinon.stub(App.StackService, 'find', function () {
  202. return stackServices;
  203. });
  204. expect(App.get('services.all')).to.eql(['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7']);
  205. expect(App.get('services.clientOnly')).to.eql(['S1']);
  206. expect(App.get('services.hasClient')).to.eql(['S2']);
  207. expect(App.get('services.hasMaster')).to.eql(['S3']);
  208. expect(App.get('services.hasSlave')).to.eql(['S4']);
  209. expect(App.get('services.noConfigTypes')).to.eql(['S5']);
  210. expect(App.get('services.monitoring')).to.eql(['S6']);
  211. App.StackService.find.restore();
  212. });
  213. });
  214. describe('#components', function () {
  215. var i = 0,
  216. testCases = [
  217. {
  218. key: 'allComponents',
  219. data: [
  220. Em.Object.create({
  221. componentName: 'C1'
  222. })
  223. ],
  224. result: ['C1']
  225. },
  226. {
  227. key: 'reassignable',
  228. data: [
  229. Em.Object.create({
  230. componentName: 'C2',
  231. isReassignable: true
  232. })
  233. ],
  234. result: ['C2']
  235. },
  236. {
  237. key: 'restartable',
  238. data: [
  239. Em.Object.create({
  240. componentName: 'C3',
  241. isRestartable: true
  242. })
  243. ],
  244. result: ['C3']
  245. },
  246. {
  247. key: 'deletable',
  248. data: [
  249. Em.Object.create({
  250. componentName: 'C4',
  251. isDeletable: true
  252. })
  253. ],
  254. result: ['C4']
  255. },
  256. {
  257. key: 'rollinRestartAllowed',
  258. data: [
  259. Em.Object.create({
  260. componentName: 'C5',
  261. isRollinRestartAllowed: true
  262. })
  263. ],
  264. result: ['C5']
  265. },
  266. {
  267. key: 'decommissionAllowed',
  268. data: [
  269. Em.Object.create({
  270. componentName: 'C6',
  271. isDecommissionAllowed: true
  272. })
  273. ],
  274. result: ['C6']
  275. },
  276. {
  277. key: 'refreshConfigsAllowed',
  278. data: [
  279. Em.Object.create({
  280. componentName: 'C7',
  281. isRefreshConfigsAllowed: true
  282. })
  283. ],
  284. result: ['C7']
  285. },
  286. {
  287. key: 'addableToHost',
  288. data: [
  289. Em.Object.create({
  290. componentName: 'C8',
  291. isAddableToHost: true
  292. })
  293. ],
  294. result: ['C8']
  295. },
  296. {
  297. key: 'addableMasterInstallerWizard',
  298. data: [
  299. Em.Object.create({
  300. componentName: 'C9',
  301. isMasterAddableInstallerWizard: true,
  302. showAddBtnInInstall: true
  303. })
  304. ],
  305. result: ['C9']
  306. },
  307. {
  308. key: 'multipleMasters',
  309. data: [
  310. Em.Object.create({
  311. componentName: 'C10',
  312. isMasterWithMultipleInstances: true
  313. })
  314. ],
  315. result: ['C10']
  316. },
  317. {
  318. key: 'slaves',
  319. data: [
  320. Em.Object.create({
  321. componentName: 'C11',
  322. isSlave: true
  323. })
  324. ],
  325. result: ['C11']
  326. },
  327. {
  328. key: 'clients',
  329. data: [
  330. Em.Object.create({
  331. componentName: 'C12',
  332. isClient: true
  333. })
  334. ],
  335. result: ['C12']
  336. }
  337. ];
  338. beforeEach(function () {
  339. sinon.stub(App.StackServiceComponent, 'find', function () {
  340. return testCases[i].data;
  341. });
  342. });
  343. afterEach(function () {
  344. i++;
  345. App.StackServiceComponent.find.restore();
  346. });
  347. testCases.forEach(function (test) {
  348. it(test.key + ' should contain ' + test.result, function () {
  349. expect(App.get('components.' + test.key)).to.eql(test.result);
  350. })
  351. })
  352. });
  353. describe("#isAccessible()", function() {
  354. beforeEach(function () {
  355. this.mock = sinon.stub(App.router, 'get');
  356. });
  357. afterEach(function () {
  358. this.mock.restore();
  359. });
  360. it("Upgrade running, element should be blocked", function() {
  361. App.set('upgradeState', "IN_PROGRESS");
  362. App.set('isAdmin', true);
  363. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  364. expect(App.isAccessible('ADMIN')).to.be.false;
  365. });
  366. it("Upgrade running, upgrade element should not be blocked", function() {
  367. App.set('upgradeState', "IN_PROGRESS");
  368. App.set('isAdmin', true);
  369. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  370. expect(App.isAccessible('upgrade_ADMIN')).to.be.true;
  371. });
  372. it("Upgrade running, upgrade element should not be blocked", function() {
  373. App.set('upgradeState', "IN_PROGRESS");
  374. App.set('isAdmin', true);
  375. App.set('supports.opsDuringRollingUpgrade', true);
  376. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  377. expect(App.isAccessible('ADMIN')).to.be.true;
  378. App.set('supports.opsDuringRollingUpgrade', false);
  379. });
  380. it("ADMIN type, isAdmin true", function() {
  381. App.set('upgradeState', "INIT");
  382. App.set('isAdmin', true);
  383. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  384. expect(App.isAccessible('ADMIN')).to.be.true;
  385. });
  386. it("ADMIN type, isAdmin false", function() {
  387. App.set('upgradeState', "INIT");
  388. App.set('isAdmin', false);
  389. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  390. expect(App.isAccessible('ADMIN')).to.be.false;
  391. });
  392. it("MANAGER type, isOperator false", function() {
  393. App.set('upgradeState', "INIT");
  394. App.set('isAdmin', true);
  395. App.set('isOperator', false);
  396. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  397. expect(App.isAccessible('MANAGER')).to.be.true;
  398. });
  399. it("MANAGER type, isAdmin false", function() {
  400. App.set('upgradeState', "INIT");
  401. App.set('isAdmin', false);
  402. App.set('isOperator', true);
  403. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  404. expect(App.isAccessible('MANAGER')).to.be.true;
  405. });
  406. it("MANAGER type, isAdmin and isOperator false", function() {
  407. App.set('upgradeState', "INIT");
  408. App.set('isAdmin', false);
  409. App.set('isOperator', false);
  410. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  411. expect(App.isAccessible('MANAGER')).to.be.false;
  412. });
  413. it("OPERATOR type, isOperator false", function() {
  414. App.set('upgradeState', "INIT");
  415. App.set('isOperator', false);
  416. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  417. expect(App.isAccessible('OPERATOR')).to.be.false;
  418. });
  419. it("OPERATOR type, isOperator false", function() {
  420. App.set('upgradeState', "INIT");
  421. App.set('isOperator', true);
  422. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  423. expect(App.isAccessible('OPERATOR')).to.be.true;
  424. });
  425. it("ONLY_ADMIN type, isAdmin false", function() {
  426. App.set('upgradeState', "INIT");
  427. App.set('isAdmin', false);
  428. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  429. expect(App.isAccessible('ONLY_ADMIN')).to.be.false;
  430. });
  431. it("ONLY_ADMIN type, isAdmin true, isOperator false", function() {
  432. App.set('upgradeState', "INIT");
  433. App.set('isAdmin', true);
  434. App.set('isOperator', false);
  435. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  436. expect(App.isAccessible('ONLY_ADMIN')).to.be.true;
  437. });
  438. it("ONLY_ADMIN type, isAdmin true, isOperator true", function() {
  439. App.set('upgradeState', "INIT");
  440. App.set('isAdmin', true);
  441. App.set('isOperator', true);
  442. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  443. expect(App.isAccessible('ONLY_ADMIN')).to.be.false;
  444. });
  445. it("unknown type", function() {
  446. App.set('upgradeState', "INIT");
  447. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  448. expect(App.isAccessible('')).to.be.false;
  449. });
  450. it("ONLY_ADMIN type, isAdmin true, isOperator true, isSuspended true", function() {
  451. App.set('upgradeState', "ABORTED");
  452. App.set('isAdmin', true);
  453. App.set('isOperator', false);
  454. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(false);
  455. this.mock.withArgs('mainAdminStackAndUpgradeController.isSuspended').returns(true);
  456. expect(App.isAccessible('ONLY_ADMIN')).to.be.true;
  457. });
  458. it("ONLY_ADMIN type, isNonWizardUser true", function() {
  459. App.set('upgradeState', "ABORTED");
  460. App.set('isAdmin', true);
  461. App.set('isOperator', false);
  462. this.mock.withArgs('wizardWatcherController.isNonWizardUser').returns(true);
  463. expect(App.isAccessible('ONLY_ADMIN')).to.be.false;
  464. });
  465. });
  466. describe('#isHadoop20Stack', function () {
  467. Em.A([
  468. {
  469. currentStackVersion: 'HDP-2.2',
  470. e: false
  471. },
  472. {
  473. currentStackVersion: 'HDP-2.1',
  474. e: false
  475. },
  476. {
  477. currentStackVersion: 'HDP-2.0',
  478. e: true
  479. },
  480. {
  481. currentStackVersion: 'HDP-2.0.0',
  482. e: true
  483. },
  484. {
  485. currentStackVersion: 'HDP-2.0.6',
  486. e: true
  487. },
  488. {
  489. currentStackVersion: 'HDPLocal-2.2',
  490. e: false
  491. },
  492. {
  493. currentStackVersion: 'HDPLocal-2.1',
  494. e: false
  495. },
  496. {
  497. currentStackVersion: 'HDPLocal-2.0',
  498. e: true
  499. },
  500. {
  501. currentStackVersion: 'HDPLocal-2.0.0',
  502. e: true
  503. },
  504. {
  505. currentStackVersion: 'HDPLocal-2.0.6',
  506. e: true
  507. }
  508. ]).forEach(function (test) {
  509. it('for ' + test.currentStackVersion + ' isHadoop20Stack = ' + test.e.toString(), function () {
  510. App.set('currentStackVersion', test.currentStackVersion);
  511. expect(App.get('isHadoop20Stack')).to.equal(test.e);
  512. });
  513. });
  514. });
  515. describe('#upgradeIsRunning', function () {
  516. Em.A([
  517. {
  518. upgradeState: 'IN_PROGRESS',
  519. m: 'should be true (1)',
  520. e: true
  521. },
  522. {
  523. upgradeState: 'HOLDING',
  524. m: 'should be true (2)',
  525. e: true
  526. },
  527. {
  528. upgradeState: 'FAKE',
  529. m: 'should be false',
  530. e: false
  531. }
  532. ]).forEach(function (test) {
  533. it(test.m, function () {
  534. App.set('upgradeState', test.upgradeState);
  535. expect(App.get('upgradeIsRunning')).to.equal(test.e);
  536. });
  537. });
  538. });
  539. describe('#upgradeAborted', function () {
  540. var cases = [
  541. {
  542. upgradeState: 'INIT',
  543. isSuspended: false,
  544. upgradeAborted: false
  545. },
  546. {
  547. upgradeState: 'INIT',
  548. isSuspended: true,
  549. upgradeAborted: false
  550. },
  551. {
  552. upgradeState: 'ABORTED',
  553. isSuspended: true,
  554. upgradeAborted: false
  555. },
  556. {
  557. upgradeState: 'ABORTED',
  558. isSuspended: false,
  559. upgradeAborted: true
  560. }
  561. ];
  562. beforeEach(function () {
  563. this.mock = sinon.stub(App.router, 'get');
  564. });
  565. afterEach(function () {
  566. this.mock.restore();
  567. });
  568. cases.forEach(function (item) {
  569. it(item.upgradeState + ", " + item.isSuspended, function () {
  570. this.mock.returns(item.isSuspended);
  571. App.set('upgradeState', item.upgradeState);
  572. App.propertyDidChange('upgradeAborted');
  573. expect(App.get('upgradeAborted')).to.equal(item.upgradeAborted);
  574. });
  575. });
  576. });
  577. describe('#wizardIsNotFinished', function () {
  578. beforeEach(function () {
  579. this.mock = sinon.stub(App.router, 'get');
  580. });
  581. afterEach(function () {
  582. this.mock.restore();
  583. });
  584. var cases = [
  585. {
  586. upgradeState: 'INIT',
  587. isSuspended: false,
  588. wizardIsNotFinished: false
  589. },
  590. {
  591. upgradeState: 'IN_PROGRESS',
  592. isSuspended: false,
  593. wizardIsNotFinished: true
  594. },
  595. {
  596. upgradeState: 'HOLDING',
  597. isSuspended: false,
  598. wizardIsNotFinished: true
  599. },
  600. {
  601. upgradeState: 'HOLDING_TIMEDOUT',
  602. isSuspended: false,
  603. wizardIsNotFinished: true
  604. },
  605. {
  606. upgradeState: 'ABORTED',
  607. isSuspended: false,
  608. wizardIsNotFinished: true
  609. },
  610. {
  611. upgradeState: 'ABORTED',
  612. isSuspended: true,
  613. wizardIsNotFinished: true
  614. }
  615. ];
  616. cases.forEach(function (item) {
  617. it(item.upgradeState, function () {
  618. App.set('upgradeState', item.upgradeState);
  619. this.mock.returns(item.isSuspended);
  620. App.propertyDidChange('wizardIsNotFinished');
  621. expect(App.get('wizardIsNotFinished')).to.equal(item.wizardIsNotFinished);
  622. });
  623. });
  624. });
  625. });