app_test.js 15 KB

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