import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
-import java.math.BigInteger;
import java.util.List;
-import java.util.concurrent.Future;
-import java.util.stream.Collectors;
import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
import org.opendaylight.openflowplugin.api.openflow.device.Xid;
import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
import org.opendaylight.openflowplugin.impl.services.AbstractTableMultipartService;
-import org.opendaylight.openflowplugin.impl.services.util.ServiceException;
import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply;
import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartRequestBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.reply.multipart.reply.body.MultipartReplyTableFeatures;
import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.multipart.request.multipart.request.body.MultipartRequestTableFeaturesBuilder;
-import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
+import org.opendaylight.yangtools.yang.binding.util.BindingMap;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+import org.opendaylight.yangtools.yang.common.Uint64;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static final Logger LOG = LoggerFactory.getLogger(SingleLayerTableMultipartService.class);
- public SingleLayerTableMultipartService(RequestContextStack requestContextStack,
- DeviceContext deviceContext,
- MultipartWriterProvider multipartWriterProvider) {
+ public SingleLayerTableMultipartService(final RequestContextStack requestContextStack,
+ final DeviceContext deviceContext,
+ final MultipartWriterProvider multipartWriterProvider) {
super(requestContextStack, deviceContext, multipartWriterProvider);
}
@Override
- protected OfHeader buildRequest(final Xid xid, final UpdateTableInput input) throws ServiceException {
+ protected OfHeader buildRequest(final Xid xid, final UpdateTableInput input) {
return new MultipartRequestBuilder()
.setXid(xid.getValue())
.setVersion(getVersion())
}
@Override
- public Future<RpcResult<UpdateTableOutput>> handleAndReply(UpdateTableInput input) {
+ public ListenableFuture<RpcResult<UpdateTableOutput>> handleAndReply(final UpdateTableInput input) {
final SettableFuture<RpcResult<UpdateTableOutput>> finalFuture = SettableFuture.create();
Futures.addCallback(handleServiceCall(input), new FutureCallback<RpcResult<List<MultipartReply>>>() {
finalFuture.set(RpcResultBuilder
.success(new UpdateTableOutputBuilder()
.setTransactionId(
- new TransactionId(BigInteger.valueOf(multipartReplies.get(0).getXid())))
+ new TransactionId(Uint64.valueOf(multipartReplies.get(0).getXid())))
.build())
.build());
.stream()
.map(MultipartReply::getMultipartReplyBody)
.filter(MultipartReplyTableFeatures.class::isInstance)
- .flatMap(multipartReplyBody -> MultipartReplyTableFeatures.class
- .cast(multipartReplyBody)
- .getTableFeatures()
+ .flatMap(multipartReplyBody -> ((MultipartReplyTableFeatures) multipartReplyBody)
+ .nonnullTableFeatures().values()
.stream())
- .collect(Collectors.toList()));
+ .collect(BindingMap.toOrderedMap()));
} catch (Exception e) {
LOG.warn("Not able to write to operational datastore: {}", e.getMessage());
}
}
@Override
- public void onFailure(Throwable throwable) {
- LOG.error("Failure multipart response for table features request. Exception: {}", throwable);
+ public void onFailure(final Throwable throwable) {
+ LOG.error("Failure multipart response for table features request", throwable);
finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed()
.withError(ErrorType.RPC, "Future error", throwable).build());
}
- });
+ }, MoreExecutors.directExecutor());
return finalFuture;
}
-}
\ No newline at end of file
+}