Search in sources :

Example 36 with Errors

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

the class FetchSnapshotResponse method errorCounts.

@Override
public Map<Errors, Integer> errorCounts() {
    Map<Errors, Integer> errors = new HashMap<>();
    Errors topLevelError = Errors.forCode(data.errorCode());
    if (topLevelError != Errors.NONE) {
        errors.put(topLevelError, 1);
    }
    for (FetchSnapshotResponseData.TopicSnapshot topicResponse : data.topics()) {
        for (FetchSnapshotResponseData.PartitionSnapshot partitionResponse : topicResponse.partitions()) {
            errors.compute(Errors.forCode(partitionResponse.errorCode()), (error, count) -> count == null ? 1 : count + 1);
        }
    }
    return errors;
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) FetchSnapshotResponseData(org.apache.kafka.common.message.FetchSnapshotResponseData) HashMap(java.util.HashMap)

Example 37 with Errors

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

the class DescribeTransactionsResponse method errorCounts.

@Override
public Map<Errors, Integer> errorCounts() {
    Map<Errors, Integer> errorCounts = new HashMap<>();
    for (TransactionState transactionState : data.transactionStates()) {
        Errors error = Errors.forCode(transactionState.errorCode());
        updateErrorCounts(errorCounts, error);
    }
    return errorCounts;
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) TransactionState(org.apache.kafka.common.message.DescribeTransactionsResponseData.TransactionState) HashMap(java.util.HashMap)

Example 38 with Errors

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

the class OffsetFetchResponse method errorCounts.

@Override
public Map<Errors, Integer> errorCounts() {
    Map<Errors, Integer> counts = new HashMap<>();
    if (!groupLevelErrors.isEmpty()) {
        // built response with v8 or above
        for (Map.Entry<String, Errors> entry : groupLevelErrors.entrySet()) {
            updateErrorCounts(counts, entry.getValue());
        }
        for (OffsetFetchResponseGroup group : data.groups()) {
            group.topics().forEach(topic -> topic.partitions().forEach(partition -> updateErrorCounts(counts, Errors.forCode(partition.errorCode()))));
        }
    } else {
        // built response with v0-v7
        updateErrorCounts(counts, error);
        data.topics().forEach(topic -> topic.partitions().forEach(partition -> updateErrorCounts(counts, Errors.forCode(partition.errorCode()))));
    }
    return counts;
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) Arrays(java.util.Arrays) OffsetFetchResponseTopic(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopic) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) HashMap(java.util.HashMap) NO_PARTITION_LEADER_EPOCH(org.apache.kafka.common.record.RecordBatch.NO_PARTITION_LEADER_EPOCH) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) Collectors(java.util.stream.Collectors) ByteBuffer(java.nio.ByteBuffer) ArrayList(java.util.ArrayList) Objects(java.util.Objects) OffsetFetchResponsePartition(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartition) List(java.util.List) OffsetFetchResponseData(org.apache.kafka.common.message.OffsetFetchResponseData) Map(java.util.Map) Entry(java.util.Map.Entry) Errors(org.apache.kafka.common.protocol.Errors) Optional(java.util.Optional) OffsetFetchResponseTopics(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseTopics) OffsetFetchResponsePartitions(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponsePartitions) Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) OffsetFetchResponseGroup(org.apache.kafka.common.message.OffsetFetchResponseData.OffsetFetchResponseGroup) HashMap(java.util.HashMap) Map(java.util.Map)

Example 39 with Errors

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

the class DescribeTransactionsRequest method getErrorResponse.

@Override
public DescribeTransactionsResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    Errors error = Errors.forException(e);
    DescribeTransactionsResponseData response = new DescribeTransactionsResponseData().setThrottleTimeMs(throttleTimeMs);
    for (String transactionalId : data.transactionalIds()) {
        DescribeTransactionsResponseData.TransactionState transactionState = new DescribeTransactionsResponseData.TransactionState().setTransactionalId(transactionalId).setErrorCode(error.code());
        response.transactionStates().add(transactionState);
    }
    return new DescribeTransactionsResponse(response);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) DescribeTransactionsResponseData(org.apache.kafka.common.message.DescribeTransactionsResponseData)

Example 40 with Errors

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

the class UpdateFeaturesResponse method errorCounts.

@Override
public Map<Errors, Integer> errorCounts() {
    Map<Errors, Integer> errorCounts = new HashMap<>();
    updateErrorCounts(errorCounts, Errors.forCode(data.errorCode()));
    for (UpdatableFeatureResult result : data.results()) {
        updateErrorCounts(errorCounts, Errors.forCode(result.errorCode()));
    }
    return errorCounts;
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) UpdatableFeatureResult(org.apache.kafka.common.message.UpdateFeaturesResponseData.UpdatableFeatureResult)

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