app_test.js 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. App.auth = ["AMBARI.ADD_DELETE_CLUSTERS", "AMBARI.ASSIGN_ROLES", "AMBARI.EDIT_STACK_REPOS", "AMBARI.MANAGE_GROUPS", "AMBARI.MANAGE_STACK_VERSIONS", "AMBARI.MANAGE_USERS", "AMBARI.MANAGE_VIEWS", "AMBARI.RENAME_CLUSTER", "AMBARI.SET_SERVICE_USERS_GROUPS", "CLUSTER.TOGGLE_ALERTS", "CLUSTER.TOGGLE_KERBEROS", "CLUSTER.UPGRADE_DOWNGRADE_STACK", "CLUSTER.VIEW_ALERTS", "CLUSTER.VIEW_CONFIGS", "CLUSTER.VIEW_METRICS", "CLUSTER.VIEW_STACK_DETAILS", "CLUSTER.VIEW_STATUS_INFO", "HOST.ADD_DELETE_COMPONENTS", "HOST.ADD_DELETE_HOSTS", "HOST.TOGGLE_MAINTENANCE", "HOST.VIEW_CONFIGS", "HOST.VIEW_METRICS", "HOST.VIEW_STATUS_INFO", "SERVICE.ADD_DELETE_SERVICES", "SERVICE.COMPARE_CONFIGS", "SERVICE.DECOMMISSION_RECOMMISSION", "SERVICE.ENABLE_HA", "SERVICE.MANAGE_CONFIG_GROUPS", "SERVICE.MODIFY_CONFIGS", "SERVICE.MOVE", "SERVICE.RUN_CUSTOM_COMMAND", "SERVICE.RUN_SERVICE_CHECK", "SERVICE.START_STOP", "SERVICE.TOGGLE_ALERTS", "SERVICE.TOGGLE_MAINTENANCE", "SERVICE.VIEW_ALERTS", "SERVICE.VIEW_CONFIGS", "SERVICE.VIEW_METRICS", "SERVICE.VIEW_STATUS_INFO", "VIEW.USE"];
  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. describe(test.title, function () {
  97. beforeEach(function () {
  98. sinon.stub(App.Service, 'find', function () {
  99. return test.service;
  100. });
  101. });
  102. afterEach(function () {
  103. App.Service.find.restore();
  104. });
  105. it('App.falconServerURL is ' + test.result, function () {
  106. expect(App.get('falconServerURL')).to.equal(test.result);
  107. });
  108. });
  109. });
  110. });
  111. describe('#currentStackVersionNumber', function () {
  112. var testCases = [
  113. {
  114. title: 'if currentStackVersion is empty then currentStackVersionNumber should be empty',
  115. currentStackVersion: '',
  116. result: ''
  117. },
  118. {
  119. title: 'if currentStackVersion is "HDP-1.3.1" then currentStackVersionNumber should be "1.3.1',
  120. currentStackVersion: 'HDP-1.3.1',
  121. result: '1.3.1'
  122. },
  123. {
  124. title: 'if currentStackVersion is "HDPLocal-1.3.1" then currentStackVersionNumber should be "1.3.1',
  125. currentStackVersion: 'HDPLocal-1.3.1',
  126. result: '1.3.1'
  127. }
  128. ];
  129. before(function () {
  130. App.set('defaultStackVersion', '');
  131. });
  132. after(function () {
  133. App.set('defaultStackVersion', 'HDP-2.0.5');
  134. });
  135. testCases.forEach(function (test) {
  136. it(test.title, function () {
  137. App.set('currentStackVersion', test.currentStackVersion);
  138. expect(App.get('currentStackVersionNumber')).to.equal(test.result);
  139. App.set('currentStackVersion', "HDP-1.2.2");
  140. });
  141. });
  142. });
  143. describe('#isHaEnabled when HDFS is installed:', function () {
  144. beforeEach(function () {
  145. sinon.stub(App.Service, 'find').returns(Em.Object.create({'isLoaded': true}));
  146. this.mock = sinon.stub(App.HostComponent, 'find');
  147. });
  148. afterEach(function () {
  149. App.Service.find.restore();
  150. this.mock.restore();
  151. });
  152. it('if hadoop stack version higher than 2 then isHaEnabled should be true', function () {
  153. this.mock.returns([]);
  154. App.propertyDidChange('isHaEnabled');
  155. expect(App.get('isHaEnabled')).to.equal(true);
  156. });
  157. it('if cluster has SECONDARY_NAMENODE then isHaEnabled should be false', function () {
  158. this.mock.returns([Em.Object.create({componentName: 'SECONDARY_NAMENODE'})]);
  159. App.propertyDidChange('isHaEnabled');
  160. expect(App.get('isHaEnabled')).to.equal(false);
  161. });
  162. });
  163. describe('#isHaEnabled when HDFS is not installed:', function () {
  164. beforeEach(function () {
  165. sinon.stub(App.Service, 'find').returns(Em.Object.create({'isLoaded': false}));
  166. });
  167. afterEach(function () {
  168. App.Service.find.restore();
  169. });
  170. it('if hadoop stack version higher than 2 but HDFS not installed then isHaEnabled should be false', function () {
  171. App.set('currentStackVersion', 'HDP-2.1');
  172. expect(App.get('isHaEnabled')).to.equal(false);
  173. App.set('currentStackVersion', "HDP-1.2.2");
  174. });
  175. });
  176. describe('#services', function () {
  177. var stackServices = [
  178. Em.Object.create({
  179. serviceName: 'S1',
  180. isClientOnlyService: true
  181. }),
  182. Em.Object.create({
  183. serviceName: 'S2',
  184. hasClient: true
  185. }),
  186. Em.Object.create({
  187. serviceName: 'S3',
  188. hasMaster: true
  189. }),
  190. Em.Object.create({
  191. serviceName: 'S4',
  192. hasSlave: true
  193. }),
  194. Em.Object.create({
  195. serviceName: 'S5',
  196. isNoConfigTypes: true
  197. }),
  198. Em.Object.create({
  199. serviceName: 'S6',
  200. isMonitoringService: true
  201. }),
  202. Em.Object.create({
  203. serviceName: 'S7'
  204. })
  205. ];
  206. beforeEach(function () {
  207. sinon.stub(App.StackService, 'find', function () {
  208. return stackServices;
  209. });
  210. });
  211. afterEach(function () {
  212. App.StackService.find.restore();
  213. });
  214. it('App.services.all', function () {
  215. expect(App.get('services.all')).to.eql(['S1', 'S2', 'S3', 'S4', 'S5', 'S6', 'S7']);
  216. });
  217. it('App.services.clientOnly', function () {
  218. expect(App.get('services.clientOnly')).to.eql(['S1']);
  219. });
  220. it('App.services.hasClient', function () {
  221. expect(App.get('services.hasClient')).to.eql(['S2']);
  222. });
  223. it('App.services.hasMaster', function () {
  224. expect(App.get('services.hasMaster')).to.eql(['S3']);
  225. });
  226. it('App.services.hasSlave', function () {
  227. expect(App.get('services.hasSlave')).to.eql(['S4']);
  228. });
  229. it('App.services.noConfigTypes', function () {
  230. expect(App.get('services.noConfigTypes')).to.eql(['S5']);
  231. });
  232. it('App.services.monitoring', function () {
  233. expect(App.get('services.monitoring')).to.eql(['S6']);
  234. });
  235. });
  236. describe('#components', function () {
  237. var i = 0,
  238. testCases = [
  239. {
  240. key: 'allComponents',
  241. data: [
  242. Em.Object.create({
  243. componentName: 'C1'
  244. })
  245. ],
  246. result: ['C1']
  247. },
  248. {
  249. key: 'reassignable',
  250. data: [
  251. Em.Object.create({
  252. componentName: 'C2',
  253. isReassignable: true
  254. })
  255. ],
  256. result: ['C2']
  257. },
  258. {
  259. key: 'restartable',
  260. data: [
  261. Em.Object.create({
  262. componentName: 'C3',
  263. isRestartable: true
  264. })
  265. ],
  266. result: ['C3']
  267. },
  268. {
  269. key: 'deletable',
  270. data: [
  271. Em.Object.create({
  272. componentName: 'C4',
  273. isDeletable: true
  274. })
  275. ],
  276. result: ['C4']
  277. },
  278. {
  279. key: 'rollinRestartAllowed',
  280. data: [
  281. Em.Object.create({
  282. componentName: 'C5',
  283. isRollinRestartAllowed: true
  284. })
  285. ],
  286. result: ['C5']
  287. },
  288. {
  289. key: 'decommissionAllowed',
  290. data: [
  291. Em.Object.create({
  292. componentName: 'C6',
  293. isDecommissionAllowed: true
  294. })
  295. ],
  296. result: ['C6']
  297. },
  298. {
  299. key: 'refreshConfigsAllowed',
  300. data: [
  301. Em.Object.create({
  302. componentName: 'C7',
  303. isRefreshConfigsAllowed: true
  304. })
  305. ],
  306. result: ['C7']
  307. },
  308. {
  309. key: 'addableToHost',
  310. data: [
  311. Em.Object.create({
  312. componentName: 'C8',
  313. isAddableToHost: true
  314. })
  315. ],
  316. result: ['C8']
  317. },
  318. {
  319. key: 'addableMasterInstallerWizard',
  320. data: [
  321. Em.Object.create({
  322. componentName: 'C9',
  323. isMasterAddableInstallerWizard: true,
  324. showAddBtnInInstall: true
  325. })
  326. ],
  327. result: ['C9']
  328. },
  329. {
  330. key: 'multipleMasters',
  331. data: [
  332. Em.Object.create({
  333. componentName: 'C10',
  334. isMasterWithMultipleInstances: true
  335. })
  336. ],
  337. result: ['C10']
  338. },
  339. {
  340. key: 'slaves',
  341. data: [
  342. Em.Object.create({
  343. componentName: 'C11',
  344. isSlave: true
  345. })
  346. ],
  347. result: ['C11']
  348. },
  349. {
  350. key: 'clients',
  351. data: [
  352. Em.Object.create({
  353. componentName: 'C12',
  354. isClient: true
  355. })
  356. ],
  357. result: ['C12']
  358. }
  359. ];
  360. beforeEach(function () {
  361. sinon.stub(App.StackServiceComponent, 'find', function () {
  362. return testCases[i].data;
  363. });
  364. });
  365. afterEach(function () {
  366. i++;
  367. App.StackServiceComponent.find.restore();
  368. });
  369. testCases.forEach(function (test) {
  370. it(test.key + ' should contain ' + test.result, function () {
  371. expect(App.get('components.' + test.key)).to.eql(test.result);
  372. })
  373. })
  374. });
  375. describe('#isHadoop20Stack', function () {
  376. Em.A([
  377. {
  378. currentStackVersion: 'HDP-2.2',
  379. e: false
  380. },
  381. {
  382. currentStackVersion: 'HDP-2.1',
  383. e: false
  384. },
  385. {
  386. currentStackVersion: 'HDP-2.0',
  387. e: true
  388. },
  389. {
  390. currentStackVersion: 'HDP-2.0.0',
  391. e: true
  392. },
  393. {
  394. currentStackVersion: 'HDP-2.0.6',
  395. e: true
  396. },
  397. {
  398. currentStackVersion: 'HDPLocal-2.2',
  399. e: false
  400. },
  401. {
  402. currentStackVersion: 'HDPLocal-2.1',
  403. e: false
  404. },
  405. {
  406. currentStackVersion: 'HDPLocal-2.0',
  407. e: true
  408. },
  409. {
  410. currentStackVersion: 'HDPLocal-2.0.0',
  411. e: true
  412. },
  413. {
  414. currentStackVersion: 'HDPLocal-2.0.6',
  415. e: true
  416. }
  417. ]).forEach(function (test) {
  418. it('for ' + test.currentStackVersion + ' isHadoop20Stack = ' + test.e.toString(), function () {
  419. App.set('currentStackVersion', test.currentStackVersion);
  420. expect(App.get('isHadoop20Stack')).to.equal(test.e);
  421. });
  422. });
  423. });
  424. describe('#upgradeIsRunning', function () {
  425. Em.A([
  426. {
  427. upgradeState: 'IN_PROGRESS',
  428. m: 'should be true (1)',
  429. e: true
  430. },
  431. {
  432. upgradeState: 'HOLDING',
  433. m: 'should be true (2)',
  434. e: true
  435. },
  436. {
  437. upgradeState: 'FAKE',
  438. m: 'should be false',
  439. e: false
  440. }
  441. ]).forEach(function (test) {
  442. it(test.m, function () {
  443. App.set('upgradeState', test.upgradeState);
  444. expect(App.get('upgradeIsRunning')).to.equal(test.e);
  445. });
  446. });
  447. });
  448. describe('#upgradeAborted', function () {
  449. var cases = [
  450. {
  451. upgradeState: 'INIT',
  452. upgradeAborted: false
  453. },
  454. {
  455. upgradeState: 'INIT',
  456. upgradeAborted: false
  457. },
  458. {
  459. upgradeState: 'ABORTED',
  460. upgradeAborted: true
  461. }
  462. ];
  463. cases.forEach(function (item) {
  464. it(item.upgradeState + ", ", function () {
  465. App.set('upgradeState', item.upgradeState);
  466. App.propertyDidChange('upgradeAborted');
  467. expect(App.get('upgradeAborted')).to.equal(item.upgradeAborted);
  468. });
  469. });
  470. });
  471. describe('#wizardIsNotFinished', function () {
  472. var cases = [
  473. {
  474. upgradeState: 'INIT',
  475. wizardIsNotFinished: false
  476. },
  477. {
  478. upgradeState: 'IN_PROGRESS',
  479. wizardIsNotFinished: true
  480. },
  481. {
  482. upgradeState: 'HOLDING',
  483. wizardIsNotFinished: true
  484. },
  485. {
  486. upgradeState: 'HOLDING_TIMEDOUT',
  487. wizardIsNotFinished: true
  488. },
  489. {
  490. upgradeState: 'ABORTED',
  491. wizardIsNotFinished: true
  492. }
  493. ];
  494. cases.forEach(function (item) {
  495. it(item.upgradeState, function () {
  496. App.set('upgradeState', item.upgradeState);
  497. App.propertyDidChange('wizardIsNotFinished');
  498. expect(App.get('wizardIsNotFinished')).to.equal(item.wizardIsNotFinished);
  499. });
  500. });
  501. });
  502. });