Search in sources :

Example 16 with Errors

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

the class StopReplicaResponse method toStruct.

@Override
protected Struct toStruct(short version) {
    Struct struct = new Struct(ApiKeys.STOP_REPLICA.responseSchema(version));
    List<Struct> responseDatas = new ArrayList<>(responses.size());
    for (Map.Entry<TopicPartition, Errors> response : responses.entrySet()) {
        Struct partitionData = struct.instance(PARTITIONS_KEY_NAME);
        TopicPartition partition = response.getKey();
        partitionData.set(PARTITIONS_TOPIC_KEY_NAME, partition.topic());
        partitionData.set(PARTITIONS_PARTITION_KEY_NAME, partition.partition());
        partitionData.set(PARTITIONS_ERROR_CODE_KEY_NAME, response.getValue().code());
        responseDatas.add(partitionData);
    }
    struct.set(PARTITIONS_KEY_NAME, responseDatas.toArray());
    struct.set(ERROR_CODE_KEY_NAME, error.code());
    return struct;
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) TopicPartition(org.apache.kafka.common.TopicPartition) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap) Struct(org.apache.kafka.common.protocol.types.Struct)

Example 17 with Errors

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

the class LeaderAndIsrRequest method getErrorResponse.

@Override
public AbstractResponse getErrorResponse(Throwable e) {
    Map<TopicPartition, Errors> responses = new HashMap<>(partitionStates.size());
    for (TopicPartition partition : partitionStates.keySet()) {
        responses.put(partition, Errors.forException(e));
    }
    short versionId = version();
    switch(versionId) {
        case 0:
            return new LeaderAndIsrResponse(Errors.NONE, responses);
        default:
            throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.LEADER_AND_ISR.latestVersion()));
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition)

Example 18 with Errors

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

the class StopReplicaRequest method getErrorResponse.

@Override
public AbstractResponse getErrorResponse(Throwable e) {
    Map<TopicPartition, Errors> responses = new HashMap<>(partitions.size());
    for (TopicPartition partition : partitions) {
        responses.put(partition, Errors.forException(e));
    }
    short versionId = version();
    switch(versionId) {
        case 0:
            return new StopReplicaResponse(Errors.NONE, responses);
        default:
            throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.STOP_REPLICA.latestVersion()));
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition)

Aggregations

Errors (org.apache.kafka.common.protocol.Errors)18 HashMap (java.util.HashMap)16 TopicPartition (org.apache.kafka.common.TopicPartition)12 LinkedHashMap (java.util.LinkedHashMap)9 ArrayList (java.util.ArrayList)7 Map (java.util.Map)7 Struct (org.apache.kafka.common.protocol.types.Struct)4 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)3 List (java.util.List)2 KafkaException (org.apache.kafka.common.KafkaException)2 OffsetCommitResponse (org.apache.kafka.common.requests.OffsetCommitResponse)2 Test (org.junit.Test)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 ClientResponse (org.apache.kafka.clients.ClientResponse)1 MockClient (org.apache.kafka.clients.MockClient)1 OffsetOutOfRangeException (org.apache.kafka.clients.consumer.OffsetOutOfRangeException)1 Cluster (org.apache.kafka.common.Cluster)1 InvalidMetadataException (org.apache.kafka.common.errors.InvalidMetadataException)1 InvalidTopicException (org.apache.kafka.common.errors.InvalidTopicException)1 RecordTooLargeException (org.apache.kafka.common.errors.RecordTooLargeException)1