Search in sources :

Example 66 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.

the class TopicSerializationTest method testErrorInConfigInvalidValueWrongType.

@Test
public void testErrorInConfigInvalidValueWrongType() {
    KafkaTopic kafkaTopic = new KafkaTopicBuilder().withMetadata(new ObjectMetaBuilder().withName("my-topic").build()).withNewSpec().withReplicas(1).withPartitions(1).withConfig(singletonMap("foo", new Object())).endSpec().build();
    try {
        TopicSerialization.fromTopicResource(kafkaTopic);
        fail("Should throw");
    } catch (InvalidTopicException e) {
        assertThat(e.getMessage(), is("KafkaTopic's spec.config has invalid entry: The key 'foo' of the topic config is invalid: The value corresponding to the key must have a string, number or boolean value but was of type java.lang.Object"));
    }
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) KafkaTopicBuilder(io.strimzi.api.kafka.model.KafkaTopicBuilder) ObjectMetaBuilder(io.fabric8.kubernetes.api.model.ObjectMetaBuilder) Test(org.junit.jupiter.api.Test)

Example 67 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.

the class TopicOperatorBaseIT method alterTopicNumPartitions.

protected void alterTopicNumPartitions(String topicName, String resourceName) throws InterruptedException, ExecutionException, TimeoutException {
    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 resource to be modified
    waitFor(() -> {
        KafkaTopic topic = operation().inNamespace(NAMESPACE).withName(resourceName).get();
        LOGGER.info("Polled topic {}, waiting for partitions change", resourceName);
        int gotValue = TopicSerialization.fromTopicResource(topic).getNumPartitions();
        LOGGER.info("Expected value {}, got value {}", changedValue, gotValue);
        return changedValue == gotValue;
    }, "Expected the topic " + topicName + "to have " + changedValue + " partitions by now");
}
Also used : NewPartitions(org.apache.kafka.clients.admin.NewPartitions) HashMap(java.util.HashMap) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic) CreatePartitionsResult(org.apache.kafka.clients.admin.CreatePartitionsResult)

Example 68 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.

the class TopicOperatorBaseIT method clearKafkaTopics.

protected final void clearKafkaTopics(final boolean deletionEnabled) throws TimeoutException, InterruptedException {
    if (deletionEnabled && kubeClient != null && operation().inNamespace(NAMESPACE).list().getItems() != null) {
        List<KafkaTopic> items = operation().inNamespace(NAMESPACE).list().getItems();
        // Wait for the operator to delete all the existing topics in Kafka
        for (KafkaTopic item : items) {
            String mdName = item.getMetadata().getName();
            String topicName = new TopicName(item).toString();
            // TODO FIXME !!
            if (topicName.startsWith("__"))
                continue;
            LOGGER.info("Deleting {} from Kube", mdName);
            operation().inNamespace(NAMESPACE).withName(mdName).withPropagationPolicy(DeletionPropagation.FOREGROUND).delete();
            LOGGER.info("Awaiting deletion of {} in Kafka", mdName);
            waitForTopicInKafka(topicName, false);
            waitForTopicInKube(mdName, false);
        }
    }
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic)

Example 69 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.

the class TopicOperatorBaseIT method assertStatusReady.

protected void assertStatusReady(String topicName) throws InterruptedException, ExecutionException, TimeoutException {
    waitFor(() -> {
        KafkaTopic kafkaTopic = operation().inNamespace(NAMESPACE).withName(topicName).get();
        if (kafkaTopic != null) {
            KafkaTopicStatus status = kafkaTopic.getStatus();
            if (status != null && Objects.equals(status.getObservedGeneration(), kafkaTopic.getMetadata().getGeneration()) && status.getConditions() != null) {
                List<Condition> conditions = status.getConditions();
                assertThat(conditions.size() > 0, is(true));
                if (conditions.stream().anyMatch(condition -> "Ready".equals(condition.getType()) && "True".equals(condition.getStatus()))) {
                    return true;
                } else {
                    LOGGER.info(conditions);
                }
            }
        } else {
            LOGGER.info("{} does not exist", topicName);
        }
        return false;
    }, "status ready for topic " + topicName);
}
Also used : KafkaTopicStatus(io.strimzi.api.kafka.model.status.KafkaTopicStatus) Condition(io.strimzi.api.kafka.model.status.Condition) KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic)

Example 70 with KafkaTopic

use of io.strimzi.api.kafka.model.KafkaTopic in project strimzi-kafka-operator by strimzi.

the class TopicOperatorBaseIT method awaitTopicConfigInKube.

protected void awaitTopicConfigInKube(String resourceName, String key, String expectedValue) throws TimeoutException, InterruptedException {
    // Wait for the resource to be modified
    waitFor(() -> {
        KafkaTopic topic = operation().inNamespace(NAMESPACE).withName(resourceName).get();
        LOGGER.info("Polled topic {}, waiting for config change", resourceName);
        String gotValue = TopicSerialization.fromTopicResource(topic).getConfig().get(key);
        LOGGER.info("Expecting value {}, got value {}", expectedValue, gotValue);
        return expectedValue.equals(gotValue);
    }, "Expected the config of topic " + resourceName + " to have " + key + "=" + expectedValue + " in Kube by now");
}
Also used : KafkaTopic(io.strimzi.api.kafka.model.KafkaTopic)

Aggregations

KafkaTopic (io.strimzi.api.kafka.model.KafkaTopic)187 Test (org.junit.jupiter.api.Test)92 KafkaTopicBuilder (io.strimzi.api.kafka.model.KafkaTopicBuilder)80 Checkpoint (io.vertx.junit5.Checkpoint)46 ObjectMetaBuilder (io.fabric8.kubernetes.api.model.ObjectMetaBuilder)38 HashMap (java.util.HashMap)32 ObjectMeta (io.fabric8.kubernetes.api.model.ObjectMeta)30 CountDownLatch (java.util.concurrent.CountDownLatch)28 NewTopic (org.apache.kafka.clients.admin.NewTopic)28 List (java.util.List)26 Map (java.util.Map)26 MeterRegistry (io.micrometer.core.instrument.MeterRegistry)22 KafkaTopicStatus (io.strimzi.api.kafka.model.status.KafkaTopicStatus)22 AsyncResult (io.vertx.core.AsyncResult)22 MaxAttemptsExceededException (io.strimzi.operator.common.MaxAttemptsExceededException)20 Vertx (io.vertx.core.Vertx)20 Matchers.containsString (org.hamcrest.Matchers.containsString)20 Watcher (io.fabric8.kubernetes.client.Watcher)18 KafkaClients (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClients)18 KafkaClientsBuilder (io.strimzi.systemtest.kafkaclients.internalClients.KafkaClientsBuilder)18