Clean code and refine javadocs for control plane manager

Change-Id: Ieaaebde69ce2ab54cb819cfad1baa34ee97a7d66
This commit is contained in:
Jian Li 2016-02-03 23:24:42 -08:00 committed by Ray Milkey
parent 2b4f32d5c9
commit c5cb4a1441
11 changed files with 275 additions and 81 deletions

View File

@ -23,15 +23,32 @@ public class ControlMetric {
private final ControlMetricType metricType; private final ControlMetricType metricType;
private final MetricValue metricValue; private final MetricValue metricValue;
/**
* Constructs a control metric using the given control metric type and
* metric value.
*
* @param metricType metric type reference
* @param metricValue metric value reference
*/
public ControlMetric(ControlMetricType metricType, MetricValue metricValue) { public ControlMetric(ControlMetricType metricType, MetricValue metricValue) {
this.metricType = metricType; this.metricType = metricType;
this.metricValue = metricValue; this.metricValue = metricValue;
} }
/**
* Returns metric type reference.
*
* @return metric type reference
*/
public ControlMetricType metricType() { public ControlMetricType metricType() {
return metricType; return metricType;
} }
/**
* Returns metric value reference.
*
* @return metric value reference
*/
public MetricValue metricValue() { public MetricValue metricValue() {
return metricValue; return metricValue;
} }

View File

@ -28,40 +28,46 @@ public interface ControlPlaneMonitorService {
/** /**
* Adds a new control metric value with a certain update interval. * Adds a new control metric value with a certain update interval.
* *
* @param controlMetric control plane metric (e.g., control message rate, cpu, memory, etc.) * @param controlMetric control plane metric (e.g., control
* @param updateInterval value update interval (time unit will be in minute) * message rate, cpu, memory, etc.)
* @param deviceId {@link org.onosproject.net.DeviceId} * @param updateIntervalInMinutes value update interval (in minute)
* @param deviceId device identifier
*/ */
void updateMetric(ControlMetric controlMetric, Integer updateInterval, Optional<DeviceId> deviceId); void updateMetric(ControlMetric controlMetric, int updateIntervalInMinutes,
Optional<DeviceId> deviceId);
/** /**
* Adds a new control metric value with a certain update interval. * Adds a new control metric value with a certain update interval.
* *
* @param controlMetric control plane metric (e.g., disk and network metrics) * @param controlMetric control plane metric (e.g., disk and
* @param updateInterval value update interval (time unit will be in minute) * network metrics)
* @param resourceName resource name * @param updateIntervalInMinutes value update interval (in minute)
* @param resourceName resource name
*/ */
void updateMetric(ControlMetric controlMetric, Integer updateInterval, String resourceName); void updateMetric(ControlMetric controlMetric, int updateIntervalInMinutes,
String resourceName);
/** /**
* Obtains the control plane load of a specific device. * Obtains the control plane load of a specific device.
* The metrics range from control messages and system metrics * The metrics range from control messages and system metrics
* (e.g., CPU and memory info) * (e.g., CPU and memory info)
* *
* @param nodeId node id {@link org.onosproject.cluster.NodeId} * @param nodeId node identifier
* @param type control metric type * @param type control metric type
* @param deviceId device id {@link org.onosproject.net.DeviceId} * @param deviceId device identifier
* @return control plane load * @return control plane load
*/ */
ControlLoad getLoad(NodeId nodeId, ControlMetricType type, Optional<DeviceId> deviceId); ControlLoad getLoad(NodeId nodeId, ControlMetricType type,
Optional<DeviceId> deviceId);
/** /**
* Obtains the control plane load of a specific device. * Obtains the control plane load of a specific device.
* The metrics range from I/O device metrics (e.g., disk and network interface) * The metrics range from I/O device metrics
* (e.g., disk and network interface)
* *
* @param nodeId node id {@link org.onosproject.cluster.NodeId} * @param nodeId node identifier
* @param type control metric type * @param type control metric type
* @param resourceName resource name * @param resourceName resource name
* @return control plane load * @return control plane load
*/ */
ControlLoad getLoad(NodeId nodeId, ControlMetricType type, String resourceName); ControlLoad getLoad(NodeId nodeId, ControlMetricType type, String resourceName);

View File

@ -27,7 +27,7 @@ public final class MetricValue {
private final long count; private final long count;
/** /**
* Constructor. * Constructs a metric value using the given rate, load and count.
* *
* @param rate rate * @param rate rate
* @param load load * @param load load

View File

@ -32,34 +32,34 @@ public interface MetricsDatabase {
/** /**
* Update metric value by specifying metric type. * Update metric value by specifying metric type.
* *
* @param metricType metric type (e.g., load, usage, etc.) * @param metricType metric type (e.g., load, usage, etc.)
* @param value metric value * @param value metric value
*/ */
void updateMetric(String metricType, double value); void updateMetric(String metricType, double value);
/** /**
* Update metric value by specifying metric type in a certain time. * Update metric value by specifying metric type in a certain time.
* *
* @param metricType metric type (e.g., load, usage, etc.) * @param metricType metric type (e.g., load, usage, etc.)
* @param value metric value * @param value metric value
* @param time update time in seconds * @param time update time in seconds
*/ */
void updateMetric(String metricType, double value, long time); void updateMetric(String metricType, double value, long time);
/** /**
* Update metric values of a collection of metric types. * Update metric values of a collection of metric types.
* *
* @param metrics a collection of metrics which consists of a pair of * @param metrics a collection of metrics which consists of a pair of
* metric type and metric value * metric type and metric value
* @param time update time in seconds * @param time update time in seconds
*/ */
void updateMetrics(Map<String, Double> metrics, long time); void updateMetrics(Map<String, Double> metrics, long time);
/** /**
* Update metric values of a collection of metric types. * Update metric values of a collection of metric types.
* *
* @param metrics a collection of metrics which consists of a pair of * @param metrics a collection of metrics which consists of a pair of
* metric type and metric value * metric type and metric value
*/ */
void updateMetrics(Map<String, Double> metrics); void updateMetrics(Map<String, Double> metrics);
@ -74,9 +74,9 @@ public interface MetricsDatabase {
/** /**
* Return most recent metric values of a given metric type for a given period. * Return most recent metric values of a given metric type for a given period.
* *
* @param metricType metric type * @param metricType metric type
* @param duration duration * @param duration duration
* @param unit time unit * @param unit time unit
* @return a collection of metric value * @return a collection of metric value
*/ */
double[] recentMetrics(String metricType, int duration, TimeUnit unit); double[] recentMetrics(String metricType, int duration, TimeUnit unit);
@ -84,7 +84,7 @@ public interface MetricsDatabase {
/** /**
* Returns minimum metric value of a given metric type. * Returns minimum metric value of a given metric type.
* *
* @param metricType metric type * @param metricType metric type
* @return metric value * @return metric value
*/ */
double minMetric(String metricType); double minMetric(String metricType);
@ -92,7 +92,7 @@ public interface MetricsDatabase {
/** /**
* Returns maximum metric value of a given metric type. * Returns maximum metric value of a given metric type.
* *
* @param metricType metric type * @param metricType metric type
* @return metric value * @return metric value
*/ */
double maxMetric(String metricType); double maxMetric(String metricType);
@ -100,7 +100,7 @@ public interface MetricsDatabase {
/** /**
* Returns a collection of metric values of a given metric type for a day. * Returns a collection of metric values of a given metric type for a day.
* *
* @param metricType metric type * @param metricType metric type
* @return a collection of metric value * @return a collection of metric value
*/ */
double[] metrics(String metricType); double[] metrics(String metricType);
@ -109,9 +109,9 @@ public interface MetricsDatabase {
* Returns a collection of metric values of a given metric type for * Returns a collection of metric values of a given metric type for
* a given period. * a given period.
* *
* @param metricType metric type * @param metricType metric type
* @param startTime start time * @param startTime start time
* @param endTime end time * @param endTime end time
* @return a collection of metric value * @return a collection of metric value
*/ */
double[] metrics(String metricType, long startTime, long endTime); double[] metrics(String metricType, long startTime, long endTime);
@ -119,7 +119,7 @@ public interface MetricsDatabase {
/** /**
* Returns the latest metric update time. * Returns the latest metric update time.
* *
* @param metricType metric type * @param metricType metric type
* @return timestamp * @return timestamp
*/ */
long lastUpdate(String metricType); long lastUpdate(String metricType);
@ -145,9 +145,9 @@ public interface MetricsDatabase {
Builder addMetricType(String metricType); Builder addMetricType(String metricType);
/** /**
* Builds a MetricDatabase instance. * Builds a metric database instance.
* *
* @return MetricDatabase instance * @return metric database instance
*/ */
MetricsDatabase build(); MetricsDatabase build();
} }

View File

@ -67,6 +67,12 @@ public final class ControlMetricsFactory {
private Set<String> diskPartitions = Sets.newConcurrentHashSet(); private Set<String> diskPartitions = Sets.newConcurrentHashSet();
private Set<String> nwInterfaces = Sets.newConcurrentHashSet(); private Set<String> nwInterfaces = Sets.newConcurrentHashSet();
/**
* Constructs a control metrics factory using the given metrics and device services.
*
* @param metricsService metric service reference
* @param deviceService device service reference
*/
private ControlMetricsFactory(MetricsService metricsService, DeviceService deviceService) { private ControlMetricsFactory(MetricsService metricsService, DeviceService deviceService) {
this.metricsService = metricsService; this.metricsService = metricsService;
registerMetrics(); registerMetrics();
@ -76,6 +82,13 @@ public final class ControlMetricsFactory {
addAllControlMessageMetrics(deviceIds); addAllControlMessageMetrics(deviceIds);
} }
/**
* Obtains the unique instance of ControlMetricsFactory.
*
* @param metricsService metric service
* @param deviceService device service
* @return instance of ControlMetricsFactory
*/
public static ControlMetricsFactory getInstance(MetricsService metricsService, public static ControlMetricsFactory getInstance(MetricsService metricsService,
DeviceService deviceService) { DeviceService deviceService) {
if (uniqueInstance == null) { if (uniqueInstance == null) {
@ -102,7 +115,7 @@ public final class ControlMetricsFactory {
/** /**
* Adds control metrics of a new device. * Adds control metrics of a new device.
* *
* @param deviceId {@link org.onosproject.net.DeviceId} * @param deviceId device identifier
*/ */
public void addControlMessageMetricsByDeviceId(DeviceId deviceId) { public void addControlMessageMetricsByDeviceId(DeviceId deviceId) {
MetricsAggregator inbound = new MetricsAggregator(metricsService, MetricsAggregator inbound = new MetricsAggregator(metricsService,
@ -171,7 +184,7 @@ public final class ControlMetricsFactory {
/** /**
* Removes control metrics of an existing device. * Removes control metrics of an existing device.
* *
* @param deviceId {@link org.onosproject.net.DeviceId} * @param deviceId device identifier
*/ */
public void removeControlMessageMetricsByDeviceId(DeviceId deviceId) { public void removeControlMessageMetricsByDeviceId(DeviceId deviceId) {
inboundPacket.remove(deviceId); inboundPacket.remove(deviceId);
@ -211,9 +224,9 @@ public final class ControlMetricsFactory {
} }
/** /**
* Returns all device ids. * Returns all device identifiers.
* *
* @return a collection of device id * @return a collection of device identifiers
*/ */
public Set<DeviceId> getDeviceIds() { public Set<DeviceId> getDeviceIds() {
return ImmutableSet.copyOf(this.deviceIds); return ImmutableSet.copyOf(this.deviceIds);
@ -222,7 +235,7 @@ public final class ControlMetricsFactory {
/** /**
* Returns all disk partition names. * Returns all disk partition names.
* *
* @return a collection of disk partition. * @return a collection of disk partitions.
*/ */
public Set<String> getDiskPartitions() { public Set<String> getDiskPartitions() {
return ImmutableSet.copyOf(this.diskPartitions); return ImmutableSet.copyOf(this.diskPartitions);
@ -231,7 +244,7 @@ public final class ControlMetricsFactory {
/** /**
* Returns all network interface names. * Returns all network interface names.
* *
* @return a collection of network interface. * @return a collection of network interfaces.
*/ */
public Set<String> getNetworkInterfaces() { public Set<String> getNetworkInterfaces() {
return ImmutableSet.copyOf(this.nwInterfaces); return ImmutableSet.copyOf(this.nwInterfaces);
@ -240,7 +253,7 @@ public final class ControlMetricsFactory {
/** /**
* Adds control metrics for all devices. * Adds control metrics for all devices.
* *
* @param deviceIds a set of deviceIds * @param deviceIds a set of device identifiers
*/ */
public void addAllControlMessageMetrics(Set<DeviceId> deviceIds) { public void addAllControlMessageMetrics(Set<DeviceId> deviceIds) {
deviceIds.forEach(v -> addControlMessageMetricsByDeviceId(v)); deviceIds.forEach(v -> addControlMessageMetricsByDeviceId(v));
@ -330,102 +343,239 @@ public final class ControlMetricsFactory {
replyPacket.clear(); replyPacket.clear();
} }
/**
* Returns CPU load metric aggregator.
*
* @return metric aggregator
*/
public MetricsAggregator cpuLoadMetric() { public MetricsAggregator cpuLoadMetric() {
return cpuLoad; return cpuLoad;
} }
/**
* Returns total CPU time metric aggregator.
*
* @return metric aggregator
*/
public MetricsAggregator totalCpuTimeMetric() { public MetricsAggregator totalCpuTimeMetric() {
return totalCpuTime; return totalCpuTime;
} }
/**
* Returns system CPU time metric aggregator.
*
* @return metric aggregator
*/
public MetricsAggregator sysCpuTimeMetric() { public MetricsAggregator sysCpuTimeMetric() {
return sysCpuTime; return sysCpuTime;
} }
/**
* Returns user CPU time metric aggregator.
*
* @return metric aggregator
*/
public MetricsAggregator userCpuTime() { public MetricsAggregator userCpuTime() {
return userCpuTime; return userCpuTime;
} }
/**
* Returns CPU idle time metric aggregator.
*
* @return metric aggregator
*/
public MetricsAggregator cpuIdleTime() { public MetricsAggregator cpuIdleTime() {
return cpuIdleTime; return cpuIdleTime;
} }
/**
* Returns free memory ratio metric aggregator.
*
* @return metric aggregator
*/
public MetricsAggregator memoryFreeRatio() { public MetricsAggregator memoryFreeRatio() {
return memoryFreeRatio; return memoryFreeRatio;
} }
/**
* Returns used memory ratio metric aggregator.
*
* @return metric aggregator
*/
public MetricsAggregator memoryUsedRatio() { public MetricsAggregator memoryUsedRatio() {
return memoryUsedRatio; return memoryUsedRatio;
} }
public MetricsAggregator diskReadBytes(String partitionName) { /**
return diskReadBytes.get(partitionName); * Returns disk read bytes metric aggregator.
*
* @param resourceName name of disk resource
* @return metric aggregator
*/
public MetricsAggregator diskReadBytes(String resourceName) {
return diskReadBytes.get(resourceName);
} }
public MetricsAggregator diskWriteBytes(String partitionName) { /**
return diskWriteBytes.get(partitionName); * Returns disk write bytes metric aggregator.
*
* @param resourceName name of disk resource
* @return metric aggregator
*/
public MetricsAggregator diskWriteBytes(String resourceName) {
return diskWriteBytes.get(resourceName);
} }
/**
* Returns incoming bytes metric aggregator.
*
* @param interfaceName name of network interface
* @return metric aggregator
*/
public MetricsAggregator nwIncomingBytes(String interfaceName) { public MetricsAggregator nwIncomingBytes(String interfaceName) {
return nwIncomingBytes.get(interfaceName); return nwIncomingBytes.get(interfaceName);
} }
/**
* Returns outgoing bytes metric aggregator.
*
* @param interfaceName name of network interface
* @return metric aggregator
*/
public MetricsAggregator nwOutgoingBytes(String interfaceName) { public MetricsAggregator nwOutgoingBytes(String interfaceName) {
return nwOutgoingBytes.get(interfaceName); return nwOutgoingBytes.get(interfaceName);
} }
/**
* Returns incoming packets metric aggregator.
*
* @param interfaceName name of network interface
* @return metric aggregator
*/
public MetricsAggregator nwIncomingPackets(String interfaceName) { public MetricsAggregator nwIncomingPackets(String interfaceName) {
return nwIncomingPackets.get(interfaceName); return nwIncomingPackets.get(interfaceName);
} }
/**
* Returns outgoing packets metric aggregator.
*
* @param interfaceName name of network interface
* @return metric aggregator
*/
public MetricsAggregator nwOutgoingPackets(String interfaceName) { public MetricsAggregator nwOutgoingPackets(String interfaceName) {
return nwOutgoingPackets.get(interfaceName); return nwOutgoingPackets.get(interfaceName);
} }
/**
* Returns inbound packet metric aggregator of all devices.
*
* @return metric aggregator
*/
public Map<DeviceId, MetricsAggregator> inboundPacket() { public Map<DeviceId, MetricsAggregator> inboundPacket() {
return ImmutableMap.copyOf(inboundPacket); return ImmutableMap.copyOf(inboundPacket);
} }
/**
* Returns outgoing packet metric aggregator of all devices.
*
* @return metric aggregator
*/
public Map<DeviceId, MetricsAggregator> outboundPacket() { public Map<DeviceId, MetricsAggregator> outboundPacket() {
return ImmutableMap.copyOf(outboundPacket); return ImmutableMap.copyOf(outboundPacket);
} }
/**
* Returns flow-mod packet metric aggregator of all devices.
*
* @return metric aggregator
*/
public Map<DeviceId, MetricsAggregator> flowmodPacket() { public Map<DeviceId, MetricsAggregator> flowmodPacket() {
return ImmutableMap.copyOf(flowmodPacket); return ImmutableMap.copyOf(flowmodPacket);
} }
/**
* Returns flow-removed packet metric aggregator of all devices.
*
* @return metric aggregator
*/
public Map<DeviceId, MetricsAggregator> flowrmvPacket() { public Map<DeviceId, MetricsAggregator> flowrmvPacket() {
return ImmutableMap.copyOf(flowrmvPacket); return ImmutableMap.copyOf(flowrmvPacket);
} }
/**
* Returns request packet metric aggregator of all devices.
*
* @return metric aggregator
*/
public Map<DeviceId, MetricsAggregator> requestPacket() { public Map<DeviceId, MetricsAggregator> requestPacket() {
return ImmutableMap.copyOf(requestPacket); return ImmutableMap.copyOf(requestPacket);
} }
/**
* Returns reply packet metric aggregator of all devices.
*
* @return metric aggregator
*/
public Map<DeviceId, MetricsAggregator> replyPacket() { public Map<DeviceId, MetricsAggregator> replyPacket() {
return ImmutableMap.copyOf(replyPacket); return ImmutableMap.copyOf(replyPacket);
} }
/**
* Returns inbound packet metric aggregator of a specified device.
*
* @param deviceId device identifier
* @return metric aggregator
*/
public MetricsAggregator inboundPacket(DeviceId deviceId) { public MetricsAggregator inboundPacket(DeviceId deviceId) {
return inboundPacket.get(deviceId); return inboundPacket.get(deviceId);
} }
/**
* Returns outbound packet metric aggregator of a specified device.
*
* @param deviceId device identifier
* @return metric aggregator
*/
public MetricsAggregator outboundPacket(DeviceId deviceId) { public MetricsAggregator outboundPacket(DeviceId deviceId) {
return outboundPacket.get(deviceId); return outboundPacket.get(deviceId);
} }
/**
* Returns flow-mod packet metric aggregator of a specified device.
*
* @param deviceId device identifier
* @return metric aggregator
*/
public MetricsAggregator flowmodPacket(DeviceId deviceId) { public MetricsAggregator flowmodPacket(DeviceId deviceId) {
return flowmodPacket.get(deviceId); return flowmodPacket.get(deviceId);
} }
/**
* Returns flow-removed packet metric aggregator of a specified device.
*
* @param deviceId device identifier
* @return metric aggregator
*/
public MetricsAggregator flowrmvPacket(DeviceId deviceId) { public MetricsAggregator flowrmvPacket(DeviceId deviceId) {
return flowrmvPacket.get(deviceId); return flowrmvPacket.get(deviceId);
} }
/**
* Returns request packet metric aggregator of a specified device.
*
* @param deviceId device identifier
* @return metric aggregator
*/
public MetricsAggregator requestPacket(DeviceId deviceId) { public MetricsAggregator requestPacket(DeviceId deviceId) {
return requestPacket.get(deviceId); return requestPacket.get(deviceId);
} }
/**
* Returns reply packet metric aggregator of a specified device.
*
* @param deviceId device identifier
* @return metric aggregator
*/
public MetricsAggregator replyPacket(DeviceId deviceId) { public MetricsAggregator replyPacket(DeviceId deviceId) {
return replyPacket.get(deviceId); return replyPacket.get(deviceId);
} }

View File

@ -28,7 +28,7 @@ public interface ControlMetricsObserver {
* Feeds the extracted value from MetricAggregator to back-end storage. * Feeds the extracted value from MetricAggregator to back-end storage.
* *
* @param metricsAggregator metric aggregator * @param metricsAggregator metric aggregator
* @param deviceId device id {@link org.onosproject.net.DeviceId} * @param deviceId device identification
*/ */
void feedMetrics(MetricsAggregator metricsAggregator, Optional<DeviceId> deviceId); void feedMetrics(MetricsAggregator metricsAggregator, Optional<DeviceId> deviceId);

View File

@ -36,6 +36,7 @@ import org.slf4j.LoggerFactory;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import static org.onosproject.cpman.ControlMetricType.CPU_IDLE_TIME; import static org.onosproject.cpman.ControlMetricType.CPU_IDLE_TIME;
@ -83,18 +84,18 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
private static final String DISK = "Disk"; private static final String DISK = "Disk";
private static final String NETWORK = "Network"; private static final String NETWORK = "Network";
private static final ImmutableSet<ControlMetricType> CPU_METRICS = private static final Set<ControlMetricType> CPU_METRICS =
ImmutableSet.of(CPU_IDLE_TIME, CPU_LOAD, SYS_CPU_TIME, ImmutableSet.of(CPU_IDLE_TIME, CPU_LOAD, SYS_CPU_TIME,
USER_CPU_TIME, TOTAL_CPU_TIME); USER_CPU_TIME, TOTAL_CPU_TIME);
private static final ImmutableSet<ControlMetricType> MEMORY_METRICS = private static final Set<ControlMetricType> MEMORY_METRICS =
ImmutableSet.of(MEMORY_FREE, MEMORY_FREE_RATIO, MEMORY_USED, ImmutableSet.of(MEMORY_FREE, MEMORY_FREE_RATIO, MEMORY_USED,
MEMORY_USED_RATIO); MEMORY_USED_RATIO);
private static final ImmutableSet<ControlMetricType> DISK_METRICS = private static final Set<ControlMetricType> DISK_METRICS =
ImmutableSet.of(DISK_READ_BYTES, DISK_WRITE_BYTES); ImmutableSet.of(DISK_READ_BYTES, DISK_WRITE_BYTES);
private static final ImmutableSet<ControlMetricType> NETWORK_METRICS = private static final Set<ControlMetricType> NETWORK_METRICS =
ImmutableSet.of(NW_INCOMING_BYTES, NW_OUTGOING_BYTES, ImmutableSet.of(NW_INCOMING_BYTES, NW_OUTGOING_BYTES,
NW_INCOMING_PACKETS, NW_OUTGOING_PACKETS); NW_INCOMING_PACKETS, NW_OUTGOING_PACKETS);
private static final ImmutableSet<ControlMetricType> CTRL_MSGS = private static final Set<ControlMetricType> CTRL_MSGS =
ImmutableSet.of(INBOUND_PACKET, OUTBOUND_PACKET, FLOW_MOD_PACKET, ImmutableSet.of(INBOUND_PACKET, OUTBOUND_PACKET, FLOW_MOD_PACKET,
FLOW_REMOVED_PACKET, REQUEST_PACKET, REPLY_PACKET); FLOW_REMOVED_PACKET, REQUEST_PACKET, REPLY_PACKET);
private Map<ControlMetricType, Double> cpuBuf; private Map<ControlMetricType, Double> cpuBuf;
@ -134,7 +135,7 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
} }
@Override @Override
public void updateMetric(ControlMetric cm, Integer updateInterval, public void updateMetric(ControlMetric cm, int updateIntervalInMinutes,
Optional<DeviceId> deviceId) { Optional<DeviceId> deviceId) {
if (deviceId.isPresent()) { if (deviceId.isPresent()) {
@ -180,7 +181,7 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
} }
@Override @Override
public void updateMetric(ControlMetric cm, Integer updateInterval, public void updateMetric(ControlMetric cm, int updateIntervalInMinutes,
String resourceName) { String resourceName) {
// update disk metrics // update disk metrics
if (DISK_METRICS.contains(cm.metricType())) { if (DISK_METRICS.contains(cm.metricType())) {
@ -252,7 +253,7 @@ public class ControlPlaneMonitor implements ControlPlaneMonitorService {
} }
private MetricsDatabase genMDbBuilder(String metricName, private MetricsDatabase genMDbBuilder(String metricName,
ImmutableSet<ControlMetricType> metricTypes) { Set<ControlMetricType> metricTypes) {
MetricsDatabase.Builder builder = new DefaultMetricsDatabase.Builder(); MetricsDatabase.Builder builder = new DefaultMetricsDatabase.Builder();
builder.withMetricName(metricName); builder.withMetricName(metricName);
metricTypes.forEach(type -> builder.addMetricType(type.toString())); metricTypes.forEach(type -> builder.addMetricType(type.toString()));

View File

@ -31,6 +31,13 @@ public class DefaultControlLoad implements ControlLoad {
private final MetricsDatabase mdb; private final MetricsDatabase mdb;
private final ControlMetricType type; private final ControlMetricType type;
/**
* Constructs a control load using the given metrics database and
* control metric type.
*
* @param mdb metrics database
* @param type control metric type
*/
public DefaultControlLoad(MetricsDatabase mdb, ControlMetricType type) { public DefaultControlLoad(MetricsDatabase mdb, ControlMetricType type) {
this.mdb = mdb; this.mdb = mdb;
this.type = type; this.type = type;

View File

@ -53,6 +53,13 @@ public final class DefaultMetricsDatabase implements MetricsDatabase {
private static final String INSUFFICIENT_DURATION = "Given duration less than one minute."; private static final String INSUFFICIENT_DURATION = "Given duration less than one minute.";
private static final String EXCEEDED_DURATION = "Given duration exceeds a day time."; private static final String EXCEEDED_DURATION = "Given duration exceeds a day time.";
/**
* Constructs a metrics database using the given metric name and
* round robin database.
*
* @param metricName metric name
* @param rrdDb round robin database
*/
private DefaultMetricsDatabase(String metricName, RrdDb rrdDb) { private DefaultMetricsDatabase(String metricName, RrdDb rrdDb) {
this.metricName = metricName; this.metricName = metricName;
this.rrdDb = rrdDb; this.rrdDb = rrdDb;

View File

@ -43,13 +43,13 @@ public class MetricsAggregator {
private static final String COUNT_NAME = "count"; private static final String COUNT_NAME = "count";
/** /**
* Constructs a new MetricsAggregator for aggregating a metric. * Constructs a new metrics aggregator for aggregating a metric.
* Instantiates the metrics service * Instantiates the metrics service
* Initializes all the general metrics for that object * Initializes all the general metrics for that object
* *
* @param metricsService MetricsService reference * @param metricsService metric service reference
* @param type Control metric type * @param type control metric type
* @param deviceId DeviceId * @param deviceId device identification
*/ */
MetricsAggregator(MetricsService metricsService, ControlMetricType type, MetricsAggregator(MetricsService metricsService, ControlMetricType type,
Optional<DeviceId> deviceId) { Optional<DeviceId> deviceId) {
@ -57,12 +57,12 @@ public class MetricsAggregator {
} }
/** /**
* Constructs a new MetricAggregator for aggregating a metric. * Constructs a new metrics aggregator for aggregating a metric.
* Instantiates the metrics service * Instantiates the metrics service
* Initializes all the general metrics for that object * Initializes all the general metrics for that object
* *
* @param metricsService MetricsService reference * @param metricsService metric service reference
* @param type Control metric type * @param type control metric type
* @param resourceName resource name (e.g., ethernet interface name) * @param resourceName resource name (e.g., ethernet interface name)
*/ */
MetricsAggregator(MetricsService metricsService, ControlMetricType type, MetricsAggregator(MetricsService metricsService, ControlMetricType type,
@ -72,12 +72,12 @@ public class MetricsAggregator {
} }
/** /**
* Constructs a new MetricAggregator for aggregating a metric. * Constructs a new metrics aggregator for aggregating a metric.
* Instantiates the metrics service * Instantiates the metrics service
* Initializes all the general metrics for that object * Initializes all the general metrics for that object
* *
* @param metricsService MetricsService reference * @param metricsService metrics service reference
* @param type Control metric type * @param type control metric type
*/ */
MetricsAggregator(MetricsService metricsService, ControlMetricType type) { MetricsAggregator(MetricsService metricsService, ControlMetricType type) {
init(metricsService, type, Optional.ofNullable(null), null); init(metricsService, type, Optional.ofNullable(null), null);
@ -86,9 +86,9 @@ public class MetricsAggregator {
/** /**
* Base method of the constructor of this class. * Base method of the constructor of this class.
* *
* @param metricsService MetricsService reference * @param metricsService metrics service reference
* @param type Control metric type * @param type control metric type
* @param deviceId DeviceId * @param deviceId device identification
* @param resourceName resource name * @param resourceName resource name
*/ */
private void init(MetricsService metricsService, ControlMetricType type, private void init(MetricsService metricsService, ControlMetricType type,
@ -116,14 +116,19 @@ public class MetricsAggregator {
this.countMeter = metricsService.createMeter(metricsComponent, metricsFeature, COUNT_NAME); this.countMeter = metricsService.createMeter(metricsComponent, metricsFeature, COUNT_NAME);
} }
/**
* Returns control metrics type.
*
* @return control metrics type
*/
public ControlMetricType getMetricsType() { public ControlMetricType getMetricsType() {
return metricsType; return metricsType;
} }
/** /**
* Increments the meter rate by {@code n}, and the meter counter by 1. * Increments the meter rate by n, and the meter counter by 1.
* *
* @param n Increment the meter rate by {@code n}. * @param n increment rate.
*/ */
public void increment(long n) { public void increment(long n) {
rateMeter.mark(n); rateMeter.mark(n);
@ -131,7 +136,7 @@ public class MetricsAggregator {
} }
/** /**
* Obtains the average load value. * Returns the average load value.
* *
* @return load value * @return load value
*/ */
@ -140,7 +145,7 @@ public class MetricsAggregator {
} }
/** /**
* Obtains the average meter rate within recent 1 minute. * Returns the average meter rate within recent 1 minute.
* *
* @return rate value * @return rate value
*/ */
@ -149,7 +154,7 @@ public class MetricsAggregator {
} }
/** /**
* Obtains the average meter count within recent 1 minute. * Returns the average meter count within recent 1 minute.
* *
* @return count value * @return count value
*/ */

View File

@ -36,6 +36,7 @@ import java.net.HttpURLConnection;
import java.net.ServerSocket; import java.net.ServerSocket;
import java.util.Optional; import java.util.Optional;
import static org.easymock.EasyMock.anyInt;
import static org.easymock.EasyMock.anyObject; import static org.easymock.EasyMock.anyObject;
import static org.easymock.EasyMock.anyString; import static org.easymock.EasyMock.anyString;
import static org.easymock.EasyMock.createMock; import static org.easymock.EasyMock.createMock;
@ -68,7 +69,7 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest {
@Test @Test
public void testCpuMetricsPost() { public void testCpuMetricsPost() {
mockControlPlaneMonitorService.updateMetric(anyObject(), anyObject(), mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(),
(Optional<DeviceId>) anyObject()); (Optional<DeviceId>) anyObject());
expectLastCall().times(5); expectLastCall().times(5);
replay(mockControlPlaneMonitorService); replay(mockControlPlaneMonitorService);
@ -77,7 +78,7 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest {
@Test @Test
public void testMemoryMetricsPost() { public void testMemoryMetricsPost() {
mockControlPlaneMonitorService.updateMetric(anyObject(), anyObject(), mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(),
(Optional<DeviceId>) anyObject()); (Optional<DeviceId>) anyObject());
expectLastCall().times(4); expectLastCall().times(4);
replay(mockControlPlaneMonitorService); replay(mockControlPlaneMonitorService);
@ -86,7 +87,7 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest {
@Test @Test
public void testDiskMetricsWithNullName() { public void testDiskMetricsWithNullName() {
mockControlPlaneMonitorService.updateMetric(anyObject(), anyObject(), anyString()); mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(), anyString());
expectLastCall().times(4); expectLastCall().times(4);
replay(mockControlPlaneMonitorService); replay(mockControlPlaneMonitorService);
basePostTest("disk-metrics-post.json", PREFIX + "/disk_metrics"); basePostTest("disk-metrics-post.json", PREFIX + "/disk_metrics");
@ -94,7 +95,7 @@ public class ControlMetricsCollectorResourceTest extends JerseyTest {
@Test @Test
public void testNetworkMetricsWithNullName() { public void testNetworkMetricsWithNullName() {
mockControlPlaneMonitorService.updateMetric(anyObject(), anyObject(), anyString()); mockControlPlaneMonitorService.updateMetric(anyObject(), anyInt(), anyString());
expectLastCall().times(8); expectLastCall().times(8);
replay(mockControlPlaneMonitorService); replay(mockControlPlaneMonitorService);
basePostTest("network-metrics-post.json", PREFIX + "/network_metrics"); basePostTest("network-metrics-post.json", PREFIX + "/network_metrics");