service_mapper_test.js 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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('utils/helper');
  20. require('mappers/server_data_mapper');
  21. require('mappers/service_metrics_mapper');
  22. describe('App.serviceMetricsMapper', function () {
  23. describe('#hbaseMapper', function() {
  24. var tests = [
  25. {
  26. components: [
  27. {
  28. ServiceComponentInfo: {
  29. component_name: "HBASE_MASTER",
  30. RegionsInTransition : [ ]
  31. },
  32. host_components: [
  33. {
  34. metrics:{
  35. hbase: {
  36. master: {
  37. IsActiveMaster: 'true',
  38. AverageLoad: 1.23456789
  39. }
  40. },
  41. master: {
  42. AssignmentManger: {
  43. ritCount: 0
  44. }
  45. }
  46. },
  47. HostRoles: {
  48. host_name: 'host1'
  49. }
  50. }
  51. ]
  52. }
  53. ],
  54. e: '1.23'
  55. },
  56. {
  57. components: [
  58. {
  59. ServiceComponentInfo: {
  60. component_name: "HBASE_MASTER",
  61. RegionsInTransition : [ ]
  62. },
  63. host_components: [
  64. {
  65. metrics:{
  66. hbase: {
  67. master: {
  68. IsActiveMaster: 'true',
  69. AverageLoad: 1.00
  70. }
  71. },
  72. master: {
  73. AssignmentManger: {
  74. ritCount: 0
  75. }
  76. }
  77. },
  78. HostRoles: {
  79. host_name: 'host1'
  80. }
  81. }
  82. ]
  83. }
  84. ],
  85. e: '1.00'
  86. },
  87. {
  88. components: [
  89. {
  90. ServiceComponentInfo: {
  91. component_name: "HBASE_MASTER",
  92. RegionsInTransition : [ ]
  93. },
  94. host_components: [
  95. {
  96. metrics:{
  97. hbase: {
  98. master: {
  99. IsActiveMaster: 'true',
  100. AverageLoad: 1
  101. }
  102. },
  103. master: {
  104. AssignmentManger: {
  105. ritCount: 0
  106. }
  107. }
  108. },
  109. HostRoles: {
  110. host_name: 'host1'
  111. }
  112. }
  113. ]
  114. }
  115. ],
  116. e: '1.00'
  117. },
  118. {
  119. components: [
  120. {
  121. ServiceComponentInfo: {
  122. component_name: "HBASE_MASTER",
  123. RegionsInTransition : [ ]
  124. },
  125. host_components: [
  126. {
  127. metrics:{
  128. hbase: {
  129. master: {
  130. IsActiveMaster: 'true',
  131. AverageLoad: 1.2
  132. }
  133. },
  134. master: {
  135. AssignmentManger: {
  136. ritCount: 0
  137. }
  138. }
  139. },
  140. HostRoles: {
  141. host_name: 'host1'
  142. }
  143. }
  144. ]
  145. }
  146. ],
  147. e: '1.20'
  148. }
  149. ];
  150. tests.forEach(function(test) {
  151. it('Round Average Load (' + test.e + ')', function () {
  152. var result = App.serviceMetricsMapper.hbaseMapper(test);
  153. expect(result.average_load).to.equal(test.e);
  154. });
  155. });
  156. });
  157. describe('#stormMapper', function() {
  158. var tests = [
  159. {
  160. stackVersionNumber: '2.2',
  161. message: 'Storm mapper, stack version 2.2',
  162. expectedValues: {
  163. total_executors: 28,
  164. nimbus_uptime: "15m 1s",
  165. free_slots: 0,
  166. used_slots: 2,
  167. total_slots: 2,
  168. total_tasks: 28,
  169. topologies: 1
  170. },
  171. components: [
  172. {
  173. "ServiceComponentInfo" : {
  174. "component_name" : "STORM_UI_SERVER",
  175. "service_name" : "STORM"
  176. },
  177. "metrics" : {
  178. "api" : {
  179. "v1": {
  180. "cluster": {
  181. "summary": {
  182. "executorsTotal": 28.0,
  183. "nimbusUptime": "15m 1s",
  184. "slotsFree": 0.0,
  185. "slotsTotal": 2.0,
  186. "slotsUsed": 2.0,
  187. "supervisors": 1.0,
  188. "tasksTotal": 28.0
  189. }
  190. },
  191. "topology": {
  192. "summary": [
  193. {
  194. "executorsTotal": 21.0,
  195. "uptime": "5m 59s",
  196. "schedulerInfo": null,
  197. "name": "WordCountida8c06640_date2901141",
  198. "workersTotal": 2.0,
  199. "status": "ACTIVE",
  200. "owner": "",
  201. "tasksTotal": 21.0,
  202. "id": "WordCountida8c06640_date2901141-2-1412195707"
  203. }
  204. ]
  205. }
  206. }
  207. }
  208. }
  209. }
  210. ]
  211. },
  212. {
  213. stackVersionNumber: '2.1',
  214. message: 'Storm mapper, stack version 2.1',
  215. expectedValues: {
  216. total_executors: 2,
  217. nimbus_uptime: "3.96 hours",
  218. free_slots: 2,
  219. used_slots: 0,
  220. total_slots: 2,
  221. total_tasks: 21,
  222. topologies: 0
  223. },
  224. components: [
  225. {
  226. "ServiceComponentInfo" : {
  227. "component_name" : "STORM_REST_API",
  228. "service_name" : "STORM"
  229. },
  230. "metrics" : {
  231. "api" : {
  232. "cluster" : {
  233. "summary" : {
  234. "executors.total" : 2.0,
  235. "nimbus.uptime" : 14250.0,
  236. "slots.free" : 2.0,
  237. "slots.total" : 2.0,
  238. "slots.used" : 0.0,
  239. "supervisors" : 1.0,
  240. "tasks.total" : 21.0,
  241. "topologies" : 0.0
  242. }
  243. }
  244. }
  245. }
  246. }
  247. ]
  248. }
  249. ];
  250. beforeEach(function () {
  251. this.stub = sinon.stub(App, 'get');
  252. });
  253. afterEach(function () {
  254. App.get.restore();
  255. });
  256. tests.forEach(function(test) {
  257. it(test.message, function() {
  258. this.stub.withArgs('currentStackVersionNumber').returns(test.stackVersionNumber);
  259. var result = App.serviceMetricsMapper.stormMapper(test);
  260. expect(result).to.include(test.expectedValues);
  261. });
  262. });
  263. });
  264. });