X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=openflowplugin-impl%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fopenflowplugin%2Fimpl%2Fservices%2Fsal%2FSalBundleServiceImpl.java;h=25a88e5b0b9c357df4fe60b58e77d0aa9b0371ca;hb=73776c548ab153dee35ca4165ca0ef2413969704;hp=8eee2f0ba92893ad61ccfc4acd756a90eb2a6536;hpb=ebd41c0628b365c9f9608add8fa931d0de87252c;p=openflowplugin.git diff --git a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImpl.java b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImpl.java index 8eee2f0ba9..25a88e5b0b 100644 --- a/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImpl.java +++ b/openflowplugin-impl/src/main/java/org/opendaylight/openflowplugin/impl/services/sal/SalBundleServiceImpl.java @@ -5,57 +5,71 @@ * 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.impl.services.sal; -import com.google.common.base.Preconditions; +import static java.util.Objects.requireNonNull; + import com.google.common.util.concurrent.FutureCallback; 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.MoreExecutors; import com.google.common.util.concurrent.SettableFuture; import java.util.ArrayList; import java.util.List; -import java.util.concurrent.Future; import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SalExperimenterMessageService; import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterInputBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessagesInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.AddBundleMessagesOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleInput; +import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.ControlBundleOutput; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.SalBundleService; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.add.bundle.messages.input.messages.Message; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleAddMessageSalBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.BundleControlSalBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.bundle.add.message.sal.SalAddMessageDataBuilder; import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.extension.onf.bundle.service.rev170124.send.experimenter.input.experimenter.message.of.choice.bundle.control.sal.SalControlDataBuilder; +import org.opendaylight.yangtools.yang.common.ErrorTag; +import org.opendaylight.yangtools.yang.common.ErrorType; 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; /** * Simple bundle extension service. */ public class SalBundleServiceImpl implements SalBundleService { + private static final Logger LOG = LoggerFactory.getLogger(SalBundleServiceImpl.class); private final SalExperimenterMessageService experimenterMessageService; public SalBundleServiceImpl(final SalExperimenterMessageService experimenterMessageService) { - this.experimenterMessageService = Preconditions - .checkNotNull(experimenterMessageService, "SalExperimenterMessageService can not be null!"); + this.experimenterMessageService = requireNonNull(experimenterMessageService, + "SalExperimenterMessageService can not be null!"); } @Override - public Future> controlBundle(ControlBundleInput input) { + public ListenableFuture> controlBundle(final ControlBundleInput input) { + LOG.debug("Control message for device {} and bundle type {}", input.getNode(), input.getType()); final SendExperimenterInputBuilder experimenterInputBuilder = new SendExperimenterInputBuilder(); experimenterInputBuilder.setNode(input.getNode()); experimenterInputBuilder.setExperimenterMessageOfChoice( new BundleControlSalBuilder().setSalControlData(new SalControlDataBuilder(input).build()).build()); - return experimenterMessageService.sendExperimenter(experimenterInputBuilder.build()); + return Futures.transform(experimenterMessageService.sendExperimenter( + experimenterInputBuilder.build()), sendExperimenterOutputRpcResult -> { + if (sendExperimenterOutputRpcResult.isSuccessful()) { + return RpcResultBuilder.success().build(); + } else { + return RpcResultBuilder.failed().build(); + } + }, MoreExecutors.directExecutor()); } @Override - public Future> addBundleMessages(AddBundleMessagesInput input) { - final List>> partialResults = new ArrayList<>(); + public ListenableFuture> addBundleMessages(final AddBundleMessagesInput input) { + final List>> partialResults = new ArrayList<>(); final SendExperimenterInputBuilder experimenterInputBuilder = new SendExperimenterInputBuilder(); final BundleAddMessageSalBuilder bundleAddMessageBuilder = new BundleAddMessageSalBuilder(); final SalAddMessageDataBuilder dataBuilder = new SalAddMessageDataBuilder(); @@ -68,25 +82,25 @@ public class SalBundleServiceImpl implements SalBundleService { dataBuilder.setBundleInnerMessage(message.getBundleInnerMessage()); experimenterInputBuilder.setExperimenterMessageOfChoice( bundleAddMessageBuilder.setSalAddMessageData(dataBuilder.build()).build()); - ListenableFuture> res = JdkFutureAdapters - .listenInPoolThread(experimenterMessageService.sendExperimenter(experimenterInputBuilder.build())); - partialResults.add(res); + partialResults.add(experimenterMessageService.sendExperimenter(experimenterInputBuilder.build())); } return processResults(partialResults); } - private static Future> processResults( - final List>> partialResults) { - final SettableFuture> result = SettableFuture.create(); - Futures.addCallback(Futures.successfulAsList(partialResults), new FutureCallback>>() { + private static ListenableFuture> processResults( + final List>> partialResults) { + final SettableFuture> result = SettableFuture.create(); + Futures.addCallback(Futures.successfulAsList(partialResults),new FutureCallback< + List>>() { @Override - public void onSuccess(List> results) { + public void onSuccess(final List> results) { final ArrayList errors = new ArrayList<>(); - final RpcResultBuilder rpcResultBuilder; - for (RpcResult res : results) { + final RpcResultBuilder rpcResultBuilder; + for (RpcResult res : results) { if (res == null) { - errors.add(RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "BundleExtensionService", - "RpcResult is null.")); + // FIXME: this should never happen + errors.add(RpcResultBuilder.newError(ErrorType.APPLICATION, + new ErrorTag("BundleExtensionService"), "RpcResult is null.")); } else if (!res.isSuccessful()) { errors.addAll(res.getErrors()); } @@ -94,17 +108,17 @@ public class SalBundleServiceImpl implements SalBundleService { if (errors.isEmpty()) { rpcResultBuilder = RpcResultBuilder.success(); } else { - rpcResultBuilder = RpcResultBuilder.failed().withRpcErrors(errors); + rpcResultBuilder = RpcResultBuilder.failed().withRpcErrors(errors); } result.set(rpcResultBuilder.build()); } @Override - public void onFailure(Throwable throwable) { - RpcResultBuilder rpcResultBuilder = RpcResultBuilder.failed(); + public void onFailure(final Throwable throwable) { + RpcResultBuilder rpcResultBuilder = RpcResultBuilder.failed(); result.set(rpcResultBuilder.build()); } }, MoreExecutors.directExecutor()); return result; } -} \ No newline at end of file +}