[ONOS-6473] Refactor getPhysicalDevices method in VirtualNetworkService

Change-Id: I3f4549f3ea630283d72a1df1e59f24f33df1b672
diff --git a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkService.java b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkService.java
index da791de..88ef56b 100644
--- a/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkService.java
+++ b/incubator/api/src/main/java/org/onosproject/incubator/net/virtual/VirtualNetworkService.java
@@ -90,11 +90,10 @@
      * port mapping mechanism.
      *
      * @param networkId network identifier
-     * @param virtualDevice the virtual device
+     * @param deviceId the virtual device identifier
      * @return collection of the specified device's identifier
      */
-    Set<DeviceId> getPhysicalDevices(NetworkId networkId,
-                                             VirtualDevice virtualDevice);
+    Set<DeviceId> getPhysicalDevices(NetworkId networkId, DeviceId deviceId);
 
     /**
      * Returns implementation of the specified service class for operating
diff --git a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/VirtualNetworkServiceAdapter.java b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/VirtualNetworkServiceAdapter.java
index ebfd8da..3e75742 100644
--- a/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/VirtualNetworkServiceAdapter.java
+++ b/incubator/api/src/test/java/org/onosproject/incubator/net/virtual/VirtualNetworkServiceAdapter.java
@@ -62,7 +62,7 @@
     }
 
     @Override
-    public Set<DeviceId> getPhysicalDevices(NetworkId networkId, VirtualDevice virtualDevice) {
+    public Set<DeviceId> getPhysicalDevices(NetworkId networkId, DeviceId deviceId) {
         return null;
     }
 
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java
index d57801b..69f849e 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManager.java
@@ -15,8 +15,8 @@
  */
 package org.onosproject.incubator.net.virtual.impl;
 
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
 import org.apache.felix.scr.annotations.Activate;
 import org.apache.felix.scr.annotations.Component;
 import org.apache.felix.scr.annotations.Deactivate;
@@ -72,6 +72,7 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Objects;
 import java.util.Set;
@@ -354,13 +355,11 @@
     }
 
     @Override
-    public Set<DeviceId> getPhysicalDevices(NetworkId networkId,
-                                             VirtualDevice virtualDevice) {
+    public Set<DeviceId> getPhysicalDevices(NetworkId networkId, DeviceId deviceId) {
         checkNotNull(networkId, "Network ID cannot be null");
-        checkNotNull(virtualDevice, "Virtual device cannot be null");
-        Set<VirtualPort> virtualPortSet =
-                getVirtualPorts(networkId, virtualDevice.id());
-        Set<DeviceId> physicalDeviceSet = Sets.newConcurrentHashSet();
+        checkNotNull(deviceId, "Virtual device ID cannot be null");
+        Set<VirtualPort> virtualPortSet = getVirtualPorts(networkId, deviceId);
+        Set<DeviceId> physicalDeviceSet = new HashSet<>();
 
         virtualPortSet.forEach(virtualPort -> {
             if (virtualPort.realizedBy() != null) {
@@ -368,7 +367,7 @@
             }
         });
 
-        return physicalDeviceSet;
+        return ImmutableSet.copyOf(physicalDeviceSet);
     }
 
     private final Map<ServiceKey, VnetService> networkServices = Maps.newConcurrentMap();
diff --git a/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManagerTest.java b/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManagerTest.java
index 9d4086e..250dc84f 100644
--- a/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManagerTest.java
+++ b/incubator/net/src/test/java/org/onosproject/incubator/net/virtual/impl/VirtualNetworkManagerTest.java
@@ -378,32 +378,28 @@
 
         Set<DeviceId> physicalDeviceSet;
         Set<DeviceId> testSet = new HashSet<>();
-        physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork1.id(), vDevice1InVnet1);
+        physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork1.id(), vDevice1InVnet1.id());
         testSet.add(PHYDID1);
         testSet.add(PHYDID2);
         assertEquals("The physical devices 1 did not match", testSet, physicalDeviceSet);
-        physicalDeviceSet.clear();
         testSet.clear();
 
-        physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork1.id(), vDevice2InVnet1);
+        physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork1.id(), vDevice2InVnet1.id());
         testSet.add(PHYDID3);
         testSet.add(PHYDID4);
         assertEquals("The physical devices 2 did not match", testSet, physicalDeviceSet);
-        physicalDeviceSet.clear();
         testSet.clear();
 
-        physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork2.id(), vDevice1InVnet2);
+        physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork2.id(), vDevice1InVnet2.id());
         testSet.add(PHYDID1);
         testSet.add(PHYDID2);
         assertEquals("The physical devices 1 did not match", testSet, physicalDeviceSet);
-        physicalDeviceSet.clear();
         testSet.clear();
 
-        physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork2.id(), vDevice2InVnet2);
+        physicalDeviceSet = manager.getPhysicalDevices(virtualNetwork2.id(), vDevice2InVnet2.id());
         testSet.add(PHYDID3);
         testSet.add(PHYDID4);
         assertEquals("The physical devices 2 did not match", testSet, physicalDeviceSet);
-        physicalDeviceSet.clear();
         testSet.clear();
     }