Search in sources :

Example 1 with DOMRpcImplementationNotAvailableException

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);
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) Set(java.util.Set) Collections2(com.google.common.collect.Collections2) DOMRpcIdentifier(org.opendaylight.mdsal.dom.api.DOMRpcIdentifier) FluentFutures(org.opendaylight.yangtools.util.concurrent.FluentFutures) QName(org.opendaylight.yangtools.yang.common.QName) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) RpcProviderService(org.opendaylight.mdsal.binding.api.RpcProviderService) RpcService(org.opendaylight.yangtools.yang.binding.RpcService) DOMRpcProviderService(org.opendaylight.mdsal.dom.api.DOMRpcProviderService) Registration(org.opendaylight.yangtools.concepts.Registration) DOMSchemaService(org.opendaylight.mdsal.dom.api.DOMSchemaService) Bundle(org.osgi.framework.Bundle) RpcRoutingStrategy(org.opendaylight.mdsal.dom.spi.RpcRoutingStrategy) ComponentDefinitionException(org.osgi.service.blueprint.container.ComponentDefinitionException) RpcRoutingStrategy(org.opendaylight.mdsal.dom.spi.RpcRoutingStrategy) QName(org.opendaylight.yangtools.yang.common.QName) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) DOMRpcIdentifier(org.opendaylight.mdsal.dom.api.DOMRpcIdentifier)

Example 2 with DOMRpcImplementationNotAvailableException

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);
}
Also used : DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) ExecuteRpc(org.opendaylight.controller.remote.rpc.messages.ExecuteRpc) DOMRpcException(org.opendaylight.mdsal.dom.api.DOMRpcException) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 3 with DOMRpcImplementationNotAvailableException

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;
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) DefaultDOMRpcException(org.opendaylight.mdsal.dom.api.DefaultDOMRpcException) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) DefaultDOMRpcException(org.opendaylight.mdsal.dom.api.DefaultDOMRpcException)

Example 4 with DOMRpcImplementationNotAvailableException

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);
    }
}
Also used : RestconfDocumentedException(org.opendaylight.restconf.common.errors.RestconfDocumentedException) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) CancellationException(java.util.concurrent.CancellationException) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) ExecutionException(java.util.concurrent.ExecutionException)

Example 5 with DOMRpcImplementationNotAvailableException

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;
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) NetconfMessage(org.opendaylight.netconf.api.NetconfMessage) DOMRpcImplementationNotAvailableException(org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException) RpcResult(org.opendaylight.yangtools.yang.common.RpcResult) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult)

Aggregations

DOMRpcImplementationNotAvailableException (org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException)8 Test (org.junit.Test)4 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)4 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)4 QName (org.opendaylight.yangtools.yang.common.QName)4 DOMRpcException (org.opendaylight.mdsal.dom.api.DOMRpcException)3 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)2 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)2 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)2 Failure (akka.actor.Status.Failure)1 Collections2 (com.google.common.collect.Collections2)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collection (java.util.Collection)1 Set (java.util.Set)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 ExecuteRpc (org.opendaylight.controller.remote.rpc.messages.ExecuteRpc)1 RpcProviderService (org.opendaylight.mdsal.binding.api.RpcProviderService)1 DOMRpcIdentifier (org.opendaylight.mdsal.dom.api.DOMRpcIdentifier)1