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