use of io.camunda.zeebe.gateway.cmd.BrokerRejectionException in project zeebe by camunda.
the class StubbedBrokerClient method sendRequestWithRetry.
@Override
public <T> void sendRequestWithRetry(final BrokerRequest<T> request, final BrokerResponseConsumer<T> responseConsumer, final Consumer<Throwable> throwableConsumer) {
brokerRequests.add(request);
try {
final RequestHandler requestHandler = requestHandlers.get(request.getClass());
final BrokerResponse<T> response = requestHandler.handle(request);
try {
if (response.isResponse()) {
responseConsumer.accept(response.getKey(), response.getResponse());
} else if (response.isRejection()) {
throwableConsumer.accept(new BrokerRejectionException(response.getRejection()));
} else if (response.isError()) {
throwableConsumer.accept(new BrokerErrorException(response.getError()));
} else {
throwableConsumer.accept(new IllegalBrokerResponseException("Expected broker response to be either response, rejection, or error, but is neither of them []"));
}
} catch (final RuntimeException e) {
throwableConsumer.accept(new BrokerResponseException(e));
}
} catch (final Exception e) {
throwableConsumer.accept(new BrokerResponseException(e));
}
}
use of io.camunda.zeebe.gateway.cmd.BrokerRejectionException in project zeebe by camunda-cloud.
the class GrpcErrorMapper method mapErrorToStatus.
private Status mapErrorToStatus(final Throwable rootError, final Throwable error, final Logger logger) {
final Builder builder = Status.newBuilder();
if (error instanceof ExecutionException) {
return mapErrorToStatus(rootError, error.getCause(), logger);
} else if (error instanceof BrokerErrorException) {
final Status status = mapBrokerErrorToStatus(rootError, ((BrokerErrorException) error).getError(), logger);
builder.mergeFrom(status);
} else if (error instanceof BrokerRejectionException) {
final Status status = mapRejectionToStatus(((BrokerRejectionException) error).getRejection());
builder.mergeFrom(status);
logger.trace("Expected to handle gRPC request, but the broker rejected it", rootError);
} else if (error instanceof TimeoutException) {
// can be thrown by transport
builder.setCode(Code.DEADLINE_EXCEEDED_VALUE).setMessage("Time out between gateway and broker: " + error.getMessage());
logger.debug("Expected to handle gRPC request, but request timed out between gateway and broker", rootError);
} else if (error instanceof InvalidBrokerRequestArgumentException) {
builder.setCode(Code.INVALID_ARGUMENT_VALUE).setMessage(error.getMessage());
logger.debug("Expected to handle gRPC request, but broker argument was invalid", rootError);
} else if (error instanceof MsgpackPropertyException) {
builder.setCode(Code.INVALID_ARGUMENT_VALUE).setMessage(error.getMessage());
logger.debug("Expected to handle gRPC request, but messagepack property was invalid", rootError);
} else if (error instanceof PartitionNotFoundException) {
builder.setCode(Code.UNAVAILABLE_VALUE).setMessage(error.getMessage());
logger.debug("Expected to handle gRPC request, but request could not be delivered", rootError);
} else if (error instanceof RequestRetriesExhaustedException) {
builder.setCode(Code.RESOURCE_EXHAUSTED_VALUE).setMessage(error.getMessage());
// added/mapped as error details to give more information to the user
for (final Throwable suppressed : error.getSuppressed()) {
builder.addDetails(Any.pack(mapErrorToStatus(rootError, suppressed, NOPLogger.NOP_LOGGER)));
}
// this error occurs when all partitions have exhausted for requests which have no fixed
// partitions - it will then also occur when back pressure kicks in, leading to a large burst
// of error logs that is, in fact, expected
logger.trace("Expected to handle gRPC request, but all retries have been exhausted", rootError);
} else if (error instanceof NoTopologyAvailableException) {
builder.setCode(Code.UNAVAILABLE_VALUE).setMessage(error.getMessage());
logger.trace("Expected to handle gRPC request, but the gateway does not know any partitions yet", rootError);
} else if (error instanceof ConnectTimeoutException) {
builder.setCode(Code.UNAVAILABLE_VALUE).setMessage(error.getMessage());
logger.warn("Expected to handle gRPC request, but a connection timeout exception occurred", rootError);
} else if (error instanceof ConnectException) {
builder.setCode(Code.UNAVAILABLE_VALUE).setMessage(error.getMessage());
logger.warn("Expected to handle gRPC request, but there was a connection error with one of the brokers", rootError);
} else {
builder.setCode(Code.INTERNAL_VALUE).setMessage("Unexpected error occurred during the request processing: " + error.getMessage());
logger.error("Expected to handle gRPC request, but an unexpected error occurred", rootError);
}
return builder.build();
}
use of io.camunda.zeebe.gateway.cmd.BrokerRejectionException in project zeebe by camunda-cloud.
the class GatewayIntegrationTest method shouldReturnRejectionWithCorrectTypeAndReason.
@Test
public void shouldReturnRejectionWithCorrectTypeAndReason() throws InterruptedException {
// given
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> errorResponse = new AtomicReference<>();
// when
client.sendRequestWithRetry(new BrokerCreateProcessInstanceRequest(), (k, r) -> {
}, error -> {
errorResponse.set(error);
latch.countDown();
});
// then
latch.await();
final var error = errorResponse.get();
assertThat(error).isInstanceOf(BrokerRejectionException.class);
final BrokerRejection rejection = ((BrokerRejectionException) error).getRejection();
assertThat(rejection.getType()).isEqualTo(RejectionType.INVALID_ARGUMENT);
assertThat(rejection.getReason()).isEqualTo("Expected at least a bpmnProcessId or a key greater than -1, but none given");
}
use of io.camunda.zeebe.gateway.cmd.BrokerRejectionException in project zeebe by zeebe-io.
the class GatewayIntegrationTest method shouldReturnRejectionWithCorrectTypeAndReason.
@Test
public void shouldReturnRejectionWithCorrectTypeAndReason() throws InterruptedException {
// given
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> errorResponse = new AtomicReference<>();
// when
client.sendRequestWithRetry(new BrokerCreateProcessInstanceRequest(), (k, r) -> {
}, error -> {
errorResponse.set(error);
latch.countDown();
});
// then
latch.await();
final var error = errorResponse.get();
assertThat(error).isInstanceOf(BrokerRejectionException.class);
final BrokerRejection rejection = ((BrokerRejectionException) error).getRejection();
assertThat(rejection.getType()).isEqualTo(RejectionType.INVALID_ARGUMENT);
assertThat(rejection.getReason()).isEqualTo("Expected at least a bpmnProcessId or a key greater than -1, but none given");
}
use of io.camunda.zeebe.gateway.cmd.BrokerRejectionException in project zeebe by zeebe-io.
the class BrokerClientTest method shouldReturnRejectionWithCorrectTypeAndReason.
@Test
public void shouldReturnRejectionWithCorrectTypeAndReason() {
// given
broker.jobs().registerCompleteCommand(b -> b.rejection(RejectionType.INVALID_ARGUMENT, "foo"));
// when
final var responseFuture = client.sendRequestWithRetry(new BrokerCompleteJobRequest(Protocol.encodePartitionId(Protocol.DEPLOYMENT_PARTITION, 79), DocumentValue.EMPTY_DOCUMENT));
// then
assertThatThrownBy(responseFuture::join).hasCauseInstanceOf(BrokerRejectionException.class).hasCause(new BrokerRejectionException(new BrokerRejection(JobIntent.COMPLETE, Protocol.encodePartitionId(Protocol.DEPLOYMENT_PARTITION, 79), RejectionType.INVALID_ARGUMENT, "foo")));
}
Aggregations