Search in sources :

Example 1 with RequestFailure

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

the class AbstractClientHandleTest method backendRespondToRequest.

/**
 * Checks, whether backend actor has received request of expected class wrapped in RequestEnvelope.
 * Then given response wrapped in ResponseEnvelope is sent.
 *
 * @param expectedRequestClass expected request class
 * @param response             response
 * @param <R>                  expected request type
 * @return request message
 */
protected <R extends Request<?, R>> R backendRespondToRequest(final Class<R> expectedRequestClass, final Response<?, ?> response) {
    final RequestEnvelope envelope = backendProbe.expectMsgClass(RequestEnvelope.class);
    Assert.assertEquals(expectedRequestClass, envelope.getMessage().getClass());
    final AbstractClientConnection<ShardBackendInfo> connection = client.getConnection(0L);
    final long sessionId = envelope.getSessionId();
    final long txSequence = envelope.getTxSequence();
    final long executionTime = 0L;
    if (response instanceof RequestSuccess) {
        final RequestSuccess<?, ?> success = (RequestSuccess<?, ?>) response;
        final SuccessEnvelope responseEnvelope = new SuccessEnvelope(success, sessionId, txSequence, executionTime);
        AccessClientUtil.completeRequest(connection, responseEnvelope);
    } else if (response instanceof RequestFailure) {
        final RequestFailure<?, ?> fail = (RequestFailure<?, ?>) response;
        final FailureEnvelope responseEnvelope = new FailureEnvelope(fail, sessionId, txSequence, executionTime);
        AccessClientUtil.completeRequest(connection, responseEnvelope);
    }
    return expectedRequestClass.cast(envelope.getMessage());
}
Also used : SuccessEnvelope(org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope) FailureEnvelope(org.opendaylight.controller.cluster.access.concepts.FailureEnvelope) RequestEnvelope(org.opendaylight.controller.cluster.access.concepts.RequestEnvelope) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure) RequestSuccess(org.opendaylight.controller.cluster.access.concepts.RequestSuccess)

Example 2 with RequestFailure

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

the class RemoteProxyTransaction method recordFailedResponse.

private Exception recordFailedResponse(final Response<?, ?> response) {
    final Exception failure;
    if (response instanceof RequestFailure) {
        failure = ((RequestFailure<?, ?>) response).getCause();
    } else {
        LOG.warn("Unhandled response {}", response);
        failure = new IllegalArgumentException("Unhandled response " + response.getClass());
    }
    if (operationFailure == null) {
        LOG.debug("Transaction {} failed", getIdentifier(), failure);
        operationFailure = failure;
    }
    return failure;
}
Also used : RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure) ReadFailedException(org.opendaylight.mdsal.common.api.ReadFailedException)

Example 3 with RequestFailure

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

the class AbstractProxyTransaction method doCommit.

final void doCommit(final VotingFuture<?> ret) {
    checkReadWrite();
    checkSealed();
    sendRequest(new TransactionDoCommitRequest(getIdentifier(), nextSequence(), localActor()), t -> {
        if (t instanceof TransactionCommitSuccess) {
            ret.voteYes();
        } else if (t instanceof RequestFailure) {
            ret.voteNo(((RequestFailure<?, ?>) t).getCause().unwrap());
        } else {
            ret.voteNo(unhandledResponseException(t));
        }
        LOG.debug("Transaction {} doCommit completed", this);
        // Needed for ProxyHistory$Local data tree rebase points.
        parent.completeTransaction(this);
        enqueuePurge();
    });
}
Also used : TransactionDoCommitRequest(org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest) TransactionCommitSuccess(org.opendaylight.controller.cluster.access.commands.TransactionCommitSuccess) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure)

Example 4 with RequestFailure

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

the class AbstractShardBackendResolver method onConnectResponse.

private void onConnectResponse(final String shardName, final long cookie, final CompletableFuture<ShardBackendInfo> future, final Object response, final Throwable failure) {
    if (failure != null) {
        LOG.debug("Connect attempt to {} failed, will retry", shardName, failure);
        future.completeExceptionally(wrap("Connection attempt failed", failure));
        return;
    }
    if (response instanceof RequestFailure) {
        final Throwable cause = ((RequestFailure<?, ?>) response).getCause().unwrap();
        LOG.debug("Connect attempt to {} failed to process", shardName, cause);
        final Throwable result = cause instanceof NotLeaderException ? wrap("Leader moved during establishment", cause) : cause;
        future.completeExceptionally(result);
        return;
    }
    LOG.debug("Resolved backend information to {}", response);
    Preconditions.checkArgument(response instanceof ConnectClientSuccess, "Unhandled response %s", response);
    final ConnectClientSuccess success = (ConnectClientSuccess) response;
    future.complete(new ShardBackendInfo(success.getBackend(), nextSessionId.getAndIncrement(), success.getVersion(), shardName, UnsignedLong.fromLongBits(cookie), success.getDataTree(), success.getMaxMessages()));
}
Also used : ConnectClientSuccess(org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess) NotLeaderException(org.opendaylight.controller.cluster.access.commands.NotLeaderException) RequestFailure(org.opendaylight.controller.cluster.access.concepts.RequestFailure)

Aggregations

RequestFailure (org.opendaylight.controller.cluster.access.concepts.RequestFailure)4 ConnectClientSuccess (org.opendaylight.controller.cluster.access.commands.ConnectClientSuccess)1 NotLeaderException (org.opendaylight.controller.cluster.access.commands.NotLeaderException)1 TransactionCommitSuccess (org.opendaylight.controller.cluster.access.commands.TransactionCommitSuccess)1 TransactionDoCommitRequest (org.opendaylight.controller.cluster.access.commands.TransactionDoCommitRequest)1 FailureEnvelope (org.opendaylight.controller.cluster.access.concepts.FailureEnvelope)1 RequestEnvelope (org.opendaylight.controller.cluster.access.concepts.RequestEnvelope)1 RequestSuccess (org.opendaylight.controller.cluster.access.concepts.RequestSuccess)1 SuccessEnvelope (org.opendaylight.controller.cluster.access.concepts.SuccessEnvelope)1 ReadFailedException (org.opendaylight.mdsal.common.api.ReadFailedException)1