use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class MetadataRequest method getErrorResponse.
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
List<MetadataResponse.TopicMetadata> topicMetadatas = new ArrayList<>();
Errors error = Errors.forException(e);
List<MetadataResponse.PartitionMetadata> partitions = Collections.emptyList();
if (topics != null) {
for (String topic : topics) topicMetadatas.add(new MetadataResponse.TopicMetadata(error, topic, false, partitions));
}
short versionId = version();
switch(versionId) {
case 0:
case 1:
case 2:
return new MetadataResponse(Collections.<Node>emptyList(), null, MetadataResponse.NO_CONTROLLER_ID, topicMetadatas);
case 3:
case 4:
case 5:
return new MetadataResponse(throttleTimeMs, Collections.<Node>emptyList(), null, MetadataResponse.NO_CONTROLLER_ID, topicMetadatas);
default:
throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.METADATA.latestVersion()));
}
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class OffsetCommitResponse method toStruct.
@Override
public Struct toStruct(short version) {
Struct struct = new Struct(ApiKeys.OFFSET_COMMIT.responseSchema(version));
struct.setIfExists(THROTTLE_TIME_MS, throttleTimeMs);
Map<String, Map<Integer, Errors>> topicsData = CollectionUtils.groupDataByTopic(responseData);
List<Struct> topicArray = new ArrayList<>();
for (Map.Entry<String, Map<Integer, Errors>> entries : topicsData.entrySet()) {
Struct topicData = struct.instance(RESPONSES_KEY_NAME);
topicData.set(TOPIC_NAME, entries.getKey());
List<Struct> partitionArray = new ArrayList<>();
for (Map.Entry<Integer, Errors> partitionEntry : entries.getValue().entrySet()) {
Struct partitionData = topicData.instance(PARTITIONS_KEY_NAME);
partitionData.set(PARTITION_ID, partitionEntry.getKey());
partitionData.set(ERROR_CODE, partitionEntry.getValue().code());
partitionArray.add(partitionData);
}
topicData.set(PARTITIONS_KEY_NAME, partitionArray.toArray());
topicArray.add(topicData);
}
struct.set(RESPONSES_KEY_NAME, topicArray.toArray());
return struct;
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class TxnOffsetCommitRequest method getErrorResponse.
@Override
public TxnOffsetCommitResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
Map<TopicPartition, Errors> errors = new HashMap<>(offsets.size());
for (TopicPartition partition : offsets.keySet()) errors.put(partition, error);
return new TxnOffsetCommitResponse(throttleTimeMs, errors);
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class TxnOffsetCommitResponse method toStruct.
@Override
protected Struct toStruct(short version) {
Struct struct = new Struct(ApiKeys.TXN_OFFSET_COMMIT.responseSchema(version));
struct.set(THROTTLE_TIME_MS, throttleTimeMs);
Map<String, Map<Integer, Errors>> mappedPartitions = CollectionUtils.groupDataByTopic(errors);
Object[] partitionsArray = new Object[mappedPartitions.size()];
int i = 0;
for (Map.Entry<String, Map<Integer, Errors>> topicAndPartitions : mappedPartitions.entrySet()) {
Struct topicPartitionsStruct = struct.instance(TOPICS_KEY_NAME);
topicPartitionsStruct.set(TOPIC_NAME, topicAndPartitions.getKey());
Map<Integer, Errors> partitionAndErrors = topicAndPartitions.getValue();
Object[] partitionAndErrorsArray = new Object[partitionAndErrors.size()];
int j = 0;
for (Map.Entry<Integer, Errors> partitionAndError : partitionAndErrors.entrySet()) {
Struct partitionAndErrorStruct = topicPartitionsStruct.instance(PARTITIONS_KEY_NAME);
partitionAndErrorStruct.set(PARTITION_ID, partitionAndError.getKey());
partitionAndErrorStruct.set(ERROR_CODE, partitionAndError.getValue().code());
partitionAndErrorsArray[j++] = partitionAndErrorStruct;
}
topicPartitionsStruct.set(PARTITIONS_KEY_NAME, partitionAndErrorsArray);
partitionsArray[i++] = topicPartitionsStruct;
}
struct.set(TOPICS_KEY_NAME, partitionsArray);
return struct;
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class WriteTxnMarkersRequest method getErrorResponse.
@Override
public WriteTxnMarkersResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
Map<Long, Map<TopicPartition, Errors>> errors = new HashMap<>(markers.size());
for (TxnMarkerEntry entry : markers) {
Map<TopicPartition, Errors> errorsPerPartition = new HashMap<>(entry.partitions.size());
for (TopicPartition partition : entry.partitions) errorsPerPartition.put(partition, error);
errors.put(entry.producerId, errorsPerPartition);
}
return new WriteTxnMarkersResponse(errors);
}
Aggregations