use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class OffsetsForLeaderEpochRequest method getErrorResponse.
@Override
public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
Map<TopicPartition, EpochEndOffset> errorResponse = new HashMap<>();
for (TopicPartition tp : epochsByPartition.keySet()) {
errorResponse.put(tp, new EpochEndOffset(error, EpochEndOffset.UNDEFINED_EPOCH_OFFSET));
}
return new OffsetsForLeaderEpochResponse(errorResponse);
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class StopReplicaRequest method getErrorResponse.
@Override
public StopReplicaResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
Map<TopicPartition, Errors> responses = new HashMap<>(partitions.size());
for (TopicPartition partition : partitions) {
responses.put(partition, error);
}
short versionId = version();
switch(versionId) {
case 0:
return new StopReplicaResponse(error, responses);
default:
throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.STOP_REPLICA.latestVersion()));
}
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class LeaderAndIsrRequest method getErrorResponse.
@Override
public LeaderAndIsrResponse getErrorResponse(int throttleTimeMs, Throwable e) {
Errors error = Errors.forException(e);
Map<TopicPartition, Errors> responses = new HashMap<>(partitionStates.size());
for (TopicPartition partition : partitionStates.keySet()) {
responses.put(partition, error);
}
short versionId = version();
switch(versionId) {
case 0:
case 1:
return new LeaderAndIsrResponse(error, responses);
default:
throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.LEADER_AND_ISR.latestVersion()));
}
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class LeaderAndIsrResponse method toStruct.
@Override
protected Struct toStruct(short version) {
Struct struct = new Struct(ApiKeys.LEADER_AND_ISR.responseSchema(version));
List<Struct> responseDatas = new ArrayList<>(responses.size());
for (Map.Entry<TopicPartition, Errors> response : responses.entrySet()) {
Struct partitionData = struct.instance(PARTITIONS_KEY_NAME);
TopicPartition partition = response.getKey();
partitionData.set(TOPIC_NAME, partition.topic());
partitionData.set(PARTITION_ID, partition.partition());
partitionData.set(ERROR_CODE, response.getValue().code());
responseDatas.add(partitionData);
}
struct.set(PARTITIONS_KEY_NAME, responseDatas.toArray());
struct.set(ERROR_CODE, error.code());
return struct;
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class ApiError method fromThrowable.
public static ApiError fromThrowable(Throwable t) {
// Avoid populating the error message if it's a generic one
Errors error = Errors.forException(t);
String message = error.message().equals(t.getMessage()) ? null : t.getMessage();
return new ApiError(error, message);
}
Aggregations