Handle openflowplugin returning null 45/5345/1
authorRobert Varga <rovarga@cisco.com>
Sat, 15 Feb 2014 02:17:36 +0000 (03:17 +0100)
committerRobert Varga <rovarga@cisco.com>
Sat, 15 Feb 2014 07:19:21 +0000 (08:19 +0100)
It turns out that openflow plugin reports success with null transaction
ID if the switch does not support a feature. This is quite bad, but we
can recover rather easily. Rework the registration contract to take care
of the changes.

Change-Id: I62fe7badeb5d792c8533762f5e68b7d37811f8ed
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/AbstractStatsTracker.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/FlowCapableContext.java
opendaylight/md-sal/statistics-manager/src/main/java/org/opendaylight/controller/md/statistics/manager/NodeStatisticsHandler.java

index 7b756d8..c29b6a7 100644 (file)
@@ -25,23 +25,38 @@ import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.base.Function;
 import com.google.common.base.Preconditions;
+import com.google.common.util.concurrent.FutureCallback;
 import com.google.common.util.concurrent.Futures;
 import com.google.common.util.concurrent.JdkFutureAdapters;
 
 abstract class AbstractStatsTracker<I, K> {
     private static final Logger logger = LoggerFactory.getLogger(AbstractStatsTracker.class);
-    private static final Function<RpcResult<? extends TransactionAware>, TransactionId> FUNCTION =
-            new Function<RpcResult<? extends TransactionAware>, TransactionId>() {
+    private final FutureCallback<RpcResult<? extends TransactionAware>> callback =
+            new FutureCallback<RpcResult<? extends TransactionAware>>() {
         @Override
-        public TransactionId apply(RpcResult<? extends TransactionAware> input) {
-            if (!input.isSuccessful()) {
-                logger.debug("Statistics request failed: {}", input.getErrors());
-                throw new RPCFailedException("Failed to send statistics request", input.getErrors());
+        public void onSuccess(RpcResult<? extends TransactionAware> result) {
+            if (result.isSuccessful()) {
+                final TransactionId id = result.getResult().getTransactionId();
+                if (id == null) {
+                    final Throwable t = new UnsupportedOperationException("No protocol support");
+                    t.fillInStackTrace();
+                    onFailure(t);
+                } else {
+                    context.registerTransaction(id);
+                }
+            } else {
+                logger.debug("Statistics request failed: {}", result.getErrors());
+
+                final Throwable t = new RPCFailedException("Failed to send statistics request", result.getErrors());
+                t.fillInStackTrace();
+                onFailure(t);
             }
+        }
 
-            return input.getResult().getTransactionId();
+        @Override
+        public void onFailure(Throwable t) {
+            logger.debug("Failed to send statistics request", t);
         }
     };
 
@@ -67,7 +82,7 @@ abstract class AbstractStatsTracker<I, K> {
     }
 
     protected final <T extends TransactionAware> void requestHelper(Future<RpcResult<T>> future) {
-        context.registerTransaction(Futures.transform(JdkFutureAdapters.listenInPoolThread(future), FUNCTION));
+        Futures.addCallback(JdkFutureAdapters.listenInPoolThread(future), callback);
     }
 
     protected final DataModificationTransaction startTransaction() {
index 27aa17a..520b344 100644 (file)
@@ -13,8 +13,6 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 
-import com.google.common.util.concurrent.ListenableFuture;
-
 /**
  * Interface exposed to AbstractStatsTracker by its parent NodeStatisticsHandler.
  * While we could simply exist without this interface, its purpose is to document
@@ -24,6 +22,6 @@ interface FlowCapableContext {
     InstanceIdentifier<Node> getNodeIdentifier();
     NodeRef getNodeRef();
     DataModificationTransaction startDataModification();
-    void registerTransaction(ListenableFuture<TransactionId> future);
-    void registerTableTransaction(ListenableFuture<TransactionId> future, Short tableId);
+    void registerTransaction(TransactionId id);
+    void registerTableTransaction(TransactionId id, Short tableId);
 }
index d62b680..ecf2cf3 100644 (file)
@@ -55,9 +55,6 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
 
 /**
  * This class handles the lifecycle of per-node statistics. It receives data
@@ -298,34 +295,14 @@ public final class NodeStatisticsHandler implements AutoCloseable, FlowCapableCo
     }
 
     @Override
-    public void registerTransaction(final ListenableFuture<TransactionId> future) {
-        Futures.addCallback(future, new FutureCallback<TransactionId>() {
-            @Override
-            public void onSuccess(TransactionId result) {
-                msgManager.recordExpectedTransaction(result);
-                logger.debug("Transaction {} for node {} sent successfully", result, targetNodeKey);
-            }
-
-            @Override
-            public void onFailure(Throwable t) {
-                logger.warn("Failed to send statistics request for node {}", targetNodeKey, t);
-            }
-        });
+    public void registerTransaction(TransactionId id) {
+        msgManager.recordExpectedTransaction(id);
+        logger.debug("Transaction {} for node {} sent successfully", id, targetNodeKey);
     }
 
     @Override
-    public void registerTableTransaction(final ListenableFuture<TransactionId> future, final Short id) {
-        Futures.addCallback(future, new FutureCallback<TransactionId>() {
-            @Override
-            public void onSuccess(TransactionId result) {
-                msgManager.recordExpectedTableTransaction(result, id);
-                logger.debug("Transaction {} for node {} table {} sent successfully", result, targetNodeKey, id);
-            }
-
-            @Override
-            public void onFailure(Throwable t) {
-                logger.warn("Failed to send table statistics request for node {} table {}", targetNodeKey, id, t);
-            }
-        });
+    public void registerTableTransaction(final TransactionId id, final Short table) {
+        msgManager.recordExpectedTableTransaction(id, table);
+        logger.debug("Transaction {} for node {} table {} sent successfully", id, targetNodeKey, table);
     }
 }