Search in sources :

Example 1 with CommitRequest

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

the class NetconfDataTreeServiceActor method onReceive.

@Override
public void onReceive(final Object message) {
    if (message instanceof GetWithFieldsRequest) {
        final GetWithFieldsRequest getRequest = (GetWithFieldsRequest) message;
        final YangInstanceIdentifier path = getRequest.getPath();
        final ListenableFuture<Optional<NormalizedNode>> future = netconfService.get(getRequest.getPath(), getRequest.getFields());
        context().stop(self());
        sendResult(future, path, sender(), self());
    } else if (message instanceof GetRequest) {
        final GetRequest getRequest = (GetRequest) message;
        final YangInstanceIdentifier path = getRequest.getPath();
        final ListenableFuture<Optional<NormalizedNode>> future = netconfService.get(path);
        context().stop(self());
        sendResult(future, path, sender(), self());
    } else if (message instanceof GetConfigWithFieldsRequest) {
        final GetConfigWithFieldsRequest getConfigRequest = (GetConfigWithFieldsRequest) message;
        final YangInstanceIdentifier path = getConfigRequest.getPath();
        final ListenableFuture<Optional<NormalizedNode>> future = netconfService.getConfig(path, getConfigRequest.getFields());
        context().stop(self());
        sendResult(future, path, sender(), self());
    } else if (message instanceof GetConfigRequest) {
        final GetConfigRequest getConfigRequest = (GetConfigRequest) message;
        final YangInstanceIdentifier path = getConfigRequest.getPath();
        final ListenableFuture<Optional<NormalizedNode>> future = netconfService.getConfig(path);
        context().stop(self());
        sendResult(future, path, sender(), self());
    } else if (message instanceof LockRequest) {
        invokeRpcCall(netconfService::lock, sender(), self());
    } else if (message instanceof MergeEditConfigRequest) {
        final MergeEditConfigRequest request = (MergeEditConfigRequest) message;
        netconfService.merge(request.getStore(), request.getNormalizedNodeMessage().getIdentifier(), request.getNormalizedNodeMessage().getNode(), Optional.ofNullable(request.getDefaultOperation()));
    } else if (message instanceof ReplaceEditConfigRequest) {
        final ReplaceEditConfigRequest request = (ReplaceEditConfigRequest) message;
        netconfService.replace(request.getStore(), request.getNormalizedNodeMessage().getIdentifier(), request.getNormalizedNodeMessage().getNode(), Optional.ofNullable(request.getDefaultOperation()));
    } else if (message instanceof CreateEditConfigRequest) {
        final CreateEditConfigRequest request = (CreateEditConfigRequest) message;
        netconfService.create(request.getStore(), request.getNormalizedNodeMessage().getIdentifier(), request.getNormalizedNodeMessage().getNode(), Optional.ofNullable(request.getDefaultOperation()));
    } else if (message instanceof DeleteEditConfigRequest) {
        final DeleteEditConfigRequest request = (DeleteEditConfigRequest) message;
        netconfService.delete(request.getStore(), request.getPath());
    } else if (message instanceof RemoveEditConfigRequest) {
        final RemoveEditConfigRequest request = (RemoveEditConfigRequest) message;
        netconfService.remove(request.getStore(), request.getPath());
    } else if (message instanceof CommitRequest) {
        submit(sender(), self());
    } else if (message instanceof DiscardChangesRequest) {
        invokeRpcCall(netconfService::discardChanges, sender(), self());
    } else if (message instanceof UnlockRequest) {
        context().stop(self());
        invokeRpcCall(netconfService::unlock, sender(), self());
    } else if (message instanceof ReceiveTimeout) {
        LOG.warn("Haven't received any message for {} seconds, cancelling transaction and stopping actor", idleTimeout);
        invokeRpcCall(netconfService::discardChanges, sender(), self());
        invokeRpcCall(netconfService::unlock, sender(), self());
        context().stop(self());
    } else {
        unhandled(message);
    }
}
Also used : GetWithFieldsRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.GetWithFieldsRequest) MergeEditConfigRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.MergeEditConfigRequest) CommitRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.CommitRequest) Optional(java.util.Optional) ReplaceEditConfigRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.ReplaceEditConfigRequest) CreateEditConfigRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.CreateEditConfigRequest) GetConfigRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.GetConfigRequest) DeleteEditConfigRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.DeleteEditConfigRequest) RemoveEditConfigRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.RemoveEditConfigRequest) ReceiveTimeout(akka.actor.ReceiveTimeout) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) UnlockRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.UnlockRequest) GetConfigWithFieldsRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.GetConfigWithFieldsRequest) GetRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.GetRequest) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) DiscardChangesRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.DiscardChangesRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) LockRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.LockRequest)

