Search in sources :

Example 1 with Coordinator

use of org.apache.kafka.common.message.FindCoordinatorResponseData.Coordinator in project kafka by apache.

the class FindCoordinatorResponse method prepareErrorResponse.

public static FindCoordinatorResponse prepareErrorResponse(Errors error, List<String> keys) {
    FindCoordinatorResponseData data = new FindCoordinatorResponseData();
    List<FindCoordinatorResponseData.Coordinator> coordinators = new ArrayList<>(keys.size());
    for (String key : keys) {
        FindCoordinatorResponseData.Coordinator coordinator = new FindCoordinatorResponseData.Coordinator().setErrorCode(error.code()).setErrorMessage(error.message()).setKey(key).setHost(Node.noNode().host()).setPort(Node.noNode().port()).setNodeId(Node.noNode().id());
        coordinators.add(coordinator);
    }
    data.setCoordinators(coordinators);
    return new FindCoordinatorResponse(data);
}
Also used : ArrayList(java.util.ArrayList) FindCoordinatorResponseData(org.apache.kafka.common.message.FindCoordinatorResponseData) Coordinator(org.apache.kafka.common.message.FindCoordinatorResponseData.Coordinator) Coordinator(org.apache.kafka.common.message.FindCoordinatorResponseData.Coordinator)

Example 2 with Coordinator

use of org.apache.kafka.common.message.FindCoordinatorResponseData.Coordinator 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

Coordinator (org.apache.kafka.common.message.FindCoordinatorResponseData.Coordinator)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 InvalidGroupIdException (org.apache.kafka.common.errors.InvalidGroupIdException)1 FindCoordinatorResponseData (org.apache.kafka.common.message.FindCoordinatorResponseData)1 FindCoordinatorResponse (org.apache.kafka.common.requests.FindCoordinatorResponse)1