Committed by
Thomas Vachuska
[ONOS-3648] Implement REST API for collecting system metrics
- Implement REST API for gathering system metrics - Add unit test for REST API - Add swagger doc for REST API Change-Id: Iedd21a5f6ed14d595e4d35c1fa08270b48a5031e
Showing
24 changed files
with
656 additions
and
113 deletions
1 | <?xml version="1.0" encoding="UTF-8"?> | 1 | <?xml version="1.0" encoding="UTF-8"?> |
2 | <!-- | 2 | <!-- |
3 | - ~ Copyright 2014-2016 Open Networking Laboratory | 3 | + ~ Copyright 2015-2016 Open Networking Laboratory |
4 | ~ | 4 | ~ |
5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); | 5 | ~ Licensed under the Apache License, Version 2.0 (the "License"); |
6 | ~ you may not use this file except in compliance with the License. | 6 | ~ you may not use this file except in compliance with the License. |
... | @@ -28,6 +28,8 @@ | ... | @@ -28,6 +28,8 @@ |
28 | <artifactId>onos-app-cpman</artifactId> | 28 | <artifactId>onos-app-cpman</artifactId> |
29 | <packaging>bundle</packaging> | 29 | <packaging>bundle</packaging> |
30 | 30 | ||
31 | + <url>http://onosproject.org</url> | ||
32 | + | ||
31 | <description>Control Plane Management Application</description> | 33 | <description>Control Plane Management Application</description> |
32 | 34 | ||
33 | <properties> | 35 | <properties> |
... | @@ -35,17 +37,42 @@ | ... | @@ -35,17 +37,42 @@ |
35 | <onos.app.category>default</onos.app.category> | 37 | <onos.app.category>default</onos.app.category> |
36 | <onos.app.url>http://onosproject.org</onos.app.url> | 38 | <onos.app.url>http://onosproject.org</onos.app.url> |
37 | <onos.app.readme>Control plane management application.</onos.app.readme> | 39 | <onos.app.readme>Control plane management application.</onos.app.readme> |
40 | + <web.context>/onos/cpman</web.context> | ||
41 | + <api.version>1.0.0</api.version> | ||
42 | + <api.title>Control Plane Manager REST API</api.title> | ||
43 | + <api.description> | ||
44 | + APIs for interacting with the Control Plane Management application. | ||
45 | + </api.description> | ||
46 | + <api.package>org.onosproject.cpman.rest</api.package> | ||
38 | </properties> | 47 | </properties> |
39 | 48 | ||
40 | <dependencies> | 49 | <dependencies> |
41 | <dependency> | 50 | <dependency> |
51 | + <groupId>org.osgi</groupId> | ||
52 | + <artifactId>org.osgi.compendium</artifactId> | ||
53 | + </dependency> | ||
54 | + <dependency> | ||
55 | + <groupId>org.osgi</groupId> | ||
56 | + <artifactId>org.osgi.core</artifactId> | ||
57 | + </dependency> | ||
58 | + <dependency> | ||
59 | + <groupId>org.apache.felix</groupId> | ||
60 | + <artifactId>org.apache.felix.scr.annotations</artifactId> | ||
61 | + </dependency> | ||
62 | + <dependency> | ||
63 | + <groupId>org.apache.karaf.shell</groupId> | ||
64 | + <artifactId>org.apache.karaf.shell.console</artifactId> | ||
65 | + <scope>compile</scope> | ||
66 | + </dependency> | ||
67 | + <dependency> | ||
42 | <groupId>org.onosproject</groupId> | 68 | <groupId>org.onosproject</groupId> |
43 | - <artifactId>onos-api</artifactId> | 69 | + <artifactId>onos-cli</artifactId> |
44 | <version>${project.version}</version> | 70 | <version>${project.version}</version> |
45 | </dependency> | 71 | </dependency> |
46 | <dependency> | 72 | <dependency> |
47 | - <groupId>org.osgi</groupId> | 73 | + <groupId>org.onosproject</groupId> |
48 | - <artifactId>org.osgi.compendium</artifactId> | 74 | + <artifactId>onos-core-serializers</artifactId> |
75 | + <version>${project.version}</version> | ||
49 | </dependency> | 76 | </dependency> |
50 | <dependency> | 77 | <dependency> |
51 | <groupId>org.onosproject</groupId> | 78 | <groupId>org.onosproject</groupId> |
... | @@ -54,6 +81,16 @@ | ... | @@ -54,6 +81,16 @@ |
54 | </dependency> | 81 | </dependency> |
55 | <dependency> | 82 | <dependency> |
56 | <groupId>org.onosproject</groupId> | 83 | <groupId>org.onosproject</groupId> |
84 | + <artifactId>onos-rest</artifactId> | ||
85 | + <version>${project.version}</version> | ||
86 | + </dependency> | ||
87 | + <dependency> | ||
88 | + <groupId>org.onosproject</groupId> | ||
89 | + <artifactId>onlab-rest</artifactId> | ||
90 | + <version>${project.version}</version> | ||
91 | + </dependency> | ||
92 | + <dependency> | ||
93 | + <groupId>org.onosproject</groupId> | ||
57 | <artifactId>onos-api</artifactId> | 94 | <artifactId>onos-api</artifactId> |
58 | <version>${project.version}</version> | 95 | <version>${project.version}</version> |
59 | <classifier>tests</classifier> | 96 | <classifier>tests</classifier> |
... | @@ -62,6 +99,49 @@ | ... | @@ -62,6 +99,49 @@ |
62 | <dependency> | 99 | <dependency> |
63 | <groupId>org.onosproject</groupId> | 100 | <groupId>org.onosproject</groupId> |
64 | <artifactId>onlab-misc</artifactId> | 101 | <artifactId>onlab-misc</artifactId> |
102 | + </dependency> | ||
103 | + <dependency> | ||
104 | + <groupId>javax.ws.rs</groupId> | ||
105 | + <artifactId>jsr311-api</artifactId> | ||
106 | + <version>1.1.1</version> | ||
107 | + <scope>provided</scope> | ||
108 | + </dependency> | ||
109 | + <dependency> | ||
110 | + <groupId>com.sun.jersey</groupId> | ||
111 | + <artifactId>jersey-servlet</artifactId> | ||
112 | + </dependency> | ||
113 | + | ||
114 | + <dependency> | ||
115 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
116 | + <artifactId>jackson-databind</artifactId> | ||
117 | + </dependency> | ||
118 | + <dependency> | ||
119 | + <groupId>com.fasterxml.jackson.core</groupId> | ||
120 | + <artifactId>jackson-annotations</artifactId> | ||
121 | + </dependency> | ||
122 | + <dependency> | ||
123 | + <groupId>com.sun.jersey</groupId> | ||
124 | + <artifactId>jersey-client</artifactId> | ||
125 | + <scope>test</scope> | ||
126 | + </dependency> | ||
127 | + <dependency> | ||
128 | + <groupId>org.easymock</groupId> | ||
129 | + <artifactId>easymock</artifactId> | ||
130 | + <scope>test</scope> | ||
131 | + </dependency> | ||
132 | + <dependency> | ||
133 | + <groupId>com.sun.jersey.jersey-test-framework</groupId> | ||
134 | + <artifactId>jersey-test-framework-core</artifactId> | ||
135 | + <scope>test</scope> | ||
136 | + </dependency> | ||
137 | + <dependency> | ||
138 | + <groupId>com.sun.jersey.jersey-test-framework</groupId> | ||
139 | + <artifactId>jersey-test-framework-grizzly2</artifactId> | ||
140 | + <scope>test</scope> | ||
141 | + </dependency> | ||
142 | + <dependency> | ||
143 | + <groupId>org.onosproject</groupId> | ||
144 | + <artifactId>onlab-osgi</artifactId> | ||
65 | <version>${project.version}</version> | 145 | <version>${project.version}</version> |
66 | <classifier>tests</classifier> | 146 | <classifier>tests</classifier> |
67 | <scope>test</scope> | 147 | <scope>test</scope> |
... | @@ -73,15 +153,40 @@ | ... | @@ -73,15 +153,40 @@ |
73 | <plugin> | 153 | <plugin> |
74 | <groupId>org.apache.felix</groupId> | 154 | <groupId>org.apache.felix</groupId> |
75 | <artifactId>maven-bundle-plugin</artifactId> | 155 | <artifactId>maven-bundle-plugin</artifactId> |
76 | - </plugin> | 156 | + <extensions>true</extensions> |
77 | - | 157 | + <configuration> |
78 | - <plugin> | 158 | + <instructions> |
79 | - <groupId>org.apache.felix</groupId> | 159 | + <_wab>src/main/webapp/</_wab> |
80 | - <artifactId>maven-scr-plugin</artifactId> | 160 | + <Include-Resource> |
81 | - </plugin> | 161 | + WEB-INF/classes/apidoc/swagger.json=target/swagger.json, |
82 | - <plugin> | 162 | + {maven-resources} |
83 | - <groupId>org.onosproject</groupId> | 163 | + </Include-Resource> |
84 | - <artifactId>onos-maven-plugin</artifactId> | 164 | + <Bundle-SymbolicName> |
165 | + ${project.groupId}.${project.artifactId} | ||
166 | + </Bundle-SymbolicName> | ||
167 | + <Import-Package> | ||
168 | + org.slf4j, | ||
169 | + org.osgi.framework, | ||
170 | + javax.ws.rs, | ||
171 | + javax.ws.rs.core, | ||
172 | + com.sun.jersey.api.core, | ||
173 | + com.sun.jersey.spi.container.servlet, | ||
174 | + com.sun.jersey.server.impl.container.servlet, | ||
175 | + com.fasterxml.jackson.databind, | ||
176 | + com.fasterxml.jackson.databind.node, | ||
177 | + com.fasterxml.jackson.core, | ||
178 | + org.apache.karaf.shell.commands, | ||
179 | + org.apache.karaf.shell.console, | ||
180 | + com.google.common.*, | ||
181 | + org.onlab.packet.*, | ||
182 | + org.onlab.rest.*, | ||
183 | + org.onosproject.*, | ||
184 | + org.onlab.util.*, | ||
185 | + org.jboss.netty.util.* | ||
186 | + </Import-Package> | ||
187 | + <Web-ContextPath>${web.context}</Web-ContextPath> | ||
188 | + </instructions> | ||
189 | + </configuration> | ||
85 | </plugin> | 190 | </plugin> |
86 | </plugins> | 191 | </plugins> |
87 | </build> | 192 | </build> | ... | ... |
... | @@ -23,7 +23,7 @@ public class ControlMetric { | ... | @@ -23,7 +23,7 @@ public class ControlMetric { |
23 | private final ControlMetricType metricType; | 23 | private final ControlMetricType metricType; |
24 | private final MetricValue metricValue; | 24 | private final MetricValue metricValue; |
25 | 25 | ||
26 | - ControlMetric(ControlMetricType metricType, MetricValue metricValue) { | 26 | + public ControlMetric(ControlMetricType metricType, MetricValue metricValue) { |
27 | this.metricType = metricType; | 27 | this.metricType = metricType; |
28 | this.metricValue = metricValue; | 28 | this.metricValue = metricValue; |
29 | } | 29 | } | ... | ... |
1 | /* | 1 | /* |
2 | - * Copyright 2015-2016 Open Networking Laboratory | 2 | + * Copyright 2016 Open Networking Laboratory |
3 | * | 3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. | 5 | * you may not use this file except in compliance with the License. |
... | @@ -16,117 +16,47 @@ | ... | @@ -16,117 +16,47 @@ |
16 | package org.onosproject.cpman; | 16 | package org.onosproject.cpman; |
17 | 17 | ||
18 | import org.apache.felix.scr.annotations.Activate; | 18 | import org.apache.felix.scr.annotations.Activate; |
19 | +import org.apache.felix.scr.annotations.Component; | ||
19 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
20 | import org.apache.felix.scr.annotations.Modified; | 21 | import org.apache.felix.scr.annotations.Modified; |
21 | -import org.apache.felix.scr.annotations.Component; | ||
22 | import org.apache.felix.scr.annotations.Reference; | 22 | import org.apache.felix.scr.annotations.Reference; |
23 | import org.apache.felix.scr.annotations.ReferenceCardinality; | 23 | import org.apache.felix.scr.annotations.ReferenceCardinality; |
24 | -import org.onlab.metrics.MetricsService; | ||
25 | import org.onosproject.core.ApplicationId; | 24 | import org.onosproject.core.ApplicationId; |
26 | import org.onosproject.core.CoreService; | 25 | import org.onosproject.core.CoreService; |
27 | import org.onosproject.net.device.DeviceService; | 26 | import org.onosproject.net.device.DeviceService; |
28 | import org.slf4j.Logger; | 27 | import org.slf4j.Logger; |
29 | - | 28 | +import org.slf4j.LoggerFactory; |
30 | -import java.util.HashSet; | ||
31 | -import java.util.Optional; | ||
32 | -import java.util.Set; | ||
33 | - | ||
34 | -import static org.slf4j.LoggerFactory.getLogger; | ||
35 | 29 | ||
36 | /** | 30 | /** |
37 | - * Control plane management application. | 31 | + * Skeletal ONOS application component. |
38 | */ | 32 | */ |
39 | @Component(immediate = true) | 33 | @Component(immediate = true) |
40 | public class ControlPlaneManager { | 34 | public class ControlPlaneManager { |
41 | 35 | ||
42 | - private final Logger log = getLogger(getClass()); | 36 | + private final Logger log = LoggerFactory.getLogger(getClass()); |
43 | - private Set<ControlMetricsObserver> controlMetricsObservers = new HashSet<>(); | ||
44 | - private ControlMetricsObserver cpObserver; | ||
45 | - | ||
46 | - private ApplicationId appId; | ||
47 | - | ||
48 | - private ControlMetricsFactory cmf; | ||
49 | - | ||
50 | - @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | ||
51 | - protected DeviceService deviceService; | ||
52 | 37 | ||
53 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 38 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
54 | protected CoreService coreService; | 39 | protected CoreService coreService; |
55 | 40 | ||
56 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 41 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
57 | - protected MetricsService metricsService; | 42 | + protected DeviceService deviceService; |
43 | + | ||
44 | + private ApplicationId appId; | ||
58 | 45 | ||
59 | @Activate | 46 | @Activate |
60 | - public void activate() { | 47 | + protected void activate() { |
61 | appId = coreService.registerApplication("org.onosproject.cpman"); | 48 | appId = coreService.registerApplication("org.onosproject.cpman"); |
62 | - | 49 | + deviceService.getAvailableDevices(); |
63 | - cmf = ControlMetricsFactory.getInstance(metricsService, deviceService); | ||
64 | - // currently disable monitoring by default | ||
65 | - // cmf.startMonitor(); | ||
66 | - | ||
67 | - registerObserver(); | ||
68 | - | ||
69 | log.info("Started"); | 50 | log.info("Started"); |
70 | } | 51 | } |
71 | 52 | ||
72 | @Deactivate | 53 | @Deactivate |
73 | - public void deactivate() { | 54 | + protected void deactivate() { |
74 | - unregisterObserver(); | ||
75 | - cmf.stopMonitor(); | ||
76 | log.info("Stopped"); | 55 | log.info("Stopped"); |
77 | } | 56 | } |
78 | 57 | ||
79 | @Modified | 58 | @Modified |
80 | - public void modified() { | 59 | + protected void modified() { |
81 | - } | ||
82 | - | ||
83 | - private void registerObserver() { | ||
84 | - cpObserver = new DefaultControlMetricsObserver(); | ||
85 | - this.addControlMetricsObserver(cpObserver); | ||
86 | - } | ||
87 | - | ||
88 | - private void unregisterObserver() { | ||
89 | - this.removeControlMetricsObserver(cpObserver); | ||
90 | - } | ||
91 | - | ||
92 | - private void executeMonitorTask() { | ||
93 | - | ||
94 | - // TODO: execute monitoring task with 1 minute period | ||
95 | - if (cmf.isMonitor()) { | ||
96 | - controlMetricsObservers.forEach(observer -> { | ||
97 | - | ||
98 | - // only OpenFlow messages are spontaneously monitored with | ||
99 | - // 1 minute period. Other system metrics will be pushed from | ||
100 | - // external monitoring agent through REST API | ||
101 | - | ||
102 | - // feed the control message stats | ||
103 | - cmf.getDeviceIds().forEach(v -> { | ||
104 | - observer.feedMetrics(cmf.inboundPacket(v), Optional.of(v)); | ||
105 | - observer.feedMetrics(cmf.outboundPacket(v), Optional.of(v)); | ||
106 | - observer.feedMetrics(cmf.flowmodPacket(v), Optional.of(v)); | ||
107 | - observer.feedMetrics(cmf.flowrmvPacket(v), Optional.of(v)); | ||
108 | - observer.feedMetrics(cmf.requestPacket(v), Optional.of(v)); | ||
109 | - observer.feedMetrics(cmf.replyPacket(v), Optional.of(v)); | ||
110 | - }); | ||
111 | - }); | ||
112 | - } | ||
113 | } | 60 | } |
114 | 61 | ||
115 | - /** | ||
116 | - * Adds a new control metrics observer. | ||
117 | - * | ||
118 | - * @param cmObserver control metric observer instance | ||
119 | - */ | ||
120 | - public void addControlMetricsObserver(ControlMetricsObserver cmObserver) { | ||
121 | - controlMetricsObservers.add(cmObserver); | ||
122 | - } | ||
123 | - | ||
124 | - /** | ||
125 | - * Removes an existing control metrics observer. | ||
126 | - * | ||
127 | - * @param cmObserver control metric observer instance | ||
128 | - */ | ||
129 | - public void removeControlMetricsObserver(ControlMetricsObserver cmObserver) { | ||
130 | - controlMetricsObservers.remove(cmObserver); | ||
131 | - } | ||
132 | } | 62 | } | ... | ... |
... | @@ -16,9 +16,9 @@ | ... | @@ -16,9 +16,9 @@ |
16 | package org.onosproject.cpman; | 16 | package org.onosproject.cpman; |
17 | 17 | ||
18 | import org.apache.felix.scr.annotations.Activate; | 18 | import org.apache.felix.scr.annotations.Activate; |
19 | +import org.apache.felix.scr.annotations.Component; | ||
19 | import org.apache.felix.scr.annotations.Deactivate; | 20 | import org.apache.felix.scr.annotations.Deactivate; |
20 | import org.apache.felix.scr.annotations.Modified; | 21 | import org.apache.felix.scr.annotations.Modified; |
21 | -import org.apache.felix.scr.annotations.Component; | ||
22 | import org.apache.felix.scr.annotations.Service; | 22 | import org.apache.felix.scr.annotations.Service; |
23 | import org.onosproject.cluster.NodeId; | 23 | import org.onosproject.cluster.NodeId; |
24 | import org.onosproject.net.DeviceId; | 24 | import org.onosproject.net.DeviceId; |
... | @@ -41,6 +41,7 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { | ... | @@ -41,6 +41,7 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { |
41 | 41 | ||
42 | @Activate | 42 | @Activate |
43 | public void activate() { | 43 | public void activate() { |
44 | + | ||
44 | } | 45 | } |
45 | 46 | ||
46 | @Deactivate | 47 | @Deactivate |
... | @@ -52,12 +53,12 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { | ... | @@ -52,12 +53,12 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService { |
52 | } | 53 | } |
53 | 54 | ||
54 | @Override | 55 | @Override |
55 | - public void updateMetric(ControlMetric cpm, int updateInterval, | 56 | + public void updateMetric(ControlMetric cpm, Integer updateInterval, |
56 | Optional<DeviceId> deviceId) { | 57 | Optional<DeviceId> deviceId) { |
57 | } | 58 | } |
58 | 59 | ||
59 | @Override | 60 | @Override |
60 | - public void updateMetric(ControlMetric controlMetric, int updateInterval, | 61 | + public void updateMetric(ControlMetric controlMetric, Integer updateInterval, |
61 | String resourceName) { | 62 | String resourceName) { |
62 | 63 | ||
63 | } | 64 | } | ... | ... |
... | @@ -33,7 +33,7 @@ public interface ControlPlaneMonitorService { | ... | @@ -33,7 +33,7 @@ public interface ControlPlaneMonitorService { |
33 | * @param updateInterval value update interval (time unit will be in minute) | 33 | * @param updateInterval value update interval (time unit will be in minute) |
34 | * @param deviceId {@link org.onosproject.net.DeviceId} | 34 | * @param deviceId {@link org.onosproject.net.DeviceId} |
35 | */ | 35 | */ |
36 | - void updateMetric(ControlMetric controlMetric, int updateInterval, Optional<DeviceId> deviceId); | 36 | + void updateMetric(ControlMetric controlMetric, Integer updateInterval, Optional<DeviceId> deviceId); |
37 | 37 | ||
38 | /** | 38 | /** |
39 | * Adds a new control metric value with a certain update interval. | 39 | * Adds a new control metric value with a certain update interval. |
... | @@ -42,7 +42,7 @@ public interface ControlPlaneMonitorService { | ... | @@ -42,7 +42,7 @@ public interface ControlPlaneMonitorService { |
42 | * @param updateInterval value update interval (time unit will be in minute) | 42 | * @param updateInterval value update interval (time unit will be in minute) |
43 | * @param resourceName resource name | 43 | * @param resourceName resource name |
44 | */ | 44 | */ |
45 | - void updateMetric(ControlMetric controlMetric, int updateInterval, String resourceName); | 45 | + void updateMetric(ControlMetric controlMetric, Integer updateInterval, String resourceName); |
46 | 46 | ||
47 | /** | 47 | /** |
48 | * Obtains the control plane load of a specific device. | 48 | * Obtains the control plane load of a specific device. | ... | ... |
... | @@ -31,14 +31,22 @@ public class DefaultControlMetricsObserver implements ControlMetricsObserver { | ... | @@ -31,14 +31,22 @@ public class DefaultControlMetricsObserver implements ControlMetricsObserver { |
31 | 31 | ||
32 | @Override | 32 | @Override |
33 | public void feedMetrics(MetricsAggregator ma, Optional<DeviceId> deviceId) { | 33 | public void feedMetrics(MetricsAggregator ma, Optional<DeviceId> deviceId) { |
34 | - MetricValue mv = new MetricValue((long) ma.getRate(), (long) ma.getLoad(), (long) ma.getCount()); | 34 | + MetricValue mv = new MetricValue.Builder() |
35 | + .rate(ma.getRate()) | ||
36 | + .count(ma.getCount()) | ||
37 | + .load(ma.getLoad()) | ||
38 | + .add(); | ||
35 | ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv); | 39 | ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv); |
36 | controlPlaneMonitorService.updateMetric(cm, 1, deviceId); | 40 | controlPlaneMonitorService.updateMetric(cm, 1, deviceId); |
37 | } | 41 | } |
38 | 42 | ||
39 | @Override | 43 | @Override |
40 | public void feedMetrics(MetricsAggregator ma, String resourceName) { | 44 | public void feedMetrics(MetricsAggregator ma, String resourceName) { |
41 | - MetricValue mv = new MetricValue((long) ma.getRate(), (long) ma.getLoad(), (long) ma.getCount()); | 45 | + MetricValue mv = new MetricValue.Builder() |
46 | + .rate(ma.getRate()) | ||
47 | + .count(ma.getCount()) | ||
48 | + .load(ma.getLoad()) | ||
49 | + .add(); | ||
42 | ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv); | 50 | ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv); |
43 | controlPlaneMonitorService.updateMetric(cm, 1, resourceName); | 51 | controlPlaneMonitorService.updateMetric(cm, 1, resourceName); |
44 | } | 52 | } | ... | ... |
... | @@ -20,7 +20,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; | ... | @@ -20,7 +20,7 @@ import static com.google.common.base.MoreObjects.toStringHelper; |
20 | /** | 20 | /** |
21 | * Primitive Metric Value. | 21 | * Primitive Metric Value. |
22 | */ | 22 | */ |
23 | -public class MetricValue { | 23 | +public final class MetricValue { |
24 | 24 | ||
25 | private final long rate; | 25 | private final long rate; |
26 | private final long load; | 26 | private final long load; |
... | @@ -33,24 +33,90 @@ public class MetricValue { | ... | @@ -33,24 +33,90 @@ public class MetricValue { |
33 | * @param load load | 33 | * @param load load |
34 | * @param count count | 34 | * @param count count |
35 | */ | 35 | */ |
36 | - MetricValue(long rate, long load, long count) { | 36 | + private MetricValue(long rate, long load, long count) { |
37 | this.rate = rate; | 37 | this.rate = rate; |
38 | this.load = load; | 38 | this.load = load; |
39 | this.count = count; | 39 | this.count = count; |
40 | } | 40 | } |
41 | 41 | ||
42 | + /** | ||
43 | + * Returns rate value. | ||
44 | + * | ||
45 | + * @return rate | ||
46 | + */ | ||
42 | public long getRate() { | 47 | public long getRate() { |
43 | return rate; | 48 | return rate; |
44 | } | 49 | } |
45 | 50 | ||
51 | + /** | ||
52 | + * Returns load value. | ||
53 | + * | ||
54 | + * @return load | ||
55 | + */ | ||
46 | public long getLoad() { | 56 | public long getLoad() { |
47 | return load; | 57 | return load; |
48 | } | 58 | } |
49 | 59 | ||
60 | + /** | ||
61 | + * Returns count value. | ||
62 | + * | ||
63 | + * @return cound | ||
64 | + */ | ||
50 | public long getCount() { | 65 | public long getCount() { |
51 | return count; | 66 | return count; |
52 | } | 67 | } |
53 | 68 | ||
69 | + /** | ||
70 | + * MetricValue builder class. | ||
71 | + */ | ||
72 | + public static final class Builder { | ||
73 | + private long rate; | ||
74 | + private long load; | ||
75 | + private long count; | ||
76 | + | ||
77 | + /** | ||
78 | + * Sets rate value. | ||
79 | + * | ||
80 | + * @param rate rate value | ||
81 | + * @return Builder object | ||
82 | + */ | ||
83 | + public Builder rate(long rate) { | ||
84 | + this.rate = rate; | ||
85 | + return this; | ||
86 | + } | ||
87 | + | ||
88 | + /** | ||
89 | + * Sets load value. | ||
90 | + * | ||
91 | + * @param load load value | ||
92 | + * @return Builder object | ||
93 | + */ | ||
94 | + public Builder load(long load) { | ||
95 | + this.load = load; | ||
96 | + return this; | ||
97 | + } | ||
98 | + | ||
99 | + /** | ||
100 | + * Sets count value. | ||
101 | + * | ||
102 | + * @param count count value | ||
103 | + * @return Builder object | ||
104 | + */ | ||
105 | + public Builder count(long count) { | ||
106 | + this.count = count; | ||
107 | + return this; | ||
108 | + } | ||
109 | + | ||
110 | + /** | ||
111 | + * Builds a MetricValue object. | ||
112 | + * | ||
113 | + * @return MetricValue object | ||
114 | + */ | ||
115 | + public MetricValue add() { | ||
116 | + return new MetricValue(rate, load, count); | ||
117 | + } | ||
118 | + } | ||
119 | + | ||
54 | @Override | 120 | @Override |
55 | public boolean equals(Object obj) { | 121 | public boolean equals(Object obj) { |
56 | if (this == obj) { | 122 | if (this == obj) { | ... | ... |
... | @@ -134,8 +134,8 @@ public class MetricsAggregator { | ... | @@ -134,8 +134,8 @@ public class MetricsAggregator { |
134 | * | 134 | * |
135 | * @return load value | 135 | * @return load value |
136 | */ | 136 | */ |
137 | - public double getLoad() { | 137 | + public long getLoad() { |
138 | - return rateMeter.getOneMinuteRate() / countMeter.getOneMinuteRate(); | 138 | + return (long) rateMeter.getOneMinuteRate() / (long) countMeter.getOneMinuteRate(); |
139 | } | 139 | } |
140 | 140 | ||
141 | /** | 141 | /** |
... | @@ -143,8 +143,8 @@ public class MetricsAggregator { | ... | @@ -143,8 +143,8 @@ public class MetricsAggregator { |
143 | * | 143 | * |
144 | * @return rate value | 144 | * @return rate value |
145 | */ | 145 | */ |
146 | - public double getRate() { | 146 | + public long getRate() { |
147 | - return rateMeter.getOneMinuteRate(); | 147 | + return (long) rateMeter.getOneMinuteRate(); |
148 | } | 148 | } |
149 | 149 | ||
150 | /** | 150 | /** |
... | @@ -152,7 +152,7 @@ public class MetricsAggregator { | ... | @@ -152,7 +152,7 @@ public class MetricsAggregator { |
152 | * | 152 | * |
153 | * @return count value | 153 | * @return count value |
154 | */ | 154 | */ |
155 | - public double getCount() { | 155 | + public long getCount() { |
156 | - return countMeter.getOneMinuteRate() * EXECUTE_PERIOD_IN_SECOND; | 156 | + return (long) countMeter.getOneMinuteRate() * EXECUTE_PERIOD_IN_SECOND; |
157 | } | 157 | } |
158 | } | 158 | } |
... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
1 | +/* | ||
2 | + * Copyright 2016 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 | + | ||
17 | +package org.onosproject.cpman.rest; | ||
18 | + | ||
19 | +import org.onlab.rest.AbstractWebApplication; | ||
20 | + | ||
21 | +import java.util.Set; | ||
22 | + | ||
23 | +/** | ||
24 | + * CPMan REST APIs web application. | ||
25 | + */ | ||
26 | +public class CPManWebApplication extends AbstractWebApplication { | ||
27 | + @Override | ||
28 | + public Set<Class<?>> getClasses() { | ||
29 | + return getClasses(ControlMetricsCollectorWebResource.class); | ||
30 | + } | ||
31 | +} |
apps/cpman/src/main/java/org/onosproject/cpman/rest/ControlMetricsCollectorWebResource.java
0 → 100644
This diff is collapsed. Click to expand it.
1 | +/* | ||
2 | + * Copyright 2016 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 | + | ||
17 | +/** | ||
18 | + * REST APIs for the control plane monitor. | ||
19 | + */ | ||
20 | +package org.onosproject.cpman.rest; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +{ | ||
2 | + "type": "object", | ||
3 | + "required": [ | ||
4 | + "cpuLoad", | ||
5 | + "totalCpuTime", | ||
6 | + "sysCpuTime", | ||
7 | + "userCpuTime", | ||
8 | + "cpuIdleTime" | ||
9 | + ], | ||
10 | + "properties": { | ||
11 | + "cpuLoad": { | ||
12 | + "type": "integer", | ||
13 | + "format": "int64", | ||
14 | + "example": "50" | ||
15 | + }, | ||
16 | + "totalCpuTime": { | ||
17 | + "type": "integer", | ||
18 | + "format": "int64", | ||
19 | + "example": "2000" | ||
20 | + }, | ||
21 | + "sysCpuTime": { | ||
22 | + "type": "integer", | ||
23 | + "format": "int64", | ||
24 | + "example": "2000" | ||
25 | + }, | ||
26 | + "userCpuTime": { | ||
27 | + "type": "integer", | ||
28 | + "format": "int64", | ||
29 | + "example": "2000" | ||
30 | + }, | ||
31 | + "cpuIdleTime": { | ||
32 | + "type": "integer", | ||
33 | + "format": "int64", | ||
34 | + "example": "2000" | ||
35 | + } | ||
36 | + } | ||
37 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +{ | ||
2 | + "type": "object", | ||
3 | + "required": [ | ||
4 | + "readBytes", | ||
5 | + "writeBytes" | ||
6 | + ], | ||
7 | + "properties": { | ||
8 | + "readBytes": { | ||
9 | + "type": "integer", | ||
10 | + "format": "int64", | ||
11 | + "example": "500" | ||
12 | + }, | ||
13 | + "writeBytes": { | ||
14 | + "type": "integer", | ||
15 | + "format": "int64", | ||
16 | + "example": "300" | ||
17 | + } | ||
18 | + } | ||
19 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +{ | ||
2 | + "type": "object", | ||
3 | + "required": [ | ||
4 | + "memoryUsedPercentage", | ||
5 | + "memoryFreePercentage", | ||
6 | + "memoryUsed", | ||
7 | + "memoryFree" | ||
8 | + ], | ||
9 | + "properties": { | ||
10 | + "memoryUsedPercentage": { | ||
11 | + "type": "integer", | ||
12 | + "format": "int64", | ||
13 | + "example": "30" | ||
14 | + }, | ||
15 | + "memoryFreePercentage": { | ||
16 | + "type": "integer", | ||
17 | + "format": "int64", | ||
18 | + "example": "70" | ||
19 | + }, | ||
20 | + "memoryUsed": { | ||
21 | + "type": "integer", | ||
22 | + "format": "int64", | ||
23 | + "example": "1024" | ||
24 | + }, | ||
25 | + "memoryFree": { | ||
26 | + "type": "integer", | ||
27 | + "format": "int64", | ||
28 | + "example": "2048" | ||
29 | + } | ||
30 | + } | ||
31 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +{ | ||
2 | + "type": "object", | ||
3 | + "required": [ | ||
4 | + "incomingBytes", | ||
5 | + "outgoingBytes", | ||
6 | + "incomingPackets", | ||
7 | + "outgoingPackets" | ||
8 | + ], | ||
9 | + "properties": { | ||
10 | + "incomingBytes": { | ||
11 | + "type": "integer", | ||
12 | + "format": "int64", | ||
13 | + "example": "1024" | ||
14 | + }, | ||
15 | + "outgoingBytes": { | ||
16 | + "type": "integer", | ||
17 | + "format": "int64", | ||
18 | + "example": "1024" | ||
19 | + }, | ||
20 | + "incomingPackets": { | ||
21 | + "type": "integer", | ||
22 | + "format": "int64", | ||
23 | + "example": "1000" | ||
24 | + }, | ||
25 | + "outgoingPackets": { | ||
26 | + "type": "integer", | ||
27 | + "format": "int64", | ||
28 | + "example": "2000" | ||
29 | + } | ||
30 | + } | ||
31 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
1 | +{ | ||
2 | + "type": "object", | ||
3 | + "required": [ | ||
4 | + "numOfCores", | ||
5 | + "numOfCpus", | ||
6 | + "cpuSpeed", | ||
7 | + "totalMemory" | ||
8 | + ], | ||
9 | + "properties": { | ||
10 | + "numOfCores": { | ||
11 | + "type": "integer", | ||
12 | + "format": "int64", | ||
13 | + "example": "6" | ||
14 | + }, | ||
15 | + "numOfCpus": { | ||
16 | + "type": "integer", | ||
17 | + "format": "int64", | ||
18 | + "example": "2" | ||
19 | + }, | ||
20 | + "cpuSpeed": { | ||
21 | + "type": "integer", | ||
22 | + "format": "int64", | ||
23 | + "example": "2048" | ||
24 | + }, | ||
25 | + "totalMemory": { | ||
26 | + "type": "integer", | ||
27 | + "format": "int64", | ||
28 | + "example": "4096" | ||
29 | + } | ||
30 | + } | ||
31 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
apps/cpman/src/main/webapp/WEB-INF/web.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<!-- | ||
3 | + ~ Copyright 2016 Open Networking Laboratory | ||
4 | + ~ | ||
5 | + ~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
6 | + ~ 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, | ||
13 | + ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
14 | + ~ See the License for the specific language governing permissions and | ||
15 | + ~ limitations under the License. | ||
16 | + --> | ||
17 | +<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
18 | + xmlns="http://java.sun.com/xml/ns/javaee" | ||
19 | + xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
20 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" | ||
21 | + id="ONOS" version="2.5"> | ||
22 | + <display-name>Control Plane REST API v1.0</display-name> | ||
23 | + | ||
24 | + <security-constraint> | ||
25 | + <web-resource-collection> | ||
26 | + <web-resource-name>Secured</web-resource-name> | ||
27 | + <url-pattern>/*</url-pattern> | ||
28 | + </web-resource-collection> | ||
29 | + <auth-constraint> | ||
30 | + <role-name>admin</role-name> | ||
31 | + </auth-constraint> | ||
32 | + </security-constraint> | ||
33 | + | ||
34 | + <security-role> | ||
35 | + <role-name>admin</role-name> | ||
36 | + </security-role> | ||
37 | + | ||
38 | + <login-config> | ||
39 | + <auth-method>BASIC</auth-method> | ||
40 | + <realm-name>karaf</realm-name> | ||
41 | + </login-config> | ||
42 | + | ||
43 | + <servlet> | ||
44 | + <servlet-name>JAX-RS Service</servlet-name> | ||
45 | + <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class> | ||
46 | + <init-param> | ||
47 | + <param-name>javax.ws.rs.Application</param-name> | ||
48 | + <param-value>org.onosproject.cpman.rest.CPManWebApplication</param-value> | ||
49 | + </init-param> | ||
50 | + <load-on-startup>1</load-on-startup> | ||
51 | + </servlet> | ||
52 | + | ||
53 | + <servlet-mapping> | ||
54 | + <servlet-name>JAX-RS Service</servlet-name> | ||
55 | + <url-pattern>/*</url-pattern> | ||
56 | + </servlet-mapping> | ||
57 | +</web-app> |
... | @@ -18,7 +18,6 @@ package org.onosproject.cpman; | ... | @@ -18,7 +18,6 @@ package org.onosproject.cpman; |
18 | import org.junit.After; | 18 | import org.junit.After; |
19 | import org.junit.Before; | 19 | import org.junit.Before; |
20 | import org.junit.Test; | 20 | import org.junit.Test; |
21 | -import org.onlab.metrics.MetricsServiceAdapter; | ||
22 | import org.onosproject.core.CoreServiceAdapter; | 21 | import org.onosproject.core.CoreServiceAdapter; |
23 | import org.onosproject.net.device.DeviceServiceAdapter; | 22 | import org.onosproject.net.device.DeviceServiceAdapter; |
24 | 23 | ||
... | @@ -37,7 +36,6 @@ public class ControlPlaneManagerTest { | ... | @@ -37,7 +36,6 @@ public class ControlPlaneManagerTest { |
37 | cpMan = new ControlPlaneManager(); | 36 | cpMan = new ControlPlaneManager(); |
38 | cpMan.coreService = new CoreServiceAdapter(); | 37 | cpMan.coreService = new CoreServiceAdapter(); |
39 | cpMan.deviceService = new DeviceServiceAdapter(); | 38 | cpMan.deviceService = new DeviceServiceAdapter(); |
40 | - cpMan.metricsService = new MetricsServiceAdapter(); | ||
41 | cpMan.activate(); | 39 | cpMan.activate(); |
42 | } | 40 | } |
43 | 41 | ... | ... |
apps/cpman/src/test/java/org/onosproject/cpman/rest/ControlMetricsCollectorResourceTest.java
0 → 100644
1 | +/* | ||
2 | + * Copyright 2016 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.rest; | ||
17 | + | ||
18 | +import com.sun.jersey.api.client.ClientResponse; | ||
19 | +import com.sun.jersey.api.client.WebResource; | ||
20 | +import com.sun.jersey.spi.container.servlet.ServletContainer; | ||
21 | +import com.sun.jersey.test.framework.AppDescriptor; | ||
22 | +import com.sun.jersey.test.framework.JerseyTest; | ||
23 | +import com.sun.jersey.test.framework.WebAppDescriptor; | ||
24 | +import org.junit.Before; | ||
25 | +import org.junit.Test; | ||
26 | +import org.onlab.osgi.ServiceDirectory; | ||
27 | +import org.onlab.osgi.TestServiceDirectory; | ||
28 | +import org.onlab.rest.BaseResource; | ||
29 | +import org.onosproject.cpman.ControlPlaneMonitorService; | ||
30 | +import org.onosproject.net.DeviceId; | ||
31 | + | ||
32 | +import javax.ws.rs.core.MediaType; | ||
33 | +import java.io.IOException; | ||
34 | +import java.io.InputStream; | ||
35 | +import java.net.HttpURLConnection; | ||
36 | +import java.net.ServerSocket; | ||
37 | +import java.util.Optional; | ||
38 | + | ||
39 | +import static org.easymock.EasyMock.anyObject; | ||
40 | +import static org.easymock.EasyMock.createMock; | ||
41 | +import static org.easymock.EasyMock.expectLastCall; | ||
42 | +import static org.easymock.EasyMock.replay; | ||
43 | +import static org.hamcrest.Matchers.is; | ||
44 | +import static org.hamcrest.Matchers.notNullValue; | ||
45 | +import static org.junit.Assert.assertThat; | ||
46 | + | ||
47 | +/** | ||
48 | + * Unit test for ControlMetricsCollector. | ||
49 | + */ | ||
50 | +public class ControlMetricsCollectorResourceTest extends JerseyTest { | ||
51 | + | ||
52 | + final ControlPlaneMonitorService mockControlPlaneMonitorService = | ||
53 | + createMock(ControlPlaneMonitorService.class); | ||
54 | + | ||
55 | + /** | ||
56 | + * Sets up the global values for all the tests. | ||
57 | + */ | ||
58 | + @Before | ||
59 | + public void setUpTest() { | ||
60 | + ServiceDirectory testDirectory = | ||
61 | + new TestServiceDirectory() | ||
62 | + .add(ControlPlaneMonitorService.class, mockControlPlaneMonitorService); | ||
63 | + BaseResource.setServiceDirectory(testDirectory); | ||
64 | + } | ||
65 | + | ||
66 | + @Test | ||
67 | + public void testCpuMetricsPost() { | ||
68 | + mockControlPlaneMonitorService.updateMetric(anyObject(), anyObject(), | ||
69 | + (Optional<DeviceId>) anyObject()); | ||
70 | + expectLastCall().times(5); | ||
71 | + replay(mockControlPlaneMonitorService); | ||
72 | + basePostTest("cpu-metrics-post.json", "cpman/cpumetrics"); | ||
73 | + } | ||
74 | + | ||
75 | + @Test | ||
76 | + public void testMemoryMetricsPost() { | ||
77 | + mockControlPlaneMonitorService.updateMetric(anyObject(), anyObject(), | ||
78 | + (Optional<DeviceId>) anyObject()); | ||
79 | + expectLastCall().times(4); | ||
80 | + replay(mockControlPlaneMonitorService); | ||
81 | + basePostTest("memory-metrics-post.json", "cpman/memorymetrics"); | ||
82 | + } | ||
83 | + | ||
84 | + @Test | ||
85 | + public void testDiskMetricsPost() { | ||
86 | + mockControlPlaneMonitorService.updateMetric(anyObject(), anyObject(), | ||
87 | + (Optional<DeviceId>) anyObject()); | ||
88 | + expectLastCall().times(2); | ||
89 | + replay(mockControlPlaneMonitorService); | ||
90 | + basePostTest("disk-metrics-post.json", "cpman/diskmetrics"); | ||
91 | + } | ||
92 | + | ||
93 | + @Test | ||
94 | + public void testNetworkMetricsPost() { | ||
95 | + mockControlPlaneMonitorService.updateMetric(anyObject(), anyObject(), | ||
96 | + (Optional<DeviceId>) anyObject()); | ||
97 | + expectLastCall().times(4); | ||
98 | + replay(mockControlPlaneMonitorService); | ||
99 | + basePostTest("network-metrics-post.json", "cpman/networkmetrics"); | ||
100 | + } | ||
101 | + | ||
102 | + @Test | ||
103 | + public void testSystemSpecsPost() { | ||
104 | + basePostTest("system-spec-post.json", "cpman/systemspecs"); | ||
105 | + } | ||
106 | + | ||
107 | + private void basePostTest(String jsonFile, String path) { | ||
108 | + final WebResource rs = resource(); | ||
109 | + InputStream jsonStream = ControlMetricsCollectorResourceTest.class | ||
110 | + .getResourceAsStream(jsonFile); | ||
111 | + | ||
112 | + assertThat(jsonStream, notNullValue()); | ||
113 | + | ||
114 | + ClientResponse response = rs.path(path) | ||
115 | + .type(MediaType.APPLICATION_JSON_TYPE) | ||
116 | + .post(ClientResponse.class, jsonStream); | ||
117 | + assertThat(response.getStatus(), is(HttpURLConnection.HTTP_OK)); | ||
118 | + } | ||
119 | + | ||
120 | + public ControlMetricsCollectorResourceTest() { | ||
121 | + super(new WebAppDescriptor.Builder("javax.ws.rs.Application", | ||
122 | + CPManWebApplication.class.getCanonicalName()) | ||
123 | + .servletClass(ServletContainer.class).build()); | ||
124 | + } | ||
125 | + | ||
126 | + /** | ||
127 | + * Assigns an available port for the test. | ||
128 | + * | ||
129 | + * @param defaultPort If a port cannot be determined, this one is used. | ||
130 | + * @return free port | ||
131 | + */ | ||
132 | + @Override | ||
133 | + public int getPort(int defaultPort) { | ||
134 | + try { | ||
135 | + ServerSocket socket = new ServerSocket(0); | ||
136 | + socket.setReuseAddress(true); | ||
137 | + int port = socket.getLocalPort(); | ||
138 | + socket.close(); | ||
139 | + return port; | ||
140 | + } catch (IOException ioe) { | ||
141 | + return defaultPort; | ||
142 | + } | ||
143 | + } | ||
144 | + | ||
145 | + @Override | ||
146 | + public AppDescriptor configure() { | ||
147 | + return new WebAppDescriptor.Builder("org.onosproject.cpman.rest").build(); | ||
148 | + } | ||
149 | +} |
-
Please register or login to post a comment