Search in sources :

Example 6 with TransactionalIdAuthorizationException

use of org.apache.kafka.common.errors.TransactionalIdAuthorizationException in project kafka by apache.

the class TransactionManagerTest method testTransactionalIdAuthorizationFailureInAddOffsetsToTxn.

@Test
public void testTransactionalIdAuthorizationFailureInAddOffsetsToTxn() {
    final TopicPartition tp = new TopicPartition("foo", 0);
    doInitTransactions();
    transactionManager.beginTransaction();
    TransactionalRequestResult sendOffsetsResult = transactionManager.sendOffsetsToTransaction(singletonMap(tp, new OffsetAndMetadata(39L)), new ConsumerGroupMetadata(consumerGroupId));
    prepareAddOffsetsToTxnResponse(Errors.TRANSACTIONAL_ID_AUTHORIZATION_FAILED, consumerGroupId, producerId, epoch);
    runUntil(transactionManager::hasError);
    assertTrue(transactionManager.lastError() instanceof TransactionalIdAuthorizationException);
    assertTrue(sendOffsetsResult.isCompleted());
    assertFalse(sendOffsetsResult.isSuccessful());
    assertTrue(sendOffsetsResult.error() instanceof TransactionalIdAuthorizationException);
    assertFatalError(TransactionalIdAuthorizationException.class);
}
Also used : ConsumerGroupMetadata(org.apache.kafka.clients.consumer.ConsumerGroupMetadata) TransactionalIdAuthorizationException(org.apache.kafka.common.errors.TransactionalIdAuthorizationException) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) Test(org.junit.jupiter.api.Test)

Example 7 with TransactionalIdAuthorizationException

use of org.apache.kafka.common.errors.TransactionalIdAuthorizationException in project kafka by apache.

the class DescribeTransactionsHandler method handleError.

private void handleError(CoordinatorKey transactionalIdKey, Errors error, Map<CoordinatorKey, Throwable> failed, List<CoordinatorKey> unmapped) {
    switch(error) {
        case TRANSACTIONAL_ID_AUTHORIZATION_FAILED:
            failed.put(transactionalIdKey, new TransactionalIdAuthorizationException("DescribeTransactions request for transactionalId `" + transactionalIdKey.idValue + "` " + "failed due to authorization failure"));
            break;
        case TRANSACTIONAL_ID_NOT_FOUND:
            failed.put(transactionalIdKey, new TransactionalIdNotFoundException("DescribeTransactions request for transactionalId `" + transactionalIdKey.idValue + "` " + "failed because the ID could not be found"));
            break;
        case COORDINATOR_LOAD_IN_PROGRESS:
            // If the coordinator is in the middle of loading, then we just need to retry
            log.debug("DescribeTransactions request for transactionalId `{}` failed because the " + "coordinator is still in the process of loading state. Will retry", transactionalIdKey.idValue);
            break;
        case NOT_COORDINATOR:
        case COORDINATOR_NOT_AVAILABLE:
            // If the coordinator is unavailable or there was a coordinator change, then we unmap
            // the key so that we retry the `FindCoordinator` request
            unmapped.add(transactionalIdKey);
            log.debug("DescribeTransactions request for transactionalId `{}` returned error {}. Will attempt " + "to find the coordinator again and retry", transactionalIdKey.idValue, error);
            break;
        default:
            failed.put(transactionalIdKey, error.exception("DescribeTransactions request for " + "transactionalId `" + transactionalIdKey.idValue + "` failed due to unexpected error"));
    }
}
Also used : TransactionalIdNotFoundException(org.apache.kafka.common.errors.TransactionalIdNotFoundException) TransactionalIdAuthorizationException(org.apache.kafka.common.errors.TransactionalIdAuthorizationException)

Aggregations

TransactionalIdAuthorizationException (org.apache.kafka.common.errors.TransactionalIdAuthorizationException)7 TopicPartition (org.apache.kafka.common.TopicPartition)6 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)4 Test (org.junit.Test)3 Test (org.junit.jupiter.api.Test)3 ConsumerGroupMetadata (org.apache.kafka.clients.consumer.ConsumerGroupMetadata)2 TransactionalIdNotFoundException (org.apache.kafka.common.errors.TransactionalIdNotFoundException)1