service_metrics_mapper_test.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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. describe('App.serviceMetricsMapper', function () {
  19. describe('#computeAdditionalRelations', function () {
  20. var tests = [
  21. {
  22. message: 'if both namenodes are standby then `display_name_advanced` for both should be `Standby NameNode`',
  23. haStateForNn1: 'standby',
  24. haStateForNn2: 'standby',
  25. expectedNameForNn1: 'Standby NameNode',
  26. expectedNameForNn2: 'Standby NameNode'
  27. },
  28. {
  29. message: 'if one namenode is active and another is standby then they should be shown as `Active NameNode` and `Standby NameNode` respectively',
  30. haStateForNn1: 'active',
  31. haStateForNn2: 'standby',
  32. expectedNameForNn1: 'Active NameNode',
  33. expectedNameForNn2: 'Standby NameNode'
  34. },
  35. {
  36. message: 'if one namenode is active and another is unknown then they should be shown as `Active NameNode` and `Standby NameNode` respectively',
  37. haStateForNn1: 'active',
  38. haStateForNn2: undefined,
  39. expectedNameForNn1: 'Active NameNode',
  40. expectedNameForNn2: 'Standby NameNode'
  41. },
  42. {
  43. message: 'if both namenodes state are unknown then `display_name_advanced` for both should be null (NN will be shown with display name as `NameNode`)',
  44. haStateForNn1: undefined,
  45. haStateForNn2: undefined,
  46. expectedNameForNn1: null,
  47. expectedNameForNn2: null
  48. }
  49. ];
  50. var services = [
  51. {
  52. ServiceInfo: {
  53. service_name: "HDFS"
  54. },
  55. components: [
  56. {
  57. ServiceComponentInfo: {
  58. component_name: "NAMENODE",
  59. service_name: "HDFS"
  60. },
  61. host_components: [
  62. {
  63. HostRoles: {
  64. component_name: "NAMENODE",
  65. host_name: "h1"
  66. },
  67. metrics: {
  68. dfs: {
  69. FSNamesystem: {
  70. HAState: ""
  71. }
  72. }
  73. }
  74. },
  75. {
  76. HostRoles: {
  77. component_name: "NAMENODE",
  78. host_name: "h2"
  79. },
  80. metrics: {
  81. dfs: {
  82. FSNamesystem: {
  83. HAState: ""
  84. }
  85. }
  86. }
  87. }
  88. ]
  89. }
  90. ]
  91. }
  92. ];
  93. var hostComponents = [
  94. {
  95. component_name: "NAMENODE",
  96. host_id: "h1",
  97. service_id: "HDFS"
  98. },
  99. {
  100. component_name: "NAMENODE",
  101. host_id: "h2",
  102. service_id: "HDFS"
  103. }
  104. ];
  105. tests.forEach(function (test) {
  106. it(test.message, function () {
  107. services[0].components[0].host_components[0].metrics.dfs.FSNamesystem.HAState = test.haStateForNn1;
  108. services[0].components[0].host_components[1].metrics.dfs.FSNamesystem.HAState = test.haStateForNn2;
  109. App.serviceMetricsMapper.computeAdditionalRelations(hostComponents, services);
  110. expect(hostComponents[0].display_name_advanced).to.equal(test.expectedNameForNn1);
  111. expect(hostComponents[1].display_name_advanced).to.equal(test.expectedNameForNn2);
  112. });
  113. });
  114. });
  115. describe('#yarnMapper', function () {
  116. it('should set ACTIVE RM first in any cases (if RM HA enabled)', function() {
  117. var item = {
  118. components: [
  119. {
  120. ServiceComponentInfo: {
  121. component_name: 'RESOURCEMANAGER'
  122. },
  123. host_components: [
  124. {
  125. HostRoles: {
  126. ha_state: null,
  127. host_name : 'h1'
  128. }
  129. },
  130. {
  131. HostRoles: {
  132. ha_state: 'ACTIVE',
  133. host_name : 'h2'
  134. },
  135. metrics: {
  136. yarn: {
  137. Queue: {
  138. root: {
  139. default: {}
  140. }
  141. }
  142. }
  143. }
  144. }
  145. ]
  146. }
  147. ]
  148. },
  149. result = App.serviceMetricsMapper.yarnMapper(item);
  150. expect(result.queue).to.equal("{\"root\":{\"default\":{}}}");
  151. });
  152. });
  153. describe("#isHostComponentPresent()", function () {
  154. var testCases = [
  155. {
  156. title: 'component is empty',
  157. data: {
  158. component: {},
  159. name: 'C1'
  160. },
  161. result: false
  162. },
  163. {
  164. title: 'component name does not match',
  165. data: {
  166. component: {
  167. ServiceComponentInfo: {
  168. component_name: ''
  169. }
  170. },
  171. name: 'C1'
  172. },
  173. result: false
  174. },
  175. {
  176. title: 'host_components is undefined',
  177. data: {
  178. component: {
  179. ServiceComponentInfo: {
  180. component_name: 'C1'
  181. }
  182. },
  183. name: 'C1'
  184. },
  185. result: false
  186. },
  187. {
  188. title: 'host_components is empty',
  189. data: {
  190. component: {
  191. ServiceComponentInfo: {
  192. component_name: 'C1'
  193. },
  194. host_components: []
  195. },
  196. name: 'C1'
  197. },
  198. result: false
  199. },
  200. {
  201. title: 'host_components has component',
  202. data: {
  203. component: {
  204. ServiceComponentInfo: {
  205. component_name: 'C1'
  206. },
  207. host_components: [{}]
  208. },
  209. name: 'C1'
  210. },
  211. result: true
  212. }
  213. ];
  214. testCases.forEach(function (test) {
  215. it(test.title, function () {
  216. expect(App.serviceMetricsMapper.isHostComponentPresent(test.data.component, test.data.name)).to.equal(test.result);
  217. });
  218. });
  219. });
  220. });