app_test.js 15 KB

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