Jian Li
Committed by Gerrit Code Review

Deprecate and clean up some classes on control metric aggregation

Since the metric aggregation logic has been moved to message
provider, now there is no caller which refers to those classes.
Due to this reason, following classes need to be purged to
maintain clean code repository.

Change-Id: Id5bcb7eda6ce3538c18007301da35df9255159ae
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.cpman.impl;
17 -
18 -import org.onosproject.net.DeviceId;
19 -
20 -import java.util.Optional;
21 -
22 -/**
23 - * Control metrics observer interface.
24 - */
25 -public interface ControlMetricsObserver {
26 -
27 - /**
28 - * Feeds the extracted value from MetricAggregator to back-end storage.
29 - *
30 - * @param metricsAggregator metric aggregator
31 - * @param deviceId device identification
32 - */
33 - void feedMetrics(MetricsAggregator metricsAggregator, Optional<DeviceId> deviceId);
34 -
35 - /**
36 - * Feeds the extracted value from MetricAggregator to back-end storage.
37 - *
38 - * @param metricsAggregator metric aggregator
39 - * @param resourceName resource name
40 - */
41 - void feedMetrics(MetricsAggregator metricsAggregator, String resourceName);
42 -}
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.cpman.impl;
17 -
18 -import org.apache.felix.scr.annotations.Reference;
19 -import org.apache.felix.scr.annotations.ReferenceCardinality;
20 -import org.onosproject.cpman.ControlMetric;
21 -import org.onosproject.cpman.ControlPlaneMonitorService;
22 -import org.onosproject.cpman.MetricValue;
23 -import org.onosproject.net.DeviceId;
24 -
25 -import java.util.Optional;
26 -
27 -/**
28 - * Default ControlMetricsObserver.
29 - */
30 -public class DefaultControlMetricsObserver implements ControlMetricsObserver {
31 -
32 - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
33 - protected ControlPlaneMonitorService controlPlaneMonitorService;
34 -
35 - @Override
36 - public void feedMetrics(MetricsAggregator ma, Optional<DeviceId> deviceId) {
37 - MetricValue mv = new MetricValue.Builder()
38 - .rate(ma.getRate())
39 - .count(ma.getCount())
40 - .load(ma.getLoad())
41 - .add();
42 - ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv);
43 - controlPlaneMonitorService.updateMetric(cm, 1, deviceId);
44 - }
45 -
46 - @Override
47 - public void feedMetrics(MetricsAggregator ma, String resourceName) {
48 - MetricValue mv = new MetricValue.Builder()
49 - .rate(ma.getRate())
50 - .count(ma.getCount())
51 - .load(ma.getLoad())
52 - .add();
53 - ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv);
54 - controlPlaneMonitorService.updateMetric(cm, 1, resourceName);
55 - }
56 -}
...\ No newline at end of file ...\ No newline at end of file
1 -/*
2 - * Copyright 2016-present Open Networking Laboratory
3 - *
4 - * Licensed under the Apache License, Version 2.0 (the "License");
5 - * you may not use this file except in compliance with the License.
6 - * You may obtain a copy of the License at
7 - *
8 - * http://www.apache.org/licenses/LICENSE-2.0
9 - *
10 - * Unless required by applicable law or agreed to in writing, software
11 - * distributed under the License is distributed on an "AS IS" BASIS,
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 - * See the License for the specific language governing permissions and
14 - * limitations under the License.
15 - */
16 -package org.onosproject.cpman.impl;
17 -
18 -import com.codahale.metrics.Meter;
19 -import org.apache.commons.lang3.StringUtils;
20 -import org.onlab.metrics.MetricsComponent;
21 -import org.onlab.metrics.MetricsFeature;
22 -import org.onlab.metrics.MetricsService;
23 -import org.onosproject.cpman.ControlMetricType;
24 -import org.onosproject.net.DeviceId;
25 -
26 -import java.util.Optional;
27 -
28 -import static com.google.common.base.Preconditions.checkNotNull;
29 -
30 -/**
31 - * An aggregator that aggregates a specific network or performance metrics via the metrics service.
32 - */
33 -public class MetricsAggregator {
34 -
35 - private Meter rateMeter;
36 - private Meter countMeter;
37 - private MetricsService metricsService;
38 - private MetricsComponent metricsComponent;
39 - private MetricsFeature metricsFeature;
40 - private ControlMetricType metricsType;
41 - private static final int EXECUTE_PERIOD_IN_SECOND = 60;
42 - private static final String RATE_NAME = "rate";
43 - private static final String COUNT_NAME = "count";
44 -
45 - /**
46 - * Constructs a new metrics aggregator for aggregating a metric.
47 - * Instantiates the metrics service
48 - * Initializes all the general metrics for that object
49 - *
50 - * @param metricsService metric service reference
51 - * @param type control metric type
52 - * @param deviceId device identification
53 - */
54 - MetricsAggregator(MetricsService metricsService, ControlMetricType type,
55 - Optional<DeviceId> deviceId) {
56 - init(metricsService, type, deviceId, null);
57 - }
58 -
59 - /**
60 - * Constructs a new metrics aggregator for aggregating a metric.
61 - * Instantiates the metrics service
62 - * Initializes all the general metrics for that object
63 - *
64 - * @param metricsService metric service reference
65 - * @param type control metric type
66 - * @param resourceName resource name (e.g., ethernet interface name)
67 - */
68 - MetricsAggregator(MetricsService metricsService, ControlMetricType type,
69 - String resourceName) {
70 - init(metricsService, type, Optional.ofNullable(null), resourceName);
71 -
72 - }
73 -
74 - /**
75 - * Constructs a new metrics aggregator for aggregating a metric.
76 - * Instantiates the metrics service
77 - * Initializes all the general metrics for that object
78 - *
79 - * @param metricsService metrics service reference
80 - * @param type control metric type
81 - */
82 - MetricsAggregator(MetricsService metricsService, ControlMetricType type) {
83 - init(metricsService, type, Optional.ofNullable(null), null);
84 - }
85 -
86 - /**
87 - * Base method of the constructor of this class.
88 - *
89 - * @param metricsService metrics service reference
90 - * @param type control metric type
91 - * @param deviceId device identification
92 - * @param resourceName resource name
93 - */
94 - private void init(MetricsService metricsService, ControlMetricType type,
95 - Optional<DeviceId> deviceId, String resourceName) {
96 - String primitiveName = type.toString();
97 - String objName = "all";
98 - if (deviceId.isPresent()) {
99 - objName = deviceId.toString();
100 - }
101 -
102 - if (StringUtils.isNotEmpty(resourceName)) {
103 - objName = resourceName;
104 - }
105 -
106 - checkNotNull(primitiveName, "Component name cannot be null");
107 - checkNotNull(objName, "Feature name cannot be null");
108 -
109 - this.metricsType = type;
110 -
111 - this.metricsService = metricsService;
112 - this.metricsComponent = metricsService.registerComponent(primitiveName);
113 - this.metricsFeature = metricsComponent.registerFeature(objName);
114 -
115 - this.rateMeter = metricsService.createMeter(metricsComponent, metricsFeature, RATE_NAME);
116 - this.countMeter = metricsService.createMeter(metricsComponent, metricsFeature, COUNT_NAME);
117 - }
118 -
119 - /**
120 - * Returns control metrics type.
121 - *
122 - * @return control metrics type
123 - */
124 - public ControlMetricType getMetricsType() {
125 - return metricsType;
126 - }
127 -
128 - /**
129 - * Increments the meter rate by n, and the meter counter by 1.
130 - *
131 - * @param n increment rate.
132 - */
133 - public void increment(long n) {
134 - rateMeter.mark(n);
135 - countMeter.mark(1);
136 - }
137 -
138 - /**
139 - * Returns the average load value.
140 - *
141 - * @return load value
142 - */
143 - public long getLoad() {
144 - return (long) rateMeter.getOneMinuteRate() / (long) countMeter.getOneMinuteRate();
145 - }
146 -
147 - /**
148 - * Returns the average meter rate within recent 1 minute.
149 - *
150 - * @return rate value
151 - */
152 - public long getRate() {
153 - return (long) rateMeter.getOneMinuteRate();
154 - }
155 -
156 - /**
157 - * Returns the average meter count within recent 1 minute.
158 - *
159 - * @return count value
160 - */
161 - public long getCount() {
162 - return (long) countMeter.getOneMinuteRate() * EXECUTE_PERIOD_IN_SECOND;
163 - }
164 -}
...\ No newline at end of file ...\ No newline at end of file