Search in sources :

Example 71 with Errors

use of org.apache.kafka.common.protocol.Errors in project kafka by apache.

the class DescribeProducersRequest method getErrorResponse.

@Override
public DescribeProducersResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    Errors error = Errors.forException(e);
    DescribeProducersResponseData response = new DescribeProducersResponseData();
    for (TopicRequest topicRequest : data.topics()) {
        TopicResponse topicResponse = new TopicResponse().setName(topicRequest.name());
        for (int partitionId : topicRequest.partitionIndexes()) {
            topicResponse.partitions().add(new PartitionResponse().setPartitionIndex(partitionId).setErrorCode(error.code()));
        }
        response.topics().add(topicResponse);
    }
    return new DescribeProducersResponse(response);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) PartitionResponse(org.apache.kafka.common.message.DescribeProducersResponseData.PartitionResponse) TopicRequest(org.apache.kafka.common.message.DescribeProducersRequestData.TopicRequest) TopicResponse(org.apache.kafka.common.message.DescribeProducersResponseData.TopicResponse) DescribeProducersResponseData(org.apache.kafka.common.message.DescribeProducersResponseData)

Example 72 with Errors

use of org.apache.kafka.common.protocol.Errors in project kafka by apache.

the class DescribeQuorumRequest method getPartitionLevelErrorResponse.

public static DescribeQuorumResponseData getPartitionLevelErrorResponse(DescribeQuorumRequestData data, Errors error) {
    short errorCode = error.code();
    List<DescribeQuorumResponseData.TopicData> topicResponses = new ArrayList<>();
    for (DescribeQuorumRequestData.TopicData topic : data.topics()) {
        topicResponses.add(new DescribeQuorumResponseData.TopicData().setTopicName(topic.topicName()).setPartitions(topic.partitions().stream().map(requestPartition -> new DescribeQuorumResponseData.PartitionData().setPartitionIndex(requestPartition.partitionIndex()).setErrorCode(errorCode)).collect(Collectors.toList())));
    }
    return new DescribeQuorumResponseData().setTopics(topicResponses);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) List(java.util.List) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) DescribeQuorumResponseData(org.apache.kafka.common.message.DescribeQuorumResponseData) Errors(org.apache.kafka.common.protocol.Errors) DescribeQuorumRequestData(org.apache.kafka.common.message.DescribeQuorumRequestData) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) Collections(java.util.Collections) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) DescribeQuorumRequestData(org.apache.kafka.common.message.DescribeQuorumRequestData) DescribeQuorumResponseData(org.apache.kafka.common.message.DescribeQuorumResponseData) ArrayList(java.util.ArrayList)

Example 73 with Errors

use of org.apache.kafka.common.protocol.Errors in project kafka by apache.

the class AlterClientQuotasRequest method getErrorResponse.

@Override
public AlterClientQuotasResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    Errors error = Errors.forException(e);
    List<AlterClientQuotasResponseData.EntryData> responseEntries = new ArrayList<>();
    for (EntryData entryData : data.entries()) {
        List<AlterClientQuotasResponseData.EntityData> responseEntities = new ArrayList<>();
        for (EntityData entityData : entryData.entity()) {
            responseEntities.add(new AlterClientQuotasResponseData.EntityData().setEntityType(entityData.entityType()).setEntityName(entityData.entityName()));
        }
        responseEntries.add(new AlterClientQuotasResponseData.EntryData().setEntity(responseEntities).setErrorCode(error.code()).setErrorMessage(error.message()));
    }
    AlterClientQuotasResponseData responseData = new AlterClientQuotasResponseData().setThrottleTimeMs(throttleTimeMs).setEntries(responseEntries);
    return new AlterClientQuotasResponse(responseData);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) EntryData(org.apache.kafka.common.message.AlterClientQuotasRequestData.EntryData) AlterClientQuotasResponseData(org.apache.kafka.common.message.AlterClientQuotasResponseData) ArrayList(java.util.ArrayList) EntityData(org.apache.kafka.common.message.AlterClientQuotasRequestData.EntityData)

Example 74 with Errors

use of org.apache.kafka.common.protocol.Errors in project kafka by apache.

the class KafkaAdminClientTest method testDescribeLogDirsOfflineDir.

