@Override public StopReplicaRequest build(short version) { return new StopReplicaRequest(controllerId, controllerEpoch, brokerEpoch, deletePartitions, partitions, version); }
@Override public StopReplicaResponse getErrorResponse(int throttleTimeMs, Throwable e) { Errors error = Errors.forException(e); Map<TopicPartition, Errors> responses = new HashMap<>(partitions.size()); for (TopicPartition partition : partitions) { responses.put(partition, error); } short versionId = version(); switch (versionId) { case 0: case 1: return new StopReplicaResponse(error, responses); default: throw new IllegalArgumentException(String.format("Version %d is not valid. Valid versions for %s are 0 to %d", versionId, this.getClass().getSimpleName(), ApiKeys.STOP_REPLICA.latestVersion())); } }
@Test public void testStopReplicaRequestNormalization() { Set<TopicPartition> tps = generateRandomTopicPartitions(10, 10); Map<TopicPartition, UpdateMetadataRequest.PartitionState> partitionStates = new HashMap<>(); for (TopicPartition tp: tps) { partitionStates.put(tp, new UpdateMetadataRequest.PartitionState(0, 0, 0, Collections.emptyList(), 0, Collections.emptyList(), Collections.emptyList())); } StopReplicaRequest.Builder builder = new StopReplicaRequest.Builder((short) 5, 0, 0, 0, false, tps); Assert.assertTrue(builder.build((short) 1).size() < builder.build((short) 0).size()); }
@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()); }
public static StopReplicaRequest parse(ByteBuffer buffer, short version) { return new StopReplicaRequest(ApiKeys.STOP_REPLICA.parseRequest(version, buffer), version); }
@Override protected Struct toStruct() { Struct struct = new Struct(ApiKeys.STOP_REPLICA.requestSchema(version())); struct.set(DELETE_PARTITIONS, deletePartitions); if (version() > 0) { // V1 Map<String, List<Integer>> topicPartitionsMap = CollectionUtils.groupPartitionsByTopic(partitions); List<Struct> topicsData = new ArrayList<>(topicPartitionsMap.size());
return new SyncGroupRequest(struct, apiVersion); case STOP_REPLICA: return new StopReplicaRequest(struct, apiVersion); case CONTROLLED_SHUTDOWN: return new ControlledShutdownRequest(struct, apiVersion);