2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.opendaylight.openflowplugin.impl.services.singlelayer;
11 import com.google.common.util.concurrent.FutureCallback;
12 import com.google.common.util.concurrent.Futures;
13 import com.google.common.util.concurrent.SettableFuture;
14 import java.math.BigInteger;
15 import java.util.List;
16 import java.util.concurrent.Future;
17 import java.util.stream.Collectors;
18 import org.opendaylight.openflowplugin.api.openflow.device.DeviceContext;
19 import org.opendaylight.openflowplugin.api.openflow.device.RequestContextStack;
20 import org.opendaylight.openflowplugin.impl.datastore.MultipartWriterProvider;
21 import org.opendaylight.openflowplugin.impl.services.AbstractTableMultipartService;
22 import org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.ConvertorExecutor;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.TransactionId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.multipart.types.rev170112.MultipartReply;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableInput;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.UpdateTableOutputBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.multipart.reply.multipart.reply.body.MultipartReplyTableFeatures;
29 import org.opendaylight.yangtools.yang.common.RpcError.ErrorType;
30 import org.opendaylight.yangtools.yang.common.RpcResult;
31 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 public class SingleLayerTableMultipartService extends AbstractTableMultipartService<MultipartReply> {
37 private static final Logger LOG = LoggerFactory.getLogger(SingleLayerTableMultipartService.class);
39 public SingleLayerTableMultipartService(RequestContextStack requestContextStack,
40 DeviceContext deviceContext,
41 ConvertorExecutor convertorExecutor,
42 MultipartWriterProvider multipartWriterProvider) {
43 super(requestContextStack, deviceContext, convertorExecutor, multipartWriterProvider);
47 public Future<RpcResult<UpdateTableOutput>> handleAndReply(UpdateTableInput input) {
48 final SettableFuture<RpcResult<UpdateTableOutput>> finalFuture = SettableFuture.create();
50 Futures.addCallback(handleServiceCall(input), new FutureCallback<RpcResult<List<MultipartReply>>>() {
52 public void onSuccess(final RpcResult<List<MultipartReply>> result) {
53 if (result.isSuccessful()) {
54 final List<MultipartReply> multipartReplies = result.getResult();
55 if (multipartReplies.isEmpty()) {
56 LOG.debug("Multipart reply to table features request shouldn't be empty list.");
57 finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed()
58 .withError(ErrorType.RPC, "Multipart reply list is empty.").build());
60 finalFuture.set(RpcResultBuilder
61 .success(new UpdateTableOutputBuilder()
62 .setTransactionId(new TransactionId(BigInteger.valueOf(multipartReplies.get(0).getXid())))
67 storeStatistics(multipartReplies
69 .map(MultipartReply::getMultipartReplyBody)
70 .filter(MultipartReplyTableFeatures.class::isInstance)
71 .flatMap(multipartReplyBody -> MultipartReplyTableFeatures.class
72 .cast(multipartReplyBody)
75 .collect(Collectors.toList()));
76 } catch (Exception e) {
77 LOG.warn("Not able to write to operational datastore: {}", e.getMessage());
81 LOG.debug("OnSuccess, rpc result unsuccessful, multipart response for rpc update-table was unsuccessful.");
82 finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed().withRpcErrors(result.getErrors())
88 public void onFailure(Throwable t) {
89 LOG.error("Failure multipart response for table features request. Exception: {}", t);
90 finalFuture.set(RpcResultBuilder.<UpdateTableOutput>failed()
91 .withError(ErrorType.RPC, "Future error", t).build());