* terms of the Eclipse Public License v1.0 which accompanies this distribution,
* and is available at http://www.eclipse.org/legal/epl-v10.html
*/
* 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 com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
package org.opendaylight.openflowplugin.impl.services.sal;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
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.SalExperimenterMessageService;
import org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.message.service.rev151020.SendExperimenterInputBuilder;
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.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.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
import org.opendaylight.yangtools.yang.common.RpcError;
import org.opendaylight.yangtools.yang.common.RpcResult;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
private final SalExperimenterMessageService experimenterMessageService;
public SalBundleServiceImpl(final SalExperimenterMessageService experimenterMessageService) {
private final SalExperimenterMessageService experimenterMessageService;
public SalBundleServiceImpl(final SalExperimenterMessageService experimenterMessageService) {
- public Future<RpcResult<Void>> controlBundle(ControlBundleInput input) {
+ public ListenableFuture<RpcResult<ControlBundleOutput>> 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());
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.<ControlBundleOutput>success().build();
+ } else {
+ return RpcResultBuilder.<ControlBundleOutput>failed().build();
+ }
+ }, MoreExecutors.directExecutor());
- public Future<RpcResult<Void>> addBundleMessages(AddBundleMessagesInput input) {
- final List<ListenableFuture<RpcResult<Void>>> partialResults = new ArrayList<>();
+ public ListenableFuture<RpcResult<AddBundleMessagesOutput>> addBundleMessages(final AddBundleMessagesInput input) {
+ final List<ListenableFuture<RpcResult<SendExperimenterOutput>>> partialResults = new ArrayList<>();
final SendExperimenterInputBuilder experimenterInputBuilder = new SendExperimenterInputBuilder();
final BundleAddMessageSalBuilder bundleAddMessageBuilder = new BundleAddMessageSalBuilder();
final SalAddMessageDataBuilder dataBuilder = new SalAddMessageDataBuilder();
final SendExperimenterInputBuilder experimenterInputBuilder = new SendExperimenterInputBuilder();
final BundleAddMessageSalBuilder bundleAddMessageBuilder = new BundleAddMessageSalBuilder();
final SalAddMessageDataBuilder dataBuilder = new SalAddMessageDataBuilder();
dataBuilder.setBundleInnerMessage(message.getBundleInnerMessage());
experimenterInputBuilder.setExperimenterMessageOfChoice(
bundleAddMessageBuilder.setSalAddMessageData(dataBuilder.build()).build());
dataBuilder.setBundleInnerMessage(message.getBundleInnerMessage());
experimenterInputBuilder.setExperimenterMessageOfChoice(
bundleAddMessageBuilder.setSalAddMessageData(dataBuilder.build()).build());
- ListenableFuture<RpcResult<Void>> res = JdkFutureAdapters
- .listenInPoolThread(experimenterMessageService.sendExperimenter(experimenterInputBuilder.build()));
- partialResults.add(res);
+ partialResults.add(experimenterMessageService.sendExperimenter(experimenterInputBuilder.build()));
- private static Future<RpcResult<Void>> processResults(
- final List<ListenableFuture<RpcResult<Void>>> partialResults) {
- final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
- Futures.addCallback(Futures.successfulAsList(partialResults), new FutureCallback<List<RpcResult<Void>>>() {
+ private static ListenableFuture<RpcResult<AddBundleMessagesOutput>> processResults(
+ final List<ListenableFuture<RpcResult<SendExperimenterOutput>>> partialResults) {
+ final SettableFuture<RpcResult<AddBundleMessagesOutput>> result = SettableFuture.create();
+ Futures.addCallback(Futures.successfulAsList(partialResults),new FutureCallback<
+ List<RpcResult<SendExperimenterOutput>>>() {
- final RpcResultBuilder<Void> rpcResultBuilder;
- for (RpcResult<Void> res : results) {
+ final RpcResultBuilder<AddBundleMessagesOutput> rpcResultBuilder;
+ for (RpcResult<SendExperimenterOutput> res : results) {
- 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."));
- public void onFailure(Throwable throwable) {
- RpcResultBuilder<Void> rpcResultBuilder = RpcResultBuilder.failed();
+ public void onFailure(final Throwable throwable) {
+ RpcResultBuilder<AddBundleMessagesOutput> rpcResultBuilder = RpcResultBuilder.failed();