Bump MRI upstreams
[openflowplugin.git] / openflowplugin-impl / src / main / java / org / opendaylight / openflowplugin / impl / services / multilayer / MultiLayerAggregateFlowMultipartService.java
index 15b1bc14df7edc2dcc2582e32a12133a4cded528..0f696787f7b0ce8f077a3a54a1ff2891975a8783 100644 (file)
@@ -8,12 +8,13 @@
 
 package org.opendaylight.openflowplugin.impl.services.multilayer;
 
-import com.google.common.base.Function;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.base.MoreObjects;
-import com.google.common.base.Preconditions;
 import com.google.common.util.concurrent.Futures;
-import java.util.List;
-import java.util.concurrent.Future;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
+import java.util.Optional;
 import java.util.stream.Collectors;
 import org.opendaylight.openflowplugin.api.OFConstants;
 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
@@ -24,10 +25,10 @@ import org.opendaylight.openflowplugin.api.openflow.device.Xid;
 import org.opendaylight.openflowplugin.api.openflow.md.core.TranslatorKey;
 import org.opendaylight.openflowplugin.impl.services.AbstractAggregateFlowMultipartService;
 import org.opendaylight.openflowplugin.impl.services.util.RequestInputUtils;
-import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
+import org.opendaylight.openflowplugin.impl.util.FlowCreatorUtil;
 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
-import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchReactor;
-import org.opendaylight.openflowplugin.openflow.md.util.FlowCreatorUtil;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.data.VersionConvertorData;
+import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.match.MatchInjector;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder;
@@ -41,11 +42,14 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731
 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.aggregate._case.MultipartRequestAggregateBuilder;
 import org.opendaylight.yangtools.yang.common.RpcResult;
 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint32;
