[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
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/ControlMetric.java b/apps/cpman/src/main/java/org/onosproject/cpman/ControlMetric.java
index a431817..fc1640f 100644
--- a/apps/cpman/src/main/java/org/onosproject/cpman/ControlMetric.java
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/ControlMetric.java
@@ -23,7 +23,7 @@
private final ControlMetricType metricType;
private final MetricValue metricValue;
- ControlMetric(ControlMetricType metricType, MetricValue metricValue) {
+ public ControlMetric(ControlMetricType metricType, MetricValue metricValue) {
this.metricType = metricType;
this.metricValue = metricValue;
}
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneManager.java b/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneManager.java
index 3305297..941cc0f 100644
--- a/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneManager.java
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneManager.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2015-2016 Open Networking Laboratory
+ * Copyright 2016 Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,117 +16,47 @@
package org.onosproject.cpman;
import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Modified;
-import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.ReferenceCardinality;
-import org.onlab.metrics.MetricsService;
import org.onosproject.core.ApplicationId;
import org.onosproject.core.CoreService;
import org.onosproject.net.device.DeviceService;
import org.slf4j.Logger;
-
-import java.util.HashSet;
-import java.util.Optional;
-import java.util.Set;
-
-import static org.slf4j.LoggerFactory.getLogger;
+import org.slf4j.LoggerFactory;
/**
- * Control plane management application.
+ * Skeletal ONOS application component.
*/
@Component(immediate = true)
public class ControlPlaneManager {
- private final Logger log = getLogger(getClass());
- private Set<ControlMetricsObserver> controlMetricsObservers = new HashSet<>();
- private ControlMetricsObserver cpObserver;
-
- private ApplicationId appId;
-
- private ControlMetricsFactory cmf;
-
- @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected DeviceService deviceService;
+ private final Logger log = LoggerFactory.getLogger(getClass());
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
protected CoreService coreService;
@Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY)
- protected MetricsService metricsService;
+ protected DeviceService deviceService;
+
+ private ApplicationId appId;
@Activate
- public void activate() {
+ protected void activate() {
appId = coreService.registerApplication("org.onosproject.cpman");
-
- cmf = ControlMetricsFactory.getInstance(metricsService, deviceService);
- // currently disable monitoring by default
- // cmf.startMonitor();
-
- registerObserver();
-
+ deviceService.getAvailableDevices();
log.info("Started");
}
@Deactivate
- public void deactivate() {
- unregisterObserver();
- cmf.stopMonitor();
+ protected void deactivate() {
log.info("Stopped");
}
@Modified
- public void modified() {
+ protected void modified() {
}
- private void registerObserver() {
- cpObserver = new DefaultControlMetricsObserver();
- this.addControlMetricsObserver(cpObserver);
- }
-
- private void unregisterObserver() {
- this.removeControlMetricsObserver(cpObserver);
- }
-
- private void executeMonitorTask() {
-
- // TODO: execute monitoring task with 1 minute period
- if (cmf.isMonitor()) {
- controlMetricsObservers.forEach(observer -> {
-
- // only OpenFlow messages are spontaneously monitored with
- // 1 minute period. Other system metrics will be pushed from
- // external monitoring agent through REST API
-
- // feed the control message stats
- cmf.getDeviceIds().forEach(v -> {
- observer.feedMetrics(cmf.inboundPacket(v), Optional.of(v));
- observer.feedMetrics(cmf.outboundPacket(v), Optional.of(v));
- observer.feedMetrics(cmf.flowmodPacket(v), Optional.of(v));
- observer.feedMetrics(cmf.flowrmvPacket(v), Optional.of(v));
- observer.feedMetrics(cmf.requestPacket(v), Optional.of(v));
- observer.feedMetrics(cmf.replyPacket(v), Optional.of(v));
- });
- });
- }
- }
-
- /**
- * Adds a new control metrics observer.
- *
- * @param cmObserver control metric observer instance
- */
- public void addControlMetricsObserver(ControlMetricsObserver cmObserver) {
- controlMetricsObservers.add(cmObserver);
- }
-
- /**
- * Removes an existing control metrics observer.
- *
- * @param cmObserver control metric observer instance
- */
- public void removeControlMetricsObserver(ControlMetricsObserver cmObserver) {
- controlMetricsObservers.remove(cmObserver);
- }
}
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneMonitor.java b/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneMonitor.java
index 2144f46..e69a915 100644
--- a/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneMonitor.java
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneMonitor.java
@@ -16,9 +16,9 @@
package org.onosproject.cpman;
import org.apache.felix.scr.annotations.Activate;
+import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Deactivate;
import org.apache.felix.scr.annotations.Modified;
-import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.onosproject.cluster.NodeId;
import org.onosproject.net.DeviceId;
@@ -41,6 +41,7 @@
@Activate
public void activate() {
+
}
@Deactivate
@@ -52,12 +53,12 @@
}
@Override
- public void updateMetric(ControlMetric cpm, int updateInterval,
+ public void updateMetric(ControlMetric cpm, Integer updateInterval,
Optional<DeviceId> deviceId) {
}
@Override
- public void updateMetric(ControlMetric controlMetric, int updateInterval,
+ public void updateMetric(ControlMetric controlMetric, Integer updateInterval,
String resourceName) {
}
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java b/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java
index d35f24f..d4e6bc5 100644
--- a/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/ControlPlaneMonitorService.java
@@ -33,7 +33,7 @@
* @param updateInterval value update interval (time unit will be in minute)
* @param deviceId {@link org.onosproject.net.DeviceId}
*/
- void updateMetric(ControlMetric controlMetric, int updateInterval, Optional<DeviceId> deviceId);
+ void updateMetric(ControlMetric controlMetric, Integer updateInterval, Optional<DeviceId> deviceId);
/**
* Adds a new control metric value with a certain update interval.
@@ -42,7 +42,7 @@
* @param updateInterval value update interval (time unit will be in minute)
* @param resourceName resource name
*/
- void updateMetric(ControlMetric controlMetric, int updateInterval, String resourceName);
+ void updateMetric(ControlMetric controlMetric, Integer updateInterval, String resourceName);
/**
* Obtains the control plane load of a specific device.
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/DefaultControlMetricsObserver.java b/apps/cpman/src/main/java/org/onosproject/cpman/DefaultControlMetricsObserver.java
index 434c165..145ea9f 100644
--- a/apps/cpman/src/main/java/org/onosproject/cpman/DefaultControlMetricsObserver.java
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/DefaultControlMetricsObserver.java
@@ -31,14 +31,22 @@
@Override
public void feedMetrics(MetricsAggregator ma, Optional<DeviceId> deviceId) {
- MetricValue mv = new MetricValue((long) ma.getRate(), (long) ma.getLoad(), (long) ma.getCount());
+ MetricValue mv = new MetricValue.Builder()
+ .rate(ma.getRate())
+ .count(ma.getCount())
+ .load(ma.getLoad())
+ .add();
ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv);
controlPlaneMonitorService.updateMetric(cm, 1, deviceId);
}
@Override
public void feedMetrics(MetricsAggregator ma, String resourceName) {
- MetricValue mv = new MetricValue((long) ma.getRate(), (long) ma.getLoad(), (long) ma.getCount());
+ MetricValue mv = new MetricValue.Builder()
+ .rate(ma.getRate())
+ .count(ma.getCount())
+ .load(ma.getLoad())
+ .add();
ControlMetric cm = new ControlMetric(ma.getMetricsType(), mv);
controlPlaneMonitorService.updateMetric(cm, 1, resourceName);
}
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/MetricValue.java b/apps/cpman/src/main/java/org/onosproject/cpman/MetricValue.java
index 3603b3a..e0f7342 100644
--- a/apps/cpman/src/main/java/org/onosproject/cpman/MetricValue.java
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/MetricValue.java
@@ -20,7 +20,7 @@
/**
* Primitive Metric Value.
*/
-public class MetricValue {
+public final class MetricValue {
private final long rate;
private final long load;
@@ -33,24 +33,90 @@
* @param load load
* @param count count
*/
- MetricValue(long rate, long load, long count) {
+ private MetricValue(long rate, long load, long count) {
this.rate = rate;
this.load = load;
this.count = count;
}
+ /**
+ * Returns rate value.
+ *
+ * @return rate
+ */
public long getRate() {
return rate;
}
+ /**
+ * Returns load value.
+ *
+ * @return load
+ */
public long getLoad() {
return load;
}
+ /**
+ * Returns count value.
+ *
+ * @return cound
+ */
public long getCount() {
return count;
}
+ /**
+ * MetricValue builder class.
+ */
+ public static final class Builder {
+ private long rate;
+ private long load;
+ private long count;
+
+ /**
+ * Sets rate value.
+ *
+ * @param rate rate value
+ * @return Builder object
+ */
+ public Builder rate(long rate) {
+ this.rate = rate;
+ return this;
+ }
+
+ /**
+ * Sets load value.
+ *
+ * @param load load value
+ * @return Builder object
+ */
+ public Builder load(long load) {
+ this.load = load;
+ return this;
+ }
+
+ /**
+ * Sets count value.
+ *
+ * @param count count value
+ * @return Builder object
+ */
+ public Builder count(long count) {
+ this.count = count;
+ return this;
+ }
+
+ /**
+ * Builds a MetricValue object.
+ *
+ * @return MetricValue object
+ */
+ public MetricValue add() {
+ return new MetricValue(rate, load, count);
+ }
+ }
+
@Override
public boolean equals(Object obj) {
if (this == obj) {
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/MetricsAggregator.java b/apps/cpman/src/main/java/org/onosproject/cpman/MetricsAggregator.java
index 139a9a4..3058402 100644
--- a/apps/cpman/src/main/java/org/onosproject/cpman/MetricsAggregator.java
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/MetricsAggregator.java
@@ -134,8 +134,8 @@
*
* @return load value
*/
- public double getLoad() {
- return rateMeter.getOneMinuteRate() / countMeter.getOneMinuteRate();
+ public long getLoad() {
+ return (long) rateMeter.getOneMinuteRate() / (long) countMeter.getOneMinuteRate();
}
/**
@@ -143,8 +143,8 @@
*
* @return rate value
*/
- public double getRate() {
- return rateMeter.getOneMinuteRate();
+ public long getRate() {
+ return (long) rateMeter.getOneMinuteRate();
}
/**
@@ -152,7 +152,7 @@
*
* @return count value
*/
- public double getCount() {
- return countMeter.getOneMinuteRate() * EXECUTE_PERIOD_IN_SECOND;
+ public long getCount() {
+ return (long) countMeter.getOneMinuteRate() * EXECUTE_PERIOD_IN_SECOND;
}
}
\ No newline at end of file
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/rest/CPManWebApplication.java b/apps/cpman/src/main/java/org/onosproject/cpman/rest/CPManWebApplication.java
new file mode 100644
index 0000000..26566f8
--- /dev/null
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/rest/CPManWebApplication.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed 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.
+ */
+
+package org.onosproject.cpman.rest;
+
+import org.onlab.rest.AbstractWebApplication;
+
+import java.util.Set;
+
+/**
+ * CPMan REST APIs web application.
+ */
+public class CPManWebApplication extends AbstractWebApplication {
+ @Override
+ public Set<Class<?>> getClasses() {
+ return getClasses(ControlMetricsCollectorWebResource.class);
+ }
+}
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/rest/ControlMetricsCollectorWebResource.java b/apps/cpman/src/main/java/org/onosproject/cpman/rest/ControlMetricsCollectorWebResource.java
new file mode 100644
index 0000000..444d3dc
--- /dev/null
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/rest/ControlMetricsCollectorWebResource.java
@@ -0,0 +1,286 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed 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.
+ */
+package org.onosproject.cpman.rest;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import org.onosproject.cpman.ControlMetric;
+import org.onosproject.cpman.ControlMetricType;
+import org.onosproject.cpman.ControlMetricsSystemSpec;
+import org.onosproject.cpman.ControlPlaneMonitorService;
+import org.onosproject.cpman.MetricValue;
+import org.onosproject.rest.AbstractWebResource;
+
+import javax.ws.rs.Consumes;
+import javax.ws.rs.POST;
+import javax.ws.rs.Path;
+import javax.ws.rs.Produces;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Optional;
+
+/**
+ * Collect control plane metrics.
+ */
+@Path("cpman")
+public class ControlMetricsCollectorWebResource extends AbstractWebResource {
+
+ final ControlPlaneMonitorService service = get(ControlPlaneMonitorService.class);
+ public static final int UPDATE_INTERVAL = 1; // 1 minute update interval
+ public static final String INVALID_SYSTEM_SPECS = "Invalid system specifications";
+
+ /**
+ * Collects CPU metrics.
+ *
+ * @param stream JSON stream
+ * @return 200 OK
+ * @onos.rsModel CpuMetricsPost
+ */
+ @POST
+ @Path("cpumetrics")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response cpuMetrics(InputStream stream) {
+ ObjectNode root = mapper().createObjectNode();
+ ControlMetric cm;
+ try {
+ ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ JsonNode cpuLoadJson = jsonTree.get("cpuLoad");
+ JsonNode totalCpuTimeJson = jsonTree.get("totalCpuTime");
+ JsonNode sysCpuTimeJson = jsonTree.get("sysCpuTime");
+ JsonNode userCpuTimeJson = jsonTree.get("userCpuTime");
+ JsonNode cpuIdleTimeJson = jsonTree.get("cpuIdleTime");
+
+ if (cpuLoadJson != null) {
+ cm = new ControlMetric(ControlMetricType.CPU_LOAD,
+ new MetricValue.Builder().load(cpuLoadJson.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (totalCpuTimeJson != null) {
+ cm = new ControlMetric(ControlMetricType.TOTAL_CPU_TIME,
+ new MetricValue.Builder().load(totalCpuTimeJson.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (sysCpuTimeJson != null) {
+ cm = new ControlMetric(ControlMetricType.SYS_CPU_TIME,
+ new MetricValue.Builder().load(sysCpuTimeJson.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (userCpuTimeJson != null) {
+ cm = new ControlMetric(ControlMetricType.USER_CPU_TIME,
+ new MetricValue.Builder().load(userCpuTimeJson.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (cpuIdleTimeJson != null) {
+ cm = new ControlMetric(ControlMetricType.CPU_IDLE_TIME,
+ new MetricValue.Builder().load(cpuIdleTimeJson.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ return ok(root).build();
+ }
+
+ /**
+ * Collects memory metrics.
+ *
+ * @param stream JSON stream
+ * @return 200 OK
+ * @onos.rsModel MemoryMetricsPost
+ */
+ @POST
+ @Path("memorymetrics")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response memoryMetrics(InputStream stream) {
+ ObjectNode root = mapper().createObjectNode();
+ ControlMetric cm;
+ try {
+ ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ JsonNode memUsedPerc = jsonTree.get("memoryUsedPercentage");
+ JsonNode memFreePerc = jsonTree.get("memoryFreePercentage");
+ JsonNode memUsed = jsonTree.get("memoryUsed");
+ JsonNode memFree = jsonTree.get("memoryFree");
+
+ if (memUsedPerc != null) {
+ cm = new ControlMetric(ControlMetricType.MEMORY_USED_PERCENTAGE,
+ new MetricValue.Builder().load(memUsedPerc.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (memFreePerc != null) {
+ cm = new ControlMetric(ControlMetricType.MEMORY_FREE_PERCENTAGE,
+ new MetricValue.Builder().load(memFreePerc.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (memUsed != null) {
+ cm = new ControlMetric(ControlMetricType.MEMORY_USED,
+ new MetricValue.Builder().load(memUsed.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (memFree != null) {
+ cm = new ControlMetric(ControlMetricType.MEMORY_FREE,
+ new MetricValue.Builder().load(memFree.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ return ok(root).build();
+ }
+
+ /**
+ * Collects disk metrics.
+ *
+ * @param stream JSON stream
+ * @return 200 OK
+ * @onos.rsModel DiskMetricsPost
+ */
+ @POST
+ @Path("diskmetrics")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response diskMetrics(InputStream stream) {
+ ObjectNode root = mapper().createObjectNode();
+ ControlMetric cm;
+ try {
+ ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ JsonNode readBytes = jsonTree.get("readBytes");
+ JsonNode writeBytes = jsonTree.get("writeBytes");
+
+ if (readBytes != null) {
+ cm = new ControlMetric(ControlMetricType.DISK_READ_BYTES,
+ new MetricValue.Builder().load(readBytes.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (writeBytes != null) {
+ cm = new ControlMetric(ControlMetricType.DISK_WRITE_BYTES,
+ new MetricValue.Builder().load(writeBytes.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ return ok(root).build();
+ }
+
+ /**
+ * Collects network metrics.
+ *
+ * @param stream JSON stream
+ * @return 200 OK
+ * @onos.rsModel NetworkMetricsPost
+ */
+ @POST
+ @Path("networkmetrics")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response networkMetrics(InputStream stream) {
+ ObjectNode root = mapper().createObjectNode();
+ ControlMetric cm;
+ try {
+ ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ JsonNode inBytes = jsonTree.get("incomingBytes");
+ JsonNode outBytes = jsonTree.get("outgoingBytes");
+ JsonNode inPackets = jsonTree.get("incomingPackets");
+ JsonNode outPackets = jsonTree.get("outgoingPackets");
+
+ if (inBytes != null) {
+ cm = new ControlMetric(ControlMetricType.NW_INCOMING_BYTES,
+ new MetricValue.Builder().load(inBytes.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (outBytes != null) {
+ cm = new ControlMetric(ControlMetricType.NW_OUTGOING_BYTES,
+ new MetricValue.Builder().load(outBytes.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (inPackets != null) {
+ cm = new ControlMetric(ControlMetricType.NW_INCOMING_PACKETS,
+ new MetricValue.Builder().load(inPackets.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ if (outPackets != null) {
+ cm = new ControlMetric(ControlMetricType.NW_OUTGOING_PACKETS,
+ new MetricValue.Builder().load(outPackets.asLong()).add());
+ service.updateMetric(cm, UPDATE_INTERVAL, Optional.ofNullable(null));
+ }
+
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ return ok(root).build();
+ }
+
+
+ /**
+ * Collects system specifications.
+ * The system specs include the various control metrics
+ * which do not require aggregation.
+ *
+ * @param stream JSON stream
+ * @return 200 OK
+ * @onos.rsModel SystemSpecsPost
+ */
+ @POST
+ @Path("systemspecs")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response systemSpecs(InputStream stream) {
+ ObjectNode root = mapper().createObjectNode();
+
+ try {
+ ObjectNode jsonTree = (ObjectNode) mapper().readTree(stream);
+ JsonNode numOfCores = jsonTree.get("numOfCores");
+ JsonNode numOfCpus = jsonTree.get("numOfCpus");
+ JsonNode cpuSpeed = jsonTree.get("cpuSpeed");
+ JsonNode totalMemory = jsonTree.get("totalMemory");
+
+ if (numOfCores != null && numOfCpus != null && cpuSpeed != null && totalMemory != null) {
+ ControlMetricsSystemSpec.Builder builder = new ControlMetricsSystemSpec.Builder();
+ ControlMetricsSystemSpec cmss = builder.numOfCores(numOfCores.asInt())
+ .numOfCpus(numOfCpus.asInt())
+ .cpuSpeed(cpuSpeed.asInt())
+ .totalMemory(totalMemory.asLong())
+ .build();
+ // TODO: need to implement spec store
+
+ } else {
+ throw new IllegalArgumentException(INVALID_SYSTEM_SPECS);
+ }
+
+ } catch (IOException e) {
+ throw new IllegalArgumentException(e.getMessage());
+ }
+ return ok(root).build();
+ }
+}
diff --git a/apps/cpman/src/main/java/org/onosproject/cpman/rest/package-info.java b/apps/cpman/src/main/java/org/onosproject/cpman/rest/package-info.java
new file mode 100644
index 0000000..cf3baaa
--- /dev/null
+++ b/apps/cpman/src/main/java/org/onosproject/cpman/rest/package-info.java
@@ -0,0 +1,20 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed 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.
+ */
+
+/**
+ * REST APIs for the control plane monitor.
+ */
+package org.onosproject.cpman.rest;
\ No newline at end of file
diff --git a/apps/cpman/src/main/resources/definitions/CpuMetricsPost.json b/apps/cpman/src/main/resources/definitions/CpuMetricsPost.json
new file mode 100644
index 0000000..9f52429
--- /dev/null
+++ b/apps/cpman/src/main/resources/definitions/CpuMetricsPost.json
@@ -0,0 +1,37 @@
+{
+ "type": "object",
+ "required": [
+ "cpuLoad",
+ "totalCpuTime",
+ "sysCpuTime",
+ "userCpuTime",
+ "cpuIdleTime"
+ ],
+ "properties": {
+ "cpuLoad": {
+ "type": "integer",
+ "format": "int64",
+ "example": "50"
+ },
+ "totalCpuTime": {
+ "type": "integer",
+ "format": "int64",
+ "example": "2000"
+ },
+ "sysCpuTime": {
+ "type": "integer",
+ "format": "int64",
+ "example": "2000"
+ },
+ "userCpuTime": {
+ "type": "integer",
+ "format": "int64",
+ "example": "2000"
+ },
+ "cpuIdleTime": {
+ "type": "integer",
+ "format": "int64",
+ "example": "2000"
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/cpman/src/main/resources/definitions/DiskMetricsPost.json b/apps/cpman/src/main/resources/definitions/DiskMetricsPost.json
new file mode 100644
index 0000000..fe0dab1
--- /dev/null
+++ b/apps/cpman/src/main/resources/definitions/DiskMetricsPost.json
@@ -0,0 +1,19 @@
+{
+ "type": "object",
+ "required": [
+ "readBytes",
+ "writeBytes"
+ ],
+ "properties": {
+ "readBytes": {
+ "type": "integer",
+ "format": "int64",
+ "example": "500"
+ },
+ "writeBytes": {
+ "type": "integer",
+ "format": "int64",
+ "example": "300"
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/cpman/src/main/resources/definitions/MemoryMetricsPost.json b/apps/cpman/src/main/resources/definitions/MemoryMetricsPost.json
new file mode 100644
index 0000000..ab815da
--- /dev/null
+++ b/apps/cpman/src/main/resources/definitions/MemoryMetricsPost.json
@@ -0,0 +1,31 @@
+{
+ "type": "object",
+ "required": [
+ "memoryUsedPercentage",
+ "memoryFreePercentage",
+ "memoryUsed",
+ "memoryFree"
+ ],
+ "properties": {
+ "memoryUsedPercentage": {
+ "type": "integer",
+ "format": "int64",
+ "example": "30"
+ },
+ "memoryFreePercentage": {
+ "type": "integer",
+ "format": "int64",
+ "example": "70"
+ },
+ "memoryUsed": {
+ "type": "integer",
+ "format": "int64",
+ "example": "1024"
+ },
+ "memoryFree": {
+ "type": "integer",
+ "format": "int64",
+ "example": "2048"
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/cpman/src/main/resources/definitions/NetworkMetricsPost.json b/apps/cpman/src/main/resources/definitions/NetworkMetricsPost.json
new file mode 100644
index 0000000..f9ad7d3
--- /dev/null
+++ b/apps/cpman/src/main/resources/definitions/NetworkMetricsPost.json
@@ -0,0 +1,31 @@
+{
+ "type": "object",
+ "required": [
+ "incomingBytes",
+ "outgoingBytes",
+ "incomingPackets",
+ "outgoingPackets"
+ ],
+ "properties": {
+ "incomingBytes": {
+ "type": "integer",
+ "format": "int64",
+ "example": "1024"
+ },
+ "outgoingBytes": {
+ "type": "integer",
+ "format": "int64",
+ "example": "1024"
+ },
+ "incomingPackets": {
+ "type": "integer",
+ "format": "int64",
+ "example": "1000"
+ },
+ "outgoingPackets": {
+ "type": "integer",
+ "format": "int64",
+ "example": "2000"
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/cpman/src/main/resources/definitions/SystemSpecsPost.json b/apps/cpman/src/main/resources/definitions/SystemSpecsPost.json
new file mode 100644
index 0000000..fc4fc16
--- /dev/null
+++ b/apps/cpman/src/main/resources/definitions/SystemSpecsPost.json
@@ -0,0 +1,31 @@
+{
+ "type": "object",
+ "required": [
+ "numOfCores",
+ "numOfCpus",
+ "cpuSpeed",
+ "totalMemory"
+ ],
+ "properties": {
+ "numOfCores": {
+ "type": "integer",
+ "format": "int64",
+ "example": "6"
+ },
+ "numOfCpus": {
+ "type": "integer",
+ "format": "int64",
+ "example": "2"
+ },
+ "cpuSpeed": {
+ "type": "integer",
+ "format": "int64",
+ "example": "2048"
+ },
+ "totalMemory": {
+ "type": "integer",
+ "format": "int64",
+ "example": "4096"
+ }
+ }
+}
\ No newline at end of file
diff --git a/apps/cpman/src/main/webapp/WEB-INF/web.xml b/apps/cpman/src/main/webapp/WEB-INF/web.xml
new file mode 100644
index 0000000..a1be00b
--- /dev/null
+++ b/apps/cpman/src/main/webapp/WEB-INF/web.xml
@@ -0,0 +1,57 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ Copyright 2016 Open Networking Laboratory
+ ~
+ ~ Licensed 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.
+ -->
+<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
+ id="ONOS" version="2.5">
+ <display-name>Control Plane REST API v1.0</display-name>
+
+ <security-constraint>
+ <web-resource-collection>
+ <web-resource-name>Secured</web-resource-name>
+ <url-pattern>/*</url-pattern>
+ </web-resource-collection>
+ <auth-constraint>
+ <role-name>admin</role-name>
+ </auth-constraint>
+ </security-constraint>
+
+ <security-role>
+ <role-name>admin</role-name>
+ </security-role>
+
+ <login-config>
+ <auth-method>BASIC</auth-method>
+ <realm-name>karaf</realm-name>
+ </login-config>
+
+ <servlet>
+ <servlet-name>JAX-RS Service</servlet-name>
+ <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
+ <init-param>
+ <param-name>javax.ws.rs.Application</param-name>
+ <param-value>org.onosproject.cpman.rest.CPManWebApplication</param-value>
+ </init-param>
+ <load-on-startup>1</load-on-startup>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>JAX-RS Service</servlet-name>
+ <url-pattern>/*</url-pattern>
+ </servlet-mapping>
+</web-app>