Search in sources :

Example 6 with LeaderAndIsrPartitionError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError in project kafka by apache.

the class LeaderAndIsrResponseTest method createTopic.

private LeaderAndIsrTopicErrorCollection createTopic(Uuid id, List<Errors> errors) {
    LeaderAndIsrTopicErrorCollection topics = new LeaderAndIsrTopicErrorCollection();
    LeaderAndIsrTopicError topic = new LeaderAndIsrTopicError();
    topic.setTopicId(id);
    List<LeaderAndIsrPartitionError> partitions = new ArrayList<>();
    int partitionIndex = 0;
    for (Errors error : errors) {
        partitions.add(new LeaderAndIsrPartitionError().setPartitionIndex(partitionIndex++).setErrorCode(error.code()));
    }
    topic.setPartitionErrors(partitions);
    topics.add(topic);
    return topics;
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Errors(org.apache.kafka.common.protocol.Errors) LeaderAndIsrTopicErrorCollection(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicErrorCollection) ArrayList(java.util.ArrayList) LeaderAndIsrTopicError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError)

Example 7 with LeaderAndIsrPartitionError

use of org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError in project kafka by apache.

the class LeaderAndIsrRequest method getErrorResponse.

@Override
public LeaderAndIsrResponse getErrorResponse(int throttleTimeMs, Throwable e) {
    LeaderAndIsrResponseData responseData = new LeaderAndIsrResponseData();
    Errors error = Errors.forException(e);
    responseData.setErrorCode(error.code());
    if (version() < 5) {
        List<LeaderAndIsrPartitionError> partitions = new ArrayList<>();
        for (LeaderAndIsrPartitionState partition : partitionStates()) {
            partitions.add(new LeaderAndIsrPartitionError().setTopicName(partition.topicName()).setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
        }
        responseData.setPartitionErrors(partitions);
    } else {
        for (LeaderAndIsrTopicState topicState : data.topicStates()) {
            List<LeaderAndIsrPartitionError> partitions = new ArrayList<>(topicState.partitionStates().size());
            for (LeaderAndIsrPartitionState partition : topicState.partitionStates()) {
                partitions.add(new LeaderAndIsrPartitionError().setPartitionIndex(partition.partitionIndex()).setErrorCode(error.code()));
            }
            responseData.topics().add(new LeaderAndIsrTopicError().setTopicId(topicState.topicId()).setPartitionErrors(partitions));
        }
    }
    return new LeaderAndIsrResponse(responseData, version());
}
Also used : LeaderAndIsrPartitionError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError) Errors(org.apache.kafka.common.protocol.Errors) LeaderAndIsrResponseData(org.apache.kafka.common.message.LeaderAndIsrResponseData) ArrayList(java.util.ArrayList) LeaderAndIsrTopicState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrTopicState) LeaderAndIsrTopicError(org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError) LeaderAndIsrPartitionState(org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState)

Aggregations

LeaderAndIsrPartitionError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError)7 Uuid (org.apache.kafka.common.Uuid)4 LeaderAndIsrResponseData (org.apache.kafka.common.message.LeaderAndIsrResponseData)4 LeaderAndIsrTopicErrorCollection (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicErrorCollection)4 Errors (org.apache.kafka.common.protocol.Errors)4 Test (org.junit.jupiter.api.Test)4 ArrayList (java.util.ArrayList)3 LeaderAndIsrTopicError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError)3 LeaderAndIsrPartitionState (org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState)2 ClusterAuthorizationException (org.apache.kafka.common.errors.ClusterAuthorizationException)1 LeaderAndIsrTopicState (org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrTopicState)1