123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- /**
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
- App = require('app');
- require('controllers/main/service/widgets/create/wizard_controller');
- describe('App.WidgetWizardController', function () {
- var controller;
- /**
- * tests the function with following hierarchical queue scenario
- * root
- * |
- * queue1
- * / \
- * queue2 queue3
- *
- */
- describe("#substitueQueueMetrics", function () {
- beforeEach(function () {
- controller = App.WidgetWizardController.create();
- sinon.stub(App.YARNService, 'find', function (k) {
- if ('YARN' === k) {
- return Em.Object.create({
- 'allQueueNames': ["root", "root/queue1", "root/queue1/queue2", "root/queue1/queue3"]
- });
- }
- });
- });
- afterEach(function () {
- controller = '';
- App.YARNService.find.restore();
- });
- var testCases = [
- {
- 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',
- inputMetrics: [
- {
- component_name: 'RESOURCEMANAGER',
- level: 'COMPONENT',
- name: 'yarn.QueueMetrics.Queue=(.+).AppsFailed',
- point_in_time: false,
- service_name: 'YARN',
- temporal: true,
- type: 'GANGLIA',
- widget_id: 'metrics/yarn/Queue/$1.replaceAll("([.])","/")/AppsFailed'
- }
- ],
- expectedResult: [
- {
- "component_name": "RESOURCEMANAGER",
- "level": "COMPONENT",
- "name": "yarn.QueueMetrics.Queue=root.AppsFailed",
- "point_in_time": false,
- "service_name": "YARN",
- "temporal": true,
- "type": "GANGLIA",
- "widget_id": "metrics/yarn/Queue/root/AppsFailed"
- },
- {
- "component_name": "RESOURCEMANAGER",
- "level": "COMPONENT",
- "name": "yarn.QueueMetrics.Queue=root.queue1.AppsFailed",
- "point_in_time": false,
- "service_name": "YARN",
- "temporal": true,
- "type": "GANGLIA",
- "widget_id": "metrics/yarn/Queue/root/queue1/AppsFailed"
- },
- {
- "component_name": "RESOURCEMANAGER",
- "level": "COMPONENT",
- "name": "yarn.QueueMetrics.Queue=root.queue1.queue2.AppsFailed",
- "point_in_time": false,
- "service_name": "YARN",
- "temporal": true,
- "type": "GANGLIA",
- "widget_id": "metrics/yarn/Queue/root/queue1/queue2/AppsFailed"
- },
- {
- "component_name": "RESOURCEMANAGER",
- "level": "COMPONENT",
- "name": "yarn.QueueMetrics.Queue=root.queue1.queue3.AppsFailed",
- "point_in_time": false,
- "service_name": "YARN",
- "temporal": true,
- "type": "GANGLIA",
- "widget_id": "metrics/yarn/Queue/root/queue1/queue3/AppsFailed"
- }
- ]
- },
- {
- 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',
- inputMetrics: [
- {
- component_name: 'RESOURCEMANAGER',
- host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
- level: 'HOSTCOMPONENT',
- name: 'Hadoop:service=ResourceManager,name=QueueMetrics(.+).AppsFailed',
- point_in_time: true,
- service_name: 'YARN',
- temporal: false,
- type: 'JMX',
- widget_id: 'metrics/yarn/Queue/$1.replaceAll(",q(\d+)=","/").substring(1)/AppsFailed'
- }
- ],
- expectedResult: [
- {
- component_name: 'RESOURCEMANAGER',
- host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
- level: 'HOSTCOMPONENT',
- name: 'Hadoop:service=ResourceManager,name=QueueMetrics,q0=root.AppsFailed',
- point_in_time: true,
- service_name: 'YARN',
- temporal: false,
- type: 'JMX',
- widget_id: 'metrics/yarn/Queue/root/AppsFailed'
- },
- {
- component_name: 'RESOURCEMANAGER',
- host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
- level: 'HOSTCOMPONENT',
- name: 'Hadoop:service=ResourceManager,name=QueueMetrics,q0=root,q1=queue1.AppsFailed',
- point_in_time: true,
- service_name: 'YARN',
- temporal: false,
- type: 'JMX',
- widget_id: 'metrics/yarn/Queue/root/queue1/AppsFailed'
- },
- {
- component_name: 'RESOURCEMANAGER',
- host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
- level: 'HOSTCOMPONENT',
- name: 'Hadoop:service=ResourceManager,name=QueueMetrics,q0=root,q1=queue1,q2=queue2.AppsFailed',
- point_in_time: true,
- service_name: 'YARN',
- temporal: false,
- type: 'JMX',
- widget_id: 'metrics/yarn/Queue/root/queue1/queue2/AppsFailed'
- },
- {
- component_name: 'RESOURCEMANAGER',
- host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
- level: 'HOSTCOMPONENT',
- name: 'Hadoop:service=ResourceManager,name=QueueMetrics,q0=root,q1=queue1,q2=queue3.AppsFailed',
- point_in_time: true,
- service_name: 'YARN',
- temporal: false,
- type: 'JMX',
- widget_id: 'metrics/yarn/Queue/root/queue1/queue3/AppsFailed'
- }
- ]
- },
- {
- msg: 'AMS Queue metric without regex in name and path should retain same name and path',
- inputMetrics: [
- {
- component_name: 'RESOURCEMANAGER',
- level: 'COMPONENT',
- name: 'yarn.QueueMetrics.Queue.Clustermetrics.AppsFailed',
- point_in_time: false,
- service_name: 'YARN',
- temporal: true,
- type: 'GANGLIA',
- widget_id: 'metrics/yarn/Queue/Clustermetrics/AppsFailed'
- }
- ],
- expectedResult: [
- {
- component_name: 'RESOURCEMANAGER',
- level: 'COMPONENT',
- name: 'yarn.QueueMetrics.Queue.Clustermetrics.AppsFailed',
- point_in_time: false,
- service_name: 'YARN',
- temporal: true,
- type: 'GANGLIA',
- widget_id: 'metrics/yarn/Queue/Clustermetrics/AppsFailed'
- }
- ]
- },
- {
- msg: 'JMX Queue metric without regex in name and path should retain same name and path',
- inputMetrics: [
- {
- component_name: 'RESOURCEMANAGER',
- host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
- level: 'HOSTCOMPONENT',
- name: 'Hadoop:service=ResourceManager,name=QueueMetrics.clusterMetric.AppsFailed',
- point_in_time: true,
- service_name: 'YARN',
- temporal: false,
- type: 'JMX',
- widget_id: 'metrics/yarn/Queue/clusterMetric/AppsFailed'
- }
- ],
- expectedResult: [
- {
- component_name: 'RESOURCEMANAGER',
- host_component_criteria: 'host_components/HostRoles/ha_state=ACTIVE',
- level: 'HOSTCOMPONENT',
- name: 'Hadoop:service=ResourceManager,name=QueueMetrics.clusterMetric.AppsFailed',
- point_in_time: true,
- service_name: 'YARN',
- temporal: false,
- type: 'JMX',
- widget_id: 'metrics/yarn/Queue/clusterMetric/AppsFailed'
- }
- ]
- }
- ];
- testCases.forEach(function (_testCase) {
- it(_testCase.msg, function () {
- var result = controller.substitueQueueMetrics(_testCase.inputMetrics);
- expect(JSON.stringify(result)).to.equal(JSON.stringify(_testCase.expectedResult));
- });
- });
- });
- });
|