service_mapper_test.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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 Ember = require('ember');
  19. var App = require('app');
  20. require('utils/helper');
  21. require('mappers/server_data_mapper');
  22. require('mappers/service_metrics_mapper');
  23. describe('App.serviceMetricsMapper', function () {
  24. describe('#hbaseMapper', function() {
  25. it ('Round Average Load', function() {
  26. var tests = [
  27. {
  28. components: [
  29. {
  30. ServiceComponentInfo: {
  31. AverageLoad: 1.23456789,
  32. component_name: "HBASE_MASTER",
  33. RegionsInTransition : [ ]
  34. }
  35. }
  36. ],
  37. e: '1.23'
  38. },
  39. {
  40. components: [
  41. {
  42. ServiceComponentInfo: {
  43. AverageLoad: 1.00,
  44. component_name: "HBASE_MASTER",
  45. RegionsInTransition : [ ]
  46. }
  47. }
  48. ],
  49. e: '1.00'
  50. },
  51. {
  52. components: [
  53. {
  54. ServiceComponentInfo: {
  55. AverageLoad: 1,
  56. component_name: "HBASE_MASTER",
  57. RegionsInTransition : [ ]
  58. }
  59. }
  60. ],
  61. e: '1.00'
  62. },
  63. {
  64. components: [
  65. {
  66. ServiceComponentInfo: {
  67. AverageLoad: 1.2,
  68. component_name: "HBASE_MASTER",
  69. RegionsInTransition : [ ]
  70. }
  71. }
  72. ],
  73. e: '1.20'
  74. }
  75. ];
  76. tests.forEach(function(test) {
  77. var result = App.serviceMetricsMapper.hbaseMapper(test);
  78. expect(result.average_load).to.equal(test.e);
  79. });
  80. });
  81. });
  82. describe('#stormMapper', function() {
  83. var tests = [
  84. {
  85. stackVersionNumber: '2.2',
  86. message: 'Storm mapper, stack version 2.2',
  87. expectedValues: {
  88. total_executors: 28,
  89. nimbus_uptime: "15m 1s",
  90. free_slots: 0,
  91. used_slots: 2,
  92. total_slots: 2,
  93. total_tasks: 28,
  94. topologies: 1
  95. },
  96. components: [
  97. {
  98. "ServiceComponentInfo" : {
  99. "component_name" : "STORM_UI_SERVER",
  100. "service_name" : "STORM"
  101. },
  102. "metrics" : {
  103. "api" : {
  104. "v1": {
  105. "cluster": {
  106. "summary": {
  107. "executorsTotal": 28.0,
  108. "nimbusUptime": "15m 1s",
  109. "slotsFree": 0.0,
  110. "slotsTotal": 2.0,
  111. "slotsUsed": 2.0,
  112. "supervisors": 1.0,
  113. "tasksTotal": 28.0
  114. }
  115. },
  116. "topology": {
  117. "summary": [
  118. {
  119. "executorsTotal": 21.0,
  120. "uptime": "5m 59s",
  121. "schedulerInfo": null,
  122. "name": "WordCountida8c06640_date2901141",
  123. "workersTotal": 2.0,
  124. "status": "ACTIVE",
  125. "owner": "",
  126. "tasksTotal": 21.0,
  127. "id": "WordCountida8c06640_date2901141-2-1412195707"
  128. }
  129. ]
  130. }
  131. }
  132. }
  133. }
  134. }
  135. ]
  136. },
  137. {
  138. stackVersionNumber: '2.1',
  139. message: 'Storm mapper, stack version 2.1',
  140. expectedValues: {
  141. total_executors: 2,
  142. nimbus_uptime: "3.96 hours",
  143. free_slots: 2,
  144. used_slots: 0,
  145. total_slots: 2,
  146. total_tasks: 21,
  147. topologies: 0
  148. },
  149. components: [
  150. {
  151. "ServiceComponentInfo" : {
  152. "component_name" : "STORM_REST_API",
  153. "service_name" : "STORM"
  154. },
  155. "metrics" : {
  156. "api" : {
  157. "cluster" : {
  158. "summary" : {
  159. "executors.total" : 2.0,
  160. "nimbus.uptime" : 14250.0,
  161. "slots.free" : 2.0,
  162. "slots.total" : 2.0,
  163. "slots.used" : 0.0,
  164. "supervisors" : 1.0,
  165. "tasks.total" : 21.0,
  166. "topologies" : 0.0
  167. }
  168. }
  169. }
  170. }
  171. }
  172. ]
  173. }
  174. ];
  175. tests.forEach(function(test) {
  176. it(test.message, function() {
  177. sinon.stub(App, 'get', function(key) {
  178. if (key == 'currentStackVersionNumber') {
  179. return test.stackVersionNumber;
  180. }
  181. });
  182. var result = App.serviceMetricsMapper.stormMapper(test);
  183. expect(result).to.include(test.expectedValues);
  184. App.get.restore();
  185. });
  186. });
  187. });
  188. });