app_test.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  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('App.isHadoop21Stack', function() {
  25. var tests = [{
  26. v:'',
  27. e:false
  28. }, {
  29. v:'HDP',
  30. e: false
  31. }, {
  32. v:'HDP1',
  33. e: false
  34. }, {
  35. v:'HDP-1',
  36. e: false
  37. }, {
  38. v:'HDP-2.0',
  39. e: false
  40. }, {
  41. v:'HDP-2.0.1000',
  42. e: false
  43. }, {
  44. v:'HDP-2.1',
  45. e: true
  46. }, {
  47. v:'HDP-2.1.3434',
  48. e: true
  49. }, {
  50. v:'HDP-2.2',
  51. e: true
  52. }, {
  53. v:'HDP-2.2.1212',
  54. e: true
  55. }];
  56. tests.forEach(function(test){
  57. it(test.v, function() {
  58. App.QuickViewLinks.prototype.setQuickLinks = function(){};
  59. App.set('currentStackVersion', test.v);
  60. var calculated = App.get('isHadoop21Stack');
  61. var expected = test.e;
  62. expect(calculated).to.equal(expected);
  63. });
  64. });
  65. });
  66. describe('Disable/enable components', function() {
  67. App.set('handleStackDependencyTest', true);
  68. modelSetup.setupStackVersion(this, 'HDP-2.1');
  69. var testableComponent = Em.Object.create({
  70. componentName: 'APP_TIMELINE_SERVER',
  71. serviceName: 'YARN'
  72. });
  73. var expectedInfo = {
  74. componentName: 'APP_TIMELINE_SERVER',
  75. properties: {
  76. global_properties: ['ats_host', 'apptimelineserver_heapsize'],
  77. site_properties: ['yarn.timeline-service.generic-application-history.store-class', 'yarn.timeline-service.store-class', 'yarn.timeline-service.leveldb-timeline-store.path']
  78. },
  79. reviewConfigs: {
  80. component_name: 'APP_TIMELINE_SERVER'
  81. },
  82. configCategory: {
  83. name: 'AppTimelineServer'
  84. }
  85. };
  86. var globalProperties = require('data/HDP2/global_properties');
  87. var siteProperties = require('data/HDP2/site_properties');
  88. var reviewConfigs = require('data/review_configs');
  89. var disableResult = App.disableComponent(testableComponent);
  90. describe('#disableComponent()', function() {
  91. // copy
  92. var _globalProperties = $.extend({}, globalProperties);
  93. var _siteProperties = $.extend({}, siteProperties);
  94. var _reviewConfigs = JSON.parse(JSON.stringify(reviewConfigs));
  95. describe('result validation', function() {
  96. it('component name should be "' + expectedInfo.componentName + '"', function() {
  97. expect(disableResult.get('componentName')).to.eql(expectedInfo.componentName);
  98. });
  99. it('config category name should be "' + expectedInfo.configCategory.name +'"', function() {
  100. expect(disableResult.get('configCategory.name')).to.eql(expectedInfo.configCategory.name);
  101. });
  102. for(var siteName in expectedInfo.properties) {
  103. (function(site) {
  104. expectedInfo.properties[site].forEach(function(property) {
  105. it(property + ' present in ' + site, function() {
  106. expect(disableResult.get('properties.' + site).mapProperty('name')).to.include(property);
  107. });
  108. }, this);
  109. })(siteName);
  110. }
  111. it('site and global properties should not be equal', function() {
  112. expect(disableResult.get('properties.global_properties')).to.not.include.members(disableResult.get('properties.site_properties'));
  113. });
  114. });
  115. describe('effect validation',function() {
  116. it('should remove global properties of component', function() {
  117. expect(_globalProperties.configProperties.mapProperty('name')).to.not.include.members(expectedInfo.properties.global_properties);
  118. });
  119. it('should remove site properties of component', function() {
  120. expect(_siteProperties.configProperties.mapProperty('name')).to.not.include.members(expectedInfo.properties.site_properties);
  121. });
  122. it('should remove review config for component', function() {
  123. var reviewConfig = _reviewConfigs.findProperty('config_name', 'services')
  124. .config_value.findProperty('service_name', testableComponent.get('serviceName'))
  125. .service_components.mapProperty('component_name');
  126. expect(reviewConfig).to.not.include(expectedInfo.reviewConfigs.component_name);
  127. });
  128. });
  129. });
  130. describe('#enableComponent', function() {
  131. App.enableComponent(disableResult);
  132. it('should add global properties of component', function() {
  133. expect(globalProperties.configProperties.mapProperty('name')).to.include.members(expectedInfo.properties.global_properties);
  134. });
  135. it('should add site properties of component', function() {
  136. expect(siteProperties.configProperties.mapProperty('name')).to.include.members(expectedInfo.properties.site_properties);
  137. });
  138. it('should add review config for component', function() {
  139. var reviewConfig = reviewConfigs.findProperty('config_name', 'services')
  140. .config_value.findProperty('service_name', testableComponent.get('serviceName'))
  141. .get('service_components').mapProperty('component_name');
  142. expect(reviewConfig).to.include(expectedInfo.reviewConfigs.component_name);
  143. });
  144. });
  145. modelSetup.restoreStackVersion(this);
  146. });
  147. describe('#stackVersionURL', function () {
  148. App.QuickViewLinks.reopen({
  149. loadTags: function () {}
  150. });
  151. var testCases = [
  152. {
  153. title: 'if currentStackVersion and defaultStackVersion are empty then stackVersionURL should contain prefix',
  154. currentStackVersion: '',
  155. defaultStackVersion: '',
  156. result: '/stacks/HDP/version/'
  157. },
  158. {
  159. title: 'if currentStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/version/1.3.1"',
  160. currentStackVersion: 'HDP-1.3.1',
  161. defaultStackVersion: '',
  162. result: '/stacks/HDP/version/1.3.1'
  163. },
  164. {
  165. title: 'if defaultStackVersion is "HDP-1.3.1" then stackVersionURL should be "/stacks/HDP/version/1.3.1"',
  166. currentStackVersion: '',
  167. defaultStackVersion: 'HDP-1.3.1',
  168. result: '/stacks/HDP/version/1.3.1'
  169. },
  170. {
  171. title: 'if defaultStackVersion and currentStackVersion are different then stackVersionURL should have currentStackVersion value',
  172. currentStackVersion: 'HDP-1.3.2',
  173. defaultStackVersion: 'HDP-1.3.1',
  174. result: '/stacks/HDP/version/1.3.2'
  175. },
  176. {
  177. title: 'if defaultStackVersion is "HDPLocal-1.3.1" then stackVersionURL should be "/stacks/HDPLocal/version/1.3.1"',
  178. currentStackVersion: '',
  179. defaultStackVersion: 'HDPLocal-1.3.1',
  180. result: '/stacks/HDPLocal/version/1.3.1'
  181. },
  182. {
  183. title: 'if currentStackVersion is "HDPLocal-1.3.1" then stackVersionURL should be "/stacks/HDPLocal/version/1.3.1"',
  184. currentStackVersion: 'HDPLocal-1.3.1',
  185. defaultStackVersion: '',
  186. result: '/stacks/HDPLocal/version/1.3.1'
  187. }
  188. ];
  189. testCases.forEach(function (test) {
  190. it(test.title, function () {
  191. App.set('currentStackVersion', test.currentStackVersion);
  192. App.set('defaultStackVersion', test.defaultStackVersion);
  193. expect(App.get('stackVersionURL')).to.equal(test.result);
  194. App.set('currentStackVersion', "HDP-1.2.2");
  195. App.set('defaultStackVersion', "HDP-1.2.2");
  196. });
  197. });
  198. });
  199. describe('#stack2VersionURL', function () {
  200. var testCases = [
  201. {
  202. title: 'if currentStackVersion and defaultStackVersion are empty then stack2VersionURL should contain prefix',
  203. currentStackVersion: '',
  204. defaultStackVersion: '',
  205. result: '/stacks2/HDP/versions/'
  206. },
  207. {
  208. title: 'if currentStackVersion is "HDP-1.3.1" then stack2VersionURL should be "/stacks2/HDP/versions/1.3.1"',
  209. currentStackVersion: 'HDP-1.3.1',
  210. defaultStackVersion: '',
  211. result: '/stacks2/HDP/versions/1.3.1'
  212. },
  213. {
  214. title: 'if defaultStackVersion is "HDP-1.3.1" then stack2VersionURL should be "/stacks/HDP/versions/1.3.1"',
  215. currentStackVersion: '',
  216. defaultStackVersion: 'HDP-1.3.1',
  217. result: '/stacks2/HDP/versions/1.3.1'
  218. },
  219. {
  220. title: 'if defaultStackVersion and currentStackVersion are different then stack2VersionURL should have currentStackVersion value',
  221. currentStackVersion: 'HDP-1.3.2',
  222. defaultStackVersion: 'HDP-1.3.1',
  223. result: '/stacks2/HDP/versions/1.3.2'
  224. },
  225. {
  226. title: 'if defaultStackVersion is "HDPLocal-1.3.1" then stack2VersionURL should be "/stacks2/HDPLocal/versions/1.3.1"',
  227. currentStackVersion: '',
  228. defaultStackVersion: 'HDPLocal-1.3.1',
  229. result: '/stacks2/HDPLocal/versions/1.3.1'
  230. },
  231. {
  232. title: 'if currentStackVersion is "HDPLocal-1.3.1" then stack2VersionURL should be "/stacks2/HDPLocal/versions/1.3.1"',
  233. currentStackVersion: 'HDPLocal-1.3.1',
  234. defaultStackVersion: '',
  235. result: '/stacks2/HDPLocal/versions/1.3.1'
  236. }
  237. ];
  238. testCases.forEach(function (test) {
  239. it(test.title, function () {
  240. App.set('currentStackVersion', test.currentStackVersion);
  241. App.set('defaultStackVersion', test.defaultStackVersion);
  242. expect(App.get('stack2VersionURL')).to.equal(test.result);
  243. App.set('currentStackVersion', "HDP-1.2.2");
  244. App.set('defaultStackVersion', "HDP-1.2.2");
  245. });
  246. });
  247. });
  248. describe('#currentStackVersionNumber', function () {
  249. var testCases = [
  250. {
  251. title: 'if currentStackVersion is empty then currentStackVersionNumber should be empty',
  252. currentStackVersion: '',
  253. result: ''
  254. },
  255. {
  256. title: 'if currentStackVersion is "HDP-1.3.1" then currentStackVersionNumber should be "1.3.1',
  257. currentStackVersion: 'HDP-1.3.1',
  258. result: '1.3.1'
  259. },
  260. {
  261. title: 'if currentStackVersion is "HDPLocal-1.3.1" then currentStackVersionNumber should be "1.3.1',
  262. currentStackVersion: 'HDPLocal-1.3.1',
  263. result: '1.3.1'
  264. }
  265. ];
  266. testCases.forEach(function (test) {
  267. it(test.title, function () {
  268. App.set('currentStackVersion', test.currentStackVersion);
  269. expect(App.get('currentStackVersionNumber')).to.equal(test.result);
  270. App.set('currentStackVersion', "HDP-1.2.2");
  271. });
  272. });
  273. });
  274. describe('#isHadoop2Stack', function () {
  275. var testCases = [
  276. {
  277. title: 'if currentStackVersion is empty then isHadoop2Stack should be false',
  278. currentStackVersion: '',
  279. result: false
  280. },
  281. {
  282. title: 'if currentStackVersion is "HDP-1.9.9" then isHadoop2Stack should be false',
  283. currentStackVersion: 'HDP-1.9.9',
  284. result: false
  285. },
  286. {
  287. title: 'if currentStackVersion is "HDP-2.0.0" then isHadoop2Stack should be true',
  288. currentStackVersion: 'HDP-2.0.0',
  289. result: true
  290. },
  291. {
  292. title: 'if currentStackVersion is "HDP-2.0.1" then isHadoop2Stack should be true',
  293. currentStackVersion: 'HDP-2.0.1',
  294. result: true
  295. }
  296. ];
  297. testCases.forEach(function (test) {
  298. it(test.title, function () {
  299. App.set('currentStackVersion', test.currentStackVersion);
  300. expect(App.get('isHadoop2Stack')).to.equal(test.result);
  301. App.set('currentStackVersion', "HDP-1.2.2");
  302. });
  303. });
  304. });
  305. describe('#isHaEnabled', function () {
  306. it('if hadoop stack version less than 2 then isHaEnabled should be false', function () {
  307. App.set('currentStackVersion', 'HDP-1.3.1');
  308. expect(App.get('isHaEnabled')).to.equal(false);
  309. App.set('currentStackVersion', "HDP-1.2.2");
  310. });
  311. it('if hadoop stack version higher than 2 then isHaEnabled should be true', function () {
  312. App.set('currentStackVersion', 'HDP-2.0.1');
  313. expect(App.get('isHaEnabled')).to.equal(true);
  314. App.set('currentStackVersion', "HDP-1.2.2");
  315. });
  316. it('if cluster has SECONDARY_NAMENODE then isHaEnabled should be false', function () {
  317. App.store.load(App.HostComponent, {
  318. id: 'SECONDARY_NAMENODE',
  319. component_name: 'SECONDARY_NAMENODE'
  320. });
  321. App.set('currentStackVersion', 'HDP-2.0.1');
  322. expect(App.get('isHaEnabled')).to.equal(false);
  323. App.set('currentStackVersion', "HDP-1.2.2");
  324. });
  325. });
  326. describe('#handleStackDependedComponents()', function () {
  327. beforeEach(function(){
  328. modelSetup.setupStackServiceComponent();
  329. });
  330. afterEach(function(){
  331. modelSetup.cleanStackServiceComponent();
  332. });
  333. it('if handleStackDependencyTest is true then stackDependedComponents should be unmodified', function () {
  334. App.set('testMode', false);
  335. App.set('handleStackDependencyTest', true);
  336. App.handleStackDependedComponents();
  337. expect(App.get('stackDependedComponents')).to.be.empty;
  338. });
  339. it('if testMode is true then stackDependedComponents should be unmodified', function () {
  340. App.set('handleStackDependencyTest', false);
  341. App.set('testMode', true);
  342. App.handleStackDependedComponents();
  343. expect(App.get('stackDependedComponents')).to.be.empty;
  344. });
  345. it('if stack contains all components then stackDependedComponents should be empty', function () {
  346. App.set('testMode', false);
  347. App.set('handleStackDependencyTest', false);
  348. App.handleStackDependedComponents();
  349. expect(App.get('stackDependedComponents')).to.be.empty;
  350. });
  351. it('if stack is missing component then push it to stackDependedComponents', function () {
  352. App.set('testMode', false);
  353. App.set('handleStackDependencyTest', false);
  354. var dtRecord = App.StackServiceComponent.find('DATANODE');
  355. dtRecord.deleteRecord();
  356. dtRecord.get('stateManager').transitionTo('loading');
  357. App.handleStackDependedComponents();
  358. expect(App.get('stackDependedComponents').mapProperty('componentName')).to.eql(["DATANODE"]);
  359. App.store.load(App.StackServiceComponent, {
  360. id: 'DATANODE',
  361. component_name: 'DATANODE',
  362. service_name: 'HDFS',
  363. component_category: 'SLAVE',
  364. is_master: false,
  365. is_client: false,
  366. stack_name: 'HDP',
  367. stack_version: '2.1'
  368. });
  369. });
  370. it('remove stack components from stackDependedComponents', function () {
  371. App.set('testMode', false);
  372. App.set('handleStackDependencyTest', false);
  373. App.set('stackDependedComponents', [
  374. Em.Object.create({
  375. componentName: "DATANODE",
  376. serviceName: "HDFS",
  377. properties: {},
  378. reviewConfigs: {},
  379. configCategory: {}
  380. }),
  381. Em.Object.create({
  382. componentName: "categoryComponent",
  383. serviceName: "",
  384. properties: {},
  385. reviewConfigs: {},
  386. configCategory: {}
  387. })
  388. ]);
  389. App.handleStackDependedComponents();
  390. expect(App.get('stackDependedComponents').mapProperty('componentName')).to.eql(["categoryComponent"]);
  391. });
  392. });
  393. });