app_test.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  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. var testCases = [
  30. {
  31. title: 'if currentStackVersion and defaultStackVersion are empty then stackVersionURL should contain prefix',
  32. currentStackVersion: '',
  33. defaultStackVersion: '',
  34. result: '/stacks/HDP/versions/'
  35. },
  36. {
  37. title: 'if currentStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/versions/1.3.1"',
  38. currentStackVersion: 'HDP-1.3.1',
  39. defaultStackVersion: '',
  40. result: '/stacks/HDP/versions/1.3.1'
  41. },
  42. {
  43. title: 'if defaultStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/versions/1.3.1"',
  44. currentStackVersion: '',
  45. defaultStackVersion: 'HDP-1.3.1',
  46. result: '/stacks/HDP/versions/1.3.1'
  47. },
  48. {
  49. title: 'if defaultStackVersion and currentStackVersion are different then stackVersionURL should have currentStackVersion value',
  50. currentStackVersion: 'HDP-1.3.2',
  51. defaultStackVersion: 'HDP-1.3.1',
  52. result: '/stacks/HDP/versions/1.3.2'
  53. },
  54. {
  55. title: 'if defaultStackVersion is "HDPLocal-1.3.1" then stackVersionURL should be "/stacks/HDPLocal/versions/1.3.1"',
  56. currentStackVersion: '',
  57. defaultStackVersion: 'HDPLocal-1.3.1',
  58. result: '/stacks/HDPLocal/versions/1.3.1'
  59. },
  60. {
  61. title: 'if currentStackVersion is "HDPLocal-1.3.1" then stackVersionURL should be "/stacks/HDPLocal/versions/1.3.1"',
  62. currentStackVersion: 'HDPLocal-1.3.1',
  63. defaultStackVersion: '',
  64. result: '/stacks/HDPLocal/versions/1.3.1'
  65. }
  66. ];
  67. testCases.forEach(function (test) {
  68. it(test.title, function () {
  69. App.set('currentStackVersion', test.currentStackVersion);
  70. App.set('defaultStackVersion', test.defaultStackVersion);
  71. expect(App.get('stackVersionURL')).to.equal(test.result);
  72. App.set('currentStackVersion', "HDP-1.2.2");
  73. App.set('defaultStackVersion', "HDP-1.2.2");
  74. });
  75. });
  76. });
  77. describe('#stack2VersionURL', function () {
  78. var testCases = [
  79. {
  80. title: 'if currentStackVersion and defaultStackVersion are empty then stack2VersionURL should contain prefix',
  81. currentStackVersion: '',
  82. defaultStackVersion: '',
  83. result: '/stacks2/HDP/versions/'
  84. },
  85. {
  86. title: 'if currentStackVersion is "HDP-1.3.1" then stack2VersionURL should be "/stacks2/HDP/versions/1.3.1"',
  87. currentStackVersion: 'HDP-1.3.1',
  88. defaultStackVersion: '',
  89. result: '/stacks2/HDP/versions/1.3.1'
  90. },
  91. {
  92. title: 'if defaultStackVersion is "HDP-1.3.1" then stack2VersionURL should be "/stacks/HDP/versions/1.3.1"',
  93. currentStackVersion: '',
  94. defaultStackVersion: 'HDP-1.3.1',
  95. result: '/stacks2/HDP/versions/1.3.1'
  96. },
  97. {
  98. title: 'if defaultStackVersion and currentStackVersion are different then stack2VersionURL should have currentStackVersion value',
  99. currentStackVersion: 'HDP-1.3.2',
  100. defaultStackVersion: 'HDP-1.3.1',
  101. result: '/stacks2/HDP/versions/1.3.2'
  102. },
  103. {
  104. title: 'if defaultStackVersion is "HDPLocal-1.3.1" then stack2VersionURL should be "/stacks2/HDPLocal/versions/1.3.1"',
  105. currentStackVersion: '',
  106. defaultStackVersion: 'HDPLocal-1.3.1',
  107. result: '/stacks2/HDPLocal/versions/1.3.1'
  108. },
  109. {
  110. title: 'if currentStackVersion is "HDPLocal-1.3.1" then stack2VersionURL should be "/stacks2/HDPLocal/versions/1.3.1"',
  111. currentStackVersion: 'HDPLocal-1.3.1',
  112. defaultStackVersion: '',
  113. result: '/stacks2/HDPLocal/versions/1.3.1'
  114. }
  115. ];
  116. testCases.forEach(function (test) {
  117. it(test.title, function () {
  118. App.set('currentStackVersion', test.currentStackVersion);
  119. App.set('defaultStackVersion', test.defaultStackVersion);
  120. expect(App.get('stack2VersionURL')).to.equal(test.result);
  121. App.set('currentStackVersion', "HDP-1.2.2");
  122. App.set('defaultStackVersion', "HDP-1.2.2");
  123. });
  124. });
  125. });
  126. describe('#falconServerURL', function () {
  127. var testCases = [
  128. {
  129. title: 'No services installed, url should be empty',
  130. service: Em.A([]),
  131. result: ''
  132. },
  133. {
  134. title: 'FALCON is not installed, url should be empty',
  135. service: Em.A([
  136. {
  137. serviceName: 'HDFS'
  138. }
  139. ]),
  140. result: ''
  141. },
  142. {
  143. title: 'FALCON is installed, url should be "host1"',
  144. service: Em.A([
  145. Em.Object.create({
  146. serviceName: 'FALCON',
  147. hostComponents: [
  148. Em.Object.create({
  149. componentName: 'FALCON_SERVER',
  150. hostName: 'host1'
  151. })
  152. ]
  153. })
  154. ]),
  155. result: 'host1'
  156. }
  157. ];
  158. testCases.forEach(function (test) {
  159. it(test.title, function () {
  160. sinon.stub(App.Service, 'find', function () {
  161. return test.service;
  162. });
  163. expect(App.get('falconServerURL')).to.equal(test.result);
  164. App.Service.find.restore();
  165. });
  166. });
  167. });
  168. describe('#currentStackVersionNumber', function () {
  169. var testCases = [
  170. {
  171. title: 'if currentStackVersion is empty then currentStackVersionNumber should be empty',
  172. currentStackVersion: '',
  173. result: ''
  174. },
  175. {
  176. title: 'if currentStackVersion is "HDP-1.3.1" then currentStackVersionNumber should be "1.3.1',
  177. currentStackVersion: 'HDP-1.3.1',
  178. result: '1.3.1'
  179. },
  180. {
  181. title: 'if currentStackVersion is "HDPLocal-1.3.1" then currentStackVersionNumber should be "1.3.1',
  182. currentStackVersion: 'HDPLocal-1.3.1',
  183. result: '1.3.1'
  184. }
  185. ];
  186. testCases.forEach(function (test) {
  187. it(test.title, function () {
  188. App.set('currentStackVersion', test.currentStackVersion);
  189. expect(App.get('currentStackVersionNumber')).to.equal(test.result);
  190. App.set('currentStackVersion', "HDP-1.2.2");
  191. });
  192. });
  193. });
  194. describe('#isHadoop2Stack', function () {
  195. var testCases = [
  196. {
  197. title: 'if currentStackVersion is empty then isHadoop2Stack should be false',
  198. currentStackVersion: '',
  199. result: false
  200. },
  201. {
  202. title: 'if currentStackVersion is "HDP-1.9.9" then isHadoop2Stack should be false',
  203. currentStackVersion: 'HDP-1.9.9',
  204. result: false
  205. },
  206. {
  207. title: 'if currentStackVersion is "HDP-2.0.0" then isHadoop2Stack should be true',
  208. currentStackVersion: 'HDP-2.0.0',
  209. result: true
  210. },
  211. {
  212. title: 'if currentStackVersion is "HDP-2.0.1" then isHadoop2Stack should be true',
  213. currentStackVersion: 'HDP-2.0.1',
  214. result: true
  215. }
  216. ];
  217. testCases.forEach(function (test) {
  218. it(test.title, function () {
  219. App.set('currentStackVersion', test.currentStackVersion);
  220. expect(App.get('isHadoop2Stack')).to.equal(test.result);
  221. App.set('currentStackVersion', "HDP-1.2.2");
  222. });
  223. });
  224. });
  225. describe('#isHadoop21Stack', function () {
  226. var tests = [
  227. {
  228. v: '',
  229. e: false
  230. },
  231. {
  232. v: 'HDP',
  233. e: false
  234. },
  235. {
  236. v: 'HDP1',
  237. e: false
  238. },
  239. {
  240. v: 'HDP-1',
  241. e: false
  242. },
  243. {
  244. v: 'HDP-2.0',
  245. e: false
  246. },
  247. {
  248. v: 'HDP-2.0.1000',
  249. e: false
  250. },
  251. {
  252. v: 'HDP-2.1',
  253. e: true
  254. },
  255. {
  256. v: 'HDP-2.1.3434',
  257. e: true
  258. },
  259. {
  260. v: 'HDP-2.2',
  261. e: true
  262. },
  263. {
  264. v: 'HDP-2.2.1212',
  265. e: true
  266. }
  267. ];
  268. tests.forEach(function (test) {
  269. it(test.v, function () {
  270. App.QuickViewLinks.prototype.setQuickLinks = function () {
  271. };
  272. App.set('currentStackVersion', test.v);
  273. var calculated = App.get('isHadoop21Stack');
  274. var expected = test.e;
  275. expect(calculated).to.equal(expected);
  276. });
  277. });
  278. });
  279. describe('#isHaEnabled', function () {
  280. it('if hadoop stack version less than 2 then isHaEnabled should be false', function () {
  281. App.set('currentStackVersion', 'HDP-1.3.1');
  282. expect(App.get('isHaEnabled')).to.equal(false);
  283. App.set('currentStackVersion', "HDP-1.2.2");
  284. });
  285. it('if hadoop stack version higher than 2 then isHaEnabled should be true', function () {
  286. App.set('currentStackVersion', 'HDP-2.0.1');
  287. expect(App.get('isHaEnabled')).to.equal(true);
  288. App.set('currentStackVersion', "HDP-1.2.2");
  289. });
  290. it('if cluster has SECONDARY_NAMENODE then isHaEnabled should be false', function () {
  291. App.store.load(App.HostComponent, {
  292. id: 'SECONDARY_NAMENODE',
  293. component_name: 'SECONDARY_NAMENODE'
  294. });
  295. App.set('currentStackVersion', 'HDP-2.0.1');
  296. expect(App.get('isHaEnabled')).to.equal(false);
  297. App.set('currentStackVersion', "HDP-1.2.2");
  298. });
  299. });
  300. describe('#services', function () {
  301. var stackServices = [
  302. Em.Object.create({
  303. serviceName: 'S1',
  304. isClientOnlyService: true
  305. }),
  306. Em.Object.create({
  307. serviceName: 'S2',
  308. hasClient: true
  309. }),
  310. Em.Object.create({
  311. serviceName: 'S3',
  312. hasMaster: true
  313. }),
  314. Em.Object.create({
  315. serviceName: 'S4',
  316. hasSlave: true
  317. }),
  318. Em.Object.create({
  319. serviceName: 'S5',
  320. isNoConfigTypes: true
  321. }),
  322. Em.Object.create({
  323. serviceName: 'S6',
  324. isMonitoringService: true
  325. }),
  326. Em.Object.create({
  327. serviceName: 'S7'
  328. })
  329. ];
  330. it('distribute services by categories', function () {
  331. sinon.stub(App.StackService, 'find', function () {
  332. return stackServices;
  333. });
  334. expect(App.get('services.all')).to.eql(['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7']);
  335. expect(App.get('services.clientOnly')).to.eql(['S1']);
  336. expect(App.get('services.hasClient')).to.eql(['S2']);
  337. expect(App.get('services.hasMaster')).to.eql(['S3']);
  338. expect(App.get('services.hasSlave')).to.eql(['S4']);
  339. expect(App.get('services.noConfigTypes')).to.eql(['S5']);
  340. expect(App.get('services.monitoring')).to.eql(['S6']);
  341. App.StackService.find.restore();
  342. });
  343. });
  344. describe('#components', function () {
  345. var testCases = [
  346. {
  347. key: 'allComponents',
  348. data: [
  349. Em.Object.create({
  350. componentName: 'C1'
  351. })
  352. ],
  353. result: ['C1']
  354. },
  355. {
  356. key: 'reassignable',
  357. data: [
  358. Em.Object.create({
  359. componentName: 'C2',
  360. isReassignable: true
  361. })
  362. ],
  363. result: ['C2']
  364. },
  365. {
  366. key: 'restartable',
  367. data: [
  368. Em.Object.create({
  369. componentName: 'C3',
  370. isRestartable: true
  371. })
  372. ],
  373. result: ['C3']
  374. },
  375. {
  376. key: 'deletable',
  377. data: [
  378. Em.Object.create({
  379. componentName: 'C4',
  380. isDeletable: true
  381. })
  382. ],
  383. result: ['C4']
  384. },
  385. {
  386. key: 'rollinRestartAllowed',
  387. data: [
  388. Em.Object.create({
  389. componentName: 'C5',
  390. isRollinRestartAllowed: true
  391. })
  392. ],
  393. result: ['C5']
  394. },
  395. {
  396. key: 'decommissionAllowed',
  397. data: [
  398. Em.Object.create({
  399. componentName: 'C6',
  400. isDecommissionAllowed: true
  401. })
  402. ],
  403. result: ['C6']
  404. },
  405. {
  406. key: 'refreshConfigsAllowed',
  407. data: [
  408. Em.Object.create({
  409. componentName: 'C7',
  410. isRefreshConfigsAllowed: true
  411. })
  412. ],
  413. result: ['C7']
  414. },
  415. {
  416. key: 'addableToHost',
  417. data: [
  418. Em.Object.create({
  419. componentName: 'C8',
  420. isAddableToHost: true
  421. })
  422. ],
  423. result: ['C8']
  424. },
  425. {
  426. key: 'addableMasterInstallerWizard',
  427. data: [
  428. Em.Object.create({
  429. componentName: 'C9',
  430. isMasterAddableInstallerWizard: true
  431. })
  432. ],
  433. result: ['C9']
  434. },
  435. {
  436. key: 'multipleMasters',
  437. data: [
  438. Em.Object.create({
  439. componentName: 'C10',
  440. isMasterWithMultipleInstances: true
  441. })
  442. ],
  443. result: ['C10']
  444. },
  445. {
  446. key: 'slaves',
  447. data: [
  448. Em.Object.create({
  449. componentName: 'C11',
  450. isSlave: true
  451. })
  452. ],
  453. result: ['C11']
  454. },
  455. {
  456. key: 'masters',
  457. data: [
  458. Em.Object.create({
  459. componentName: 'C12',
  460. isMaster: true
  461. })
  462. ],
  463. result: ['C12']
  464. },
  465. {
  466. key: 'clients',
  467. data: [
  468. Em.Object.create({
  469. componentName: 'C13',
  470. isClient: true
  471. })
  472. ],
  473. result: ['C13']
  474. }
  475. ];
  476. testCases.forEach(function (test) {
  477. it(test.key + ' should contain ' + test.result, function () {
  478. sinon.stub(App.StackServiceComponent, 'find', function () {
  479. return test.data;
  480. });
  481. expect(App.get('components.' + test.key)).to.eql(test.result);
  482. App.StackServiceComponent.find.restore();
  483. })
  484. })
  485. });
  486. });