Search in sources :

Example 16 with FindCoordinatorResponse

use of org.apache.kafka.common.requests.FindCoordinatorResponse in project kafka by apache.

the class CoordinatorStrategy method handleResponse.

@Override
public LookupResult<CoordinatorKey> handleResponse(Set<CoordinatorKey> keys, AbstractResponse abstractResponse) {
    Map<CoordinatorKey, Integer> mappedKeys = new HashMap<>();
    Map<CoordinatorKey, Throwable> failedKeys = new HashMap<>();
    for (CoordinatorKey key : unrepresentableKeys) {
        failedKeys.put(key, new InvalidGroupIdException("The given group id '" + key.idValue + "' cannot be represented in a request."));
    }
    for (Coordinator coordinator : ((FindCoordinatorResponse) abstractResponse).coordinators()) {
        CoordinatorKey key;
        if (// old version without batching
        coordinator.key() == null)
            key = requireSingletonAndType(keys);
        else {
            key = (type == CoordinatorType.GROUP) ? CoordinatorKey.byGroupId(coordinator.key()) : CoordinatorKey.byTransactionalId(coordinator.key());
        }
        handleError(Errors.forCode(coordinator.errorCode()), key, coordinator.nodeId(), mappedKeys, failedKeys);
    }
    return new LookupResult<>(failedKeys, mappedKeys);
}
Also used : FindCoordinatorResponse(org.apache.kafka.common.requests.FindCoordinatorResponse) HashMap(java.util.HashMap) InvalidGroupIdException(org.apache.kafka.common.errors.InvalidGroupIdException) Coordinator(org.apache.kafka.common.message.FindCoordinatorResponseData.Coordinator)

Aggregations

FindCoordinatorResponse (org.apache.kafka.common.requests.FindCoordinatorResponse)16 Node (org.apache.kafka.common.Node)12 MockClient (org.apache.kafka.clients.MockClient)10 Cluster (org.apache.kafka.common.Cluster)10 MockTime (org.apache.kafka.common.utils.MockTime)10 Time (org.apache.kafka.common.utils.Time)9 Metadata (org.apache.kafka.clients.Metadata)8 PartitionAssignor (org.apache.kafka.clients.consumer.internals.PartitionAssignor)8 Test (org.junit.Test)8 HashMap (java.util.HashMap)6 LinkedHashMap (java.util.LinkedHashMap)4 TopicPartition (org.apache.kafka.common.TopicPartition)3 LogContext (org.apache.kafka.common.utils.LogContext)3 ByteBuffer (java.nio.ByteBuffer)2 HashSet (java.util.HashSet)2 FindCoordinatorResponseData (org.apache.kafka.common.message.FindCoordinatorResponseData)2 AbstractRequest (org.apache.kafka.common.requests.AbstractRequest)2 JoinGroupRequest (org.apache.kafka.common.requests.JoinGroupRequest)2 Test (org.junit.jupiter.api.Test)2 InetSocketAddress (java.net.InetSocketAddress)1