Search in sources :

Example 6 with ApiVersion

use of org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion in project kafka by apache.

the class ApiVersionsResponseTest method verifyVersions.

private void verifyVersions(short forwardableAPIKey, short minVersion, short maxVersion, ApiVersionCollection commonResponse) {
    ApiVersion expectedVersionsForForwardableAPI = new ApiVersion().setApiKey(forwardableAPIKey).setMinVersion(minVersion).setMaxVersion(maxVersion);
    assertEquals(expectedVersionsForForwardableAPI, commonResponse.find(forwardableAPIKey));
}
Also used : ApiVersion(org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion)

Example 7 with ApiVersion

use of org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion in project kafka by apache.

the class NetworkClient method handleApiVersionsResponse.

private void handleApiVersionsResponse(List<ClientResponse> responses, InFlightRequest req, long now, ApiVersionsResponse apiVersionsResponse) {
    final String node = req.destination;
    if (apiVersionsResponse.data().errorCode() != Errors.NONE.code()) {
        if (req.request.version() == 0 || apiVersionsResponse.data().errorCode() != Errors.UNSUPPORTED_VERSION.code()) {
            log.warn("Received error {} from node {} when making an ApiVersionsRequest with correlation id {}. Disconnecting.", Errors.forCode(apiVersionsResponse.data().errorCode()), node, req.header.correlationId());
            this.selector.close(node);
            processDisconnection(responses, node, now, ChannelState.LOCAL_CLOSE);
        } else {
            // Starting from Apache Kafka 2.4, ApiKeys field is populated with the supported versions of
            // the ApiVersionsRequest when an UNSUPPORTED_VERSION error is returned.
            // If not provided, the client falls back to version 0.
            short maxApiVersion = 0;
            if (apiVersionsResponse.data().apiKeys().size() > 0) {
                ApiVersion apiVersion = apiVersionsResponse.data().apiKeys().find(ApiKeys.API_VERSIONS.id);
                if (apiVersion != null) {
                    maxApiVersion = apiVersion.maxVersion();
                }
            }
            nodesNeedingApiVersionsFetch.put(node, new ApiVersionsRequest.Builder(maxApiVersion));
        }
        return;
    }
    NodeApiVersions nodeVersionInfo = new NodeApiVersions(apiVersionsResponse.data().apiKeys());
    apiVersions.update(node, nodeVersionInfo);
    this.connectionStates.ready(node);
    log.debug("Node {} has finalized features epoch: {}, finalized features: {}, supported features: {}, API versions: {}.", node, apiVersionsResponse.data().finalizedFeaturesEpoch(), apiVersionsResponse.data().finalizedFeatures(), apiVersionsResponse.data().supportedFeatures(), nodeVersionInfo);
}
Also used : ApiVersion(org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion) ApiVersionsRequest(org.apache.kafka.common.requests.ApiVersionsRequest)

Example 8 with ApiVersion

use of org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion in project kafka by apache.

the class NodeApiVersions method toString.

/**
 * Convert the object to a string.
 *
 * @param lineBreaks True if we should add a linebreak after each api.
 */
public String toString(boolean lineBreaks) {
    // The apiVersion collection may not be in sorted order.  We put it into
    // a TreeMap before printing it out to ensure that we always print in
    // ascending order.
    TreeMap<Short, String> apiKeysText = new TreeMap<>();
    for (ApiVersion supportedVersion : this.supportedVersions.values()) apiKeysText.put(supportedVersion.apiKey(), apiVersionToText(supportedVersion));
    for (ApiVersion apiVersion : unknownApis) apiKeysText.put(apiVersion.apiKey(), apiVersionToText(apiVersion));
    // which may happen when the remote is too old.
    for (ApiKeys apiKey : ApiKeys.zkBrokerApis()) {
        if (!apiKeysText.containsKey(apiKey.id)) {
            StringBuilder bld = new StringBuilder();
            bld.append(apiKey.name).append("(").append(apiKey.id).append("): ").append("UNSUPPORTED");
            apiKeysText.put(apiKey.id, bld.toString());
        }
    }
    String separator = lineBreaks ? ",\n\t" : ", ";
    StringBuilder bld = new StringBuilder();
    bld.append("(");
    if (lineBreaks)
        bld.append("\n\t");
    bld.append(Utils.join(apiKeysText.values(), separator));
    if (lineBreaks)
        bld.append("\n");
    bld.append(")");
    return bld.toString();
}
Also used : ApiVersion(org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) TreeMap(java.util.TreeMap)

