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