app_test.js 17 KB

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