Search in sources :

Example 6 with ModifyTransactionRequest

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

the class RemoteProxyTransactionTest method testForwardToRemoteModifyAbort.

@Test
public void testForwardToRemoteModifyAbort() throws Exception {
    final TestProbe probe = createProbe();
    final ModifyTransactionRequestBuilder builder = new ModifyTransactionRequestBuilder(TRANSACTION_ID, probe.ref());
    builder.setSequence(0L);
    builder.setAbort();
    final ModifyTransactionRequest request = builder.build();
    final ModifyTransactionRequest received = testForwardToRemote(request, ModifyTransactionRequest.class);
    Assert.assertEquals(request.getTarget(), received.getTarget());
    Assert.assertTrue(received.getPersistenceProtocol().isPresent());
    Assert.assertEquals(PersistenceProtocol.ABORT, received.getPersistenceProtocol().get());
}
Also used : ModifyTransactionRequestBuilder(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder) TestProbe(akka.testkit.TestProbe) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) Test(org.junit.Test)

Example 7 with ModifyTransactionRequest

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

the class RemoteProxyTransactionTest method testModification.

private <T extends TransactionModification> void testModification(final Runnable modification, final Class<T> cls, final YangInstanceIdentifier expectedPath) {
    modification.run();
    final ModifyTransactionRequest request = transaction.commitRequest(false);
    final List<TransactionModification> modifications = request.getModifications();
    Assert.assertEquals(1, modifications.size());
    Assert.assertThat(modifications, hasItem(both(isA(cls)).and(hasPath(expectedPath))));
}
Also used : TransactionModification(org.opendaylight.controller.cluster.access.commands.TransactionModification) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)

Example 8 with ModifyTransactionRequest

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

the class RemoteProxyTransaction method handleReplayedRemoteRequest.

@Override
void handleReplayedRemoteRequest(final TransactionRequest<?> request, @Nullable final Consumer<Response<?, ?>> callback, final long enqueuedTicks) {
    final Consumer<Response<?, ?>> cb = callback != null ? callback : resp -> {
    };
    final Optional<Long> optTicks = Optional.of(Long.valueOf(enqueuedTicks));
    if (request instanceof ModifyTransactionRequest) {
        handleReplayedModifyTransactionRequest(enqueuedTicks, cb, (ModifyTransactionRequest) request);
    } else if (request instanceof ReadTransactionRequest) {
        ensureFlushedBuider(optTicks);
        enqueueRequest(new ReadTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ReadTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            cb.accept(resp);
        }, enqueuedTicks);
    } else if (request instanceof ExistsTransactionRequest) {
        ensureFlushedBuider(optTicks);
        enqueueRequest(new ExistsTransactionRequest(getIdentifier(), nextSequence(), localActor(), ((ExistsTransactionRequest) request).getPath(), isSnapshotOnly()), resp -> {
            recordFinishedRequest(resp);
            cb.accept(resp);
        }, enqueuedTicks);
    } else if (request instanceof TransactionPreCommitRequest) {
        ensureFlushedBuider(optTicks);
        final TransactionRequest<?> tmp = new TransactionPreCommitRequest(getIdentifier(), nextSequence(), localActor());
        enqueueRequest(tmp, resp -> {
            recordSuccessfulRequest(tmp);
            cb.accept(resp);
        }, enqueuedTicks);
    } else if (request instanceof TransactionDoCommitRequest) {
        ensureFlushedBuider(optTicks);
        enqueueRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), callback, enqueuedTicks);
    } else if (request instanceof TransactionAbortRequest) {
        ensureFlushedBuider(optTicks);
        enqueueDoAbort(callback, enqueuedTicks);
    } else if (request instanceof TransactionPurgeRequest) {
        enqueuePurge(callback, enqueuedTicks);
    } else if (request instanceof IncrementTransactionSequenceRequest) {
        final IncrementTransactionSequenceRequest req = (IncrementTransactionSequenceRequest) request;
        ensureFlushedBuider(optTicks);
        enqueueRequest(new IncrementTransactionSequenceRequest(getIdentifier(), nextSequence(), localActor(), snapshotOnly, req.getIncrement()), callback, enqueuedTicks);
        incrementSequence(req.getIncrement());
    } 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) TransactionPurgeRequest(org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest) AbstractReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.AbstractReadTransactionRequest) ReadTransactionRequest(org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest) 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) Response(org.opendaylight.controller.cluster.access.concepts.Response) TransactionDoCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest) ExistsTransactionRequest(org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest) IncrementTransactionSequenceRequest(org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest) TransactionAbortRequest(org.opendaylight.controller.cluster.access.commands.TransactionAbortRequest) ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest) TransactionPreCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionPreCommitRequest)

Example 9 with ModifyTransactionRequest

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

the class RemoteProxyTransaction method flushState.

@Override
java.util.Optional<ModifyTransactionRequest> flushState() {
    if (!builderBusy) {
        return java.util.Optional.empty();
    }
    final ModifyTransactionRequest request = builder.build();
    builderBusy = false;
    return java.util.Optional.of(request);
}
Also used : ModifyTransactionRequest(org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)

Example 10 with ModifyTransactionRequest

use of org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest 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)

Aggregations

ModifyTransactionRequest (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequest)21 Test (org.junit.Test)12 TestProbe (akka.testkit.TestProbe)10 ModifyTransactionRequestBuilder (org.opendaylight.controller.cluster.access.commands.ModifyTransactionRequestBuilder)9 AbortLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbortLocalTransactionRequest)5 CommitLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.CommitLocalTransactionRequest)5 Response (org.opendaylight.controller.cluster.access.concepts.Response)5 TransactionModification (org.opendaylight.controller.cluster.access.commands.TransactionModification)4 AbstractLocalTransactionRequest (org.opendaylight.controller.cluster.access.commands.AbstractLocalTransactionRequest)3 ExistsTransactionRequest (org.opendaylight.controller.cluster.access.commands.ExistsTransactionRequest)3 IncrementTransactionSequenceRequest (org.opendaylight.controller.cluster.access.commands.IncrementTransactionSequenceRequest)3 ReadTransactionRequest (org.opendaylight.controller.cluster.access.commands.ReadTransactionRequest)3 TransactionDelete (org.opendaylight.controller.cluster.access.commands.TransactionDelete)3 TransactionMerge (org.opendaylight.controller.cluster.access.commands.TransactionMerge)3 TransactionPurgeRequest (org.opendaylight.controller.cluster.access.commands.TransactionPurgeRequest)3 TransactionRequest (org.opendaylight.controller.cluster.access.commands.TransactionRequest)3 TransactionWrite (org.opendaylight.controller.cluster.access.commands.TransactionWrite)3 AbstractDataTreeModificationCursor (org.opendaylight.controller.cluster.datastore.util.AbstractDataTreeModificationCursor)3 Optional (com.google.common.base.Optional)2 CheckedFuture (com.google.common.util.concurrent.CheckedFuture)2