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();
}
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);
}
}
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();
}
Aggregations