use of org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException in project controller by opendaylight.
the class FrontendReadWriteTransaction method handleModifyTransaction.
@Nullable
private TransactionSuccess<?> handleModifyTransaction(final ModifyTransactionRequest request, final RequestEnvelope envelope, final long now) throws RequestException {
// We need to examine the persistence protocol first to see if this is an idempotent request. If there is no
// protocol, there is nothing for us to do.
final java.util.Optional<PersistenceProtocol> maybeProto = request.getPersistenceProtocol();
if (!maybeProto.isPresent()) {
applyModifications(request.getModifications());
return replyModifySuccess(request.getSequence());
}
switch(maybeProto.get()) {
case ABORT:
if (ABORTING.equals(state)) {
LOG.debug("{}: Transaction {} already aborting", persistenceId(), getIdentifier());
return null;
}
final ReadWriteShardDataTreeTransaction openTransaction = checkOpen();
startAbort();
openTransaction.abort(() -> {
recordAndSendSuccess(envelope, now, new ModifyTransactionSuccess(getIdentifier(), request.getSequence()));
finishAbort();
});
return null;
case READY:
ensureReady(request.getModifications());
return replyModifySuccess(request.getSequence());
case SIMPLE:
ensureReady(request.getModifications());
directCommit(envelope, now);
return null;
case THREE_PHASE:
ensureReady(request.getModifications());
coordinatedCommit(envelope, now);
return null;
default:
LOG.warn("{}: rejecting unsupported protocol {}", persistenceId(), maybeProto.get());
throw new UnsupportedRequestException(request);
}
}
use of org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException in project controller by opendaylight.
the class Shard method handleRequest.
@Nullable
private RequestSuccess<?, ?> handleRequest(final RequestEnvelope envelope, final long now) throws RequestException {
// We are not the leader, hence we want to fail-fast.
if (!isLeader() || paused || !isLeaderActive()) {
LOG.debug("{}: not currently active leader, rejecting request {}. isLeader: {}, isLeaderActive: {}," + "isLeadershipTransferInProgress: {}, paused: {}", persistenceId(), envelope, isLeader(), isLeaderActive(), isLeadershipTransferInProgress(), paused);
throw new NotLeaderException(getSelf());
}
final Request<?, ?> request = envelope.getMessage();
if (request instanceof TransactionRequest) {
final TransactionRequest<?> txReq = (TransactionRequest<?>) request;
final ClientIdentifier clientId = txReq.getTarget().getHistoryId().getClientId();
return getFrontend(clientId).handleTransactionRequest(txReq, envelope, now);
} else if (request instanceof LocalHistoryRequest) {
final LocalHistoryRequest<?> lhReq = (LocalHistoryRequest<?>) request;
final ClientIdentifier clientId = lhReq.getTarget().getClientId();
return getFrontend(clientId).handleLocalHistoryRequest(lhReq, envelope, now);
} else {
LOG.warn("{}: rejecting unsupported request {}", persistenceId(), request);
throw new UnsupportedRequestException(request);
}
}
use of org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException in project controller by opendaylight.
the class FrontendReadWriteTransaction method handleCommitLocalTransaction.
private void handleCommitLocalTransaction(final CommitLocalTransactionRequest request, final RequestEnvelope envelope, final long now) throws RequestException {
final DataTreeModification sealedModification = checkSealed();
if (!sealedModification.equals(request.getModification())) {
LOG.warn("Expecting modification {}, commit request has {}", sealedModification, request.getModification());
throw new UnsupportedRequestException(request);
}
final java.util.Optional<Exception> optFailure = request.getDelayedFailure();
if (optFailure.isPresent()) {
state = new Ready(history().createFailedCohort(getIdentifier(), sealedModification, optFailure.get()));
} else {
state = new Ready(history().createReadyCohort(getIdentifier(), sealedModification));
}
if (request.isCoordinated()) {
coordinatedCommit(envelope, now);
} else {
directCommit(envelope, now);
}
}
Aggregations