/** * Construct a new builder which allows any supported version */ public Builder(ApiKeys apiKey) { this(apiKey, apiKey.oldestVersion(), apiKey.latestVersion()); }
protected void saslAuthenticateVersion(ApiVersionsResponse apiVersionsResponse) { ApiVersion authenticateVersion = apiVersionsResponse.apiVersion(ApiKeys.SASL_AUTHENTICATE.id); if (authenticateVersion != null) this.saslAuthenticateVersion = (short) Math.min(authenticateVersion.maxVersion, ApiKeys.SASL_AUTHENTICATE.latestVersion()); }
public static Builder forConsumer(boolean requireTimestamp, IsolationLevel isolationLevel) { short minVersion = 0; if (isolationLevel == IsolationLevel.READ_COMMITTED) minVersion = 2; else if (requireTimestamp) minVersion = 1; return new Builder(minVersion, ApiKeys.LIST_OFFSETS.latestVersion(), CONSUMER_REPLICA_ID, isolationLevel); }
public boolean isVersionSupported(short apiVersion) { return apiVersion >= oldestVersion() && apiVersion <= latestVersion(); }
public ApiVersion(ApiKeys apiKey) { this(apiKey.id, apiKey.oldestVersion(), apiKey.latestVersion()); }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { short versionId = version(); switch (versionId) { case 0: case 1: return new DescribeLogDirsResponse(throttleTimeMs, new HashMap<String, LogDirInfo>()); default: throw new IllegalArgumentException( String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.DESCRIBE_LOG_DIRS.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { short versionId = version(); switch (versionId) { case 0: case 1: List<String> enabledMechanisms = Collections.emptyList(); return new SaslHandshakeResponse(Errors.forException(e), enabledMechanisms); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.SASL_HANDSHAKE.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { short versionId = version(); switch (versionId) { case 0: case 1: return new SaslAuthenticateResponse(Errors.forException(e), e.getMessage()); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.SASL_AUTHENTICATE.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { short versionId = version(); switch (versionId) { case 0: case 1: case 2: return new ControlledShutdownResponse(Errors.forException(e), Collections.emptySet()); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.CONTROLLED_SHUTDOWN.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable throwable) { short versionId = version(); switch (versionId) { case 0: case 1: return new DescribeAclsResponse(throttleTimeMs, ApiError.fromThrowable(throwable), Collections.emptySet()); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.DESCRIBE_ACLS.latestVersion())); } }
@Override public AbstractResponse getErrorResponse(int throttleTimeMs, Throwable e) { short versionId = version(); if (versionId <= 5) return new UpdateMetadataResponse(Errors.forException(e)); else throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.UPDATE_METADATA.latestVersion())); }
/** * Return the most recent version supported by both the node and the local software. */ public short latestUsableVersion(ApiKeys apiKey) { return latestUsableVersion(apiKey, apiKey.oldestVersion(), apiKey.latestVersion()); }
public static Builder forConsumer(int maxWait, int minBytes, Map<TopicPartition, PartitionData> fetchData) { return new Builder(ApiKeys.FETCH.oldestVersion(), ApiKeys.FETCH.latestVersion(), CONSUMER_REPLICA_ID, maxWait, minBytes, fetchData); }
private OffsetsForLeaderEpochRequest createLeaderEpochRequest() { Map<TopicPartition, OffsetsForLeaderEpochRequest.PartitionData> epochs = new HashMap<>(); epochs.put(new TopicPartition("topic1", 0), new OffsetsForLeaderEpochRequest.PartitionData(Optional.of(0), 1)); epochs.put(new TopicPartition("topic1", 1), new OffsetsForLeaderEpochRequest.PartitionData(Optional.of(0), 1)); epochs.put(new TopicPartition("topic2", 2), new OffsetsForLeaderEpochRequest.PartitionData(Optional.empty(), 3)); return new OffsetsForLeaderEpochRequest.Builder(ApiKeys.OFFSET_FOR_LEADER_EPOCH.latestVersion(), epochs).build(); }
@Test public void testErrorCountsFromGetErrorResponse() { HashMap<TopicPartition, LeaderAndIsrRequest.PartitionState> partitionStates = new HashMap<>(); partitionStates.put(new TopicPartition("foo", 0), new LeaderAndIsrRequest.PartitionState(15, 1, 10, Collections.singletonList(10), 20, Collections.singletonList(10), false)); partitionStates.put(new TopicPartition("foo", 1), new LeaderAndIsrRequest.PartitionState(15, 1, 10, Collections.singletonList(10), 20, Collections.singletonList(10), false)); LeaderAndIsrRequest request = new LeaderAndIsrRequest.Builder(ApiKeys.LEADER_AND_ISR.latestVersion(), 15, 20, 0, partitionStates, Collections.<Node>emptySet()).build(); LeaderAndIsrResponse response = request.getErrorResponse(0, Errors.CLUSTER_AUTHORIZATION_FAILED.exception()); assertEquals(Collections.singletonMap(Errors.CLUSTER_AUTHORIZATION_FAILED, 2), response.errorCounts()); }
@Test public void verifyFetchResponseFullWrites() throws Exception { verifyFetchResponseFullWrite(ApiKeys.FETCH.latestVersion(), createFetchResponse(123)); verifyFetchResponseFullWrite(ApiKeys.FETCH.latestVersion(), createFetchResponse(Errors.FETCH_SESSION_ID_NOT_FOUND, 123)); for (short version = 0; version <= ApiKeys.FETCH.latestVersion(); version++) { verifyFetchResponseFullWrite(version, createFetchResponse()); } }
@Test public void testErrorCountsFromGetErrorResponse() { StopReplicaRequest request = new StopReplicaRequest.Builder(ApiKeys.STOP_REPLICA.latestVersion(), 15, 20, 0, false, Utils.mkSet(new TopicPartition("foo", 0), new TopicPartition("foo", 1))).build(); StopReplicaResponse response = request.getErrorResponse(0, Errors.CLUSTER_AUTHORIZATION_FAILED.exception()); assertEquals(Collections.singletonMap(Errors.CLUSTER_AUTHORIZATION_FAILED, 2), response.errorCounts()); }
@Test public void testBuildWithCurrentMessageFormat() { ByteBuffer buffer = ByteBuffer.allocate(256); MemoryRecordsBuilder builder = MemoryRecords.builder(buffer, RecordBatch.CURRENT_MAGIC_VALUE, CompressionType.NONE, TimestampType.CREATE_TIME, 0L); builder.append(10L, null, "a".getBytes()); Map<TopicPartition, MemoryRecords> produceData = new HashMap<>(); produceData.put(new TopicPartition("test", 0), builder.build()); ProduceRequest.Builder requestBuilder = ProduceRequest.Builder.forMagic(RecordBatch.CURRENT_MAGIC_VALUE, (short) 1, 5000, produceData, null); assertEquals(3, requestBuilder.oldestAllowedVersion()); assertEquals(ApiKeys.PRODUCE.latestVersion(), requestBuilder.latestAllowedVersion()); }
private void checkOlderFetchVersions() throws Exception { int latestVersion = ApiKeys.FETCH.latestVersion(); for (int i = 0; i < latestVersion; ++i) { checkErrorResponse(createFetchRequest(i), new UnknownServerException()); checkRequest(createFetchRequest(i)); checkResponse(createFetchResponse(), i); } }
@Test public void testControlledShutdownResponse() { ControlledShutdownResponse response = createControlledShutdownResponse(); short version = ApiKeys.CONTROLLED_SHUTDOWN.latestVersion(); Struct struct = response.toStruct(version); ByteBuffer buffer = toBuffer(struct); ControlledShutdownResponse deserialized = ControlledShutdownResponse.parse(buffer, version); assertEquals(response.error(), deserialized.error()); assertEquals(response.partitionsRemaining(), deserialized.partitionsRemaining()); }