DeviceDataException erradicated 48/20948/2
authorMartin Bobak <mbobak@cisco.com>
Fri, 22 May 2015 10:06:02 +0000 (12:06 +0200)
committerMartin Bobak <mbobak@cisco.com>
Fri, 22 May 2015 12:33:17 +0000 (14:33 +0200)
OFJ's DeviceRequestFailedException is used instead of ofp own exception
that just wrapped exception from OFJ.

Change-Id: I53f118782ed677a82958a6ad42dedf37b6aee109
Signed-off-by: Martin Bobak <mbobak@cisco.com>
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/exception/DeviceDataException.java [deleted file]
openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/handlers/DeviceReplyProcessor.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/DeviceContextImpl.java
openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImpl.java
openflowplugin-impl/src/test/java/org/opendaylight/openflowplugin/impl/device/listener/MultiMsgCollectorImplTest.java

diff --git a/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/exception/DeviceDataException.java b/openflowplugin-api/src/main/java/org/opendaylight/openflowplugin/api/openflow/device/exception/DeviceDataException.java
deleted file mode 100644 (file)
index 48f99d2..0000000
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-
-package org.opendaylight.openflowplugin.api.openflow.device.exception;
-
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.Error;
-
-/**
- * @deprecated FIXME: TO BE REMOVED: migrate to org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException.
- */
-@Deprecated
-public class DeviceDataException extends Exception {
-
-    /**
-     *
-     */
-    private static final long serialVersionUID = 1L;
-    private Error error;
-
-    public DeviceDataException(final String message) {
-        super(message);
-    }
-
-    public DeviceDataException(final String message, final Throwable cause) {
-        super(message, cause);
-    }
-
-    public DeviceDataException(final String message, final Error error) {
-        super(message);
-        this.error= error;
-    }
-
-    public Error getError() {
-        return error;
-    }
-}
index 29206bb46a93bf5abf36c3668a02c3296b054ed5..e4304e47f70cb252ee0e7279930b0d88e2fec8ce 100644 (file)
@@ -9,26 +9,29 @@
 package org.opendaylight.openflowplugin.api.openflow.device.handlers;
 
 import java.util.List;
