Search in sources :

Example 1 with RequestException

use of org.opendaylight.controller.cluster.access.concepts.RequestException in project controller by opendaylight.

the class Shard method handleConnectClient.

@SuppressWarnings("checkstyle:IllegalCatch")
private void handleConnectClient(final ConnectClientRequest message) {
    try {
        final ClientIdentifier clientId = message.getTarget();
        final LeaderFrontendState existing = findFrontend(clientId);
        if (existing != null) {
            existing.touch();
        }
        if (!isLeader() || !isLeaderActive()) {
            LOG.info("{}: not currently leader, rejecting request {}. isLeader: {}, isLeaderActive: {}," + "isLeadershipTransferInProgress: {}.", persistenceId(), message, isLeader(), isLeaderActive(), isLeadershipTransferInProgress());
            throw new NotLeaderException(getSelf());
        }
        final ABIVersion selectedVersion = selectVersion(message);
        final LeaderFrontendState frontend;
        if (existing == null) {
            frontend = new LeaderFrontendState(persistenceId(), clientId, store);
            knownFrontends.put(clientId.getFrontendId(), frontend);
            LOG.debug("{}: created state {} for client {}", persistenceId(), frontend, clientId);
        } else {
            frontend = existing;
        }
        frontend.reconnect();
        message.getReplyTo().tell(new ConnectClientSuccess(message.getTarget(), message.getSequence(), getSelf(), ImmutableList.of(), store.getDataTree(), CLIENT_MAX_MESSAGES).toVersion(selectedVersion), ActorRef.noSender());
    } catch (RequestException | RuntimeException e) {
        message.getReplyTo().tell(new Failure(e), ActorRef.noSender());
    }
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) ClientIdentifier(org.opendaylight.controller.cluster.access.concepts.ClientIdentifier) ABIVersion(org.opendaylight.controller.cluster.access.ABIVersion) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) UnsupportedRequestException(org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) Failure(akka.actor.Status.Failure)

Example 2 with RequestException

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

Example 3 with RequestException

use of org.opendaylight.controller.cluster.access.concepts.RequestException in project controller by opendaylight.

the class AbstractTransactionRequestTest method toRequestFailureTest.

@Test
public void toRequestFailureTest() {
    final Throwable cause = new Throwable();
    final RequestException exception = new RuntimeRequestException("fail", cause);
    final TransactionFailure failure = object().toRequestFailure(exception);
    Assert.assertNotNull(failure);
}
Also used : RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) AbstractRequestTest(org.opendaylight.controller.cluster.access.concepts.AbstractRequestTest) Test(org.junit.Test)

Example 4 with RequestException

use of org.opendaylight.controller.cluster.access.concepts.RequestException in project controller by opendaylight.

the class ConnectClientRequestTest method toRequestFailureTest.

@Test
public void toRequestFailureTest() throws Exception {
    final RequestException exception = new DeadTransactionException(ImmutableRangeSet.of());
    final ConnectClientFailure failure = OBJECT.toRequestFailure(exception);
    Assert.assertNotNull(failure);
}
Also used : RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) AbstractRequestTest(org.opendaylight.controller.cluster.access.concepts.AbstractRequestTest) Test(org.junit.Test)

Example 5 with RequestException

use of org.opendaylight.controller.cluster.access.concepts.RequestException in project controller by opendaylight.

the class ClientActorBehavior method internalOnRequestFailure.

private ClientActorBehavior<T> internalOnRequestFailure(final FailureEnvelope command) {
    final AbstractClientConnection<T> conn = getConnection(command);
    if (conn != null) {
        /*
             * We are talking to multiple actors, which may be lagging behind our state significantly. This has
             * the effect that we may be receiving responses from a previous connection after we have created a new
             * one to a different actor.
             *
             * Since we are already replaying requests to the new actor, we want to ignore errors reported on the old
             * connection -- for example NotLeaderException, which must not cause a new reconnect. Check the envelope's
             * sessionId and if it does not match our current connection just ignore it.
             */
        final Optional<T> optBackend = conn.getBackendInfo();
        if (optBackend.isPresent() && optBackend.get().getSessionId() != command.getSessionId()) {
            LOG.debug("{}: Mismatched current connection {} and envelope {}, ignoring response", persistenceId(), conn, command);
            return this;
        }
    }
    final RequestFailure<?, ?> failure = command.getMessage();
    final RequestException cause = failure.getCause();
    if (cause instanceof RetiredGenerationException) {
        LOG.error("{}: current generation {} has been superseded", persistenceId(), getIdentifier(), cause);
        haltClient(cause);
        poison(cause);
        return null;
    }
    if (cause instanceof NotLeaderException) {
        if (conn instanceof ReconnectingClientConnection) {
            // Already reconnecting, do not churn the logs
            return this;
        } else if (conn != null) {
            LOG.info("{}: connection {} indicated no leadership, reconnecting it", persistenceId(), conn, cause);
            return conn.reconnect(this, cause);
        }
    }
    if (cause instanceof OutOfSequenceEnvelopeException) {
        if (conn instanceof ReconnectingClientConnection) {
            // Already reconnecting, do not churn the logs
            return this;
        } else if (conn != null) {
            LOG.info("{}: connection {} indicated sequencing mismatch on {} sequence {} ({}), reconnecting it", persistenceId(), conn, failure.getTarget(), failure.getSequence(), command.getTxSequence(), cause);
            return conn.reconnect(this, cause);
        }
    }
    return onRequestFailure(command);
}
Also used : NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) OutOfSequenceEnvelopeException(org.opendaylight.controller.cluster.access.commands.OutOfSequenceEnvelopeException) RuntimeRequestException(org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException) RequestException(org.opendaylight.controller.cluster.access.concepts.RequestException) RetiredGenerationException(org.opendaylight.controller.cluster.access.concepts.RetiredGenerationException)

Aggregations

RequestException (org.opendaylight.controller.cluster.access.concepts.RequestException)6 RuntimeRequestException (org.opendaylight.controller.cluster.access.concepts.RuntimeRequestException)5 Test (org.junit.Test)2 NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)2 AbstractRequestTest (org.opendaylight.controller.cluster.access.concepts.AbstractRequestTest)2 UnsupportedRequestException (org.opendaylight.controller.cluster.access.concepts.UnsupportedRequestException)2 Failure (akka.actor.Status.Failure)1 Stopwatch (com.google.common.base.Stopwatch)1 TimeoutException (java.util.concurrent.TimeoutException)1 ABIVersion (org.opendaylight.controller.cluster.access.ABIVersion)1 ConnectClientSuccess (org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess)1 OutOfSequenceEnvelopeException (org.opendaylight.controller.cluster.access.commands.OutOfSequenceEnvelopeException)1 ClientIdentifier (org.opendaylight.controller.cluster.access.concepts.ClientIdentifier)1 RetiredGenerationException (org.opendaylight.controller.cluster.access.concepts.RetiredGenerationException)1 DataTreeModification (org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification)1