X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fopenflow%2Fmd%2Fcore%2Fsession%2FMessageDispatchServiceImpl.java;h=f3c122b723e16da42da360d701c3278c4b894376;hb=611180ac770b6038b526c54994701db16d1a8567;hp=b4516508964e12ef314028e2799914bf5198445b;hpb=b7fc0b9c1b66a1976db3b5f748c7d378d7c7c2d8;p=openflowplugin.git diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImpl.java index b451650896..f3c122b723 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/session/MessageDispatchServiceImpl.java @@ -11,17 +11,17 @@ import com.google.common.base.Function; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.JdkFutureAdapters; import com.google.common.util.concurrent.ListenableFuture; -import com.google.common.util.concurrent.SettableFuture; -import org.opendaylight.controller.sal.common.util.RpcErrors; -import org.opendaylight.controller.sal.common.util.Rpcs; + import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter; import org.opendaylight.openflowplugin.ConnectionException; -import org.opendaylight.openflowplugin.openflow.md.OFConstants; -import org.opendaylight.openflowplugin.openflow.md.core.ConnectionConductor; -import org.opendaylight.openflowplugin.openflow.md.core.SwitchConnectionDistinguisher; +import org.opendaylight.openflowplugin.api.openflow.md.core.ConnectionConductor; +import org.opendaylight.openflowplugin.api.openflow.md.core.SwitchConnectionDistinguisher; +import org.opendaylight.openflowplugin.api.openflow.md.core.session.IMessageDispatchService; +import org.opendaylight.openflowplugin.api.openflow.md.core.session.SessionContext; +import org.opendaylight.openflowplugin.openflow.md.util.RpcResultUtil; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowOutputBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev131103.TransactionId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupOutputBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterOutput; @@ -29,14 +29,12 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.Upd import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.*; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.port.service.rev131107.UpdatePortOutputBuilder; -import org.opendaylight.yangtools.yang.common.RpcError; import org.opendaylight.yangtools.yang.common.RpcResult; +import org.opendaylight.yangtools.yang.common.RpcResultBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.math.BigInteger; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.Future; /** @@ -47,9 +45,6 @@ import java.util.concurrent.Future; public class MessageDispatchServiceImpl implements IMessageDispatchService { private static final Logger LOG = LoggerFactory.getLogger(MessageDispatchServiceImpl.class); - private static final String CONNECTION_ERROR_MESSAGE = "Session for the cookie is invalid. Reason: " - + "the switch has been recently disconnected OR inventory provides outdated information."; - private SessionContext session; /** @@ -72,7 +67,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { private ConnectionAdapter getConnectionAdapter(SwitchConnectionDistinguisher cookie) throws ConnectionException { if (!session.isValid()) { - LOG.warn("Session for the cookie {} is invalid.", cookie); + LOG.warn("No valid connection found for the node [datapath-id : {}]", session.getSessionKey().getId()); throw new ConnectionException(CONNECTION_ERROR_MESSAGE); } LOG.debug("finding connecton for cookie value {}. ", cookie); @@ -96,35 +91,16 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).barrier(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } - private SettableFuture> getRpcErrorFuture(ConnectionException e) { - List rpcErrorList = getConnectionErrorAsRpcErrors(e); - SettableFuture> futureWithError = SettableFuture.create(); - futureWithError.set(Rpcs.getRpcResult(false, rpcErrorList)); - return futureWithError; - } - - private List getConnectionErrorAsRpcErrors(ConnectionException e) { - List rpcErrorList = new ArrayList<>(); - rpcErrorList.add(RpcErrors.getRpcError(OFConstants.APPLICATION_TAG, - OFConstants.ERROR_TAG_TIMEOUT, - CONNECTION_ERROR_MESSAGE, - RpcError.ErrorSeverity.WARNING, - e.getMessage(), - RpcError.ErrorType.TRANSPORT, - e.getCause())); - return rpcErrorList; - } - @Override public Future> experimenter(ExperimenterInput input, SwitchConnectionDistinguisher cookie) { try { return getConnectionAdapter(cookie).experimenter(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -135,7 +111,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { response = getConnectionAdapter(cookie).flowMod(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } // appending xid @@ -150,8 +126,10 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { flowModOutput.setTransactionId(new TransactionId(bigIntXid)); UpdateFlowOutput result = flowModOutput.build(); - RpcResult rpcResult = Rpcs.getRpcResult( - inputArg.isSuccessful(), result, inputArg.getErrors()); + RpcResult rpcResult = RpcResultBuilder + .status(inputArg.isSuccessful()) + .withResult(result).withRpcErrors(inputArg.getErrors()) + .build(); return rpcResult; } }); @@ -164,7 +142,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).getAsync(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -173,7 +151,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).getConfig(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -182,7 +160,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).getFeatures(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -192,7 +170,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).getQueueConfig(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -203,7 +181,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { response = getConnectionAdapter(cookie).groupMod(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } // appending xid @@ -218,8 +196,9 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { groupModOutput.setTransactionId(new TransactionId(bigIntXid)); UpdateGroupOutput result = groupModOutput.build(); - RpcResult rpcResult = Rpcs.getRpcResult( - inputArg.isSuccessful(), result, inputArg.getErrors()); + RpcResult rpcResult = RpcResultBuilder + .status(inputArg.isSuccessful()).withResult(result) + .withRpcErrors(inputArg.getErrors()).build(); return rpcResult; } }); @@ -234,7 +213,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { response = getConnectionAdapter(cookie).meterMod(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } // appending xid @@ -249,8 +228,9 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { meterModOutput.setTransactionId(new TransactionId(bigIntXid)); UpdateMeterOutput result = meterModOutput.build(); - RpcResult rpcResult = Rpcs.getRpcResult( - inputArg.isSuccessful(), result, inputArg.getErrors()); + RpcResult rpcResult = RpcResultBuilder + .status(inputArg.isSuccessful()).withResult(result) + .withRpcErrors(inputArg.getErrors()).build(); return rpcResult; } }); @@ -263,7 +243,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).multipartRequest(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -272,7 +252,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).packetOut(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -283,7 +263,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { response = getConnectionAdapter(cookie).portMod(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } // appending xid @@ -298,8 +278,9 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { portModOutput.setTransactionId(new TransactionId(bigIntXid)); UpdatePortOutput result = portModOutput.build(); - RpcResult rpcResult = Rpcs.getRpcResult( - inputArg.isSuccessful(), result, inputArg.getErrors()); + RpcResult rpcResult = RpcResultBuilder + .status(inputArg.isSuccessful()).withResult(result) + .withRpcErrors(inputArg.getErrors()).build(); return rpcResult; } }); @@ -312,7 +293,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).roleRequest(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -321,7 +302,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).setAsync(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -330,7 +311,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).setConfig(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } @@ -339,7 +320,7 @@ public class MessageDispatchServiceImpl implements IMessageDispatchService { try { return getConnectionAdapter(cookie).tableMod(input); } catch (ConnectionException e) { - return getRpcErrorFuture(e); + return RpcResultUtil.getRpcErrorFuture(e); } } }