Example 9 with ApiVersion

use of org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion in project kafka by apache.

the class NodeApiVersions method apiVersionToText.

private String apiVersionToText(ApiVersion apiVersion) {
    StringBuilder bld = new StringBuilder();
    ApiKeys apiKey = null;
    if (ApiKeys.hasId(apiVersion.apiKey())) {
        apiKey = ApiKeys.forId(apiVersion.apiKey());
        bld.append(apiKey.name).append("(").append(apiKey.id).append("): ");
    } else {
        bld.append("UNKNOWN(").append(apiVersion.apiKey()).append("): ");
    }
    if (apiVersion.minVersion() == apiVersion.maxVersion()) {
        bld.append(apiVersion.minVersion());
    } else {
        bld.append(apiVersion.minVersion()).append(" to ").append(apiVersion.maxVersion());
    }
    if (apiKey != null) {
        ApiVersion supportedVersion = supportedVersions.get(apiKey);
        if (apiKey.latestVersion() < supportedVersion.minVersion()) {
            bld.append(" [unusable: node too new]");
        } else if (supportedVersion.maxVersion() < apiKey.oldestVersion()) {
            bld.append(" [unusable: node too old]");
        } else {
            short latestUsableVersion = Utils.min(apiKey.latestVersion(), supportedVersion.maxVersion());
            bld.append(" [usable: ").append(latestUsableVersion).append("]");
        }
    }
    return bld.toString();
}
Also used : ApiKeys(org.apache.kafka.common.protocol.ApiKeys) ApiVersion(org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion)

Example 10 with ApiVersion

use of org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion in project kafka by apache.

the class RequestResponseTest method createApiVersionResponse.

private ApiVersionsResponse createApiVersionResponse() {
    ApiVersionCollection apiVersions = new ApiVersionCollection();
    apiVersions.add(new ApiVersion().setApiKey((short) 0).setMinVersion((short) 0).setMaxVersion((short) 2));
    return new ApiVersionsResponse(new ApiVersionsResponseData().setErrorCode(Errors.NONE.code()).setThrottleTimeMs(0).setApiKeys(apiVersions));
}
Also used : ApiVersionCollection(org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersionCollection) ApiVersion(org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion) ApiVersionsResponseData(org.apache.kafka.common.message.ApiVersionsResponseData)

Aggregations

ApiVersion (org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersion)28 Test (org.junit.jupiter.api.Test)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ApiKeys (org.apache.kafka.common.protocol.ApiKeys)7 ApiVersionCollection (org.apache.kafka.common.message.ApiVersionsResponseData.ApiVersionCollection)6 ApiVersionsResponse (org.apache.kafka.common.requests.ApiVersionsResponse)6 NodeApiVersions (org.apache.kafka.clients.NodeApiVersions)5 ApiVersionsResponseData (org.apache.kafka.common.message.ApiVersionsResponseData)4 RecordMetadata (org.apache.kafka.clients.producer.RecordMetadata)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3 ByteBuffer (java.nio.ByteBuffer)2 Node (org.apache.kafka.common.Node)2 DeleteGroupsResponseData (org.apache.kafka.common.message.DeleteGroupsResponseData)2 DeletableGroupResult (org.apache.kafka.common.message.DeleteGroupsResponseData.DeletableGroupResult)2 DeletableGroupResultCollection (org.apache.kafka.common.message.DeleteGroupsResponseData.DeletableGroupResultCollection)2 ListenerName (org.apache.kafka.common.network.ListenerName)2 NioEchoServer (org.apache.kafka.common.network.NioEchoServer)2 SaslChannelBuilder (org.apache.kafka.common.network.SaslChannelBuilder)2 ApiVersionsRequest (org.apache.kafka.common.requests.ApiVersionsRequest)2 DeleteGroupsResponse (org.apache.kafka.common.requests.DeleteGroupsResponse)2