Search in sources :

Example 1 with BrokerRejectionException

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));
    }
}
Also used : IllegalBrokerResponseException(io.camunda.zeebe.gateway.cmd.IllegalBrokerResponseException) BrokerErrorException(io.camunda.zeebe.gateway.cmd.BrokerErrorException) BrokerResponseException(io.camunda.zeebe.gateway.cmd.BrokerResponseException) IllegalBrokerResponseException(io.camunda.zeebe.gateway.cmd.IllegalBrokerResponseException) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) BrokerResponseException(io.camunda.zeebe.gateway.cmd.BrokerResponseException) BrokerErrorException(io.camunda.zeebe.gateway.cmd.BrokerErrorException) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) IllegalBrokerResponseException(io.camunda.zeebe.gateway.cmd.IllegalBrokerResponseException)

Example 2 with BrokerRejectionException

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();
}
Also used : Status(com.google.rpc.Status) InvalidBrokerRequestArgumentException(io.camunda.zeebe.gateway.cmd.InvalidBrokerRequestArgumentException) MsgpackPropertyException(io.camunda.zeebe.msgpack.MsgpackPropertyException) NoTopologyAvailableException(io.camunda.zeebe.gateway.cmd.NoTopologyAvailableException) RequestRetriesExhaustedException(io.camunda.zeebe.gateway.impl.broker.RequestRetriesExhaustedException) Builder(com.google.rpc.Status.Builder) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) PartitionNotFoundException(io.camunda.zeebe.gateway.cmd.PartitionNotFoundException) BrokerErrorException(io.camunda.zeebe.gateway.cmd.BrokerErrorException) ExecutionException(java.util.concurrent.ExecutionException) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) TimeoutException(java.util.concurrent.TimeoutException) ConnectTimeoutException(io.netty.channel.ConnectTimeoutException) ConnectException(java.net.ConnectException)

Example 3 with BrokerRejectionException

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");
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) Test(org.junit.Test)

Example 4 with BrokerRejectionException

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");
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) BrokerCreateProcessInstanceRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) Test(org.junit.Test)

Example 5 with BrokerRejectionException

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")));
}
Also used : BrokerCompleteJobRequest(io.camunda.zeebe.gateway.impl.broker.request.BrokerCompleteJobRequest) BrokerRejection(io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection) BrokerRejectionException(io.camunda.zeebe.gateway.cmd.BrokerRejectionException) Test(org.junit.Test)

Aggregations

BrokerRejectionException (io.camunda.zeebe.gateway.cmd.BrokerRejectionException)12 BrokerErrorException (io.camunda.zeebe.gateway.cmd.BrokerErrorException)6 BrokerRejection (io.camunda.zeebe.gateway.impl.broker.response.BrokerRejection)6 Test (org.junit.Test)6 Status (com.google.rpc.Status)3 Builder (com.google.rpc.Status.Builder)3 BrokerResponseException (io.camunda.zeebe.gateway.cmd.BrokerResponseException)3 IllegalBrokerResponseException (io.camunda.zeebe.gateway.cmd.IllegalBrokerResponseException)3 InvalidBrokerRequestArgumentException (io.camunda.zeebe.gateway.cmd.InvalidBrokerRequestArgumentException)3 NoTopologyAvailableException (io.camunda.zeebe.gateway.cmd.NoTopologyAvailableException)3 PartitionNotFoundException (io.camunda.zeebe.gateway.cmd.PartitionNotFoundException)3 RequestRetriesExhaustedException (io.camunda.zeebe.gateway.impl.broker.RequestRetriesExhaustedException)3 BrokerCompleteJobRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerCompleteJobRequest)3 BrokerCreateProcessInstanceRequest (io.camunda.zeebe.gateway.impl.broker.request.BrokerCreateProcessInstanceRequest)3 MsgpackPropertyException (io.camunda.zeebe.msgpack.MsgpackPropertyException)3 ConnectTimeoutException (io.netty.channel.ConnectTimeoutException)3 ConnectException (java.net.ConnectException)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3