Search in sources :

Example 1 with NewPartitions

use of org.apache.kafka.clients.admin.NewPartitions in project strimzi by strimzi.

the class ControllerAssignedKafkaImpl method increasePartitions.

@Override
public void increasePartitions(Topic topic, Handler<AsyncResult<Void>> handler) {
    final NewPartitions newPartitions = NewPartitions.increaseTo(topic.getNumPartitions());
    final Map<String, NewPartitions> request = Collections.singletonMap(topic.getTopicName().toString(), newPartitions);
    KafkaFuture<Void> future = adminClient.createPartitions(request).values().get(topic.getTopicName().toString());
    queueWork(new UniWork<>("increasePartitions", future, handler));
}
Also used : NewPartitions(org.apache.kafka.clients.admin.NewPartitions)

Example 2 with NewPartitions

use of org.apache.kafka.clients.admin.NewPartitions in project strimzi by strimzi.

the class ControllerIT method alterTopicNumPartitions.

private void alterTopicNumPartitions(TestContext context, String topicName, String configMapName) throws InterruptedException, ExecutionException {
    int changedValue = 2;
    NewPartitions newPartitions = NewPartitions.increaseTo(changedValue);
    Map<String, NewPartitions> map = new HashMap<>(1);
    map.put(topicName, newPartitions);
    CreatePartitionsResult createPartitionsResult = adminClient.createPartitions(map);
    createPartitionsResult.all().get();
    // Wait for the configmap to be modified
    waitFor(context, () -> {
        ConfigMap cm = kubeClient.configMaps().inNamespace(NAMESPACE).withName(configMapName).get();
        LOGGER.info("Polled configmap {}, waiting for partitions change", configMapName);
        int gotValue = TopicSerialization.fromConfigMap(cm).getNumPartitions();
        LOGGER.info("Got value {}", gotValue);
        return changedValue == gotValue;
    }, timeout, "Expected the configmap to have been deleted by now");
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) NewPartitions(org.apache.kafka.clients.admin.NewPartitions) HashMap(java.util.HashMap) CreatePartitionsResult(org.apache.kafka.clients.admin.CreatePartitionsResult)

Example 3 with NewPartitions

use of org.apache.kafka.clients.admin.NewPartitions in project apache-kafka-on-k8s by banzaicloud.

the class CreatePartitionsRequest method toStruct.

@Override
protected Struct toStruct() {
    Struct struct = new Struct(ApiKeys.CREATE_PARTITIONS.requestSchema(version()));
    List<Struct> topicPartitionsList = new ArrayList<>();
    for (Map.Entry<String, NewPartitions> topicPartitionCount : this.newPartitions.entrySet()) {
        Struct topicPartitionCountStruct = struct.instance(TOPIC_PARTITIONS_KEY_NAME);
        topicPartitionCountStruct.set(TOPIC_NAME, topicPartitionCount.getKey());
        NewPartitions count = topicPartitionCount.getValue();
        Struct partitionCountStruct = topicPartitionCountStruct.instance(NEW_PARTITIONS_KEY_NAME);
        partitionCountStruct.set(COUNT_KEY_NAME, count.totalCount());
        Object[][] assignments = null;
        if (count.assignments() != null) {
            assignments = new Object[count.assignments().size()][];
            int i = 0;
            for (List<Integer> partitionAssignment : count.assignments()) {
                assignments[i] = partitionAssignment.toArray(new Object[0]);
                i++;
            }
        }
        partitionCountStruct.set(ASSIGNMENT_KEY_NAME, assignments);
        topicPartitionCountStruct.set(NEW_PARTITIONS_KEY_NAME, partitionCountStruct);
        topicPartitionsList.add(topicPartitionCountStruct);
    }
    struct.set(TOPIC_PARTITIONS_KEY_NAME, topicPartitionsList.toArray(new Object[0]));
    struct.set(TIMEOUT_KEY_NAME, this.timeout);
    struct.set(VALIDATE_ONLY_KEY_NAME, this.validateOnly);
    return struct;
}
Also used : NewPartitions(org.apache.kafka.clients.admin.NewPartitions) ArrayList(java.util.ArrayList) HashMap(java.util.HashMap) Map(java.util.Map) Struct(org.apache.kafka.common.protocol.types.Struct)

Aggregations

NewPartitions (org.apache.kafka.clients.admin.NewPartitions)3 HashMap (java.util.HashMap)2 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 CreatePartitionsResult (org.apache.kafka.clients.admin.CreatePartitionsResult)1 Struct (org.apache.kafka.common.protocol.types.Struct)1