Committed by
Ray Milkey
Code clean up for control plane manager
- Exception handlers should preserve the original exception - Collection.isEmpty() should be used to test for emptiness Change-Id: Ic76cf94f84fa761bb64b608df61fbd259c7990c4
Showing
4 changed files
with
23 additions
and
40 deletions
... | @@ -80,7 +80,7 @@ public class ResourceNameCompleter extends AbstractCompleter { | ... | @@ -80,7 +80,7 @@ public class ResourceNameCompleter extends AbstractCompleter { |
80 | 80 | ||
81 | SortedSet<String> strings = delegate.getStrings(); | 81 | SortedSet<String> strings = delegate.getStrings(); |
82 | 82 | ||
83 | - if (set.size() != 0) { | 83 | + if (!set.isEmpty()) { |
84 | set.forEach(strings::add); | 84 | set.forEach(strings::add); |
85 | } | 85 | } |
86 | } | 86 | } | ... | ... |
... | @@ -35,14 +35,11 @@ import org.onosproject.ui.RequestHandler; | ... | @@ -35,14 +35,11 @@ import org.onosproject.ui.RequestHandler; |
35 | import org.onosproject.ui.UiMessageHandler; | 35 | import org.onosproject.ui.UiMessageHandler; |
36 | import org.onosproject.ui.chart.ChartModel; | 36 | import org.onosproject.ui.chart.ChartModel; |
37 | import org.onosproject.ui.chart.ChartRequestHandler; | 37 | import org.onosproject.ui.chart.ChartRequestHandler; |
38 | -import org.slf4j.Logger; | ||
39 | -import org.slf4j.LoggerFactory; | ||
40 | 38 | ||
41 | import java.util.Collection; | 39 | import java.util.Collection; |
42 | import java.util.Map; | 40 | import java.util.Map; |
43 | import java.util.Optional; | 41 | import java.util.Optional; |
44 | import java.util.Set; | 42 | import java.util.Set; |
45 | -import java.util.concurrent.ExecutionException; | ||
46 | import java.util.concurrent.TimeUnit; | 43 | import java.util.concurrent.TimeUnit; |
47 | import java.util.stream.LongStream; | 44 | import java.util.stream.LongStream; |
48 | 45 | ||
... | @@ -54,8 +51,6 @@ import static org.onosproject.cpman.ControlResource.Type.CONTROL_MESSAGE; | ... | @@ -54,8 +51,6 @@ import static org.onosproject.cpman.ControlResource.Type.CONTROL_MESSAGE; |
54 | */ | 51 | */ |
55 | public class CpmanViewMessageHandler extends UiMessageHandler { | 52 | public class CpmanViewMessageHandler extends UiMessageHandler { |
56 | 53 | ||
57 | - private final Logger log = LoggerFactory.getLogger(getClass()); | ||
58 | - | ||
59 | private static final String CPMAN_DATA_REQ = "cpmanDataRequest"; | 54 | private static final String CPMAN_DATA_REQ = "cpmanDataRequest"; |
60 | private static final String CPMAN_DATA_RESP = "cpmanDataResponse"; | 55 | private static final String CPMAN_DATA_RESP = "cpmanDataResponse"; |
61 | private static final String CPMANS = "cpmans"; | 56 | private static final String CPMANS = "cpmans"; |
... | @@ -131,16 +126,10 @@ public class CpmanViewMessageHandler extends UiMessageHandler { | ... | @@ -131,16 +126,10 @@ public class CpmanViewMessageHandler extends UiMessageHandler { |
131 | ClusterService cs, DeviceId deviceId) { | 126 | ClusterService cs, DeviceId deviceId) { |
132 | Map<ControlMetricType, Long> data = Maps.newHashMap(); | 127 | Map<ControlMetricType, Long> data = Maps.newHashMap(); |
133 | for (ControlMetricType cmt : CONTROL_MESSAGE_METRICS) { | 128 | for (ControlMetricType cmt : CONTROL_MESSAGE_METRICS) { |
134 | - ControlLoadSnapshot cls; | 129 | + ControlLoadSnapshot cls = cpms.getLoadSync(cs.getLocalNode().id(), |
135 | - try { | 130 | + cmt, NUM_OF_DATA_POINTS, TimeUnit.MINUTES, Optional.of(deviceId)); |
136 | - cls = cpms.getLoad(cs.getLocalNode().id(), | 131 | + data.put(cmt, Math.round(LongStream.of(cls.recent()).average().getAsDouble())); |
137 | - cmt, NUM_OF_DATA_POINTS, TimeUnit.MINUTES, | 132 | + timestamp = cls.time(); |
138 | - Optional.of(deviceId)).get(); | ||
139 | - data.put(cmt, Math.round(LongStream.of(cls.recent()).average().getAsDouble())); | ||
140 | - timestamp = cls.time(); | ||
141 | - } catch (InterruptedException | ExecutionException e) { | ||
142 | - log.warn(e.getMessage()); | ||
143 | - } | ||
144 | } | 133 | } |
145 | return data; | 134 | return data; |
146 | } | 135 | } | ... | ... |
... | @@ -94,7 +94,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -94,7 +94,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
94 | sample.setValue(metricType, value); | 94 | sample.setValue(metricType, value); |
95 | sample.update(); | 95 | sample.update(); |
96 | } catch (IOException e) { | 96 | } catch (IOException e) { |
97 | - log.error("Failed to update metric value due to {}", e.getMessage()); | 97 | + log.error("Failed to update metric value due to {}", e); |
98 | } | 98 | } |
99 | } | 99 | } |
100 | 100 | ||
... | @@ -112,12 +112,12 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -112,12 +112,12 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
112 | checkArgument(rrdDb.containsDs(k), NON_EXIST_METRIC); | 112 | checkArgument(rrdDb.containsDs(k), NON_EXIST_METRIC); |
113 | sample.setValue(k, v); | 113 | sample.setValue(k, v); |
114 | } catch (IOException e) { | 114 | } catch (IOException e) { |
115 | - log.error("Failed to update metric value due to {}", e.getMessage()); | 115 | + log.error("Failed to update metric value due to {}", e); |
116 | } | 116 | } |
117 | }); | 117 | }); |
118 | sample.update(); | 118 | sample.update(); |
119 | } catch (IOException e) { | 119 | } catch (IOException e) { |
120 | - log.error("Failed to update metric values due to {}", e.getMessage()); | 120 | + log.error("Failed to update metric values due to {}", e); |
121 | } | 121 | } |
122 | } | 122 | } |
123 | 123 | ||
... | @@ -127,7 +127,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -127,7 +127,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
127 | checkArgument(rrdDb.containsDs(metricType), NON_EXIST_METRIC); | 127 | checkArgument(rrdDb.containsDs(metricType), NON_EXIST_METRIC); |
128 | return rrdDb.getDatasource(metricType).getLastValue(); | 128 | return rrdDb.getDatasource(metricType).getLastValue(); |
129 | } catch (IOException e) { | 129 | } catch (IOException e) { |
130 | - log.error("Failed to obtain metric value due to {}", e.getMessage()); | 130 | + log.error("Failed to obtain metric value due to {}", e); |
131 | return 0D; | 131 | return 0D; |
132 | } | 132 | } |
133 | } | 133 | } |
... | @@ -146,7 +146,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -146,7 +146,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
146 | return new double[0]; | 146 | return new double[0]; |
147 | } | 147 | } |
148 | } catch (IOException e) { | 148 | } catch (IOException e) { |
149 | - log.error("Failed to obtain metric values due to {}", e.getMessage()); | 149 | + log.error("Failed to obtain metric values due to {}", e); |
150 | return new double[0]; | 150 | return new double[0]; |
151 | } | 151 | } |
152 | } | 152 | } |
... | @@ -159,7 +159,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -159,7 +159,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
159 | long startTime = endTime - SECONDS_OF_DAY + 1; | 159 | long startTime = endTime - SECONDS_OF_DAY + 1; |
160 | return minMetric(metricType, startTime, endTime); | 160 | return minMetric(metricType, startTime, endTime); |
161 | } catch (IOException e) { | 161 | } catch (IOException e) { |
162 | - log.error("Failed to obtain metric value due to {}", e.getMessage()); | 162 | + log.error("Failed to obtain metric value due to {}", e); |
163 | return 0D; | 163 | return 0D; |
164 | } | 164 | } |
165 | } | 165 | } |
... | @@ -172,7 +172,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -172,7 +172,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
172 | long startTime = endTime - SECONDS_OF_DAY; | 172 | long startTime = endTime - SECONDS_OF_DAY; |
173 | return maxMetric(metricType, startTime, endTime); | 173 | return maxMetric(metricType, startTime, endTime); |
174 | } catch (IOException e) { | 174 | } catch (IOException e) { |
175 | - log.error("Failed to obtain metric value due to {}", e.getMessage()); | 175 | + log.error("Failed to obtain metric value due to {}", e); |
176 | return 0D; | 176 | return 0D; |
177 | } | 177 | } |
178 | } | 178 | } |
... | @@ -185,7 +185,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -185,7 +185,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
185 | long startTime = endTime - SECONDS_OF_DAY; | 185 | long startTime = endTime - SECONDS_OF_DAY; |
186 | return metrics(metricType, startTime, endTime); | 186 | return metrics(metricType, startTime, endTime); |
187 | } catch (IOException e) { | 187 | } catch (IOException e) { |
188 | - log.error("Failed to obtain metric values due to {}", e.getMessage()); | 188 | + log.error("Failed to obtain metric values due to {}", e); |
189 | return new double[0]; | 189 | return new double[0]; |
190 | } | 190 | } |
191 | } | 191 | } |
... | @@ -202,7 +202,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -202,7 +202,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
202 | return new double[0]; | 202 | return new double[0]; |
203 | } | 203 | } |
204 | } catch (IOException e) { | 204 | } catch (IOException e) { |
205 | - log.error("Failed to obtain metric values due to {}", e.getMessage()); | 205 | + log.error("Failed to obtain metric values due to {}", e); |
206 | return new double[0]; | 206 | return new double[0]; |
207 | } | 207 | } |
208 | } | 208 | } |
... | @@ -213,7 +213,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -213,7 +213,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
213 | checkArgument(rrdDb.containsDs(metricType), NON_EXIST_METRIC); | 213 | checkArgument(rrdDb.containsDs(metricType), NON_EXIST_METRIC); |
214 | return rrdDb.getLastUpdateTime(); | 214 | return rrdDb.getLastUpdateTime(); |
215 | } catch (IOException e) { | 215 | } catch (IOException e) { |
216 | - log.error("Failed to obtain last update time due to {}", e.getMessage()); | 216 | + log.error("Failed to obtain last update time due to {}", e); |
217 | return 0L; | 217 | return 0L; |
218 | } | 218 | } |
219 | } | 219 | } |
... | @@ -296,7 +296,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -296,7 +296,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
296 | public MetricsDatabase build() { | 296 | public MetricsDatabase build() { |
297 | checkNotNull(metricName, METRIC_NAME_MSG); | 297 | checkNotNull(metricName, METRIC_NAME_MSG); |
298 | checkNotNull(resourceName, RESOURCE_NAME_MSG); | 298 | checkNotNull(resourceName, RESOURCE_NAME_MSG); |
299 | - checkArgument(dsDefs.size() != 0, METRIC_TYPE_MSG); | 299 | + checkArgument(!dsDefs.isEmpty(), METRIC_TYPE_MSG); |
300 | 300 | ||
301 | // define the resolution of monitored metrics | 301 | // define the resolution of monitored metrics |
302 | rrdDef = new RrdDef(DB_PATH + SPLITTER + metricName + | 302 | rrdDef = new RrdDef(DB_PATH + SPLITTER + metricName + |
... | @@ -317,7 +317,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { | ... | @@ -317,7 +317,7 @@ public final class DefaultMetricsDatabase implements MetricsDatabase { |
317 | // always store the metric data in memory... | 317 | // always store the metric data in memory... |
318 | rrdDb = new RrdDb(rrdDef, RrdBackendFactory.getFactory(STORING_METHOD)); | 318 | rrdDb = new RrdDb(rrdDef, RrdBackendFactory.getFactory(STORING_METHOD)); |
319 | } catch (IOException e) { | 319 | } catch (IOException e) { |
320 | - log.warn("Failed to create a new round-robin database due to {}", e.getMessage()); | 320 | + log.warn("Failed to create a new round-robin database due to {}", e); |
321 | } | 321 | } |
322 | 322 | ||
323 | return new DefaultMetricsDatabase(metricName, resourceName, rrdDb); | 323 | return new DefaultMetricsDatabase(metricName, resourceName, rrdDb); | ... | ... |
... | @@ -27,8 +27,8 @@ import org.onosproject.cpman.ControlResource; | ... | @@ -27,8 +27,8 @@ import org.onosproject.cpman.ControlResource; |
27 | import org.onosproject.cpman.MetricValue; | 27 | import org.onosproject.cpman.MetricValue; |
28 | import org.onosproject.cpman.SystemInfo; | 28 | import org.onosproject.cpman.SystemInfo; |
29 | import org.onosproject.cpman.impl.DefaultSystemInfo; | 29 | import org.onosproject.cpman.impl.DefaultSystemInfo; |
30 | -import org.onosproject.cpman.impl.SystemMetricsAggregator; | ||
31 | import org.onosproject.cpman.impl.SystemInfoFactory; | 30 | import org.onosproject.cpman.impl.SystemInfoFactory; |
31 | +import org.onosproject.cpman.impl.SystemMetricsAggregator; | ||
32 | import org.onosproject.rest.AbstractWebResource; | 32 | import org.onosproject.rest.AbstractWebResource; |
33 | import org.slf4j.Logger; | 33 | import org.slf4j.Logger; |
34 | import org.slf4j.LoggerFactory; | 34 | import org.slf4j.LoggerFactory; |
... | @@ -36,7 +36,6 @@ import org.slf4j.LoggerFactory; | ... | @@ -36,7 +36,6 @@ import org.slf4j.LoggerFactory; |
36 | import javax.ws.rs.Consumes; | 36 | import javax.ws.rs.Consumes; |
37 | import javax.ws.rs.POST; | 37 | import javax.ws.rs.POST; |
38 | import javax.ws.rs.Path; | 38 | import javax.ws.rs.Path; |
39 | -import javax.ws.rs.Produces; | ||
40 | import javax.ws.rs.core.MediaType; | 39 | import javax.ws.rs.core.MediaType; |
41 | import javax.ws.rs.core.Response; | 40 | import javax.ws.rs.core.Response; |
42 | import java.io.IOException; | 41 | import java.io.IOException; |
... | @@ -87,7 +86,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -87,7 +86,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
87 | @POST | 86 | @POST |
88 | @Path("cpu_metrics") | 87 | @Path("cpu_metrics") |
89 | @Consumes(MediaType.APPLICATION_JSON) | 88 | @Consumes(MediaType.APPLICATION_JSON) |
90 | - @Produces(MediaType.APPLICATION_JSON) | ||
91 | public Response cpuMetrics(InputStream stream) { | 89 | public Response cpuMetrics(InputStream stream) { |
92 | ObjectNode root = mapper().createObjectNode(); | 90 | ObjectNode root = mapper().createObjectNode(); |
93 | ControlMetric cm; | 91 | ControlMetric cm; |
... | @@ -134,7 +132,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -134,7 +132,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
134 | aggregator.increment(ControlMetricType.CPU_IDLE_TIME, cpuIdleTime); | 132 | aggregator.increment(ControlMetricType.CPU_IDLE_TIME, cpuIdleTime); |
135 | 133 | ||
136 | } catch (IOException e) { | 134 | } catch (IOException e) { |
137 | - throw new IllegalArgumentException(e.getMessage()); | 135 | + throw new IllegalArgumentException(e); |
138 | } | 136 | } |
139 | return ok(root).build(); | 137 | return ok(root).build(); |
140 | } | 138 | } |
... | @@ -149,7 +147,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -149,7 +147,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
149 | @POST | 147 | @POST |
150 | @Path("memory_metrics") | 148 | @Path("memory_metrics") |
151 | @Consumes(MediaType.APPLICATION_JSON) | 149 | @Consumes(MediaType.APPLICATION_JSON) |
152 | - @Produces(MediaType.APPLICATION_JSON) | ||
153 | public Response memoryMetrics(InputStream stream) { | 150 | public Response memoryMetrics(InputStream stream) { |
154 | ObjectNode root = mapper().createObjectNode(); | 151 | ObjectNode root = mapper().createObjectNode(); |
155 | ControlMetric cm; | 152 | ControlMetric cm; |
... | @@ -190,7 +187,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -190,7 +187,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
190 | aggregator.increment(ControlMetricType.MEMORY_FREE, memFree); | 187 | aggregator.increment(ControlMetricType.MEMORY_FREE, memFree); |
191 | 188 | ||
192 | } catch (IOException e) { | 189 | } catch (IOException e) { |
193 | - throw new IllegalArgumentException(e.getMessage()); | 190 | + throw new IllegalArgumentException(e); |
194 | } | 191 | } |
195 | return ok(root).build(); | 192 | return ok(root).build(); |
196 | } | 193 | } |
... | @@ -205,7 +202,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -205,7 +202,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
205 | @POST | 202 | @POST |
206 | @Path("disk_metrics") | 203 | @Path("disk_metrics") |
207 | @Consumes(MediaType.APPLICATION_JSON) | 204 | @Consumes(MediaType.APPLICATION_JSON) |
208 | - @Produces(MediaType.APPLICATION_JSON) | ||
209 | public Response diskMetrics(InputStream stream) { | 205 | public Response diskMetrics(InputStream stream) { |
210 | ObjectNode root = mapper().createObjectNode(); | 206 | ObjectNode root = mapper().createObjectNode(); |
211 | ControlMetric cm; | 207 | ControlMetric cm; |
... | @@ -237,7 +233,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -237,7 +233,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
237 | ControlMetricType.DISK_WRITE_BYTES, writeBytes); | 233 | ControlMetricType.DISK_WRITE_BYTES, writeBytes); |
238 | } | 234 | } |
239 | } catch (IOException e) { | 235 | } catch (IOException e) { |
240 | - throw new IllegalArgumentException(e.getMessage()); | 236 | + throw new IllegalArgumentException(e); |
241 | } | 237 | } |
242 | return ok(root).build(); | 238 | return ok(root).build(); |
243 | } | 239 | } |
... | @@ -252,7 +248,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -252,7 +248,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
252 | @POST | 248 | @POST |
253 | @Path("network_metrics") | 249 | @Path("network_metrics") |
254 | @Consumes(MediaType.APPLICATION_JSON) | 250 | @Consumes(MediaType.APPLICATION_JSON) |
255 | - @Produces(MediaType.APPLICATION_JSON) | ||
256 | public Response networkMetrics(InputStream stream) { | 251 | public Response networkMetrics(InputStream stream) { |
257 | ObjectNode root = mapper().createObjectNode(); | 252 | ObjectNode root = mapper().createObjectNode(); |
258 | ControlMetric cm; | 253 | ControlMetric cm; |
... | @@ -299,7 +294,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -299,7 +294,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
299 | ControlMetricType.NW_OUTGOING_PACKETS, outPackets); | 294 | ControlMetricType.NW_OUTGOING_PACKETS, outPackets); |
300 | } | 295 | } |
301 | } catch (IOException e) { | 296 | } catch (IOException e) { |
302 | - throw new IllegalArgumentException(e.getMessage()); | 297 | + throw new IllegalArgumentException(e); |
303 | } | 298 | } |
304 | return ok(root).build(); | 299 | return ok(root).build(); |
305 | } | 300 | } |
... | @@ -316,7 +311,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -316,7 +311,6 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
316 | @POST | 311 | @POST |
317 | @Path("system_info") | 312 | @Path("system_info") |
318 | @Consumes(MediaType.APPLICATION_JSON) | 313 | @Consumes(MediaType.APPLICATION_JSON) |
319 | - @Produces(MediaType.APPLICATION_JSON) | ||
320 | public Response systemInfo(InputStream stream) { | 314 | public Response systemInfo(InputStream stream) { |
321 | ObjectNode root = mapper().createObjectNode(); | 315 | ObjectNode root = mapper().createObjectNode(); |
322 | 316 | ||
... | @@ -343,7 +337,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { | ... | @@ -343,7 +337,7 @@ public class SystemMetricsCollectorWebResource extends AbstractWebResource { |
343 | } | 337 | } |
344 | 338 | ||
345 | } catch (IOException e) { | 339 | } catch (IOException e) { |
346 | - throw new IllegalArgumentException(e.getMessage()); | 340 | + throw new IllegalArgumentException(e); |
347 | } | 341 | } |
348 | return ok(root).build(); | 342 | return ok(root).build(); |
349 | } | 343 | } | ... | ... |
-
Please register or login to post a comment