Bug 6284 - Cancellation exceptions during operation execution
[ovsdb.git] / southbound / southbound-impl / src / main / java / org / opendaylight / ovsdb / southbound / ovsdb / transact / TransactInvokerImpl.java
index cc7056d65b18013d7c37e785fbdb3dae1ebb6231..92ba86b2aff44d71cacdb2e30a74a512ca0bb34d 100644 (file)
@@ -7,20 +7,23 @@
  */
 package org.opendaylight.ovsdb.southbound.ovsdb.transact;
 
+import com.google.common.util.concurrent.ListenableFuture;
+import java.util.Collection;
 import java.util.List;
+import java.util.concurrent.ExecutionException;
 
+import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
 import org.opendaylight.ovsdb.lib.operations.OperationResult;
 import org.opendaylight.ovsdb.lib.operations.TransactionBuilder;
 import org.opendaylight.ovsdb.lib.schema.DatabaseSchema;
 import org.opendaylight.ovsdb.southbound.OvsdbConnectionInstance;
+import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
 import org.opendaylight.yangtools.yang.binding.DataObject;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.util.concurrent.ListenableFuture;
-
 public class TransactInvokerImpl implements TransactInvoker {
     private static final Logger LOG = LoggerFactory.getLogger(TransactInvokerImpl.class);
     private OvsdbConnectionInstance connectionInstance;
@@ -34,23 +37,34 @@ public class TransactInvokerImpl implements TransactInvoker {
     @Override
     public void invoke(TransactCommand command, BridgeOperationalState state,
                        AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> events) {
-        TransactionBuilder tb = new TransactionBuilder(connectionInstance, dbSchema);
+        TransactionBuilder tb = new TransactionBuilder(connectionInstance.getOvsdbClient(), dbSchema);
         command.execute(tb, state, events);
         invoke(command, tb);
     }
 
+    @Override
+    public void invoke(TransactCommand command, BridgeOperationalState state,
+                       Collection<DataTreeModification<Node>> modifications) {
+        TransactionBuilder tb = new TransactionBuilder(connectionInstance.getOvsdbClient(), dbSchema);
+        command.execute(tb, state, modifications);
+        invoke(command, tb);
+    }
+
     private void invoke(TransactCommand command, TransactionBuilder tb) {
         ListenableFuture<List<OperationResult>> result = tb.execute();
         LOG.debug("invoke: command: {}, tb: {}", command, tb);
         if (tb.getOperations().size() > 0) {
             try {
-                List<OperationResult> got = result.get();
-                LOG.debug("OVSDB transaction result: {}", got);
-            } catch (Exception e) {
+                if (!result.isCancelled()) {
+                    List<OperationResult> got = result.get();
+                    LOG.debug("OVSDB transaction result: {}", got);
+                } else {
+                    LOG.debug("Operation task cancelled for transaction : {}", tb);
+                }
+            } catch (InterruptedException | ExecutionException e) {
                 LOG.warn("Transact execution exception: ", e);
             }
             LOG.trace("invoke exit command: {}, tb: {}", command, tb);
         }
     }
-
 }