Search in sources :

Example 1 with SchemaPathMessage

use of org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage in project netconf by opendaylight.

the class ProxyDOMActionService method invokeAction.

@Override
public FluentFuture<DOMActionResult> invokeAction(final Absolute type, final DOMDataTreeIdentifier domDataTreeIdentifier, final ContainerNode input) {
    requireNonNull(type);
    requireNonNull(input);
    requireNonNull(domDataTreeIdentifier);
    LOG.info("{}: Action Operation invoked with schema type: {} and node: {}.", id, type, input);
    final ContainerNodeMessage containerNodeMessage = new ContainerNodeMessage(input);
    final Future<Object> scalaFuture = Patterns.ask(masterActorRef, new InvokeActionMessage(new SchemaPathMessage(type), containerNodeMessage, domDataTreeIdentifier), actorResponseWaitTime);
    final SettableFuture<DOMActionResult> settableFuture = SettableFuture.create();
    scalaFuture.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                if (failure instanceof ClusteringActionException) {
                    settableFuture.setException(failure);
                } else {
                    settableFuture.setException(new ClusteringActionException(id + ": Exception during remote Action invocation.", failure));
                }
                return;
            }
            if (response instanceof EmptyResultResponse) {
                settableFuture.set(null);
                return;
            }
            final Collection<? extends RpcError> errors = ((InvokeActionMessageReply) response).getRpcErrors();
            final ContainerNodeMessage containerNodeMessage = ((InvokeActionMessageReply) response).getContainerNodeMessage();
            final DOMActionResult result;
            if (containerNodeMessage == null) {
                result = new SimpleDOMActionResult(ImmutableList.copyOf(errors));
            } else {
                result = new SimpleDOMActionResult(containerNodeMessage.getNode(), ImmutableList.copyOf(errors));
            }
            settableFuture.set(result);
        }
    }, actorSystem.dispatcher());
    return FluentFuture.from(settableFuture);
}
Also used : SchemaPathMessage(org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage) RpcError(org.opendaylight.yangtools.yang.common.RpcError) EmptyResultResponse(org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyResultResponse) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult) InvokeActionMessage(org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage) ClusteringActionException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException) ContainerNodeMessage(org.opendaylight.netconf.topology.singleton.messages.ContainerNodeMessage) Collection(java.util.Collection) DOMActionResult(org.opendaylight.mdsal.dom.api.DOMActionResult) SimpleDOMActionResult(org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)

Example 2 with SchemaPathMessage

use of org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage in project netconf by opendaylight.

the class ProxyDOMRpcService method invokeRpc.

@Override
public FluentFuture<DOMRpcResult> invokeRpc(final QName type, final NormalizedNode input) {
    LOG.trace("{}: Rpc operation invoked with schema type: {} and node: {}.", id, type, input);
    final NormalizedNodeMessage normalizedNodeMessage = input != null ? new NormalizedNodeMessage(YangInstanceIdentifier.empty(), input) : null;
    final Future<Object> scalaFuture = Patterns.ask(masterActorRef, new InvokeRpcMessage(new SchemaPathMessage(type), normalizedNodeMessage), actorResponseWaitTime);
    final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
    scalaFuture.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                if (failure instanceof ClusteringRpcException) {
                    settableFuture.setException(failure);
                } else {
                    settableFuture.setException(new ClusteringRpcException(id + ": Exception during remote rpc invocation.", failure));
                }
                return;
            }
            if (response instanceof EmptyResultResponse) {
                settableFuture.set(null);
                return;
            }
            final Collection<? extends RpcError> errors = ((InvokeRpcMessageReply) response).getRpcErrors();
            final NormalizedNodeMessage normalizedNodeMessageResult = ((InvokeRpcMessageReply) response).getNormalizedNodeMessage();
            final DOMRpcResult result;
            if (normalizedNodeMessageResult == null) {
                result = new DefaultDOMRpcResult(ImmutableList.copyOf(errors));
            } else {
                result = new DefaultDOMRpcResult(normalizedNodeMessageResult.getNode(), errors);
            }
            settableFuture.set(result);
        }
    }, actorSystem.dispatcher());
    return FluentFuture.from(settableFuture);
}
Also used : DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) SchemaPathMessage(org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage) RpcError(org.opendaylight.yangtools.yang.common.RpcError) EmptyResultResponse(org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyResultResponse) InvokeRpcMessage(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessage) ClusteringRpcException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException) Collection(java.util.Collection)

Aggregations

Collection (java.util.Collection)2 SchemaPathMessage (org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage)2 EmptyResultResponse (org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyResultResponse)2 RpcError (org.opendaylight.yangtools.yang.common.RpcError)2 DOMActionResult (org.opendaylight.mdsal.dom.api.DOMActionResult)1 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)1 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)1 SimpleDOMActionResult (org.opendaylight.mdsal.dom.spi.SimpleDOMActionResult)1 ClusteringActionException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringActionException)1 ClusteringRpcException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException)1 ContainerNodeMessage (org.opendaylight.netconf.topology.singleton.messages.ContainerNodeMessage)1 NormalizedNodeMessage (org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage)1 InvokeActionMessage (org.opendaylight.netconf.topology.singleton.messages.action.InvokeActionMessage)1 InvokeRpcMessage (org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessage)1