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