wizard_controller_test.js 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  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. App = require('app');
  19. require('controllers/main/service/widgets/create/wizard_controller');
  20. describe('App.WidgetWizardController', function () {
  21. var controller;
  22. /**
  23. * tests the function with following hierarchical queue scenario
  24. * root
  25. * |
  26. * queue1
  27. * / \
  28. * queue2 queue3
  29. *
  30. */
  31. describe("#substitueQueueMetrics", function () {
  32. beforeEach(function () {
  33. controller = App.WidgetWizardController.create();
  34. sinon.stub(App.YARNService, 'find', function (k) {
  35. if ('YARN' === k) {
  36. return Em.Object.create({
  37. 'allQueueNames': ["root", "root/queue1", "root/queue1/queue2", "root/queue1/queue3"]
  38. });
  39. }
  40. });
  41. });
  42. afterEach(function () {
  43. controller = '';
  44. App.YARNService.find.restore();
  45. });
  46. var testCases = [
  47. {
  48. msg: 'AMS Queue metric with regex as name and regex as path should be replaced with actual metric name and path of all existing queues',
  49. inputMetrics: [
  50. {
  51. component_name: 'RESOURCEMANAGER',
  52. level: 'COMPONENT',
  53. name: 'yarn.QueueMetrics.Queue=(.+).AppsFailed',
  54. point_in_time: false,
  55. service_name: 'YARN',
  56. temporal: true,
  57. type: 'GANGLIA',
  58. widget_id: 'metrics/yarn/Queue/$1.replaceAll("([.])","/")/AppsFailed'
  59. }
  60. ],
  61. expectedResult: [
  62. {
  63. "component_name": "RESOURCEMANAGER",
  64. "level": "COMPONENT",
  65. "name": "yarn.QueueMetrics.Queue=root.AppsFailed",
  66. "point_in_time": false,
  67. "service_name": "YARN",
  68. "temporal": true,
  69. "type": "GANGLIA",
  70. "widget_id": "metrics/yarn/Queue/root/AppsFailed"
  71. },
  72. {
  73. "component_name": "RESOURCEMANAGER",
  74. "level": "COMPONENT",
  75. "name": "yarn.QueueMetrics.Queue=root.queue1.AppsFailed",
  76. "point_in_time": false,
  77. "service_name": "YARN",
  78. "temporal": true,
  79. "type": "GANGLIA",
  80. "widget_id": "metrics/yarn/Queue/root/queue1/AppsFailed"
  81. },
  82. {
  83. "component_name": "RESOURCEMANAGER",
  84. "level": "COMPONENT",
  85. "name": "yarn.QueueMetrics.Queue=root.queue1.queue2.AppsFailed",
  86. "point_in_time": false,
  87. "service_name": "YARN",
  88. "temporal": true,
  89. "type": "GANGLIA",
  90. "widget_id": "metrics/yarn/Queue/root/queue1/queue2/AppsFailed"
  91. },
  92. {
  93. "component_name": "RESOURCEMANAGER",
  94. "level": "COMPONENT",
  95. "name": "yarn.QueueMetrics.Queue=root.queue1.queue3.AppsFailed",
  96. "point_in_time": false,
  97. "service_name": "YARN",
  98. "temporal": true,
  99. "type": "GANGLIA",
  100. "widget_id": "metrics/yarn/Queue/root/queue1/queue3/AppsFailed"
  101. }
  102. ]
  103. },
  104. {
  105. msg: 'JMX Queue metric with regex as name and regex as path should be replaced with actual metric name and path of all existing queues',
  106. inputMetrics: [
  107. {
  108. component_name: 'RESOURCEMANAGER',
  109. host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
  110. level: 'HOSTCOMPONENT',
  111. name: 'Hadoop:service=ResourceManager,name=QueueMetrics(.+).AppsFailed',
  112. point_in_time: true,
  113. service_name: 'YARN',
  114. temporal: false,
  115. type: 'JMX',
  116. widget_id: 'metrics/yarn/Queue/$1.replaceAll(",q(\d+)=","/").substring(1)/AppsFailed'
  117. }
  118. ],
  119. expectedResult: [
  120. {
  121. component_name: 'RESOURCEMANAGER',
  122. host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
  123. level: 'HOSTCOMPONENT',
  124. name: 'Hadoop:service=ResourceManager,name=QueueMetrics,q0=root.AppsFailed',
  125. point_in_time: true,
  126. service_name: 'YARN',
  127. temporal: false,
  128. type: 'JMX',
  129. widget_id: 'metrics/yarn/Queue/root/AppsFailed'
  130. },
  131. {
  132. component_name: 'RESOURCEMANAGER',
  133. host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
  134. level: 'HOSTCOMPONENT',
  135. name: 'Hadoop:service=ResourceManager,name=QueueMetrics,q0=root,q1=queue1.AppsFailed',
  136. point_in_time: true,
  137. service_name: 'YARN',
  138. temporal: false,
  139. type: 'JMX',
  140. widget_id: 'metrics/yarn/Queue/root/queue1/AppsFailed'
  141. },
  142. {
  143. component_name: 'RESOURCEMANAGER',
  144. host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
  145. level: 'HOSTCOMPONENT',
  146. name: 'Hadoop:service=ResourceManager,name=QueueMetrics,q0=root,q1=queue1,q2=queue2.AppsFailed',
  147. point_in_time: true,
  148. service_name: 'YARN',
  149. temporal: false,
  150. type: 'JMX',
  151. widget_id: 'metrics/yarn/Queue/root/queue1/queue2/AppsFailed'
  152. },
  153. {
  154. component_name: 'RESOURCEMANAGER',
  155. host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
  156. level: 'HOSTCOMPONENT',
  157. name: 'Hadoop:service=ResourceManager,name=QueueMetrics,q0=root,q1=queue1,q2=queue3.AppsFailed',
  158. point_in_time: true,
  159. service_name: 'YARN',
  160. temporal: false,
  161. type: 'JMX',
  162. widget_id: 'metrics/yarn/Queue/root/queue1/queue3/AppsFailed'
  163. }
  164. ]
  165. },
  166. {
  167. msg: 'AMS Queue metric without regex in name and path should retain same name and path',
  168. inputMetrics: [
  169. {
  170. component_name: 'RESOURCEMANAGER',
  171. level: 'COMPONENT',
  172. name: 'yarn.QueueMetrics.Queue.Clustermetrics.AppsFailed',
  173. point_in_time: false,
  174. service_name: 'YARN',
  175. temporal: true,
  176. type: 'GANGLIA',
  177. widget_id: 'metrics/yarn/Queue/Clustermetrics/AppsFailed'
  178. }
  179. ],
  180. expectedResult: [
  181. {
  182. component_name: 'RESOURCEMANAGER',
  183. level: 'COMPONENT',
  184. name: 'yarn.QueueMetrics.Queue.Clustermetrics.AppsFailed',
  185. point_in_time: false,
  186. service_name: 'YARN',
  187. temporal: true,
  188. type: 'GANGLIA',
  189. widget_id: 'metrics/yarn/Queue/Clustermetrics/AppsFailed'
  190. }
  191. ]
  192. },
  193. {
  194. msg: 'JMX Queue metric without regex in name and path should retain same name and path',
  195. inputMetrics: [
  196. {
  197. component_name: 'RESOURCEMANAGER',
  198. host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
  199. level: 'HOSTCOMPONENT',
  200. name: 'Hadoop:service=ResourceManager,name=QueueMetrics.clusterMetric.AppsFailed',
  201. point_in_time: true,
  202. service_name: 'YARN',
  203. temporal: false,
  204. type: 'JMX',
  205. widget_id: 'metrics/yarn/Queue/clusterMetric/AppsFailed'
  206. }
  207. ],
  208. expectedResult: [
  209. {
  210. component_name: 'RESOURCEMANAGER',
  211. host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
  212. level: 'HOSTCOMPONENT',
  213. name: 'Hadoop:service=ResourceManager,name=QueueMetrics.clusterMetric.AppsFailed',
  214. point_in_time: true,
  215. service_name: 'YARN',
  216. temporal: false,
  217. type: 'JMX',
  218. widget_id: 'metrics/yarn/Queue/clusterMetric/AppsFailed'
  219. }
  220. ]
  221. }
  222. ];
  223. testCases.forEach(function (_testCase) {
  224. it(_testCase.msg, function () {
  225. var result = controller.substitueQueueMetrics(_testCase.inputMetrics);
  226. expect(JSON.stringify(result)).to.equal(JSON.stringify(_testCase.expectedResult));
  227. });
  228. });
  229. });
  230. });