Search in sources :

Example 1 with ServiceException

use of org.opendaylight.openflowplugin.impl.services.util.ServiceException in project openflowplugin by opendaylight.

the class SalExperimenterMessageServiceImpl method buildRequest.

@Override
protected OfHeader buildRequest(Xid xid, SendExperimenterInput input) throws ServiceException {
    final TypeVersionKey key = new TypeVersionKey(input.getExperimenterMessageOfChoice().getImplementedInterface(), getVersion());
    final ConverterMessageToOFJava<ExperimenterMessageOfChoice, ExperimenterDataOfChoice> messageConverter = extensionConverterProvider.getMessageConverter(key);
    if (messageConverter == null) {
        throw new ServiceException(new ConverterNotFoundException(key.toString()));
    }
    final ExperimenterInputBuilder experimenterInputBld;
    if (messageConverter instanceof BundleMessageDataInjector) {
        ((BundleMessageDataInjector) messageConverter).setNode(input.getNode());
        ((BundleMessageDataInjector) messageConverter).setXid(xid.getValue());
    }
    try {
        experimenterInputBld = new ExperimenterInputBuilder().setExperimenter(messageConverter.getExperimenterId()).setExpType(messageConverter.getType()).setExperimenterDataOfChoice(messageConverter.convert(input.getExperimenterMessageOfChoice())).setVersion(getVersion()).setXid(xid.getValue());
    } catch (ConversionException e) {
        throw new ServiceException(e);
    }
    return experimenterInputBld.build();
}
Also used : TypeVersionKey(org.opendaylight.openflowplugin.extension.api.TypeVersionKey) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) ExperimenterInputBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ConverterNotFoundException(org.opendaylight.openflowplugin.extension.api.exception.ConverterNotFoundException) BundleMessageDataInjector(org.opendaylight.openflowplugin.extension.api.BundleMessageDataInjector) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice)

Example 2 with ServiceException

use of org.opendaylight.openflowplugin.impl.services.util.ServiceException in project openflowplugin by opendaylight.

the class MultiLayerExperimenterMultipartService method buildRequest.

@Override
@SuppressWarnings("unchecked")
protected OfHeader buildRequest(Xid xid, SendExperimenterMpRequestInput input) throws ServiceException {
    final TypeVersionKey key = new TypeVersionKey<>(input.getExperimenterMessageOfChoice().getImplementedInterface(), getVersion());
    final ConverterMessageToOFJava<ExperimenterMessageOfChoice, ExperimenterDataOfChoice> messageConverter = getExtensionConverterProvider().getMessageConverter(key);
    if (Objects.isNull(messageConverter)) {
        throw new ServiceException(new ConverterNotFoundException(key.toString()));
    }
    try {
        return RequestInputUtils.createMultipartHeader(MultipartType.OFPMPEXPERIMENTER, xid.getValue(), getVersion()).setMultipartRequestBody(new MultipartRequestExperimenterCaseBuilder().setMultipartRequestExperimenter(new MultipartRequestExperimenterBuilder().setExperimenter(messageConverter.getExperimenterId()).setExpType(messageConverter.getType()).setExperimenterDataOfChoice(messageConverter.convert(input.getExperimenterMessageOfChoice())).build()).build()).build();
    } catch (final ConversionException e) {
        throw new ServiceException(e);
    }
}
Also used : TypeVersionKey(org.opendaylight.openflowplugin.extension.api.TypeVersionKey) ConversionException(org.opendaylight.openflowplugin.extension.api.exception.ConversionException) MultipartRequestExperimenterBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) ExperimenterMessageOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice) ConverterNotFoundException(org.opendaylight.openflowplugin.extension.api.exception.ConverterNotFoundException) MultipartRequestExperimenterCaseBuilder(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCaseBuilder) ExperimenterDataOfChoice(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice)

Example 3 with ServiceException

use of org.opendaylight.openflowplugin.impl.services.util.ServiceException in project openflowplugin by opendaylight.

the class AbstractService method handleServiceCall.

