Search in sources :

Example 1 with SubmitRequest

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

the class WriteTransactionActorTestAdapter method testSubmit.

@Test
public void testSubmit() {
    doReturn(emptyFluentFuture()).when(mockWriteTx).commit();
    actorRef.tell(new SubmitRequest(), probe.ref());
    verify(mockWriteTx).commit();
    probe.expectMsgClass(Success.class);
}
Also used : SubmitRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest) Test(org.junit.Test)

Example 2 with SubmitRequest

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

the class WriteTransactionActorTestAdapter method testSubmitFail.

@Test
public void testSubmitFail() {
    final RpcError rpcError = RpcResultBuilder.newError(RpcError.ErrorType.APPLICATION, "fail", "fail");
    final TransactionCommitFailedException cause = new TransactionCommitFailedException("fail", rpcError);
    when(mockWriteTx.commit()).thenReturn(FluentFutures.immediateFailedFluentFuture(cause));
    actorRef.tell(new SubmitRequest(), probe.ref());
    verify(mockWriteTx).commit();
    final Failure response = probe.expectMsgClass(Failure.class);
    assertEquals(cause, response.cause());
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) RpcError(org.opendaylight.yangtools.yang.common.RpcError) SubmitRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest) Failure(akka.actor.Status.Failure) Test(org.junit.Test)

Example 3 with SubmitRequest

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

the class ActorProxyTransactionFacade method commit.

@Override
public FluentFuture<? extends CommitInfo> commit() {
    LOG.debug("{}: Commit via actor {}", id, masterTxActor);
    final Future<Object> future = Patterns.ask(masterTxActor, new SubmitRequest(), askTimeout);
    final SettableFuture<CommitInfo> 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(newTransactionCommitFailedException(processFailure(failure)));
                return;
            }
            LOG.debug("{}: Commit succeeded", id);
            settableFuture.set(CommitInfo.empty());
        }

        private TransactionCommitFailedException newTransactionCommitFailedException(final Throwable failure) {
            return new TransactionCommitFailedException(String.format("%s: Commit of transaction failed", getIdentifier()), failure);
        }
    }, executionContext);
    return FluentFuture.from(settableFuture);
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) SubmitRequest(org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest) CommitInfo(org.opendaylight.mdsal.common.api.CommitInfo)

Example 4 with SubmitRequest

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

Aggregations

SubmitRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.SubmitRequest)4 Test (org.junit.Test)2 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)2 Failure (akka.actor.Status.Failure)1 CommitInfo (org.opendaylight.mdsal.common.api.CommitInfo)1 NormalizedNodeMessage (org.opendaylight.netconf.topology.singleton.messages.NormalizedNodeMessage)1 CancelRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.CancelRequest)1 DeleteRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.DeleteRequest)1 MergeRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.MergeRequest)1 PutRequest (org.opendaylight.netconf.topology.singleton.messages.transactions.PutRequest)1 RpcError (org.opendaylight.yangtools.yang.common.RpcError)1