use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class AlterReplicaLogDirsResponse method toStruct.
@Override
protected Struct toStruct(short version) {
Struct struct = new Struct(ApiKeys.ALTER_REPLICA_LOG_DIRS.responseSchema(version));
struct.set(THROTTLE_TIME_MS, throttleTimeMs);
Map<String, Map<Integer, Errors>> responsesByTopic = CollectionUtils.groupDataByTopic(responses);
List<Struct> topicStructArray = new ArrayList<>();
for (Map.Entry<String, Map<Integer, Errors>> responsesByTopicEntry : responsesByTopic.entrySet()) {
Struct topicStruct = struct.instance(TOPICS_KEY_NAME);
topicStruct.set(TOPIC_NAME, responsesByTopicEntry.getKey());
List<Struct> partitionStructArray = new ArrayList<>();
for (Map.Entry<Integer, Errors> responsesByPartitionEntry : responsesByTopicEntry.getValue().entrySet()) {
Struct partitionStruct = topicStruct.instance(PARTITIONS_KEY_NAME);
Errors response = responsesByPartitionEntry.getValue();
partitionStruct.set(PARTITION_ID, responsesByPartitionEntry.getKey());
partitionStruct.set(ERROR_CODE, response.code());
partitionStructArray.add(partitionStruct);
}
topicStruct.set(PARTITIONS_KEY_NAME, partitionStructArray.toArray());
topicStructArray.add(topicStruct);
}
struct.set(TOPICS_KEY_NAME, topicStructArray.toArray());
return struct;
}
use of org.apache.kafka.common.protocol.Errors in project kafka by apache.
the class OffsetFetchRequest method getErrorResponse.
public OffsetFetchResponse getErrorResponse(int throttleTimeMs, Errors error) {
Map<TopicPartition, OffsetFetchResponse.PartitionData> responsePartitions = new HashMap<>();
if (version() < 2) {
OffsetFetchResponse.PartitionData partitionError = new OffsetFetchResponse.PartitionData(OffsetFetchResponse.INVALID_OFFSET, Optional.empty(), OffsetFetchResponse.NO_METADATA, error);
for (OffsetFetchRequestTopic topic : this.data.topics()) {
for (int partitionIndex : topic.partitionIndexes()) {
responsePartitions.put(new TopicPartition(topic.name(), partitionIndex), partitionError);
}
}
return new OffsetFetchResponse(error, responsePartitions);
}
if (version() == 2) {
return new OffsetFetchResponse(error, responsePartitions);
}
if (version() >= 3 && version() < 8) {
return new OffsetFetchResponse(throttleTimeMs, error, responsePartitions);
}
List<String> groupIds = groupIds();
Map<String, Errors> errorsMap = new HashMap<>(groupIds.size());
Map<String, Map<TopicPartition, OffsetFetchResponse.PartitionData>> partitionMap = new HashMap<>(groupIds.size());
for (String g : groupIds) {
errorsMap.put(g, error);
partitionMap.put(g, responsePartitions);
}
return new OffsetFetchResponse(throttleTimeMs, errorsMap, partitionMap);
}
use of org.apache.kafka.common.protocol.Errors in project kafka by apache.
the class OffsetsForLeaderEpochRequest method getErrorResponse.
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
OffsetForLeaderEpochResponseData responseData = new OffsetForLeaderEpochResponseData();
data.topics().forEach(topic -> {
OffsetForLeaderTopicResult topicData = new OffsetForLeaderTopicResult().setTopic(topic.topic());
topic.partitions().forEach(partition -> topicData.partitions().add(new EpochEndOffset().setPartition(partition.partition()).setErrorCode(error.code()).setLeaderEpoch(UNDEFINED_EPOCH).setEndOffset(UNDEFINED_EPOCH_OFFSET)));
responseData.topics().add(topicData);
});
return new OffsetsForLeaderEpochResponse(responseData);
}
use of org.apache.kafka.common.protocol.Errors in project kafka by apache.
the class FetchRequest method getErrorResponse.
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
// For versions 13+ the error is indicated by setting the top-level error code, and no partitions will be returned.
// For earlier versions, the error is indicated in two ways: by setting the same error code in all partitions,
// and by setting the top-level error code. The form where we set the same error code in all partitions
// is needed in order to maintain backwards compatibility with older versions of the protocol
// in which there was no top-level error code. Note that for incremental fetch responses, there
// may not be any partitions at all in the response. For this reason, the top-level error code
// is essential for them.
Errors error = Errors.forException(e);
List<FetchResponseData.FetchableTopicResponse> topicResponseList = new ArrayList<>();
// For version 13+, we know the client can handle a top level error code, so we don't need to send back partitions too.
if (version() < 13) {
data.topics().forEach(topic -> {
List<FetchResponseData.PartitionData> partitionResponses = topic.partitions().stream().map(partition -> FetchResponse.partitionResponse(partition.partition(), error)).collect(Collectors.toList());
topicResponseList.add(new FetchResponseData.FetchableTopicResponse().setTopic(topic.topic()).setTopicId(topic.topicId()).setPartitions(partitionResponses));
});
}
return new FetchResponse(new FetchResponseData().setThrottleTimeMs(throttleTimeMs).setErrorCode(error.code()).setSessionId(data.sessionId()).setResponses(topicResponseList));
}
use of org.apache.kafka.common.protocol.Errors in project kafka by apache.
the class FindCoordinatorRequest method getErrorResponse.
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
FindCoordinatorResponseData response = new FindCoordinatorResponseData();
if (version() >= 2) {
response.setThrottleTimeMs(throttleTimeMs);
}
Errors error = Errors.forException(e);
if (version() < MIN_BATCHED_VERSION) {
return FindCoordinatorResponse.prepareOldResponse(error, Node.noNode());
} else {
return FindCoordinatorResponse.prepareErrorResponse(error, data.coordinatorKeys());
}
}
Aggregations