use of org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException in project controller by opendaylight.
the class ActionProviderBean method registerFallback.
private void registerFallback(final Class<RpcService> interfaceClass) {
final Collection<QName> paths = RpcUtil.decomposeRpcService(interfaceClass, schemaService.getGlobalContext(), RpcRoutingStrategy::isContextBasedRouted);
if (paths.isEmpty()) {
LOG.warn("{}: interface {} has no actions defined", ACTION_PROVIDER, interfaceClass);
return;
}
final Set<DOMRpcIdentifier> rpcs = ImmutableSet.copyOf(Collections2.transform(paths, DOMRpcIdentifier::create));
reg = domRpcProvider.registerRpcImplementation((rpc, input) -> FluentFutures.immediateFailedFluentFuture(new DOMRpcImplementationNotAvailableException("Action %s has no instance matching %s", rpc, input)), rpcs);
LOG.debug("Registered provider for {}", interfaceName);
}
use of org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException in project controller by opendaylight.
the class OpsBrokerTest method testExecuteRpcFailureWithException.
@Test
public void testExecuteRpcFailureWithException() {
when(domRpcService1.invokeRpc(eq(TEST_RPC), any())).thenReturn(FluentFutures.immediateFailedFluentFuture(new DOMRpcImplementationNotAvailableException("NOT FOUND")));
final ExecuteRpc executeMsg = ExecuteRpc.from(TEST_RPC_ID, null);
rpcInvoker1.tell(executeMsg, rpcRegistry1Probe.getRef());
final Failure rpcResponse = rpcRegistry1Probe.expectMsgClass(Duration.ofSeconds(5), Failure.class);
assertTrue(rpcResponse.cause() instanceof DOMRpcException);
}
use of org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException in project netconf by opendaylight.
the class NetconfDeviceRpc method invokeRpc.
@Override
@SuppressWarnings("checkstyle:IllegalCatch")
public ListenableFuture<DOMRpcResult> invokeRpc(final QName type, final NormalizedNode input) {
final ListenableFuture<RpcResult<NetconfMessage>> delegateFuture = communicator.sendRequest(transformer.toRpcRequest(type, input), type);
final SettableFuture<DOMRpcResult> ret = SettableFuture.create();
Futures.addCallback(delegateFuture, new FutureCallback<RpcResult<NetconfMessage>>() {
@Override
public void onSuccess(final RpcResult<NetconfMessage> result) {
try {
ret.set(result.isSuccessful() ? transformer.toRpcResult(result.getResult(), type) : new DefaultDOMRpcResult(result.getErrors()));
} catch (Exception cause) {
ret.setException(new DefaultDOMRpcException("Unable to parse rpc reply. type: " + type + " input: " + input, cause));
}
}
@Override
public void onFailure(final Throwable cause) {
ret.setException(new DOMRpcImplementationNotAvailableException(cause, "Unable to invoke rpc %s", type));
}
}, MoreExecutors.directExecutor());
return ret;
}
use of org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException in project netconf by opendaylight.
the class RestconfImpl method checkRpcResponse.
@SuppressWarnings("checkstyle:avoidHidingCauseException")
private static DOMRpcResult checkRpcResponse(final ListenableFuture<? extends DOMRpcResult> response) {
if (response == null) {
return null;
}
try {
final DOMRpcResult retValue = response.get();
if (retValue.getErrors().isEmpty()) {
return retValue;
}
LOG.debug("RpcError message {}", retValue.getErrors());
throw new RestconfDocumentedException("RpcError message", null, retValue.getErrors());
} catch (final InterruptedException e) {
final String errMsg = "The operation was interrupted while executing and did not complete.";
LOG.debug("Rpc Interrupt - {}", errMsg, e);
throw new RestconfDocumentedException(errMsg, ErrorType.RPC, ErrorTag.PARTIAL_OPERATION, e);
} catch (final ExecutionException e) {
LOG.debug("Execution RpcError: ", e);
Throwable cause = e.getCause();
if (cause == null) {
throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.", e);
}
while (cause.getCause() != null) {
cause = cause.getCause();
}
if (cause instanceof IllegalArgumentException) {
throw new RestconfDocumentedException(cause.getMessage(), ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
} else if (cause instanceof DOMRpcImplementationNotAvailableException) {
throw new RestconfDocumentedException(cause.getMessage(), ErrorType.APPLICATION, ErrorTag.OPERATION_NOT_SUPPORTED);
}
throw new RestconfDocumentedException("The operation encountered an unexpected error while executing.", cause);
} catch (final CancellationException e) {
final String errMsg = "The operation was cancelled while executing.";
LOG.debug("Cancel RpcExecution: {}", errMsg, e);
throw new RestconfDocumentedException(errMsg, ErrorType.RPC, ErrorTag.PARTIAL_OPERATION);
}
}
use of org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException in project netconf by opendaylight.
the class SchemalessNetconfDeviceRpc method handleRpc.
private ListenableFuture<DOMRpcResult> handleRpc(@NonNull final QName type, @NonNull final NormalizedNode input, final MessageTransformer<NetconfMessage> transformer) {
final ListenableFuture<RpcResult<NetconfMessage>> delegateFuture = listener.sendRequest(transformer.toRpcRequest(type, input), type);
final SettableFuture<DOMRpcResult> ret = SettableFuture.create();
Futures.addCallback(delegateFuture, new FutureCallback<RpcResult<NetconfMessage>>() {
@Override
public void onSuccess(final RpcResult<NetconfMessage> result) {
ret.set(result.isSuccessful() ? transformer.toRpcResult(result.getResult(), type) : new DefaultDOMRpcResult(result.getErrors()));
}
@Override
public void onFailure(final Throwable cause) {
ret.setException(new DOMRpcImplementationNotAvailableException(cause, "Unable to invoke rpc %s on device %s", type, deviceId));
}
}, MoreExecutors.directExecutor());
return ret;
}
Aggregations