Search in sources :

Example 6 with ApiKeys

use of org.apache.kafka.common.protocol.ApiKeys in project kafka by apache.

the class NodeApiVersionsTest method testUnsupportedVersionsToString.

@Test
public void testUnsupportedVersionsToString() {
    NodeApiVersions versions = new NodeApiVersions(Collections.<ApiVersion>emptyList());
    StringBuilder bld = new StringBuilder();
    String prefix = "(";
    for (ApiKeys apiKey : ApiKeys.values()) {
        bld.append(prefix).append(apiKey.name).append("(").append(apiKey.id).append("): UNSUPPORTED");
        prefix = ", ";
    }
    bld.append(")");
    assertEquals(bld.toString(), versions.toString());
}
Also used : ApiKeys(org.apache.kafka.common.protocol.ApiKeys) Test(org.junit.Test)

Example 7 with ApiKeys

use of org.apache.kafka.common.protocol.ApiKeys in project kafka by apache.

the class NodeApiVersionsTest method testVersionsToString.

@Test
public void testVersionsToString() {
    List<ApiVersion> versionList = new ArrayList<>();
    for (ApiKeys apiKey : ApiKeys.values()) {
        if (apiKey == ApiKeys.CONTROLLED_SHUTDOWN_KEY) {
            versionList.add(new ApiVersion(apiKey.id, (short) 0, (short) 0));
        } else if (apiKey == ApiKeys.DELETE_TOPICS) {
            versionList.add(new ApiVersion(apiKey.id, (short) 10000, (short) 10001));
        } else {
            versionList.add(new ApiVersion(apiKey));
        }
    }
    NodeApiVersions versions = new NodeApiVersions(versionList);
    StringBuilder bld = new StringBuilder();
    String prefix = "(";
    for (ApiKeys apiKey : ApiKeys.values()) {
        bld.append(prefix);
        if (apiKey == ApiKeys.CONTROLLED_SHUTDOWN_KEY) {
            bld.append("ControlledShutdown(7): 0 [unusable: node too old]");
        } else if (apiKey == ApiKeys.DELETE_TOPICS) {
            bld.append("DeleteTopics(20): 10000 to 10001 [unusable: node too new]");
        } else {
            bld.append(apiKey.name).append("(").append(apiKey.id).append("): ");
            if (apiKey.oldestVersion() == apiKey.latestVersion()) {
                bld.append(apiKey.oldestVersion());
            } else {
                bld.append(apiKey.oldestVersion()).append(" to ").append(apiKey.latestVersion());
            }
            bld.append(" [usable: ").append(apiKey.latestVersion()).append("]");
        }
        prefix = ", ";
    }
    bld.append(")");
    assertEquals(bld.toString(), versions.toString());
}
Also used : ApiVersion(org.apache.kafka.common.requests.ApiVersionsResponse.ApiVersion) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with ApiKeys

use of org.apache.kafka.common.protocol.ApiKeys in project kafka by apache.

the class NodeApiVersionsTest method testUsableVersionLatestVersions.

@Test
public void testUsableVersionLatestVersions() {
    List<ApiVersion> versionList = new LinkedList<>();
    for (ApiVersion apiVersion : ApiVersionsResponse.API_VERSIONS_RESPONSE.apiVersions()) {
        versionList.add(apiVersion);
    }
    // Add an API key that we don't know about.
    versionList.add(new ApiVersion((short) 100, (short) 0, (short) 1));
    NodeApiVersions versions = new NodeApiVersions(versionList);
    for (ApiKeys apiKey : ApiKeys.values()) {
        assertEquals(apiKey.latestVersion(), versions.usableVersion(apiKey));
    }
}
Also used : ApiVersion(org.apache.kafka.common.requests.ApiVersionsResponse.ApiVersion) ApiKeys(org.apache.kafka.common.protocol.ApiKeys) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Example 9 with ApiKeys

use of org.apache.kafka.common.protocol.ApiKeys in project kafka by apache.

the class AbstractRequest method getRequest.

