yarn_defaults_provider_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with this
  4. * work for additional information regarding copyright ownership. The ASF
  5. * licenses this file to you under the Apache License, Version 2.0 (the
  6. * "License"); you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. * License for the specific language governing permissions and limitations under
  15. * the License.
  16. */
  17. var App = require('app');
  18. require('utils/configs/defaults_providers/defaultsProvider');
  19. require('utils/configs/defaults_providers/yarn_defaults_provider');
  20. describe('YARNDefaultsProvider', function() {
  21. afterEach(function() {
  22. App.YARNDefaultsProvider.set('clusterData', null);
  23. App.YARNDefaultsProvider.set('reservedRam', null);
  24. App.YARNDefaultsProvider.set('hBaseRam', null);
  25. App.YARNDefaultsProvider.set('containers', null);
  26. App.YARNDefaultsProvider.set('recommendedMinimumContainerSize', null);
  27. App.YARNDefaultsProvider.set('ramPerContainer', null);
  28. App.YARNDefaultsProvider.set('mapMemory', null);
  29. App.YARNDefaultsProvider.set('reduceMemory', null);
  30. App.YARNDefaultsProvider.set('amMemory', null);
  31. });
  32. describe('#clusterDataIsValid', function() {
  33. var tests = [
  34. {clusterData: {disk: 12,ram: 48,cpu: 12,hBaseInstalled: false},e: true},
  35. {clusterData: {disk: null,ram: 48,cpu: 12,hBaseInstalled: false},e: false},
  36. {clusterData: {disk: 12,ram: null,cpu: 12,hBaseInstalled: false},e: false},
  37. {clusterData: {disk: 12,ram: 48,cpu: null,hBaseInstalled: false},e: false},
  38. {clusterData: {disk: 12,ram: 48,cpu: 12,hBaseInstalled: null},e: false},
  39. {clusterData: {disk: 12,ram: 48,cpu: 12},e: false},
  40. {clusterData: {disk: 12,ram: 48,hBaseInstalled: true},e: false},
  41. {clusterData: {disk: 12,cpu: 12,hBaseInstalled: true},e: false},
  42. {clusterData: {ram: 48,cpu: 12,hBaseInstalled: false},e: false}
  43. ];
  44. tests.forEach(function(test) {
  45. it((test.e?'valid':'invalid') + ' clusterData', function() {
  46. App.YARNDefaultsProvider.set('clusterData', test.clusterData);
  47. expect(App.YARNDefaultsProvider.clusterDataIsValid()).to.equal(test.e);
  48. });
  49. });
  50. });
  51. describe('#reservedMemoryRecommendations', function() {
  52. var tests = [
  53. {ram: null, e: {os: 1, hbase: 1}},
  54. {ram: 2, e: {os: 1, hbase: 1}},
  55. {ram: 4, e: {os: 1, hbase: 1}},
  56. {ram: 6, e: {os: 2, hbase: 1}},
  57. {ram: 8, e: {os: 2, hbase: 1}},
  58. {ram: 12, e: {os: 2, hbase: 2}},
  59. {ram: 16, e: {os: 2, hbase: 2}},
  60. {ram: 20, e: {os: 4, hbase: 4}},
  61. {ram: 24, e: {os: 4, hbase: 4}},
  62. {ram: 36, e: {os: 6, hbase: 8}},
  63. {ram: 48, e: {os: 6, hbase: 8}},
  64. {ram: 56, e: {os: 8, hbase: 8}},
  65. {ram: 64, e: {os: 8, hbase: 8}},
  66. {ram: 68, e: {os: 8, hbase: 8}},
  67. {ram: 72, e: {os: 8, hbase: 8}},
  68. {ram: 84, e: {os: 12, hbase: 16}},
  69. {ram: 96, e: {os: 12, hbase: 16}},
  70. {ram: 112, e: {os: 24, hbase: 24}},
  71. {ram: 128, e: {os: 24, hbase: 24}},
  72. {ram: 196, e: {os: 32, hbase: 32}},
  73. {ram: 256, e: {os: 32, hbase: 32}},
  74. {ram: 384, e: {os: 64, hbase: 64}},
  75. {ram: 512, e: {os: 64, hbase: 64}},
  76. {ram: 756, e: {os: 64, hbase: 64}}
  77. ];
  78. App.YARNDefaultsProvider.set('clusterData');
  79. tests.forEach(function(test) {
  80. it('ram: ' + test.ram + ' GB', function() {
  81. sinon.spy(App.YARNDefaultsProvider, 'reservedMemoryRecommendations');
  82. App.YARNDefaultsProvider.set('clusterData', {
  83. disk: 12,
  84. ram: test.ram,
  85. cpu: 12,
  86. hBaseInstalled: false
  87. });
  88. expect(App.YARNDefaultsProvider.get('reservedRam')).to.equal(test.e.os);
  89. expect(App.YARNDefaultsProvider.get('hBaseRam')).to.equal(test.e.hbase);
  90. expect(App.YARNDefaultsProvider.reservedMemoryRecommendations.calledOnce).to.be.true;
  91. App.YARNDefaultsProvider.reservedMemoryRecommendations.restore();
  92. });
  93. });
  94. });
  95. describe('#recommendedMinimumContainerSize', function() {
  96. it('No clusterData', function() {
  97. App.YARNDefaultsProvider.set('clusterData', null);
  98. expect(App.YARNDefaultsProvider.get('recommendedMinimumContainerSize')).to.equal(null);
  99. });
  100. it('No clusterData.ram', function() {
  101. App.YARNDefaultsProvider.set('clusterData', {});
  102. expect(App.YARNDefaultsProvider.get('recommendedMinimumContainerSize')).to.equal(null);
  103. });
  104. var tests = [
  105. {ram: 3, e: 256},
  106. {ram: 4, e: 512},
  107. {ram: 6, e: 512},
  108. {ram: 8, e: 1024},
  109. {ram: 12, e: 1024},
  110. {ram: 24, e: 2048}
  111. ];
  112. tests.forEach(function(test) {
  113. it('ram: ' + test.ram + ' GB', function() {
  114. App.YARNDefaultsProvider.set('clusterData', {
  115. disk: 12,
  116. ram: test.ram,
  117. cpu: 12,
  118. hBaseInstalled: false
  119. });
  120. expect(App.YARNDefaultsProvider.get('recommendedMinimumContainerSize')).to.equal(test.e);
  121. });
  122. });
  123. });
  124. describe('#containers', function() {
  125. it('No clusterData', function() {
  126. App.YARNDefaultsProvider.set('clusterData', null);
  127. expect(App.YARNDefaultsProvider.get('containers')).to.equal(null);
  128. });
  129. it('Some clusterData metric is null', function() {
  130. App.YARNDefaultsProvider.set('clusterData', {disk: null, cpu: 1, ram: 1});
  131. expect(App.YARNDefaultsProvider.get('containers')).to.equal(null);
  132. App.YARNDefaultsProvider.set('clusterData', {disk: 1, cpu: null, ram: 1});
  133. expect(App.YARNDefaultsProvider.get('containers')).to.equal(null);
  134. App.YARNDefaultsProvider.set('clusterData', {disk:1, cpu: 1, ram: null});
  135. expect(App.YARNDefaultsProvider.get('containers')).to.equal(null);
  136. });
  137. var tests = [
  138. {
  139. clusterData: {
  140. disk: 12,
  141. ram: 48,
  142. cpu: 12,
  143. hBaseInstalled: false
  144. },
  145. e: 21
  146. },
  147. {
  148. clusterData: {
  149. disk: 6,
  150. ram: 48,
  151. cpu: 6,
  152. hBaseInstalled: true
  153. },
  154. e: 11
  155. }
  156. ];
  157. tests.forEach(function(test) {
  158. it((test.hBaseInstalled?'With':'Without') + ' hBase', function() {
  159. App.YARNDefaultsProvider.set('clusterData', test.clusterData);
  160. expect(App.YARNDefaultsProvider.get('containers')).to.equal(test.e);
  161. });
  162. });
  163. });
  164. describe('#ramPerContainer', function() {
  165. it('No clusterData', function() {
  166. App.YARNDefaultsProvider.set('clusterData', null);
  167. expect(App.YARNDefaultsProvider.get('ramPerContainer')).to.equal(null);
  168. });
  169. var tests = [
  170. {
  171. clusterData: {
  172. disk: 12,
  173. ram: 48,
  174. cpu: 12,
  175. hBaseInstalled: false
  176. },
  177. e: 2048
  178. },
  179. {
  180. clusterData: {
  181. disk: 12,
  182. ram: 16,
  183. cpu: 12,
  184. hBaseInstalled: true
  185. },
  186. e: 1024
  187. }
  188. ];
  189. tests.forEach(function(test) {
  190. it((test.hBaseInstalled?'With':'Without') + ' hBase', function() {
  191. App.YARNDefaultsProvider.set('clusterData', test.clusterData);
  192. expect(App.YARNDefaultsProvider.get('ramPerContainer')).to.equal(test.e);
  193. });
  194. });
  195. });
  196. describe('#getDefaults', function() {
  197. var tests = [
  198. {
  199. localDB: {},
  200. m: 'Empty localDB',
  201. e: null
  202. },
  203. {
  204. localDB: {
  205. "masterComponentHosts": []
  206. },
  207. m: 'localDB without hosts',
  208. e: null
  209. },
  210. {
  211. localDB: {
  212. "hosts": {}
  213. },
  214. m: 'localDB without masterComponentHosts amd slaveComponentHosts',
  215. e: null
  216. },
  217. {
  218. localDB: {
  219. "hosts": {
  220. "host1": {"name": "host1","cpu": 8,"memory": "25165824.00","disk_info": [{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'}]},
  221. "host2": {"name": "host2","cpu": 4,"memory": "25165824.00","disk_info": [{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'}]}
  222. },
  223. "masterComponentHosts": [],
  224. "slaveComponentHosts": [
  225. {
  226. "componentName": "NODEMANAGER",
  227. "hosts": [{"hostName": "host2"}]
  228. }
  229. ]
  230. },
  231. m: 'Without HBase',
  232. e: {
  233. 'mapreduce.map.java.opts': '-Xmx2048m',
  234. 'mapreduce.map.memory.mb': 2560,
  235. 'mapreduce.reduce.java.opts': '-Xmx2048m',
  236. 'mapreduce.reduce.memory.mb': 2560,
  237. 'yarn.app.mapreduce.am.command-opts': '-Xmx2048m',
  238. 'yarn.app.mapreduce.am.resource.mb': 2560,
  239. 'yarn.nodemanager.resource.memory-mb': 20480,
  240. 'yarn.scheduler.maximum-allocation-mb': 20480,
  241. 'yarn.scheduler.minimum-allocation-mb': 2560,
  242. 'mapreduce.task.io.sort.mb': 1024
  243. }
  244. },
  245. {
  246. localDB: {
  247. "hosts": {
  248. "host1": {"name": "host1","cpu": 8,"memory": "25165824.00","disk_info": [{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'}]},
  249. "host2": {"name": "host2","cpu": 4,"memory": "12582912.00","disk_info": [{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'}]}
  250. },
  251. "masterComponentHosts": [
  252. {"component": "HBASE_MASTER","hostName": "host1","serviceId": "HDFS"}
  253. ],
  254. "slaveComponentHosts": [
  255. {
  256. "componentName": "NODEMANAGER",
  257. "hosts": [{"hostName": "host2"}]
  258. }
  259. ]
  260. },
  261. m: 'With HBase',
  262. e: {
  263. 'mapreduce.map.java.opts': '-Xmx819m',
  264. 'mapreduce.map.memory.mb': 1024,
  265. 'mapreduce.reduce.java.opts': '-Xmx1638m',
  266. 'mapreduce.reduce.memory.mb': 2048,
  267. 'yarn.app.mapreduce.am.command-opts': '-Xmx1638m',
  268. 'yarn.app.mapreduce.am.resource.mb': 2048,
  269. 'yarn.nodemanager.resource.memory-mb': 8192,
  270. 'yarn.scheduler.maximum-allocation-mb': 8192,
  271. 'yarn.scheduler.minimum-allocation-mb': 1024,
  272. 'mapreduce.task.io.sort.mb': 410
  273. }
  274. }
  275. ];
  276. tests.forEach(function(test) {
  277. it(test.m, function() {
  278. App.YARNDefaultsProvider.set('clusterData', null);
  279. var configs = App.YARNDefaultsProvider.getDefaults(test.localDB);
  280. for(var config in configs) {
  281. if (test.e) {
  282. expect(configs[config]).to.equal(test.e[config]);
  283. }
  284. else {
  285. expect(configs[config] == 0 || configs[config] == null).to.equal(true);
  286. }
  287. }
  288. });
  289. });
  290. });
  291. });