@Test
public void testDescribeLogDirsOfflineDir() throws ExecutionException, InterruptedException {
    Set<Integer> brokers = singleton(0);
    String logDir = "/var/data/kafka";
    Errors error = Errors.KAFKA_STORAGE_ERROR;
    try (AdminClientUnitTestEnv env = mockClientEnv()) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        env.kafkaClient().prepareResponseFrom(prepareDescribeLogDirsResponse(error, logDir, emptyList()), env.cluster().nodeById(0));
        DescribeLogDirsResult result = env.adminClient().describeLogDirs(brokers);
        Map<Integer, KafkaFuture<Map<String, LogDirDescription>>> descriptions = result.descriptions();
        assertEquals(brokers, descriptions.keySet());
        assertNotNull(descriptions.get(0));
        Map<String, LogDirDescription> descriptionsMap = descriptions.get(0).get();
        assertEquals(singleton(logDir), descriptionsMap.keySet());
        assertEquals(error.exception().getClass(), descriptionsMap.get(logDir).error().getClass());
        assertEquals(emptySet(), descriptionsMap.get(logDir).replicaInfos().keySet());
        Map<Integer, Map<String, LogDirDescription>> allDescriptions = result.allDescriptions().get();
        assertEquals(brokers, allDescriptions.keySet());
        Map<String, LogDirDescription> allMap = allDescriptions.get(0);
        assertNotNull(allMap);
        assertEquals(singleton(logDir), allMap.keySet());
        assertEquals(error.exception().getClass(), allMap.get(logDir).error().getClass());
        assertEquals(emptySet(), allMap.get(logDir).replicaInfos().keySet());
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) KafkaFuture(org.apache.kafka.common.KafkaFuture) Map(java.util.Map) HashMap(java.util.HashMap) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 75 with Errors

use of org.apache.kafka.common.protocol.Errors in project kafka by apache.

the class KafkaAdminClientTest method testAlterConsumerGroupOffsetsNonRetriableErrors.

@Test
public void testAlterConsumerGroupOffsetsNonRetriableErrors() throws Exception {
    // Non-retriable errors throw an exception
    final TopicPartition tp1 = new TopicPartition("foo", 0);
    final List<Errors> nonRetriableErrors = Arrays.asList(Errors.GROUP_AUTHORIZATION_FAILED, Errors.INVALID_GROUP_ID, Errors.GROUP_ID_NOT_FOUND);
    try (AdminClientUnitTestEnv env = new AdminClientUnitTestEnv(mockCluster(1, 0))) {
        env.kafkaClient().setNodeApiVersions(NodeApiVersions.create());
        for (Errors error : nonRetriableErrors) {
            env.kafkaClient().prepareResponse(prepareFindCoordinatorResponse(Errors.NONE, env.cluster().controller()));
            env.kafkaClient().prepareResponse(prepareOffsetCommitResponse(tp1, error));
            Map<TopicPartition, OffsetAndMetadata> offsets = new HashMap<>();
            offsets.put(tp1, new OffsetAndMetadata(123L));
            AlterConsumerGroupOffsetsResult errorResult = env.adminClient().alterConsumerGroupOffsets(GROUP_ID, offsets);
            TestUtils.assertFutureError(errorResult.all(), error.exception().getClass());
            TestUtils.assertFutureError(errorResult.partitionResult(tp1), error.exception().getClass());
        }
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) OffsetAndMetadata(org.apache.kafka.clients.consumer.OffsetAndMetadata) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Aggregations

Errors (org.apache.kafka.common.protocol.Errors)167 HashMap (java.util.HashMap)115 TopicPartition (org.apache.kafka.common.TopicPartition)87 Map (java.util.Map)61 ArrayList (java.util.ArrayList)46 LinkedHashMap (java.util.LinkedHashMap)31 Test (org.junit.jupiter.api.Test)31 List (java.util.List)19 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)19 HashSet (java.util.HashSet)18 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)18 InvalidTopicException (org.apache.kafka.common.errors.InvalidTopicException)17 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)17 MetadataResponse (org.apache.kafka.common.requests.MetadataResponse)17 KafkaException (org.apache.kafka.common.KafkaException)16 Node (org.apache.kafka.common.Node)16 Cluster (org.apache.kafka.common.Cluster)15 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)14 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)14 Collections (java.util.Collections)13