[ONOS-5957] Meter lists filter also by meterId if desired.
Change-Id: I735cdf0936708fd9bd7252c28052927a425f9633
diff --git a/cli/src/main/java/org/onosproject/cli/net/MetersListCommand.java b/cli/src/main/java/org/onosproject/cli/net/MetersListCommand.java
index 16277bd..575ee37 100644
--- a/cli/src/main/java/org/onosproject/cli/net/MetersListCommand.java
+++ b/cli/src/main/java/org/onosproject/cli/net/MetersListCommand.java
@@ -21,10 +21,13 @@
import org.onosproject.cli.AbstractShellCommand;
import org.onosproject.net.DeviceId;
import org.onosproject.net.meter.Meter;
+import org.onosproject.net.meter.MeterId;
import org.onosproject.net.meter.MeterService;
import java.util.Collection;
+import static com.google.common.base.Strings.isNullOrEmpty;
+
/**
* Lists all meters.
*/
@@ -36,19 +39,36 @@
required = false, multiValued = false)
String uri = null;
+ @Argument(index = 1, name = "meter", description = "Meter ID",
+ required = false, multiValued = false)
+ String meterstr = null;
+
+ MeterId meterId = null;
@Override
protected void execute() {
+
+ if (!isNullOrEmpty(meterstr)) {
+ meterId = MeterId.meterId(Long.parseLong(meterstr));
+ }
+
MeterService service = get(MeterService.class);
- Collection<Meter> meters = service.getAllMeters();
- if (uri != null) {
- DeviceId deviceId = DeviceId.deviceId(uri);
- Collection<Meter> devMeters = Collections2.filter(meters,
- m -> m.deviceId().equals(deviceId));
- printMeters(devMeters);
+ if (meterId != null && uri != null) {
+ Meter m = service.getMeter(DeviceId.deviceId(uri), meterId);
+ if (m != null) {
+ print("%s", m);
+ } else {
+ error("Meter %s not found for device %s", meterId, uri);
+ }
} else {
- printMeters(meters);
+ Collection<Meter> meters = service.getAllMeters();
+ if (uri == null) {
+ printMeters(meters);
+ } else {
+ printMeters(Collections2.filter(meters,
+ m -> m.deviceId().equals(DeviceId.deviceId(uri))));
+ }
}
}