use of org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic in project kafka by apache.
the class RequestResponseTest method createCreatePartitionsRequestWithAssignments.
private CreatePartitionsRequest createCreatePartitionsRequestWithAssignments(short version) {
CreatePartitionsTopicCollection topics = new CreatePartitionsTopicCollection();
CreatePartitionsAssignment myTopicAssignment = new CreatePartitionsAssignment().setBrokerIds(singletonList(2));
topics.add(new CreatePartitionsTopic().setName("my_topic").setCount(3).setAssignments(singletonList(myTopicAssignment)));
topics.add(new CreatePartitionsTopic().setName("my_other_topic").setCount(3).setAssignments(asList(new CreatePartitionsAssignment().setBrokerIds(asList(2, 3)), new CreatePartitionsAssignment().setBrokerIds(asList(3, 1)))));
CreatePartitionsRequestData data = new CreatePartitionsRequestData().setTimeoutMs(0).setValidateOnly(false).setTopics(topics);
return new CreatePartitionsRequest(data, version);
}
use of org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic in project kafka by apache.
the class MockController method createPartitions.
@Override
public synchronized CompletableFuture<List<CreatePartitionsTopicResult>> createPartitions(long deadlineNs, List<CreatePartitionsTopic> topicList) {
if (!active) {
CompletableFuture<List<CreatePartitionsTopicResult>> future = new CompletableFuture<>();
future.completeExceptionally(NOT_CONTROLLER_EXCEPTION);
return future;
}
List<CreatePartitionsTopicResult> results = new ArrayList<>();
for (CreatePartitionsTopic topic : topicList) {
if (topicNameToId.containsKey(topic.name())) {
results.add(new CreatePartitionsTopicResult().setName(topic.name()).setErrorCode(Errors.NONE.code()).setErrorMessage(null));
} else {
results.add(new CreatePartitionsTopicResult().setName(topic.name()).setErrorCode(Errors.UNKNOWN_TOPIC_OR_PARTITION.code()).setErrorMessage("No such topic as " + topic.name()));
}
}
return CompletableFuture.completedFuture(results);
}
use of org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic in project kafka by apache.
the class KafkaAdminClient method createPartitions.
@Override
public CreatePartitionsResult createPartitions(final Map<String, NewPartitions> newPartitions, final CreatePartitionsOptions options) {
final Map<String, KafkaFutureImpl<Void>> futures = new HashMap<>(newPartitions.size());
final CreatePartitionsTopicCollection topics = new CreatePartitionsTopicCollection(newPartitions.size());
for (Map.Entry<String, NewPartitions> entry : newPartitions.entrySet()) {
final String topic = entry.getKey();
final NewPartitions newPartition = entry.getValue();
List<List<Integer>> newAssignments = newPartition.assignments();
List<CreatePartitionsAssignment> assignments = newAssignments == null ? null : newAssignments.stream().map(brokerIds -> new CreatePartitionsAssignment().setBrokerIds(brokerIds)).collect(Collectors.toList());
topics.add(new CreatePartitionsTopic().setName(topic).setCount(newPartition.totalCount()).setAssignments(assignments));
futures.put(topic, new KafkaFutureImpl<>());
}
if (!topics.isEmpty()) {
final long now = time.milliseconds();
final long deadline = calcDeadlineMs(now, options.timeoutMs());
final Call call = getCreatePartitionsCall(options, futures, topics, Collections.emptyMap(), now, deadline);
runnable.call(call, now);
}
return new CreatePartitionsResult(new HashMap<>(futures));
}
Aggregations