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());
}
Aggregations