+import org.opendaylight.yangtools.yang.common.Uint8;
 
 public class MultiLayerAggregateFlowMultipartService extends AbstractAggregateFlowMultipartService<MultipartReply> {
 
     private final TranslatorLibrary translatorLibrary;
     private final ConvertorExecutor convertorExecutor;
+    private final VersionConvertorData data;
 
     public MultiLayerAggregateFlowMultipartService(final RequestContextStack requestContextStack,
                                                    final DeviceContext deviceContext,
@@ -54,33 +58,38 @@ public class MultiLayerAggregateFlowMultipartService extends AbstractAggregateFl
         super(requestContextStack, deviceContext);
         this.convertorExecutor = convertorExecutor;
         this.translatorLibrary = translatorLibrary;
+        data = new VersionConvertorData(getVersion());
     }
 
 
     @Override
-    protected OfHeader buildRequest(final Xid xid, final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) throws ServiceException {
-        final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder = new MultipartRequestAggregateCaseBuilder();
+    protected OfHeader buildRequest(final Xid xid,
+                                    final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
+        final MultipartRequestAggregateCaseBuilder multipartRequestAggregateCaseBuilder
+                = new MultipartRequestAggregateCaseBuilder();
         final MultipartRequestAggregateBuilder mprAggregateRequestBuilder = new MultipartRequestAggregateBuilder();
-        final short tableId = MoreObjects.firstNonNull(input.getTableId(), OFConstants.OFPTT_ALL);
+        final Uint8 tableId = MoreObjects.firstNonNull(input.getTableId(), OFConstants.OFPTT_ALL);
         mprAggregateRequestBuilder.setTableId(tableId);
         long outputPortValue = MoreObjects.firstNonNull(input.getOutPort(), OFConstants.OFPP_ANY).longValue();
-        mprAggregateRequestBuilder.setOutPort(outputPortValue);
+        mprAggregateRequestBuilder.setOutPort(Uint32.valueOf(outputPortValue));
 
-        final short version = getVersion();
-        if (version == OFConstants.OFP_VERSION_1_3) {
+        final Uint8 version = getVersion();
+        if (OFConstants.OFP_VERSION_1_3.equals(version)) {
 
             if (input.getCookie() == null) {
                 mprAggregateRequestBuilder.setCookie(OFConstants.DEFAULT_COOKIE);
             } else {
-                mprAggregateRequestBuilder.setCookie(MoreObjects.firstNonNull(input.getCookie().getValue(), OFConstants.DEFAULT_COOKIE));
+                mprAggregateRequestBuilder
+                        .setCookie(MoreObjects.firstNonNull(input.getCookie().getValue(), OFConstants.DEFAULT_COOKIE));
             }
 
             if (input.getCookieMask() == null) {
                 mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
             } else {
-                mprAggregateRequestBuilder.setCookieMask(MoreObjects.firstNonNull(input.getCookieMask().getValue(), OFConstants.DEFAULT_COOKIE_MASK));
+                mprAggregateRequestBuilder.setCookieMask(
+                        MoreObjects.firstNonNull(input.getCookieMask().getValue(), OFConstants.DEFAULT_COOKIE_MASK));
             }
-            long outGroup = MoreObjects.firstNonNull(input.getOutGroup(), OFConstants.OFPG_ANY);
+            Uint32 outGroup = MoreObjects.firstNonNull(input.getOutGroup(), OFConstants.OFPG_ANY);
             mprAggregateRequestBuilder.setOutGroup(outGroup);
         } else {
             mprAggregateRequestBuilder.setOutGroup(OFConstants.OFPG_ANY);
@@ -88,16 +97,17 @@ public class MultiLayerAggregateFlowMultipartService extends AbstractAggregateFl
             mprAggregateRequestBuilder.setCookieMask(OFConstants.DEFAULT_COOKIE_MASK);
         }
 
-        MatchReactor.getInstance().convert(input.getMatch(), version, mprAggregateRequestBuilder, convertorExecutor);
+        // convert and inject match
+        final Optional<Object> conversionMatch = convertorExecutor.convert(input.getMatch(), data);
+        MatchInjector.inject(conversionMatch, mprAggregateRequestBuilder, data.getVersion());
 
         FlowCreatorUtil.setWildcardedFlowMatch(version, mprAggregateRequestBuilder);
 
         // Set request body to main multipart request
-        multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder
-            .build());
+        multipartRequestAggregateCaseBuilder.setMultipartRequestAggregate(mprAggregateRequestBuilder.build());
 
-        final MultipartRequestInputBuilder mprInput = RequestInputUtils.createMultipartHeader(
-            MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
+        final MultipartRequestInputBuilder mprInput = RequestInputUtils
+                .createMultipartHeader(MultipartType.OFPMPAGGREGATE, xid.getValue(), version);
 
         mprInput.setMultipartRequestBody(multipartRequestAggregateCaseBuilder.build());
 
@@ -105,29 +115,33 @@ public class MultiLayerAggregateFlowMultipartService extends AbstractAggregateFl
     }
 
     @Override
-    public Future<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> handleAndReply(final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
+    public ListenableFuture<RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>> handleAndReply(
+            final GetAggregateFlowStatisticsFromFlowTableForGivenMatchInput input) {
         return Futures.transform(handleServiceCall(input),
-            (Function<RpcResult<List<MultipartReply>>, RpcResult<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>>) result -> {
-                if (Preconditions.checkNotNull(result).isSuccessful()) {
-                    final MessageTranslator<MultipartReply, AggregatedFlowStatistics> messageTranslator = translatorLibrary
-                        .lookupTranslator(new TranslatorKey(getVersion(), MultipartReplyAggregateCase.class.getName()));
-
-                    return RpcResultBuilder
-                        .success(new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
-                            .setAggregatedFlowStatistics(result
-                                .getResult()
-                                .stream()
-                                .map(multipartReply -> messageTranslator
-                                    .translate(multipartReply, getDeviceInfo(), null))
-                                .collect(Collectors.toList())))
-                        .build();
+            result -> {
+                if (requireNonNull(result).isSuccessful()) {
+                    final MessageTranslator<MultipartReply, AggregatedFlowStatistics>
+                             messageTranslator = translatorLibrary.lookupTranslator(
+                                 new TranslatorKey(getVersion(),
+                                               MultipartReplyAggregateCase.class.getName()));
+
+                    return RpcResultBuilder.success(
+                             new GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutputBuilder()
+                                     .setAggregatedFlowStatistics(result.getResult().stream()
+                                                                          .map(multipartReply ->
+                                                                                       messageTranslator
+                                                                                  .translate(
+                                                                                          multipartReply,
+                                                                                          getDeviceInfo(),
+                                                                                          null))
+                                                                          .collect(Collectors.toList()))
+                                     .build())
+                             .build();
                 }
 
                 return RpcResultBuilder
-                    .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
-                    .withRpcErrors(result.getErrors())
-                    .build();
-            });
+                             .<GetAggregateFlowStatisticsFromFlowTableForGivenMatchOutput>failed()
+                             .withRpcErrors(result.getErrors()).build();
+            }, MoreExecutors.directExecutor());
     }
-
 }