public ListenableFuture<RpcResult<O>> handleServiceCall(@Nonnull final I input, @Nullable final Function<OfHeader, Boolean> isComplete) {
    Preconditions.checkNotNull(input);
    final Class<?> requestType = input instanceof DataContainer ? DataContainer.class.cast(input).getImplementedInterface() : input.getClass();
    getMessageSpy().spyMessage(requestType, MessageSpy.StatisticsGroup.TO_SWITCH_ENTERED);
    LOG.trace("Handling general service call");
    final RequestContext<O> requestContext = requestContextStack.createRequestContext();
    if (Objects.isNull(requestContext)) {
        LOG.trace("Request context refused.");
        getMessageSpy().spyMessage(AbstractService.class, MessageSpy.StatisticsGroup.TO_SWITCH_DISREGARDED);
        return Futures.immediateFuture(RpcResultBuilder.<O>failed().withError(RpcError.ErrorType.APPLICATION, "", "Request quota exceeded").build());
    }
    if (Objects.isNull(requestContext.getXid())) {
        getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.StatisticsGroup.TO_SWITCH_RESERVATION_REJECTED);
        return RequestContextUtil.closeRequestContextWithRpcError(requestContext, "Outbound queue wasn't able to reserve XID.");
    }
    getMessageSpy().spyMessage(requestContext.getClass(), MessageSpy.StatisticsGroup.TO_SWITCH_READY_FOR_SUBMIT);
    final Xid xid = requestContext.getXid();
    OfHeader request = null;
    try {
        request = buildRequest(xid, input);
        Verify.verify(xid.getValue().equals(request.getXid()), "Expected XID %s got %s", xid.getValue(), request.getXid());
    } catch (ServiceException ex) {
        LOG.error("Failed to build request for {}, forfeiting request {}", input, xid.getValue(), ex);
        RequestContextUtil.closeRequestContextWithRpcError(requestContext, "failed to build request input: " + ex.getMessage());
    } finally {
        final OutboundQueue outboundQueue = getDeviceContext().getPrimaryConnectionContext().getOutboundQueueProvider();
        if (Objects.nonNull(isComplete)) {
            outboundQueue.commitEntry(xid.getValue(), request, createCallback(requestContext, requestType), isComplete);
        } else {
            outboundQueue.commitEntry(xid.getValue(), request, createCallback(requestContext, requestType));
        }
    }
    return requestContext.getFuture();
}
Also used : OutboundQueue(org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue) DataContainer(org.opendaylight.yangtools.yang.binding.DataContainer) Xid(org.opendaylight.openflowplugin.api.openflow.device.Xid) ServiceException(org.opendaylight.openflowplugin.impl.services.util.ServiceException) OfHeader(org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)

Aggregations

ServiceException (org.opendaylight.openflowplugin.impl.services.util.ServiceException)3 TypeVersionKey (org.opendaylight.openflowplugin.extension.api.TypeVersionKey)2 ConversionException (org.opendaylight.openflowplugin.extension.api.exception.ConversionException)2 ConverterNotFoundException (org.opendaylight.openflowplugin.extension.api.exception.ConverterNotFoundException)2 ExperimenterDataOfChoice (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.experimenter.core.ExperimenterDataOfChoice)2 ExperimenterMessageOfChoice (org.opendaylight.yang.gen.v1.urn.opendaylight.openflowplugin.experimenter.types.rev151020.experimenter.core.message.ExperimenterMessageOfChoice)2 OutboundQueue (org.opendaylight.openflowjava.protocol.api.connection.OutboundQueue)1 Xid (org.opendaylight.openflowplugin.api.openflow.device.Xid)1 BundleMessageDataInjector (org.opendaylight.openflowplugin.extension.api.BundleMessageDataInjector)1 ExperimenterInputBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.ExperimenterInputBuilder)1 OfHeader (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.OfHeader)1 MultipartRequestExperimenterCaseBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.MultipartRequestExperimenterCaseBuilder)1 MultipartRequestExperimenterBuilder (org.opendaylight.yang.gen.v1.urn.opendaylight.openflow.protocol.rev130731.multipart.request.multipart.request.body.multipart.request.experimenter._case.MultipartRequestExperimenterBuilder)1 DataContainer (org.opendaylight.yangtools.yang.binding.DataContainer)1