Search in sources :

Example 1 with LeaderAndIsrTopicState

use of org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrTopicState 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

ArrayList (java.util.ArrayList)1 LeaderAndIsrPartitionState (org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrPartitionState)1 LeaderAndIsrTopicState (org.apache.kafka.common.message.LeaderAndIsrRequestData.LeaderAndIsrTopicState)1 LeaderAndIsrResponseData (org.apache.kafka.common.message.LeaderAndIsrResponseData)1 LeaderAndIsrPartitionError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrPartitionError)1 LeaderAndIsrTopicError (org.apache.kafka.common.message.LeaderAndIsrResponseData.LeaderAndIsrTopicError)1 Errors (org.apache.kafka.common.protocol.Errors)1