Search in sources :

Example 16 with NormalizedNodeMessage

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

the class ActorProxyTransactionFacade method merge.

@Override
public void merge(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data) {
    LOG.debug("{}: Merge {} {} via actor {}", id, store, path, masterTxActor);
    masterTxActor.tell(new MergeRequest(store, new NormalizedNodeMessage(path, data)), ActorRef.noSender());
}
Also used : MergeRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.MergeRequest) NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage)

Example 17 with NormalizedNodeMessage

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

the class ActorProxyTransactionFacade method read.

@Override
public FluentFuture<Optional<NormalizedNode>> read(final LogicalDatastoreType store, final YangInstanceIdentifier path) {
    LOG.debug("{}: Read {} {} via actor {}", id, store, path, masterTxActor);
    final Future<Object> future = Patterns.ask(masterTxActor, new ReadRequest(store, path), askTimeout);
    final SettableFuture<Optional<NormalizedNode>> settableFuture = SettableFuture.create();
    future.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                LOG.debug("{}: Read {} {} failed", id, store, path, failure);
                final Throwable processedFailure = processFailure(failure);
                if (processedFailure instanceof ReadFailedException) {
                    settableFuture.setException(processedFailure);
                } else {
                    settableFuture.setException(new ReadFailedException("Read of store " + store + " path " + path + " failed", processedFailure));
                }
                return;
            }
            LOG.debug("{}: Read {} {} succeeded: {}", id, store, path, response);
            if (response instanceof EmptyReadResponse) {
                settableFuture.set(Optional.empty());
                return;
            }
            if (response instanceof NormalizedNodeMessage) {
                final NormalizedNodeMessage data = (NormalizedNodeMessage) response;
                settableFuture.set(Optional.of(data.getNode()));
            }
        }
    }, executionContext);
    return FluentFuture.from(settableFuture);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage) Optional(java.util.Optional) EmptyReadResponse(org.opendaylight.netconf.topology.singleton.messages.transactions.EmptyReadResponse) ReadRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest)

Example 18 with NormalizedNodeMessage

use of org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage 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)

Example 19 with NormalizedNodeMessage

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

the class WriteAdapter method handle.

@SuppressWarnings("checkstyle:IllegalCatch")
public void handle(final Object message, final ActorRef sender, final ActorContext context, final ActorRef self) {
    // TODO Maybe we should store it and fail the submit immediately?.
    try {
        if (message instanceof MergeRequest) {
            final MergeRequest mergeRequest = (MergeRequest) message;
            final NormalizedNodeMessage data = mergeRequest.getNormalizedNodeMessage();
            tx.merge(mergeRequest.getStore(), data.getIdentifier(), data.getNode());
        } else if (message instanceof PutRequest) {
            final PutRequest putRequest = (PutRequest) message;
            final NormalizedNodeMessage data = putRequest.getNormalizedNodeMessage();
            tx.put(putRequest.getStore(), data.getIdentifier(), data.getNode());
        } else if (message instanceof DeleteRequest) {
            final DeleteRequest deleteRequest = (DeleteRequest) message;
            tx.delete(deleteRequest.getStore(), deleteRequest.getPath());
        } else if (message instanceof CancelRequest) {
            cancel(context, sender, self);
        } else if (message instanceof SubmitRequest) {
            submit(sender, self, context);
        }
    } catch (final RuntimeException exception) {
        LOG.error("Write command has failed.", exception);
    }
}
Also used : MergeRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.MergeRequest) NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage) PutRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.PutRequest) CancelRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.CancelRequest) SubmitRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest) DeleteRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.DeleteRequest)

Example 20 with NormalizedNodeMessage

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

the class ActorProxyNetconfServiceFacade method create.

@Override
public ListenableFuture<? extends DOMRpcResult> create(final LogicalDatastoreType store, final YangInstanceIdentifier path, final NormalizedNode data, final Optional<ModifyAction> defaultOperation) {
    LOG.debug("{}: Create {} {} via actor {}", id, store, path, masterActor);
    masterActor.tell(new CreateEditConfigRequest(store, new NormalizedNodeMessage(path, data), defaultOperation.orElse(null)), ActorRef.noSender());
    return createResult();
}
Also used : NormalizedNodeMessage(org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage) CreateEditConfigRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.CreateEditConfigRequest)

Aggregations

NormalizedNodeMessage (org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage)20 Test (org.junit.Test)12 Optional (java.util.Optional)5 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)4 MergeRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.MergeRequest)3 PutRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.PutRequest)3 ReadRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.ReadRequest)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 CreateEditConfigRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.CreateEditConfigRequest)2 GetConfigRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.GetConfigRequest)2 GetRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.GetRequest)2 MergeEditConfigRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.MergeEditConfigRequest)2 ReplaceEditConfigRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.ReplaceEditConfigRequest)2 Success (akka.actor.Status.Success)1 Collection (java.util.Collection)1 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)1 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)1 ClusteringRpcException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException)1 SchemaPathMessage (org.opendaylight.netconf.topology.singleton.messages.SchemaPathMessage)1 InvokeRpcMessage (org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessage)1