Search in sources :

Example 1 with KafkaTopicException

use of io.confluent.ksql.exception.KafkaTopicException in project ksql by confluentinc.

the class KafkaTopicClientImpl method validateTopicProperties.

private void validateTopicProperties(final String topic, final int numPartitions, final short replicationFactor) {
    Map<String, TopicDescription> topicDescriptions = describeTopics(Collections.singletonList(topic));
    TopicDescription topicDescription = topicDescriptions.get(topic);
    if (topicDescription.partitions().size() != numPartitions || topicDescription.partitions().get(0).replicas().size() < replicationFactor) {
        throw new KafkaTopicException(String.format("Topic '%s' does not conform to the requirements Partitions:%d v %d. Replication: %d " + "v %d", topic, topicDescription.partitions().size(), numPartitions, topicDescription.partitions().get(0).replicas().size(), replicationFactor));
    }
    // Topic with the partitions and replicas exists, reuse it!
    log.debug("Did not create topic {} with {} partitions and replication-factor {} since it already " + "exists", topic, numPartitions, replicationFactor);
}
Also used : KafkaTopicException(io.confluent.ksql.exception.KafkaTopicException) TopicDescription(org.apache.kafka.clients.admin.TopicDescription)

Example 2 with KafkaTopicException

use of io.confluent.ksql.exception.KafkaTopicException in project ksql by confluentinc.

the class KsqlRestApplicationTest method shouldNotFailIfTopicExistsOnCreation.

@Test
public void shouldNotFailIfTopicExistsOnCreation() {
    topicClient.createTopic(COMMAND_TOPIC, 1, (short) 1, commandTopicConfig);
    EasyMock.expectLastCall().andThrow(new KafkaTopicException("blah"));
    EasyMock.replay(topicClient);
    KsqlRestApplication.ensureCommandTopic(restConfig, topicClient, COMMAND_TOPIC);
    EasyMock.verify(topicClient);
}
Also used : KafkaTopicException(io.confluent.ksql.exception.KafkaTopicException) Test(org.junit.Test)

Aggregations

KafkaTopicException (io.confluent.ksql.exception.KafkaTopicException)2 TopicDescription (org.apache.kafka.clients.admin.TopicDescription)1 Test (org.junit.Test)1