Example 2 with CommitRequest

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

the class NetconfDataTreeServiceActorTest method testCommitFail.

@Test
public void testCommitFail() {
    final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "fail", "fail");
    final TransactionCommitFailedException failure = new TransactionCommitFailedException("fail", rpcError);
    final NetconfServiceFailedException cause = new NetconfServiceFailedException(String.format("%s: Commit of operation failed", 1), failure);
    when(netconfService.commit()).thenReturn(FluentFutures.immediateFailedFluentFuture(cause));
    actorRef.tell(new CommitRequest(), probe.ref());
    verify(netconfService).commit();
    final Status.Failure response = probe.expectMsgClass(Status.Failure.class);
    assertEquals(cause, response.cause());
}
Also used : CommitRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.CommitRequest) Status(akka.actor.Status) TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) NetconfServiceFailedException(org.opendaylight.netconf.topology.singleton.impl.netconf.NetconfServiceFailedException) RpcError(org.opendaylight.yangtools.yang.common.RpcError) Test(org.junit.Test)

Example 3 with CommitRequest

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

the class NetconfDataTreeServiceActorTest method testCommit.

@Test
public void testCommit() {
    doReturn(FluentFutures.immediateFluentFuture(new DefaultDOMRpcResult())).when(netconfService).commit();
    actorRef.tell(new CommitRequest(), probe.ref());
    verify(netconfService).commit();
    probe.expectMsgClass(InvokeRpcMessageReply.class);
}
Also used : CommitRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.CommitRequest) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) Test(org.junit.Test)

Example 4 with CommitRequest

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

the class ActorProxyNetconfServiceFacade method commit.

@Override
public ListenableFuture<? extends DOMRpcResult> commit() {
    LOG.debug("{}: Commit via actor {}", id, masterActor);
    final Future<Object> future = Patterns.ask(masterActor, new CommitRequest(), askTimeout);
    final SettableFuture<DOMRpcResult> settableFuture = SettableFuture.create();
    future.onComplete(new OnComplete<>() {

        @Override
        public void onComplete(final Throwable failure, final Object response) {
            if (failure != null) {
                LOG.debug("{}: Commit failed", id, failure);
                settableFuture.setException(newNetconfServiceFailedException(processFailure(failure)));
            } else if (response instanceof InvokeRpcMessageReply) {
                LOG.debug("{}: Commit succeeded", id);
                settableFuture.set(mapInvokeRpcMessageReplyToDOMRpcResult((InvokeRpcMessageReply) response));
            } else {
                settableFuture.setException(new ClusteringRpcException("Commit operation returned unexpected type"));
                LOG.error("{}: Commit via actor {} returned unexpected type", id, masterActor);
            }
        }

        private NetconfServiceFailedException newNetconfServiceFailedException(final Throwable failure) {
            return new NetconfServiceFailedException(String.format("%s: Commit of operation failed", getDeviceId()), failure);
        }
    }, executionContext);
    return settableFuture;
}
Also used : CommitRequest(org.opendaylight.netconf.topology.singleton.messages.netconf.CommitRequest) DefaultDOMRpcResult(org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult) DOMRpcResult(org.opendaylight.mdsal.dom.api.DOMRpcResult) ClusteringRpcException(org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException) InvokeRpcMessageReply(org.opendaylight.netconf.topology.singleton.messages.rpc.InvokeRpcMessageReply)

Aggregations

CommitRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.CommitRequest)4 Test (org.junit.Test)2 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)2 ReceiveTimeout (akka.actor.ReceiveTimeout)1 Status (akka.actor.Status)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Optional (java.util.Optional)1 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)1 DOMRpcResult (org.opendaylight.mdsal.dom.api.DOMRpcResult)1 NetconfServiceFailedException (org.opendaylight.netconf.topology.singleton.impl.netconf.NetconfServiceFailedException)1 ClusteringRpcException (org.opendaylight.netconf.topology.singleton.impl.utils.ClusteringRpcException)1 CreateEditConfigRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.CreateEditConfigRequest)1 DeleteEditConfigRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.DeleteEditConfigRequest)1 DiscardChangesRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.DiscardChangesRequest)1 GetConfigRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.GetConfigRequest)1 GetConfigWithFieldsRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.GetConfigWithFieldsRequest)1 GetRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.GetRequest)1 GetWithFieldsRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.GetWithFieldsRequest)1 LockRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.LockRequest)1 MergeEditConfigRequest (org.opendaylight.netconf.topology.singleton.messages.netconf.MergeEditConfigRequest)1