app_test.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  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('#isHadoop2Stack', function () {
  142. before(function () {
  143. App.set('defaultStackVersion', '');
  144. });
  145. after(function () {
  146. App.set('defaultStackVersion', 'HDP-2.0.5');
  147. });
  148. var testCasesWithoutHDFSDefined = [
  149. {
  150. title: 'if currentStackVersion is empty then isHadoop2Stack should be false',
  151. currentStackVersion: '',
  152. result: false
  153. },
  154. {
  155. title: 'if currentStackVersion is "HDP-1.9.9" then isHadoop2Stack should be false',
  156. currentStackVersion: 'HDP-1.9.9',
  157. result: false
  158. },
  159. {
  160. title: 'if currentStackVersion is "HDP-2.0.0" then isHadoop2Stack should be true',
  161. currentStackVersion: 'HDP-2.0.0',
  162. result: true
  163. },
  164. {
  165. title: 'if currentStackVersion is "HDP-2.0.1" then isHadoop2Stack should be true',
  166. currentStackVersion: 'HDP-2.0.1',
  167. result: true
  168. }
  169. ];
  170. testCasesWithoutHDFSDefined.forEach(function (test) {
  171. it(test.title, function () {
  172. App.set('currentStackVersion', test.currentStackVersion);
  173. expect(App.get('isHadoop2Stack')).to.equal(test.result);
  174. App.set('currentStackVersion', "HDP-1.2.2");
  175. });
  176. });
  177. it('HDFS service version should get priority when defined', function () {
  178. var stackServices = [
  179. Em.Object.create({
  180. serviceName: 'HDFS',
  181. serviceVersion: '2.1'
  182. })
  183. ];
  184. sinon.stub(App.StackService, 'find', function () {
  185. return stackServices;
  186. });
  187. App.set('currentStackVersion', '0.8');
  188. App.set('isStackServicesLoaded', true);
  189. expect(App.get('isHadoop2Stack')).to.equal(true);
  190. App.set('isStackServicesLoaded', false);
  191. App.set('currentStackVersion', "HDP-1.2.2");
  192. App.StackService.find.restore();
  193. });
  194. });
  195. describe('#isHaEnabled when HDFS is installed:', function () {
  196. beforeEach(function () {
  197. sinon.stub(App.Service, 'find', function () {
  198. return [
  199. {
  200. id: 'HDFS',
  201. serviceName: 'HDFS'
  202. }
  203. ];
  204. });
  205. });
  206. afterEach(function () {
  207. App.Service.find.restore();
  208. });
  209. it('if hadoop stack version less than 2 then isHaEnabled should be false', function () {
  210. App.set('currentStackVersion', 'HDP-1.3.1');
  211. expect(App.get('isHaEnabled')).to.equal(false);
  212. App.set('currentStackVersion', "HDP-1.2.2");
  213. });
  214. it('if hadoop stack version higher than 2 then isHaEnabled should be true', function () {
  215. App.set('currentStackVersion', 'HDP-2.0.1');
  216. expect(App.get('isHaEnabled')).to.equal(true);
  217. App.set('currentStackVersion', "HDP-1.2.2");
  218. });
  219. it('if cluster has SECONDARY_NAMENODE then isHaEnabled should be false', function () {
  220. App.store.load(App.HostComponent, {
  221. id: 'SECONDARY_NAMENODE',
  222. component_name: 'SECONDARY_NAMENODE'
  223. });
  224. App.set('currentStackVersion', 'HDP-2.0.1');
  225. expect(App.get('isHaEnabled')).to.equal(false);
  226. App.set('currentStackVersion', "HDP-1.2.2");
  227. });
  228. });
  229. describe('#isHaEnabled when HDFS is not installed:', function () {
  230. beforeEach(function () {
  231. sinon.stub(App.Service, 'find', function () {
  232. return [
  233. {
  234. id: 'ZOOKEEPER',
  235. serviceName: 'ZOOKEEPER'
  236. }
  237. ];
  238. });
  239. });
  240. afterEach(function () {
  241. App.Service.find.restore();
  242. });
  243. it('if hadoop stack version higher than 2 but HDFS not installed then isHaEnabled should be false', function () {
  244. App.set('currentStackVersion', 'HDP-2.1');
  245. expect(App.get('isHaEnabled')).to.equal(false);
  246. App.set('currentStackVersion', "HDP-1.2.2");
  247. });
  248. });
  249. describe('#services', function () {
  250. var stackServices = [
  251. Em.Object.create({
  252. serviceName: 'S1',
  253. isClientOnlyService: true
  254. }),
  255. Em.Object.create({
  256. serviceName: 'S2',
  257. hasClient: true
  258. }),
  259. Em.Object.create({
  260. serviceName: 'S3',
  261. hasMaster: true
  262. }),
  263. Em.Object.create({
  264. serviceName: 'S4',
  265. hasSlave: true
  266. }),
  267. Em.Object.create({
  268. serviceName: 'S5',
  269. isNoConfigTypes: true
  270. }),
  271. Em.Object.create({
  272. serviceName: 'S6',
  273. isMonitoringService: true
  274. }),
  275. Em.Object.create({
  276. serviceName: 'S7'
  277. })
  278. ];
  279. it('distribute services by categories', function () {
  280. sinon.stub(App.StackService, 'find', function () {
  281. return stackServices;
  282. });
  283. expect(App.get('services.all')).to.eql(['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7']);
  284. expect(App.get('services.clientOnly')).to.eql(['S1']);
  285. expect(App.get('services.hasClient')).to.eql(['S2']);
  286. expect(App.get('services.hasMaster')).to.eql(['S3']);
  287. expect(App.get('services.hasSlave')).to.eql(['S4']);
  288. expect(App.get('services.noConfigTypes')).to.eql(['S5']);
  289. expect(App.get('services.monitoring')).to.eql(['S6']);
  290. App.StackService.find.restore();
  291. });
  292. });
  293. describe('#components', function () {
  294. var i = 0,
  295. testCases = [
  296. {
  297. key: 'allComponents',
  298. data: [
  299. Em.Object.create({
  300. componentName: 'C1'
  301. })
  302. ],
  303. result: ['C1']
  304. },
  305. {
  306. key: 'reassignable',
  307. data: [
  308. Em.Object.create({
  309. componentName: 'C2',
  310. isReassignable: true
  311. })
  312. ],
  313. result: ['C2']
  314. },
  315. {
  316. key: 'restartable',
  317. data: [
  318. Em.Object.create({
  319. componentName: 'C3',
  320. isRestartable: true
  321. })
  322. ],
  323. result: ['C3']
  324. },
  325. {
  326. key: 'deletable',
  327. data: [
  328. Em.Object.create({
  329. componentName: 'C4',
  330. isDeletable: true
  331. })
  332. ],
  333. result: ['C4']
  334. },
  335. {
  336. key: 'rollinRestartAllowed',
  337. data: [
  338. Em.Object.create({
  339. componentName: 'C5',
  340. isRollinRestartAllowed: true
  341. })
  342. ],
  343. result: ['C5']
  344. },
  345. {
  346. key: 'decommissionAllowed',
  347. data: [
  348. Em.Object.create({
  349. componentName: 'C6',
  350. isDecommissionAllowed: true
  351. })
  352. ],
  353. result: ['C6']
  354. },
  355. {
  356. key: 'refreshConfigsAllowed',
  357. data: [
  358. Em.Object.create({
  359. componentName: 'C7',
  360. isRefreshConfigsAllowed: true
  361. })
  362. ],
  363. result: ['C7']
  364. },
  365. {
  366. key: 'addableToHost',
  367. data: [
  368. Em.Object.create({
  369. componentName: 'C8',
  370. isAddableToHost: true
  371. })
  372. ],
  373. result: ['C8']
  374. },
  375. {
  376. key: 'addableMasterInstallerWizard',
  377. data: [
  378. Em.Object.create({
  379. componentName: 'C9',
  380. isMasterAddableInstallerWizard: true
  381. })
  382. ],
  383. result: ['C9']
  384. },
  385. {
  386. key: 'multipleMasters',
  387. data: [
  388. Em.Object.create({
  389. componentName: 'C10',
  390. isMasterWithMultipleInstances: true
  391. })
  392. ],
  393. result: ['C10']
  394. },
  395. {
  396. key: 'slaves',
  397. data: [
  398. Em.Object.create({
  399. componentName: 'C11',
  400. isSlave: true
  401. })
  402. ],
  403. result: ['C11']
  404. },
  405. {
  406. key: 'clients',
  407. data: [
  408. Em.Object.create({
  409. componentName: 'C12',
  410. isClient: true
  411. })
  412. ],
  413. result: ['C12']
  414. }
  415. ];
  416. beforeEach(function () {
  417. sinon.stub(App.StackServiceComponent, 'find', function () {
  418. return testCases[i].data;
  419. });
  420. });
  421. afterEach(function () {
  422. i++;
  423. App.StackServiceComponent.find.restore();
  424. });
  425. testCases.forEach(function (test) {
  426. it(test.key + ' should contain ' + test.result, function () {
  427. expect(App.get('components.' + test.key)).to.eql(test.result);
  428. })
  429. })
  430. });
  431. describe("#isAccessible()", function() {
  432. it("Upgrade running, element should be blocked", function() {
  433. App.set('upgradeState', "IN_PROGRESS");
  434. App.set('isAdmin', true);
  435. expect(App.isAccessible('ADMIN')).to.be.false;
  436. });
  437. it("Upgrade running, upgrade element should not be blocked", function() {
  438. App.set('upgradeState', "IN_PROGRESS");
  439. App.set('isAdmin', true);
  440. expect(App.isAccessible('upgrade_ADMIN')).to.be.true;
  441. });
  442. it("ADMIN type, isAdmin true", function() {
  443. App.set('upgradeState', "INIT");
  444. App.set('isAdmin', true);
  445. expect(App.isAccessible('ADMIN')).to.be.true;
  446. });
  447. it("ADMIN type, isAdmin false", function() {
  448. App.set('upgradeState', "INIT");
  449. App.set('isAdmin', false);
  450. expect(App.isAccessible('ADMIN')).to.be.false;
  451. });
  452. it("MANAGER type, isOperator false", function() {
  453. App.set('upgradeState', "INIT");
  454. App.set('isAdmin', true);
  455. App.set('isOperator', false);
  456. expect(App.isAccessible('MANAGER')).to.be.true;
  457. });
  458. it("MANAGER type, isAdmin false", function() {
  459. App.set('upgradeState', "INIT");
  460. App.set('isAdmin', false);
  461. App.set('isOperator', true);
  462. expect(App.isAccessible('MANAGER')).to.be.true;
  463. });
  464. it("MANAGER type, isAdmin and isOperator false", function() {
  465. App.set('upgradeState', "INIT");
  466. App.set('isAdmin', false);
  467. App.set('isOperator', false);
  468. expect(App.isAccessible('MANAGER')).to.be.false;
  469. });
  470. it("OPERATOR type, isOperator false", function() {
  471. App.set('upgradeState', "INIT");
  472. App.set('isOperator', false);
  473. expect(App.isAccessible('OPERATOR')).to.be.false;
  474. });
  475. it("OPERATOR type, isOperator false", function() {
  476. App.set('upgradeState', "INIT");
  477. App.set('isOperator', true);
  478. expect(App.isAccessible('OPERATOR')).to.be.true;
  479. });
  480. it("ONLY_ADMIN type, isAdmin false", function() {
  481. App.set('upgradeState', "INIT");
  482. App.set('isAdmin', false);
  483. expect(App.isAccessible('ONLY_ADMIN')).to.be.false;
  484. });
  485. it("ONLY_ADMIN type, isAdmin true, isOperator false", function() {
  486. App.set('upgradeState', "INIT");
  487. App.set('isAdmin', true);
  488. App.set('isOperator', false);
  489. expect(App.isAccessible('ONLY_ADMIN')).to.be.true;
  490. });
  491. it("ONLY_ADMIN type, isAdmin true, isOperator true", function() {
  492. App.set('upgradeState', "INIT");
  493. App.set('isAdmin', true);
  494. App.set('isOperator', true);
  495. expect(App.isAccessible('ONLY_ADMIN')).to.be.false;
  496. });
  497. it("unknown type", function() {
  498. App.set('upgradeState', "INIT");
  499. expect(App.isAccessible('')).to.be.false;
  500. });
  501. });
  502. });