Merge "[VOL-3673] Adding per device filter to dhcpl2relay-allocations command"
diff --git a/app/src/main/java/org/opencord/dhcpl2relay/cli/DhcpL2RelayAllocationsCommand.java b/app/src/main/java/org/opencord/dhcpl2relay/cli/DhcpL2RelayAllocationsCommand.java
index 4d38e8f..1455e2f 100644
--- a/app/src/main/java/org/opencord/dhcpl2relay/cli/DhcpL2RelayAllocationsCommand.java
+++ b/app/src/main/java/org/opencord/dhcpl2relay/cli/DhcpL2RelayAllocationsCommand.java
@@ -15,11 +15,19 @@
  */
 package org.opencord.dhcpl2relay.cli;
 
+import org.apache.karaf.shell.api.action.Argument;
 import org.apache.karaf.shell.api.action.Command;
+import org.apache.karaf.shell.api.action.Completion;
 import org.apache.karaf.shell.api.action.lifecycle.Service;
 import org.onosproject.cli.AbstractShellCommand;
+import org.onosproject.cli.net.DeviceIdCompleter;
+import org.onosproject.net.DeviceId;
+import org.opencord.dhcpl2relay.DhcpAllocationInfo;
 import org.opencord.dhcpl2relay.DhcpL2RelayService;
 
+import java.util.Map;
+import java.util.stream.Collectors;
+
 /**
  *  Shows the Successful DHCP allocations relayed by the dhcpl2relay.
  */
@@ -27,11 +35,25 @@
 @Command(scope = "onos", name = "dhcpl2relay-allocations",
         description = "Shows the Successful DHCP allocations relayed by the dhcpl2relay")
 public class DhcpL2RelayAllocationsCommand extends AbstractShellCommand {
+
+    @Argument(index = 0, name = "deviceId", description = "Access device ID")
+    @Completion(DeviceIdCompleter.class)
+    private String strDeviceId = null;
+
     @Override
     protected void doExecute() {
         DhcpL2RelayService service = get(DhcpL2RelayService.class);
 
-        service.getAllocationInfo().forEach((key, value) -> {
+        Map<String, DhcpAllocationInfo> allocations = service.getAllocationInfo();
+
+        if (strDeviceId != null && !strDeviceId.isEmpty()) {
+            DeviceId deviceId = DeviceId.deviceId(strDeviceId);
+            allocations = allocations.entrySet().stream()
+                    .filter(a -> a.getValue().location().deviceId().equals(deviceId))
+                    .collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue()));
+        }
+
+        allocations.forEach((key, value) -> {
             print("SubscriberId=%s,ConnectPoint=%s,State=%s,MAC=%s,VLAN=%s,"
                     + "CircuitId=%s,IP Allocated=%s,Allocation Timestamp=%s",
                     value.subscriberId(), value.location(), value.type(),
diff --git a/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayConfigTest.java b/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayConfigTest.java
index e218088..493f45d 100644
--- a/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayConfigTest.java
+++ b/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayConfigTest.java
@@ -114,7 +114,7 @@
     /**
      * Mocks the network config registry.
      */
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings({"unchecked", "TypeParameterUnusedInFormals"})
     static final class TestNetworkConfigRegistry
             extends NetworkConfigRegistryAdapter {
         @Override
diff --git a/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayTestBase.java b/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayTestBase.java
index df480a7..ccecb51 100755
--- a/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayTestBase.java
+++ b/app/src/test/java/org/opencord/dhcpl2relay/impl/DhcpL2RelayTestBase.java
@@ -586,12 +586,14 @@
         }
 
         @Override
+        @SuppressWarnings({"TypeParameterUnusedInFormals"})
         public <T> T invokeAny(Collection<? extends Callable<T>> tasks)
                 throws ExecutionException, InterruptedException {
             throw new UnsupportedOperationException();
         }
 
         @Override
+        @SuppressWarnings({"TypeParameterUnusedInFormals"})
         public <T> T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit)
                 throws ExecutionException, InterruptedException, TimeoutException {
             throw new UnsupportedOperationException();
@@ -618,6 +620,7 @@
         }
 
         @Override
+        @SuppressWarnings({"TypeParameterUnusedInFormals"})
         public <T> Future<T> submit(Callable<T> task) {
             throw new UnsupportedOperationException();
         }