Search in sources :

Example 6 with ReadTransactionRequest

use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.

the class RemoteProxyTransaction method handleForwardedRequest.

void handleForwardedRequest(final TransactionRequest<?> request, final Consumer<Response<?, ?>> callback) {
    if (request instanceof ModifyTransactionRequest) {
        handleForwardedModifyTransactionRequest(callback, (ModifyTransactionRequest) request);
    } else if (request instanceof ReadTransactionRequest) {
        ensureFlushedBuider();
        sendRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            callback.accept(resp);
        });
    } else if (request instanceof ExistsTransactionRequest) {
        ensureFlushedBuider();
        sendRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            callback.accept(resp);
        });
    } else if (request instanceof TransactionPreCommitRequest) {
        ensureFlushedBuider();
        final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
        sendRequest(tmp, resp -> {
            recordSuccessfulRequest(tmp);
            callback.accept(resp);
        });
    } else if (request instanceof TransactionDoCommitRequest) {
        ensureFlushedBuider();
        sendRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback);
    } else if (request instanceof TransactionAbortRequest) {
        ensureFlushedBuider();
        sendDoAbort(callback);
    } else if (request instanceof TransactionPurgeRequest) {
        enqueuePurge(callback);
    } else {
        throw new IllegalArgumentException("Unhandled request {}" + request);
    }
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) TransactionDelete(org.opendaylight.controller.cluster.access.commands.TransactionDelete) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) TransactionWrite(org.opendaylight.controller.cluster.access.commands.TransactionWrite) LoggerFactory(org.slf4j.LoggerFactory) CheckedFuture(com.google.common.util.concurrent.CheckedFuture) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) Response(org.opendaylight.controller.cluster.access.concepts.Response) MappingCheckedFuture(org.opendaylight.mdsal.common.api.MappingCheckedFuture) SettableFuture(com.google.common.util.concurrent.SettableFuture) TransactionModification(org.opendaylight.controller.cluster.access.commands.TransactionModification) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) ExistsTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure) Optional(com.google.common.base.Optional) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) Nullable(javax.annotation.Nullable) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) AbstractLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Logger(org.slf4j.Logger) TransactionDoCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest) TransactionMerge(org.opendaylight.controller.cluster.access.commands.TransactionMerge) PersistenceProtocol(org.opendaylight.controller.cluster.access.commands.PersistenceProtocol) AbstractDataTreeModificationCursor(org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess) TransactionAbortRequest(org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest) TransactionPreCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest) Consumer(java.util.function.Consumer) Futures(com.google.common.util.concurrent.Futures) TransactionSuccess(org.opendaylight.controller.cluster.access.commands.TransactionSuccess) PathArgument(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) TransactionIdentifier(org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) TransactionDoCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) TransactionAbortRequest(org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) AbortLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest) AbstractLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest) CommitLocalTransactionRequest(org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) TransactionPreCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest)

Example 7 with ReadTransactionRequest

use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.

the class RemoteProxyTransactionTest method testRead.

@Override
@Test
public void testRead() throws Exception {
    final TransactionTester<RemoteProxyTransaction> tester = getTester();
    final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read = transaction.read(PATH_2);
    final ReadTransactionRequest req = tester.expectTransactionRequest(ReadTransactionRequest.class);
    final Optional<NormalizedNode<?, ?>> result = Optional.of(DATA_1);
    tester.replySuccess(new ReadTransactionSuccess(TRANSACTION_ID, req.getSequence(), result));
    assertFutureEquals(result, read);
}
Also used : ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException) Optional(com.google.common.base.Optional) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess) Test(org.junit.Test)

Example 8 with ReadTransactionRequest

use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.

the class FrontendReadWriteTransactionTest method testReadAfterAbort.

@Test(expected = IllegalStateException.class)
public void testReadAfterAbort() throws RequestException {
    final ModifyTransactionRequestBuilder b = new ModifyTransactionRequestBuilder(TX_ID, mock(ActorRef.class));
    b.setSequence(0);
    b.setAbort();
    final TransactionRequest<?> abortReq = b.build();
    assertNull(handleRequest(abortReq));
    verify(mockParent).abortTransaction(same(shardTransaction), any(Runnable.class));
    handleRequest(new ReadTransactionRequest(TX_ID, 0, mock(ActorRef.class), YangInstanceIdentifier.EMPTY, true));
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) ActorRef(akka.actor.ActorRef) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) Test(org.junit.Test)

Example 9 with ReadTransactionRequest

use of org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest in project controller by opendaylight.

the class LocalProxyTransaction method handleReadRequest.

private boolean handleReadRequest(final TransactionRequest<?> request, @Nullable final Consumer<Response<?, ?>> callback) {
    // listeners, which we do not want to execute while we are reconnecting.
    if (request instanceof ReadTransactionRequest) {
        final YangInstanceIdentifier path = ((ReadTransactionRequest) request).getPath();
        final Optional<NormalizedNode<?, ?>> result = Optional.fromJavaUtil(readOnlyView().readNode(path));
        if (callback != null) {
            // XXX: FB does not see that callback is final, on stack and has be check for non-null.
            final Consumer<Response<?, ?>> fbIsStupid = Preconditions.checkNotNull(callback);
            executeInActor(() -> fbIsStupid.accept(new ReadTransactionSuccess(request.getTarget(), request.getSequence(), result)));
        }
        return true;
    } else if (request instanceof ExistsTransactionRequest) {
        final YangInstanceIdentifier path = ((ExistsTransactionRequest) request).getPath();
        final boolean result = readOnlyView().readNode(path).isPresent();
        if (callback != null) {
            // XXX: FB does not see that callback is final, on stack and has be check for non-null.
            final Consumer<Response<?, ?>> fbIsStupid = Preconditions.checkNotNull(callback);
            executeInActor(() -> fbIsStupid.accept(new ExistsTransactionSuccess(request.getTarget(), request.getSequence(), result)));
        }
        return true;
    } else {
        return false;
    }
}
Also used : Response(org.opendaylight.controller.cluster.access.concepts.Response) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) Consumer(java.util.function.Consumer) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) ExistsTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess) ReadTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess)

Aggregations

ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)9 Test (org.junit.Test)6 ReadTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ReadTransactionSuccess)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)4 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)4 TestProbe (akka.testkit.TestProbe)3 Optional (com.google.common.base.Optional)3 Consumer (java.util.function.Consumer)3 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)3 ExistsTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ExistsTransactionSuccess)3 ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)3 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)3 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)3 ActorRef (akka.actor.ActorRef)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)2 Futures (com.google.common.util.concurrent.Futures)2 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 SettableFuture (com.google.common.util.concurrent.SettableFuture)2 Nullable (javax.annotation.Nullable)2