X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=vpnservice%2Fvpnmanager%2Fvpnmanager-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fnetvirt%2Fvpnmanager%2FInterfaceStateChangeListener.java;h=7f7a292b94337aea4be3408952be591bcacb84b4;hb=61961cea27d47c39f76a20b7094ec1b7a5366d57;hp=a3c04fec9b047c45d5a0d8cbffd06047ac3e3211;hpb=06d3b0d63d7cab796af20e6c91491b6f9d7d8c01;p=netvirt.git diff --git a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/InterfaceStateChangeListener.java b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/InterfaceStateChangeListener.java index a3c04fec9b..7f7a292b94 100644 --- a/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/InterfaceStateChangeListener.java +++ b/vpnservice/vpnmanager/vpnmanager-impl/src/main/java/org/opendaylight/netvirt/vpnmanager/InterfaceStateChangeListener.java @@ -9,12 +9,14 @@ package org.opendaylight.netvirt.vpnmanager; import com.google.common.base.Optional; +import com.google.common.util.concurrent.CheckedFuture; import com.google.common.util.concurrent.ListenableFuture; import org.opendaylight.controller.md.sal.binding.api.DataBroker; import org.opendaylight.controller.md.sal.binding.api.DataChangeListener; import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator; import org.opendaylight.netvirt.vpnmanager.utilities.InterfaceUtils; import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface; @@ -32,6 +34,7 @@ import java.math.BigInteger; import java.util.ArrayList; import java.util.List; import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; public class InterfaceStateChangeListener extends AbstractDataChangeListener implements AutoCloseable { private static final Logger LOG = LoggerFactory.getLogger(InterfaceStateChangeListener.class); @@ -50,7 +53,7 @@ public class InterfaceStateChangeListener extends AbstractDataChangeListener>>() { @Override public List> call() throws Exception { - WriteTransaction writeTxn = broker.newWriteOnlyTransaction(); - vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnInterface, ifIndex, false, writeTxn); - List> futures = new ArrayList<>(); - futures.add(writeTxn.submit()); - return futures; + WriteTransaction writeConfigTxn = broker.newWriteOnlyTransaction(); + WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction(); + vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnInterface, ifIndex, false, + writeConfigTxn, writeOperTxn); + CheckedFuture futures = writeOperTxn.submit(); + try { + futures.get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Error adding Oper data for interface {} to vpn {} on dpn {}", interfaceName, + vpnInterface.getVpnInstanceName(), dpnId); + throw new RuntimeException(e.getMessage()); + } + futures = writeConfigTxn.submit(); + try { + futures.get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Error adding Config data for interface {} to vpn {} on dpn {}", interfaceName, + vpnInterface.getVpnInstanceName(), dpnId); + throw new RuntimeException(e.getMessage()); + } + return null; } }); } else { @@ -116,11 +135,17 @@ public class InterfaceStateChangeListener extends AbstractDataChangeListener>>() { @Override public List> call() throws Exception { - WriteTransaction writeTxn = broker.newWriteOnlyTransaction(); - handleRouterInterfacesUpEvent(routerName, interfaceName, writeTxn); - List> futures = new ArrayList<>(); - futures.add(writeTxn.submit()); - return futures; + WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction(); + handleRouterInterfacesUpEvent(routerName, interfaceName, writeOperTxn); + CheckedFuture futures = writeOperTxn.submit(); + try { + futures.get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Error adding as router interface for interface {} to router {} ", interfaceName, + routerName); + throw new RuntimeException(e.getMessage()); + } + return null; } }); } else { @@ -160,7 +185,7 @@ public class InterfaceStateChangeListener extends AbstractDataChangeListener>>() { @Override public List> call() throws Exception { - WriteTransaction writeTxn = broker.newWriteOnlyTransaction(); - vpnInterfaceManager.processVpnInterfaceDown(dpnId, interfaceName, ifIndex, false, false, writeTxn); + WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction(); + WriteTransaction writeConfigTxn = broker.newWriteOnlyTransaction(); + vpnInterfaceManager.processVpnInterfaceDown(dpnId, interfaceName, ifIndex, false, false, + writeConfigTxn, writeOperTxn); RouterInterface routerInterface = VpnUtil.getConfiguredRouterInterface(broker, interfaceName); if (routerInterface != null) { final String routerName = routerInterface.getRouterName(); - handleRouterInterfacesDownEvent(routerName, interfaceName, dpnId, writeTxn); + handleRouterInterfacesDownEvent(routerName, interfaceName, dpnId, writeOperTxn); + } + CheckedFuture futures = writeOperTxn.submit(); + try { + futures.get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Error removing Oper data for interface {} from vpn {} on dpn {}", interfaceName, + vpnInterface.getVpnInstanceName(), dpnId); + throw new RuntimeException(e.getMessage()); + } + futures = writeConfigTxn.submit(); + try { + futures.get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Error removing Config data for interface {} from vpn {} on dpn {}", interfaceName, + vpnInterface.getVpnInstanceName(), dpnId); + throw new RuntimeException(e.getMessage()); } - List> futures = new ArrayList<>(); - futures.add(writeTxn.submit()); - return futures; + return null; } }); } @@ -210,16 +251,23 @@ public class InterfaceStateChangeListener extends AbstractDataChangeListener>>() { @Override public List> call() throws Exception { - WriteTransaction writeTxn = broker.newWriteOnlyTransaction(); + WriteTransaction writeConfigTxn = broker.newWriteOnlyTransaction(); + WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction(); vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnInterface, ifIndex, - true, writeTxn); - List> futures = new ArrayList<>(); - futures.add(writeTxn.submit()); - return futures; + true, writeConfigTxn, writeOperTxn); + CheckedFuture futures = writeConfigTxn.submit(); + try { + futures.get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Error updating UP for interface {} in vpn {} on dpn {}", interfaceName, + vpnInterface.getVpnInstanceName(), dpnId); + throw new RuntimeException(e.getMessage()); + } + return null; } }); } else if (update.getOperStatus().equals(Interface.OperStatus.Down)) { @@ -228,11 +276,27 @@ public class InterfaceStateChangeListener extends AbstractDataChangeListener>>() { @Override public List> call() throws Exception { - WriteTransaction writeTxn = broker.newWriteOnlyTransaction(); - vpnInterfaceManager.processVpnInterfaceDown(dpnId, interfaceName, ifIndex, true, false, writeTxn); - List> futures = new ArrayList<>(); - futures.add(writeTxn.submit()); - return futures; + WriteTransaction writeConfigTxn = broker.newWriteOnlyTransaction(); + WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction(); + vpnInterfaceManager.processVpnInterfaceDown(dpnId, interfaceName, ifIndex, true, false, + writeConfigTxn, writeOperTxn); + CheckedFuture futures = writeOperTxn.submit(); + try { + futures.get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Error updating DOWN for interface {} from vpn {} on dpn {}", interfaceName, + vpnInterface.getVpnInstanceName(), dpnId); + throw new RuntimeException(e.getMessage()); + } + futures = writeConfigTxn.submit(); + try { + futures.get(); + } catch (InterruptedException | ExecutionException e) { + LOG.error("Error updating DOWN for interface {} from vpn {} on dpn {}", interfaceName, + vpnInterface.getVpnInstanceName(), dpnId); + throw new RuntimeException(e.getMessage()); + } + return null; } }); } @@ -241,14 +305,15 @@ public class InterfaceStateChangeListener extends AbstractDataChangeListener