/**
     * Factory method for getting a request object based on ApiKey ID and a buffer
     */
public static RequestAndSize getRequest(int requestId, short version, ByteBuffer buffer) {
    ApiKeys apiKey = ApiKeys.forId(requestId);
    Struct struct = apiKey.parseRequest(version, buffer);
    AbstractRequest request;
    switch(apiKey) {
        case PRODUCE:
            request = new ProduceRequest(struct, version);
            break;
        case FETCH:
            request = new FetchRequest(struct, version);
            break;
        case LIST_OFFSETS:
            request = new ListOffsetRequest(struct, version);
            break;
        case METADATA:
            request = new MetadataRequest(struct, version);
            break;
        case OFFSET_COMMIT:
            request = new OffsetCommitRequest(struct, version);
            break;
        case OFFSET_FETCH:
            request = new OffsetFetchRequest(struct, version);
            break;
        case GROUP_COORDINATOR:
            request = new GroupCoordinatorRequest(struct, version);
            break;
        case JOIN_GROUP:
            request = new JoinGroupRequest(struct, version);
            break;
        case HEARTBEAT:
            request = new HeartbeatRequest(struct, version);
            break;
        case LEAVE_GROUP:
            request = new LeaveGroupRequest(struct, version);
            break;
        case SYNC_GROUP:
            request = new SyncGroupRequest(struct, version);
            break;
        case STOP_REPLICA:
            request = new StopReplicaRequest(struct, version);
            break;
        case CONTROLLED_SHUTDOWN_KEY:
            request = new ControlledShutdownRequest(struct, version);
            break;
        case UPDATE_METADATA_KEY:
            request = new UpdateMetadataRequest(struct, version);
            break;
        case LEADER_AND_ISR:
            request = new LeaderAndIsrRequest(struct, version);
            break;
        case DESCRIBE_GROUPS:
            request = new DescribeGroupsRequest(struct, version);
            break;
        case LIST_GROUPS:
            request = new ListGroupsRequest(struct, version);
            break;
        case SASL_HANDSHAKE:
            request = new SaslHandshakeRequest(struct, version);
            break;
        case API_VERSIONS:
            request = new ApiVersionsRequest(struct, version);
            break;
        case CREATE_TOPICS:
            request = new CreateTopicsRequest(struct, version);
            break;
        case DELETE_TOPICS:
            request = new DeleteTopicsRequest(struct, version);
            break;
        default:
            throw new AssertionError(String.format("ApiKey %s is not currently handled in `getRequest`, the " + "code should be updated to do so.", apiKey));
    }
    return new RequestAndSize(request, struct.sizeOf());
}
Also used : Struct(org.apache.kafka.common.protocol.types.Struct) ApiKeys(org.apache.kafka.common.protocol.ApiKeys)

Aggregations

ApiKeys (org.apache.kafka.common.protocol.ApiKeys)9 ApiVersion (org.apache.kafka.common.requests.ApiVersionsResponse.ApiVersion)3 Test (org.junit.Test)3 SchemaException (org.apache.kafka.common.protocol.types.SchemaException)2 Struct (org.apache.kafka.common.protocol.types.Struct)2 ByteBuffer (java.nio.ByteBuffer)1 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 TreeMap (java.util.TreeMap)1 AuthenticationException (org.apache.kafka.common.errors.AuthenticationException)1 IllegalSaslStateException (org.apache.kafka.common.errors.IllegalSaslStateException)1 UnsupportedSaslMechanismException (org.apache.kafka.common.errors.UnsupportedSaslMechanismException)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1 AbstractRequest (org.apache.kafka.common.requests.AbstractRequest)1 AbstractResponse (org.apache.kafka.common.requests.AbstractResponse)1 RequestHeader (org.apache.kafka.common.requests.RequestHeader)1 ResponseHeader (org.apache.kafka.common.requests.ResponseHeader)1 SaslHandshakeRequest (org.apache.kafka.common.requests.SaslHandshakeRequest)1