Exception during netvirt CSIT 96/90296/3
authorKarthikeyan Krishnan <karthikeyangceb007@gmail.com>
Fri, 5 Jun 2020 06:06:53 +0000 (11:36 +0530)
committerKarthikeyan Krishnan <karthikeyangceb007@gmail.com>
Fri, 5 Jun 2020 09:51:00 +0000 (15:21 +0530)
Issue:
======
2020-06-04T06:17:55,547 | ERROR | jobcoordinator-main-task-138 |
VpnSubnetRouteHandler            | 364 -
org.opendaylight.netvirt.vpnmanager-impl - 0.11.0.SNAPSHOT | SUBNETROUTE:
onInterfaceUp: Unable to handle interface up event for port
015fb82e-c78a-40bd-85a0-88091273a7dd in subnet
9a942efe-ef93-483a-a3e6-b8c5cb01b218
java.lang.IllegalArgumentException: Multiple entries with same key:

VpnInterfacesKey{_interfaceName=015fb82e-c78a-40bd-85a0-88091273a7dd}
=VpnInterfaces{_interfaceName=015fb82e-c78a-40bd-85a0-88091273a7dd,
augmentation=[]} and
VpnInterfacesKey{_interfaceName=015fb82e-c78a-40bd-85a0-88091273a7dd}
=VpnInterfaces{getInterfaceName=015fb82e-c78a-40bd-85a0-88091273a7dd,
augmentation=[]}. To index multiple values under a key, use
Multimaps.index.
at com.google.common.collect.Maps.uniqueIndex(Maps.java:1338)
~[bundleFile:?] at
com.google.common.collect.Maps.uniqueIndex(Maps.java:1293)
~[bundleFile:?] at
org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.subnet
.op.data.subnet.op.data.entry.SubnetToDpnBuilder.setVpnInterfaces(SubnetToDpnBuilder.java:148)
~[bundleFile:?]
at
org.opendaylight.netvirt.vpnmanager.SubnetOpDpnManager.addInterfaceToDpn(SubnetOpDpnManager.java:137)
~[bundleFile:?]
at
org.opendaylight.netvirt.vpnmanager.VpnSubnetRouteHandler.onInterfaceUp(VpnSubnetRouteHandler.java:613)
[bundleFile:?]

Solution:
=========
Have handled the proper fix for processing map data

Signed-off-by: Karthikeyan Krishnan <karthikeyangceb007@gmail.com>
Change-Id: I744f8ceadeaa65c82ea3f963bc323699caa06f13

vpnmanager/impl/src/main/java/org/opendaylight/netvirt/vpnmanager/SubnetOpDpnManager.java

index a82765c7104e07c030a7a4d569e2085859b3d64f..906e61ce8f525d93245c9ff0e1ee5516cf398a4a 100644 (file)
@@ -8,7 +8,9 @@
 package org.opendaylight.netvirt.vpnmanager;
 
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Optional;
 import java.util.concurrent.ExecutionException;
 import javax.inject.Inject;
@@ -64,8 +66,8 @@ public class SubnetOpDpnManager {
                 return null;
             }
             SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder().withKey(new SubnetToDpnKey(dpnId));
-            List<VpnInterfaces> vpnIntfList = new ArrayList<>();
-            subDpnBuilder.setVpnInterfaces(vpnIntfList);
+            Map<VpnInterfacesKey, VpnInterfaces> vpnInterfaceMap = new HashMap<>();
+            subDpnBuilder.setVpnInterfaces(vpnInterfaceMap);
             SubnetToDpn subDpn = subDpnBuilder.build();
             SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn,
                     VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
@@ -127,14 +129,13 @@ public class SubnetOpDpnManager {
                 subDpn = optionalSubDpn.get();
             }
             SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(subDpn);
-            List<VpnInterfaces> vpnIntfList = new ArrayList<>();
-            vpnIntfList = subDpnBuilder.getVpnInterfaces() != null
-                    ? new ArrayList<>(subDpnBuilder.getVpnInterfaces().values()) : vpnIntfList;
-
+            Map<VpnInterfacesKey, VpnInterfaces> vpnInterfaceMap = new HashMap<>();
+            vpnInterfaceMap = subDpnBuilder.getVpnInterfaces() != null
+                    ? new HashMap<>(subDpnBuilder.getVpnInterfaces()) : vpnInterfaceMap;
             VpnInterfaces vpnIntfs =
                 new VpnInterfacesBuilder().withKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
-            vpnIntfList.add(vpnIntfs);
-            subDpnBuilder.setVpnInterfaces(vpnIntfList);
+            vpnInterfaceMap.put(vpnIntfs.key(), vpnIntfs);
+            subDpnBuilder.setVpnInterfaces(vpnInterfaceMap);
             subDpn = subDpnBuilder.build();
             SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId, subDpn,
                     VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
@@ -215,18 +216,19 @@ public class SubnetOpDpnManager {
             }
 
             SubnetToDpnBuilder subDpnBuilder = new SubnetToDpnBuilder(optionalSubDpn.get());
-            List<VpnInterfaces> vpnIntfList = new ArrayList<>();
-            vpnIntfList = (subDpnBuilder.getVpnInterfaces() != null && !subDpnBuilder.getVpnInterfaces().isEmpty())
-                    ? new ArrayList<>(subDpnBuilder.getVpnInterfaces().values()) : vpnIntfList;
+            Map<VpnInterfacesKey, VpnInterfaces> vpnInterfaceMap = new HashMap<>();
+
+            vpnInterfaceMap = (subDpnBuilder.getVpnInterfaces() != null && !subDpnBuilder.getVpnInterfaces().isEmpty())
+                    ? new HashMap<>(subDpnBuilder.getVpnInterfaces()) : vpnInterfaceMap;
             VpnInterfaces vpnIntfs =
                 new VpnInterfacesBuilder().withKey(new VpnInterfacesKey(intfName)).setInterfaceName(intfName).build();
-            vpnIntfList.remove(vpnIntfs);
-            if (vpnIntfList.isEmpty()) {
+            vpnInterfaceMap.remove(vpnIntfs.key());
+            if (vpnInterfaceMap.isEmpty()) {
                 // Remove the DPN as well
                 removeDpnFromSubnet(subnetId, dpnId);
                 dpnRemoved = true;
             } else {
-                subDpnBuilder.setVpnInterfaces(vpnIntfList);
+                subDpnBuilder.setVpnInterfaces(vpnInterfaceMap);
                 SingleTransactionDataBroker.syncWrite(broker, LogicalDatastoreType.OPERATIONAL, dpnOpId,
                     subDpnBuilder.build(), VpnUtil.SINGLE_TRANSACTION_BROKER_NO_RETRY);
             }