yarn_defaults_provider_test.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  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. var yarnDefaultProvider;
  21. describe('YARNDefaultsProvider', function() {
  22. beforeEach(function() {
  23. yarnDefaultProvider = App.YARNDefaultsProvider.create();
  24. });
  25. afterEach(function() {
  26. yarnDefaultProvider.set('clusterData', null);
  27. yarnDefaultProvider.set('reservedRam', null);
  28. yarnDefaultProvider.set('hBaseRam', null);
  29. yarnDefaultProvider.set('containers', null);
  30. yarnDefaultProvider.set('recommendedMinimumContainerSize', null);
  31. yarnDefaultProvider.set('ramPerContainer', null);
  32. yarnDefaultProvider.set('mapMemory', null);
  33. yarnDefaultProvider.set('reduceMemory', null);
  34. yarnDefaultProvider.set('amMemory', null);
  35. });
  36. describe('#clusterDataIsValid', function() {
  37. var tests = Em.A([
  38. {clusterData: {disk: 12,ram: 48,cpu: 12,hBaseInstalled: false},e: true},
  39. {clusterData: {disk: null,ram: 48,cpu: 12,hBaseInstalled: false},e: false},
  40. {clusterData: {disk: 12,ram: null,cpu: 12,hBaseInstalled: false},e: false},
  41. {clusterData: {disk: 12,ram: 48,cpu: null,hBaseInstalled: false},e: false},
  42. {clusterData: {disk: 12,ram: 48,cpu: 12,hBaseInstalled: null},e: false},
  43. {clusterData: {disk: 12,ram: 48,cpu: 12},e: false},
  44. {clusterData: {disk: 12,ram: 48,hBaseInstalled: true},e: false},
  45. {clusterData: {disk: 12,cpu: 12,hBaseInstalled: true},e: false},
  46. {clusterData: {ram: 48,cpu: 12,hBaseInstalled: false},e: false}
  47. ]);
  48. tests.forEach(function(test) {
  49. it((test.e?'valid':'invalid') + ' clusterData', function() {
  50. yarnDefaultProvider.set('clusterData', test.clusterData);
  51. expect(yarnDefaultProvider.clusterDataIsValid()).to.equal(test.e);
  52. });
  53. });
  54. });
  55. describe('#reservedMemoryRecommendations', function() {
  56. var tests = Em.A([
  57. {ram: null, e: {os: 1, hbase: 1}},
  58. {ram: 2, e: {os: 1, hbase: 1}},
  59. {ram: 4, e: {os: 1, hbase: 1}},
  60. {ram: 6, e: {os: 2, hbase: 1}},
  61. {ram: 8, e: {os: 2, hbase: 1}},
  62. {ram: 12, e: {os: 2, hbase: 2}},
  63. {ram: 16, e: {os: 2, hbase: 2}},
  64. {ram: 20, e: {os: 4, hbase: 4}},
  65. {ram: 24, e: {os: 4, hbase: 4}},
  66. {ram: 36, e: {os: 6, hbase: 8}},
  67. {ram: 48, e: {os: 6, hbase: 8}},
  68. {ram: 56, e: {os: 8, hbase: 8}},
  69. {ram: 64, e: {os: 8, hbase: 8}},
  70. {ram: 68, e: {os: 8, hbase: 8}},
  71. {ram: 72, e: {os: 8, hbase: 8}},
  72. {ram: 84, e: {os: 12, hbase: 16}},
  73. {ram: 96, e: {os: 12, hbase: 16}},
  74. {ram: 112, e: {os: 24, hbase: 24}},
  75. {ram: 128, e: {os: 24, hbase: 24}},
  76. {ram: 196, e: {os: 32, hbase: 32}},
  77. {ram: 256, e: {os: 32, hbase: 32}},
  78. {ram: 384, e: {os: 64, hbase: 64}},
  79. {ram: 512, e: {os: 64, hbase: 64}},
  80. {ram: 756, e: {os: 64, hbase: 64}}
  81. ]);
  82. tests.forEach(function(test) {
  83. it('ram: ' + test.ram + ' GB', function() {
  84. sinon.spy(yarnDefaultProvider, 'reservedMemoryRecommendations');
  85. yarnDefaultProvider.set('clusterData', {
  86. disk: 12,
  87. ram: test.ram,
  88. cpu: 12,
  89. hBaseInstalled: false
  90. });
  91. expect(yarnDefaultProvider.get('reservedRam')).to.equal(test.e.os);
  92. expect(yarnDefaultProvider.get('hBaseRam')).to.equal(test.e.hbase);
  93. expect(yarnDefaultProvider.reservedMemoryRecommendations.calledOnce).to.equal(true);
  94. yarnDefaultProvider.reservedMemoryRecommendations.restore();
  95. });
  96. });
  97. });
  98. describe('#recommendedMinimumContainerSize', function() {
  99. it('No clusterData', function() {
  100. yarnDefaultProvider.set('clusterData', null);
  101. expect(yarnDefaultProvider.get('recommendedMinimumContainerSize')).to.equal(null);
  102. });
  103. it('No clusterData.ram', function() {
  104. yarnDefaultProvider.set('clusterData', {});
  105. expect(yarnDefaultProvider.get('recommendedMinimumContainerSize')).to.equal(null);
  106. });
  107. var tests = Em.A([
  108. {ram: 3, e: 256},
  109. {ram: 4, e: 256},
  110. {ram: 6, e: 512},
  111. {ram: 8, e: 512},
  112. {ram: 12, e: 1024},
  113. {ram: 24, e: 1024}
  114. ]);
  115. tests.forEach(function(test) {
  116. it('ram: ' + test.ram + ' GB', function() {
  117. yarnDefaultProvider.set('clusterData', {
  118. disk: 12,
  119. ram: test.ram,
  120. cpu: 12,
  121. hBaseInstalled: false
  122. });
  123. expect(yarnDefaultProvider.get('recommendedMinimumContainerSize')).to.equal(test.e);
  124. });
  125. });
  126. });
  127. describe('#containers', function() {
  128. it('No clusterData', function() {
  129. yarnDefaultProvider.set('clusterData', null);
  130. expect(yarnDefaultProvider.get('containers')).to.equal(null);
  131. });
  132. it('Some clusterData metric is null', function() {
  133. yarnDefaultProvider.set('clusterData', {disk: null, cpu: 1, ram: 1});
  134. expect(yarnDefaultProvider.get('containers')).to.equal(null);
  135. yarnDefaultProvider.set('clusterData', {disk: 1, cpu: null, ram: 1});
  136. expect(yarnDefaultProvider.get('containers')).to.equal(null);
  137. yarnDefaultProvider.set('clusterData', {disk:1, cpu: 1, ram: null});
  138. expect(yarnDefaultProvider.get('containers')).to.equal(null);
  139. });
  140. var tests = Em.A([
  141. {
  142. clusterData: {
  143. disk: 12,
  144. ram: 48,
  145. cpu: 12,
  146. hBaseInstalled: false
  147. },
  148. e: 21
  149. },
  150. {
  151. clusterData: {
  152. disk: 6,
  153. ram: 48,
  154. cpu: 6,
  155. hBaseInstalled: true
  156. },
  157. e: 11
  158. }
  159. ]);
  160. tests.forEach(function(test) {
  161. it((test.hBaseInstalled?'With':'Without') + ' hBase', function() {
  162. yarnDefaultProvider.set('clusterData', test.clusterData);
  163. expect(yarnDefaultProvider.get('containers')).to.equal(test.e);
  164. });
  165. });
  166. });
  167. describe('#ramPerContainer', function() {
  168. it('No clusterData', function() {
  169. yarnDefaultProvider.set('clusterData', null);
  170. expect(yarnDefaultProvider.get('ramPerContainer')).to.equal(null);
  171. });
  172. var tests = Em.A([
  173. {
  174. clusterData: {
  175. disk: 12,
  176. ram: 48,
  177. cpu: 12,
  178. hBaseInstalled: false
  179. },
  180. e: 2048
  181. },
  182. {
  183. clusterData: {
  184. disk: 12,
  185. ram: 16,
  186. cpu: 12,
  187. hBaseInstalled: true
  188. },
  189. e: 1024
  190. }
  191. ]);
  192. tests.forEach(function(test) {
  193. it((test.hBaseInstalled?'With':'Without') + ' hBase', function() {
  194. yarnDefaultProvider.set('clusterData', test.clusterData);
  195. expect(yarnDefaultProvider.get('ramPerContainer')).to.equal(test.e);
  196. });
  197. });
  198. });
  199. describe('#getDefaults', function() {
  200. var tests = Em.A([
  201. {
  202. localDB: {},
  203. m: 'Empty localDB',
  204. e: null
  205. },
  206. {
  207. localDB: {
  208. "masterComponentHosts": []
  209. },
  210. m: 'localDB without hosts',
  211. e: null
  212. },
  213. {
  214. localDB: {
  215. "hosts": {}
  216. },
  217. m: 'localDB without masterComponentHosts amd slaveComponentHosts',
  218. e: null
  219. },
  220. {
  221. localDB: {
  222. "hosts": {
  223. "host1": {"name": "host1","cpu": 8,"memory": "25165824.00","disk_info": [{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'}]},
  224. "host2": {"name": "host2","cpu": 4,"memory": "25165824.00","disk_info": [{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'}]}
  225. },
  226. "masterComponentHosts": [],
  227. "slaveComponentHosts": [
  228. {
  229. "componentName": "NODEMANAGER",
  230. "hosts": [{"hostName": "host2"}]
  231. }
  232. ]
  233. },
  234. m: 'Without HBase',
  235. e: {
  236. 'mapreduce.map.java.opts': '-Xmx2048m',
  237. 'mapreduce.map.memory.mb': 2560,
  238. 'mapreduce.reduce.java.opts': '-Xmx2048m',
  239. 'mapreduce.reduce.memory.mb': 2560,
  240. 'yarn.app.mapreduce.am.command-opts': '-Xmx2048m',
  241. 'yarn.app.mapreduce.am.resource.mb': 2560,
  242. 'yarn.nodemanager.resource.memory-mb': 20480,
  243. 'yarn.scheduler.maximum-allocation-mb': 20480,
  244. 'yarn.scheduler.minimum-allocation-mb': 2560,
  245. 'mapreduce.task.io.sort.mb': 1024
  246. }
  247. },
  248. {
  249. localDB: {
  250. "hosts": {
  251. "host1": {"name": "host1","cpu": 8,"memory": "25165824.00","disk_info": [{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'}]},
  252. "host2": {"name": "host2","cpu": 4,"memory": "12582912.00","disk_info": [{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'},{mountpoint:'/'}]}
  253. },
  254. "masterComponentHosts": [
  255. {"component": "HBASE_MASTER","hostName": "host1","serviceId": "HDFS"}
  256. ],
  257. "slaveComponentHosts": [
  258. {
  259. "componentName": "NODEMANAGER",
  260. "hosts": [{"hostName": "host2"}]
  261. }
  262. ]
  263. },
  264. m: 'With HBase',
  265. e: {
  266. 'mapreduce.map.java.opts': '-Xmx819m',
  267. 'mapreduce.map.memory.mb': 1024,
  268. 'mapreduce.reduce.java.opts': '-Xmx819m',
  269. 'mapreduce.reduce.memory.mb': 1024,
  270. 'yarn.app.mapreduce.am.command-opts': '-Xmx819m',
  271. 'yarn.app.mapreduce.am.resource.mb': 1024,
  272. 'yarn.nodemanager.resource.memory-mb': 8192,
  273. 'yarn.scheduler.maximum-allocation-mb': 8192,
  274. 'yarn.scheduler.minimum-allocation-mb': 1024,
  275. 'mapreduce.task.io.sort.mb': 410
  276. }
  277. }
  278. ]);
  279. tests.forEach(function(test) {
  280. yarnDefaultProvider = App.YARNDefaultsProvider.create();
  281. describe(test.m, function() {
  282. yarnDefaultProvider.set('clusterData', null);
  283. var configs = yarnDefaultProvider.getDefaults(test.localDB);
  284. Em.keys(configs).forEach(function(config) {
  285. it(config, function() {
  286. if (test.e) {
  287. expect(configs[config]).to.equal(test.e[config]);
  288. }
  289. else {
  290. expect(configs[config] == 0 || configs[config] == null).to.equal(true);
  291. }
  292. });
  293. });
  294. });
  295. });
  296. });
  297. });