app_test.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589
  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('#upgradeIsRunning', function () {
  376. Em.A([
  377. {
  378. upgradeState: 'IN_PROGRESS',
  379. m: 'should be true (1)',
  380. e: true
  381. },
  382. {
  383. upgradeState: 'HOLDING',
  384. m: 'should be true (2)',
  385. e: true
  386. },
  387. {
  388. upgradeState: 'FAKE',
  389. m: 'should be false',
  390. e: false
  391. }
  392. ]).forEach(function (test) {
  393. it(test.m, function () {
  394. App.set('upgradeState', test.upgradeState);
  395. expect(App.get('upgradeIsRunning')).to.equal(test.e);
  396. });
  397. });
  398. });
  399. describe('#upgradeSuspended', function () {
  400. var cases = [
  401. {
  402. upgradeState: 'INIT',
  403. isSuspended: false,
  404. upgradeSuspended: false
  405. },
  406. {
  407. upgradeState: 'ABORTED',
  408. isSuspended: false,
  409. upgradeSuspended: false
  410. },
  411. {
  412. upgradeState: 'ABORTED',
  413. isSuspended: true,
  414. upgradeSuspended: true
  415. }
  416. ];
  417. beforeEach(function() {
  418. this.mock = sinon.stub(App.router, 'get');
  419. });
  420. afterEach(function() {
  421. this.mock.restore();
  422. });
  423. cases.forEach(function (test) {
  424. it(test.upgradeState + ", isSuspended=" + test.isSuspended, function () {
  425. App.set('upgradeState', test.upgradeState);
  426. this.mock.returns(test.isSuspended);
  427. App.propertyDidChange('upgradeSuspended');
  428. expect(App.get('upgradeSuspended')).to.equal(test.upgradeSuspended);
  429. });
  430. });
  431. });
  432. describe('#upgradeAborted', function () {
  433. var cases = [
  434. {
  435. upgradeState: 'INIT',
  436. isSuspended: false,
  437. upgradeAborted: false
  438. },
  439. {
  440. upgradeState: 'ABORTED',
  441. isSuspended: true,
  442. upgradeAborted: false
  443. },
  444. {
  445. upgradeState: 'ABORTED',
  446. isSuspended: false,
  447. upgradeAborted: true
  448. }
  449. ];
  450. beforeEach(function() {
  451. this.mock = sinon.stub(App.router, 'get');
  452. });
  453. afterEach(function() {
  454. this.mock.restore();
  455. });
  456. cases.forEach(function (test) {
  457. it(test.upgradeState + ", isSuspended=" + test.isSuspended, function () {
  458. App.set('upgradeState', test.upgradeState);
  459. this.mock.returns(test.isSuspended);
  460. App.propertyDidChange('upgradeAborted');
  461. expect(App.get('upgradeAborted')).to.equal(test.upgradeAborted);
  462. });
  463. });
  464. });
  465. describe('#wizardIsNotFinished', function () {
  466. var cases = [
  467. {
  468. upgradeState: 'INIT',
  469. wizardIsNotFinished: false
  470. },
  471. {
  472. upgradeState: 'IN_PROGRESS',
  473. wizardIsNotFinished: true
  474. },
  475. {
  476. upgradeState: 'HOLDING',
  477. wizardIsNotFinished: true
  478. },
  479. {
  480. upgradeState: 'HOLDING_TIMEDOUT',
  481. wizardIsNotFinished: true
  482. },
  483. {
  484. upgradeState: 'ABORTED',
  485. wizardIsNotFinished: true
  486. }
  487. ];
  488. cases.forEach(function (item) {
  489. it(item.upgradeState, function () {
  490. App.set('upgradeState', item.upgradeState);
  491. App.propertyDidChange('wizardIsNotFinished');
  492. expect(App.get('wizardIsNotFinished')).to.equal(item.wizardIsNotFinished);
  493. });
  494. });
  495. });
  496. describe("#upgradeHolding", function () {
  497. var cases = [
  498. {
  499. upgradeState: 'INIT',
  500. upgradeAborted: false,
  501. upgradeHolding: false
  502. },
  503. {
  504. upgradeState: 'HOLDING',
  505. upgradeAborted: false,
  506. upgradeHolding: true
  507. },
  508. {
  509. upgradeState: 'HOLDING_FAILED',
  510. upgradeAborted: false,
  511. upgradeHolding: true
  512. },
  513. {
  514. upgradeState: 'INIT',
  515. upgradeAborted: true,
  516. upgradeHolding: true
  517. }
  518. ];
  519. beforeEach(function() {
  520. this.mock = sinon.stub(App.router, 'get');
  521. });
  522. afterEach(function() {
  523. this.mock.restore();
  524. });
  525. cases.forEach(function (test) {
  526. it(test.upgradeState + ", upgradeAborted=" + test.upgradeAborted, function () {
  527. App.reopen({
  528. upgradeAborted: test.upgradeAborted,
  529. upgradeState: test.upgradeState
  530. });
  531. App.propertyDidChange('upgradeHolding');
  532. expect(App.get('upgradeHolding')).to.equal(test.upgradeHolding);
  533. });
  534. });
  535. });
  536. });