Search in sources :

Example 6 with CreatePartitionsTopic

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);
}
Also used : CreatePartitionsTopicCollection(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopicCollection) CreatePartitionsAssignment(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsAssignment) CreatePartitionsRequestData(org.apache.kafka.common.message.CreatePartitionsRequestData) CreatePartitionsTopic(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic)

Example 7 with CreatePartitionsTopic

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);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) CreatePartitionsTopicResult(org.apache.kafka.common.message.CreatePartitionsResponseData.CreatePartitionsTopicResult) CreatePartitionsTopic(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic)

Example 8 with CreatePartitionsTopic

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));
}
Also used : CreatePartitionsTopicCollection(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopicCollection) HashMap(java.util.HashMap) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) CreatePartitionsAssignment(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsAssignment) LinkedList(java.util.LinkedList) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) TreeMap(java.util.TreeMap) HashMap(java.util.HashMap) CreatePartitionsTopic(org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic)

Aggregations

CreatePartitionsTopic (org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopic)8 ArrayList (java.util.ArrayList)4 List (java.util.List)4 CreatePartitionsTopicResult (org.apache.kafka.common.message.CreatePartitionsResponseData.CreatePartitionsTopicResult)4 CreatePartitionsAssignment (org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsAssignment)3 CreatePartitionsTopicCollection (org.apache.kafka.common.message.CreatePartitionsRequestData.CreatePartitionsTopicCollection)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 CreatePartitionsRequestData (org.apache.kafka.common.message.CreatePartitionsRequestData)2 CreateTopicsRequestData (org.apache.kafka.common.message.CreateTopicsRequestData)2 CreatableTopic (org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic)2 CreateTopicsResponseData (org.apache.kafka.common.message.CreateTopicsResponseData)2 Test (org.junit.jupiter.api.Test)2 Arrays.asList (java.util.Arrays.asList)1 Collections.singletonList (java.util.Collections.singletonList)1 LinkedList (java.util.LinkedList)1 NoSuchElementException (java.util.NoSuchElementException)1 TreeMap (java.util.TreeMap)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CountDownLatch (java.util.concurrent.CountDownLatch)1