Add ovsdb/netvirt ui to vpnservice netvirt code.
[netvirt.git] / vpnservice / vpnmanager / vpnmanager-impl / src / main / java / org / opendaylight / netvirt / vpnmanager / RouterInterfaceListener.java
index 9e6e35f3b219bce0e6fd1a404235125005b72104..4683941bd0fbcad2231ff8abb7125f29b5d6be71 100644 (file)
@@ -7,10 +7,13 @@
  */\r
 package org.opendaylight.netvirt.vpnmanager;\r
 \r
+import com.google.common.util.concurrent.ListenableFuture;\r
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;\r
 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;\r
+import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;\r
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;\r
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;\r
+import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;\r
 import org.opendaylight.genius.mdsalutil.MDSALUtil;\r
 import org.opendaylight.netvirt.vpnmanager.utilities.InterfaceUtils;\r
 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.neutronvpn.rev150602.RouterInterfacesMap;\r
@@ -21,6 +24,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;\r
 import org.slf4j.LoggerFactory;\r
 \r
+import java.util.ArrayList;\r
+import java.util.List;\r
+import java.util.concurrent.Callable;\r
+\r
 public class RouterInterfaceListener extends AbstractDataChangeListener<Interfaces> {\r
     private static final Logger LOG = LoggerFactory.getLogger(RouterInterfaceListener.class);\r
     private ListenerRegistration<DataChangeListener> listenerRegistration;\r
@@ -54,27 +61,46 @@ public class RouterInterfaceListener extends AbstractDataChangeListener<Interfac
     protected void add(InstanceIdentifier<Interfaces> identifier, Interfaces interfaceInfo) {\r
         LOG.trace("Add event - key: {}, value: {}", identifier, interfaceInfo);\r
         final String routerId = identifier.firstKeyOf(RouterInterfaces.class).getRouterId().getValue();\r
-        String interfaceName = interfaceInfo.getInterfaceId();\r
-\r
-        MDSALUtil.syncWrite(broker, LogicalDatastoreType.CONFIGURATION, \r
-                VpnUtil.getRouterInterfaceId(interfaceName), VpnUtil.getRouterInterface(interfaceName, routerId));\r
-\r
+        final String interfaceName = interfaceInfo.getInterfaceId();\r
         org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface interfaceState =\r
                 InterfaceUtils.getInterfaceStateFromOperDS(broker, interfaceName);\r
-        if (interfaceState != null) {\r
-            LOG.debug("Handling interface {} in router {} add scenario", interfaceName, routerId);\r
-            vpnInterfaceManager.addToNeutronRouterDpnsMap(routerId, interfaceName);\r
-        } else {\r
-            LOG.warn("Interface {} not yet operational to handle router interface add event in router {}", interfaceName, routerId);\r
-        }\r
+        DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();\r
+        dataStoreCoordinator.enqueueJob(interfaceName,\r
+                new Callable<List<ListenableFuture<Void>>>() {\r
+                    @Override\r
+                    public List<ListenableFuture<Void>> call() throws Exception {\r
+                        WriteTransaction writeTxn = broker.newWriteOnlyTransaction();\r
+                        LOG.debug("Handling interface {} in router {} add scenario", interfaceName, routerId);\r
+                        writeTxn.put(LogicalDatastoreType.CONFIGURATION,\r
+                                VpnUtil.getRouterInterfaceId(interfaceName),\r
+                                VpnUtil.getRouterInterface(interfaceName, routerId), true);\r
+                        LOG.debug("Added the Router {} and interface {} in the ODL-L3VPN RouterInterface map",\r
+                                routerId, interfaceName);\r
+                        vpnInterfaceManager.addToNeutronRouterDpnsMap(routerId, interfaceName, writeTxn);\r
+                        List<ListenableFuture<Void>> futures = new ArrayList<>();\r
+                        futures.add(writeTxn.submit());\r
+                        return futures;\r
+                    }\r
+                });\r
     }\r
 \r
     @Override\r
     protected void remove(InstanceIdentifier<Interfaces> identifier, Interfaces interfaceInfo) {\r
         LOG.trace("Remove event - key: {}, value: {}", identifier, interfaceInfo);\r
         final String routerId = identifier.firstKeyOf(RouterInterfaces.class).getRouterId().getValue();\r
-        String interfaceName = interfaceInfo.getInterfaceId();\r
-        vpnInterfaceManager.removeFromNeutronRouterDpnsMap(routerId, interfaceName);\r
+        final String interfaceName = interfaceInfo.getInterfaceId();\r
+        DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();\r
+        dataStoreCoordinator.enqueueJob(interfaceName,\r
+                new Callable<List<ListenableFuture<Void>>>() {\r
+                    @Override\r
+                    public List<ListenableFuture<Void>> call() throws Exception {\r
+                        WriteTransaction writeTxn = broker.newWriteOnlyTransaction();\r
+                        vpnInterfaceManager.removeFromNeutronRouterDpnsMap(routerId, interfaceName, writeTxn);\r
+                        List<ListenableFuture<Void>> futures = new ArrayList<>();\r
+                        futures.add(writeTxn.submit());\r
+                        return futures;\r
+                    }\r
+                });\r
     }\r
 \r
     @Override\r