Search in sources :

Example 1 with DefaultDOMRpcException

use of org.opendaylight.mdsal.dom.api.DefaultDOMRpcException 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)

Aggregations

DOMRpcImplementationNotAvailableException (org.opendaylight.mdsal.dom.api.DOMRpcImplementationNotAvailableException)1 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)1 DefaultDOMRpcException (org.opendaylight.mdsal.dom.api.DefaultDOMRpcException)1 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)1 NetconfMessage (org.opendaylight.netconf.api.NetconfMessage)1 RpcResult (org.opendaylight.yangtools.yang.common.RpcResult)1