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());
}
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))));
}
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);
}
}
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);
}
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);
}
}
Aggregations