Search in sources :

Example 1 with UnsupportedRequestException

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);
    }
}
Also used : ModifyTransactionSuccess(org.opendaylight.controller.cluster.access.commands.ModifyTransactionSuccess) PersistenceProtocol(org.opendaylight.controller.cluster.access.commands.PersistenceProtocol) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) Nullable(javax.annotation.Nullable)

Example 2 with UnsupportedRequestException

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);
    }
}
Also used : NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) LocalHistoryRequest(org.opendaylight.controller.cluster.access.commands.LocalHistoryRequest) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) TransactionRequest(org.opendaylight.controller.cluster.access.commands.TransactionRequest) Nullable(javax.annotation.Nullable)

Example 3 with UnsupportedRequestException

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);
    }
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)

Aggregations

UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)3 Nullable (javax.annotation.Nullable)2 LocalHistoryRequest (org.opendaylight.controller.cluster.access.commands.LocalHistoryRequest)1 ModifyTransactionSuccess (org.opendaylight.controller.cluster.access.commands.ModifyTransactionSuccess)1 NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)1 PersistenceProtocol (org.opendaylight.controller.cluster.access.commands.PersistenceProtocol)1 TransactionRequest (org.opendaylight.controller.cluster.access.commands.TransactionRequest)1 ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)1 RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)1 RuntimeRequestException (org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException)1 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)1