use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class SaslClientAuthenticator method receiveToken.
private byte[] receiveToken() throws IOException {
if (saslAuthenticateVersion == DISABLE_KAFKA_SASL_AUTHENTICATE_HEADER) {
return receiveResponseOrToken();
} else {
SaslAuthenticateResponse response = (SaslAuthenticateResponse) receiveKafkaResponse();
if (response != null) {
Errors error = response.error();
if (error != Errors.NONE) {
setSaslState(SaslState.FAILED);
String errMsg = response.errorMessage();
throw errMsg == null ? error.exception() : error.exception(errMsg);
}
return Utils.readBytes(response.saslAuthBytes());
} else
return null;
}
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class LeaderAndIsrResponseTest method testErrorCountsNoTopLevelError.
@Test
public void testErrorCountsNoTopLevelError() {
Map<TopicPartition, Errors> errors = new HashMap<>();
errors.put(new TopicPartition("foo", 0), Errors.NONE);
errors.put(new TopicPartition("foo", 1), Errors.CLUSTER_AUTHORIZATION_FAILED);
LeaderAndIsrResponse response = new LeaderAndIsrResponse(Errors.NONE, errors);
Map<Errors, Integer> errorCounts = response.errorCounts();
assertEquals(2, errorCounts.size());
assertEquals(1, errorCounts.get(Errors.NONE).intValue());
assertEquals(1, errorCounts.get(Errors.CLUSTER_AUTHORIZATION_FAILED).intValue());
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class RequestResponseTest method createLeaderAndIsrResponse.
private LeaderAndIsrResponse createLeaderAndIsrResponse() {
Map<TopicPartition, Errors> responses = new HashMap<>();
responses.put(new TopicPartition("test", 0), Errors.NONE);
return new LeaderAndIsrResponse(Errors.NONE, responses);
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class RequestResponseTest method createStopReplicaResponse.
private StopReplicaResponse createStopReplicaResponse() {
Map<TopicPartition, Errors> responses = new HashMap<>();
responses.put(new TopicPartition("test", 0), Errors.NONE);
return new StopReplicaResponse(Errors.NONE, responses);
}
use of org.apache.kafka.common.protocol.Errors in project apache-kafka-on-k8s by banzaicloud.
the class ProduceRequest method getErrorResponse.
@Override
public ProduceResponse getErrorResponse(int throttleTimeMs, Throwable e) {
/* In case the producer doesn't actually want any response */
if (acks == 0)
return null;
Errors error = Errors.forException(e);
Map<TopicPartition, ProduceResponse.PartitionResponse> responseMap = new HashMap<>();
ProduceResponse.PartitionResponse partitionResponse = new ProduceResponse.PartitionResponse(error);
for (TopicPartition tp : partitions()) responseMap.put(tp, partitionResponse);
short versionId = version();
switch(versionId) {
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
return new ProduceResponse(responseMap, throttleTimeMs);
default:
throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.PRODUCE.latestVersion()));
}
}
Aggregations