-
+import org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.device.exception.DeviceDataException;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.*;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.FlowRemoved;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PacketInMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.PortStatusMessage;
 
 /**
- *
  * @author tkubas
- *
  */
 public interface DeviceReplyProcessor {
 
     /**
      * Method that set future to context in Map
+     *
      * @param ofHeader
      */
     public void processReply(OfHeader ofHeader);
 
     /**
      * Method that set future to context in Map
+     *
      * @param xid,
      * @param ofHeaderList
      */
@@ -36,25 +39,29 @@ public interface DeviceReplyProcessor {
 
     /**
      * Method that set exception to the future
+     *
      * @param xid,
-     * @param deviceDataException
+     * @param deviceRequestFailedException
      */
-    public void processException(Xid xid, DeviceDataException deviceDataException);
+    public void processException(Xid xid, DeviceRequestFailedException deviceRequestFailedException);
 
     /**
      * Method process async flow removed from device
+     *
      * @param flowRemoved
      */
     public void processFlowRemovedMessage(FlowRemoved flowRemoved);
 
     /**
      * Method process async port status from device
+     *
      * @param portStatus
      */
     public void processPortStatusMessage(PortStatusMessage portStatus);
 
     /**
      * Method process async packet in from device
+     *
      * @param packetInMessage
      */
     public void processPacketInMessage(PacketInMessage packetInMessage);
index 099fbc50d5f03f92d7815474541903985977e296..bc68428c28461bb407fc2b7aac6daf7ccd4c5efb 100644 (file)
@@ -27,6 +27,7 @@ import org.opendaylight.controller.md.sal.binding.api.NotificationService;
 import org.opendaylight.controller.md.sal.binding.api.ReadTransaction;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
+import org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue;
 import org.opendaylight.openflowjava.protocol.api.connection.OutboundQueueHandlerRegistration;
 import org.opendaylight.openflowplugin.api.openflow.connection.ConnectionContext;
@@ -37,7 +38,6 @@ import org.opendaylight.openflowplugin.api.openflow.device.MessageTranslator;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.TranslatorLibrary;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.device.exception.DeviceDataException;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceContextClosedHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceDisconnectedHandler;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
@@ -117,7 +117,7 @@ public class DeviceContextImpl implements DeviceContext {
     }
 
     @Override
-        public Long getReservedXid() {
+    public Long getReservedXid() {
         return outboundQueueProvider.reserveEntry();
     }
 
@@ -232,8 +232,8 @@ public class DeviceContextImpl implements DeviceContext {
     }
 
     @Override
-    public void processException(final Xid xid, final DeviceDataException deviceDataException) {
-        messageSpy.spyMessage(deviceDataException.getClass(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE);
+    public void processException(final Xid xid, final DeviceRequestFailedException deviceRequestFailedException) {
+        messageSpy.spyMessage(deviceRequestFailedException.getClass(), MessageSpy.STATISTIC_GROUP.FROM_SWITCH_PUBLISHED_FAILURE);
     }
 
     @Override
index 1acca2d0506ded99412fef1ff5ee54b8cdac9b9e..33c71c292513c706794e47edb32182842f0b6c95 100644 (file)
@@ -17,12 +17,14 @@ import com.google.common.cache.RemovalNotification;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeUnit;
+import org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.device.exception.DeviceDataException;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.common.types.rev130731.MultipartType;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessage;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ErrorMessageBuilder;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply;
 import org.opendaylight.yangtools.yang.common.RpcError;
 import org.opendaylight.yangtools.yang.common.RpcResult;
@@ -33,9 +35,7 @@ import org.slf4j.LoggerFactory;
 
 /**
  * <p>
- * openflowplugin-api
- * org.opendaylight.openflowplugin.impl.openflow.device
- *
  * Implementation for {@link MultiMsgCollector} interface
  *
  * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
@@ -95,8 +95,9 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector {
         if (cachedRef == null) {
             MultipartType multipartType = reply.getType();
             LOG.trace("Orphaned multipart msg with XID : {} of type {}", xid, multipartType);
+
             deviceReplyProcessor.processException(new Xid(xid),
-                    new DeviceDataException("unknown xid received for multipart of type " + multipartType));
+                    new DeviceRequestFailedException("unknown xid received for multipart of type " + multipartType, getErrorMessageWithXid(xid)));
             return;
         }
 
@@ -108,11 +109,17 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector {
                 cachedRef.publishCollection(xid); // settable future has now whole collection
                 cache.invalidate(xid);              // we don't need a reference anymore - remove explicitly
             }
-        } catch (DeviceDataException e) {
+        } catch (DeviceRequestFailedException e) {
             deviceReplyProcessor.processException(new Xid(xid), e);
         }
     }
 
+    private ErrorMessage getErrorMessageWithXid(final long xid) {
+        final ErrorMessageBuilder errorMessageBuilder = new ErrorMessageBuilder();
+        errorMessageBuilder.setXid(xid);
+        return errorMessageBuilder.build();
+    }
+
     @Override
     public void setDeviceReplyProcessor(final DeviceReplyProcessor deviceReplyProcessor) {
         this.deviceReplyProcessor = deviceReplyProcessor;
@@ -120,8 +127,8 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector {
 
     @Override
     public void invalidateRequestContext(final RequestContext<List<MultipartReply>> requestContext) {
-        MultiCollectorObject  multiCollectorObject = cache.getIfPresent(requestContext);
-        if (null != multiCollectorObject){
+        MultiCollectorObject multiCollectorObject = cache.getIfPresent(requestContext);
+        if (null != multiCollectorObject) {
             multiCollectorObject.invalidateFutureByTimeout(requestContext.getXid().getValue());
         }
     }
@@ -135,7 +142,7 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector {
             this.requestContext = Preconditions.checkNotNull(requestContext);
         }
 
-        void add(final MultipartReply reply) throws DeviceDataException {
+        void add(final MultipartReply reply) throws DeviceRequestFailedException {
             /* Rise possible exception if it possible */
             msgTypeValidation(reply.getType(), reply.getXid());
             replyCollection.add(reply);
@@ -158,7 +165,8 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector {
 
         void invalidateFutureByTimeout(final long key) {
             final String msg = "MultiMsgCollector can not wait for last multipart any more";
-            DeviceDataException deviceDataException = new DeviceDataException(msg);
+
+            DeviceRequestFailedException deviceDataException = new DeviceRequestFailedException(msg, getErrorMessageWithXid(key));
             final RpcResult<List<MultipartReply>> rpcResult = RpcResultBuilder
                     .<List<MultipartReply>>failed()
                     .withError(RpcError.ErrorType.APPLICATION, String.format("Message processing failed : %s", deviceDataException.getError()), deviceDataException)
@@ -174,7 +182,7 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector {
         }
 
 
-        private void msgTypeValidation(final MultipartType type, final long key) throws DeviceDataException {
+        private void msgTypeValidation(final MultipartType type, final long key) throws DeviceRequestFailedException {
             if (msgType == null) {
                 msgType = type;
                 return;
@@ -183,7 +191,7 @@ public class MultiMsgCollectorImpl implements MultiMsgCollector {
                 final String msg = "MultiMsgCollector get incorrect multipart msg with type {}"
                         + " but expected type is {}";
                 LOG.trace(msg, type, msgType);
-                throw new DeviceDataException("multipart message type mismatch");
+                throw new DeviceRequestFailedException("multipart message type mismatch", getErrorMessageWithXid(key));
             }
         }
     }
index 0df10537f4b5f6b9eeab07af737d8ca7f9078b00..f0307d28d8613ff53e27b40d135d206995ae7b9b 100644 (file)
@@ -20,9 +20,9 @@ import org.mockito.Captor;
 import org.mockito.Mock;
 import org.mockito.Mockito;
 import org.mockito.runners.MockitoJUnitRunner;
+import org.opendaylight.openflowjava.protocol.api.connection.DeviceRequestFailedException;
 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
 import org.opendaylight.openflowplugin.api.openflow.device.Xid;
-import org.opendaylight.openflowplugin.api.openflow.device.exception.DeviceDataException;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.DeviceReplyProcessor;
 import org.opendaylight.openflowplugin.api.openflow.device.handlers.MultiMsgCollector;
 import org.opendaylight.openflowplugin.impl.connection.testutil.MsgGeneratorTestUtils;
@@ -49,7 +49,7 @@ public class MultiMsgCollectorImplTest {
     @Mock
     DeviceReplyProcessor deviceProcessor;
     @Captor
-    ArgumentCaptor<DeviceDataException> ddeCaptor;
+    ArgumentCaptor<DeviceRequestFailedException> ddeCaptor;
     @Captor
     ArgumentCaptor<Xid> xidCaptor;
     @Captor