Search in sources :

Example 1 with ExperimenterCoreMessageItemBuilder

use of org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.send.experimenter.mp.request.output.ExperimenterCoreMessageItemBuilder in project openflowplugin by opendaylight.

the class MultiLayerExperimenterMultipartService method handleAndReply.

@Override
@SuppressWarnings("unchecked")
public Future<RpcResult<SendExperimenterMpRequestOutput>> handleAndReply(SendExperimenterMpRequestInput input) {
    final ListenableFuture<RpcResult<List<MultipartReply>>> multipartFuture = handleServiceCall(input);
    final SettableFuture<RpcResult<SendExperimenterMpRequestOutput>> finalFuture = SettableFuture.create();
    class CallBackImpl implements FutureCallback<RpcResult<List<MultipartReply>>> {

        @Override
        public void onSuccess(@Nonnull final RpcResult<List<MultipartReply>> result) {
            if (result.isSuccessful()) {
                final List<MultipartReply> multipartReplies = result.getResult();
                if (multipartReplies.isEmpty()) {
                    LOG.warn("Multipart reply to Experimenter-Mp request shouldn't be empty list.");
                    finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withError(ErrorType.RPC, "Multipart reply list is empty.").build());
                } else {
                    LOG.debug("OnSuccess, rpc result successful," + " multipart response for rpc sendExperimenterMpRequest with xid {} obtained.", multipartReplies.get(0).getXid());
                    final SendExperimenterMpRequestOutputBuilder sendExpMpReqOutputBuilder = new SendExperimenterMpRequestOutputBuilder();
                    final List<ExperimenterCoreMessageItem> expCoreMessageItem = new ArrayList<>();
                    for (MultipartReply multipartReply : multipartReplies) {
                        final MultipartReplyExperimenterCase caseBody = (MultipartReplyExperimenterCase) multipartReply.getMultipartReplyBody();
                        final MultipartReplyExperimenter replyBody = caseBody.getMultipartReplyExperimenter();
                        final ExperimenterDataOfChoice vendorData = replyBody.getExperimenterDataOfChoice();
                        final MessageTypeKey<? extends ExperimenterDataOfChoice> key = new MessageTypeKey<>(getVersion(), (Class<? extends ExperimenterDataOfChoice>) vendorData.getImplementedInterface());
                        final ConvertorMessageFromOFJava<ExperimenterDataOfChoice, MessagePath> messageConverter = getExtensionConverterProvider().getMessageConverter(key);
                        if (messageConverter == null) {
                            LOG.warn("Custom converter for {}[OF:{}] not found", vendorData.getImplementedInterface(), getVersion());
                            finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withError(ErrorType.RPC, "Custom converter not found.").build());
                            return;
                        }
                        try {
                            final ExperimenterMessageOfChoice messageOfChoice = messageConverter.convert(vendorData, MessagePath.MPMESSAGE_RPC_OUTPUT);
                            final ExperimenterCoreMessageItemBuilder expCoreMessageItemBuilder = new ExperimenterCoreMessageItemBuilder();
                            expCoreMessageItemBuilder.setExperimenterMessageOfChoice(messageOfChoice);
                            expCoreMessageItem.add(expCoreMessageItemBuilder.build());
                        } catch (final ConversionException e) {
                            LOG.error("Conversion of experimenter message reply failed. Exception: {}", e);
                            finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withError(ErrorType.RPC, "Conversion of experimenter rpc output failed.").build());
                            return;
                        }
                    }
                    sendExpMpReqOutputBuilder.setExperimenterCoreMessageItem(expCoreMessageItem);
                    finalFuture.set(RpcResultBuilder.success(sendExpMpReqOutputBuilder.build()).build());
                }
            } else {
                LOG.warn("OnSuccess, rpc result unsuccessful," + " multipart response for rpc sendExperimenterMpRequest was unsuccessful.");
                finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withRpcErrors(result.getErrors()).build());
            }
        }

        @Override
        public void onFailure(final Throwable throwable) {
            LOG.warn("Failure multipart response for Experimenter-Mp request. Exception: {}", throwable);
            finalFuture.set(RpcResultBuilder.<SendExperimenterMpRequestOutput>failed().withError(ErrorType.RPC, "Future error", throwable).build());
        }
    }
    Futures.addCallback(multipartFuture, new CallBackImpl(), MoreExecutors.directExecutor());
    return finalFuture;
}
Also used : MultipartReply(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply) ArrayList(java.util.ArrayList) MultipartReplyExperimenter(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenter) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice) ArrayList(java.util.ArrayList) List(java.util.List) MessageTypeKey(org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey) FutureCallback(com.google.common.util.concurrent.FutureCallback) MultipartReplyExperimenterCase(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) ExperimenterCoreMessageItemBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.send.experimenter.mp.request.output.ExperimenterCoreMessageItemBuilder) Nonnull(javax.annotation.Nonnull) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) MessagePath(org.opendaylight.openflowplugin.extension.api.path.MessagePath) SendExperimenterMpRequestOutputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutputBuilder) ExperimenterCoreMessageItem(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.send.experimenter.mp.request.output.ExperimenterCoreMessageItem) SendExperimenterMpRequestOutput(org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutput)

Aggregations

FutureCallback (com.google.common.util.concurrent.FutureCallback)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 MessageTypeKey (org.opendaylight.openflowjava.protocol.api.keys.MessageTypeKey)1 ConversionException (org.opendaylight.openflowplugin.extension.api.exception.ConversionException)1 MessagePath (org.opendaylight.openflowplugin.extension.api.path.MessagePath)1 SendExperimenterMpRequestOutput (org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutput)1 SendExperimenterMpRequestOutputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.SendExperimenterMpRequestOutputBuilder)1 ExperimenterCoreMessageItem (org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.send.experimenter.mp.request.output.ExperimenterCoreMessageItem)1 ExperimenterCoreMessageItemBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.experimenter.mp.message.service.rev151020.send.experimenter.mp.request.output.ExperimenterCoreMessageItemBuilder)1 MultipartReply (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.MultipartReply)1 ExperimenterDataOfChoice (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice)1 MultipartReplyExperimenterCase (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.MultipartReplyExperimenterCase)1 MultipartReplyExperimenter (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.reply.multipart.reply.body.multipart.reply.experimenter._case.MultipartReplyExperimenter)1 ExperimenterMessageOfChoice (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1