Search in sources :

Example 96 with Errors

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;
    }
}
Also used : SaslAuthenticateResponse(org.apache.kafka.common.requests.SaslAuthenticateResponse) Errors(org.apache.kafka.common.protocol.Errors)

Example 97 with Errors

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());
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) Test(org.junit.Test)

Example 98 with Errors

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);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopicPartition(org.apache.kafka.common.TopicPartition)

Example 99 with Errors

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);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopicPartition(org.apache.kafka.common.TopicPartition)

Example 100 with Errors

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()));
    }
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition)

Aggregations

Errors (org.apache.kafka.common.protocol.Errors)167 HashMap (java.util.HashMap)115 TopicPartition (org.apache.kafka.common.TopicPartition)87 Map (java.util.Map)61 ArrayList (java.util.ArrayList)46 LinkedHashMap (java.util.LinkedHashMap)31 Test (org.junit.jupiter.api.Test)31 List (java.util.List)19 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)19 HashSet (java.util.HashSet)18 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)18 InvalidTopicException (org.apache.kafka.common.errors.InvalidTopicException)17 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)17 MetadataResponse (org.apache.kafka.common.requests.MetadataResponse)17 KafkaException (org.apache.kafka.common.KafkaException)16 Node (org.apache.kafka.common.Node)16 Cluster (org.apache.kafka.common.Cluster)15 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)14 ChannelBuilder (org.apache.kafka.common.network.ChannelBuilder)14 Collections (java.util.Collections)13