Search in sources :

Example 1 with KafkaDeleteTopicsException

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

the class KafkaTopicClientImpl method deleteTopics.

@Override
public void deleteTopics(final Collection<String> topicsToDelete) {
    if (topicsToDelete.isEmpty()) {
        return;
    }
    final DeleteTopicsResult deleteTopicsResult = adminClient.get().deleteTopics(topicsToDelete);
    final Map<String, KafkaFuture<Void>> results = deleteTopicsResult.topicNameValues();
    final List<String> failList = Lists.newArrayList();
    final List<Pair<String, Throwable>> exceptionList = Lists.newArrayList();
    for (final Map.Entry<String, KafkaFuture<Void>> entry : results.entrySet()) {
        try {
            entry.getValue().get(30, TimeUnit.SECONDS);
        } catch (final Exception e) {
            final Throwable rootCause = ExceptionUtils.getRootCause(e);
            if (rootCause instanceof TopicDeletionDisabledException) {
                throw new TopicDeletionDisabledException("Topic deletion is disabled. " + "To delete the topic, you must set '" + DELETE_TOPIC_ENABLE + "' to true in " + "the Kafka broker configuration.");
            } else if (rootCause instanceof TopicAuthorizationException) {
                throw new KsqlTopicAuthorizationException(AclOperation.DELETE, Collections.singleton(entry.getKey()));
            } else if (!(rootCause instanceof UnknownTopicOrPartitionException)) {
                LOG.error(String.format("Could not delete topic '%s'", entry.getKey()), e);
                failList.add(entry.getKey());
                exceptionList.add(new Pair<>(entry.getKey(), rootCause));
            }
        }
    }
    if (!failList.isEmpty()) {
        throw new KafkaDeleteTopicsException("Failed to clean up topics: " + String.join(",", failList), exceptionList);
    }
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) TopicDeletionDisabledException(org.apache.kafka.common.errors.TopicDeletionDisabledException) KafkaDeleteTopicsException(io.confluent.ksql.exception.KafkaDeleteTopicsException) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) KafkaDeleteTopicsException(io.confluent.ksql.exception.KafkaDeleteTopicsException) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) ExecutionException(java.util.concurrent.ExecutionException) KsqlServerException(io.confluent.ksql.util.KsqlServerException) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) TopicDeletionDisabledException(org.apache.kafka.common.errors.TopicDeletionDisabledException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) KsqlException(io.confluent.ksql.util.KsqlException) UnsupportedVersionException(org.apache.kafka.common.errors.UnsupportedVersionException) UnknownTopicOrPartitionException(org.apache.kafka.common.errors.UnknownTopicOrPartitionException) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) Map(java.util.Map) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) TopicAuthorizationException(org.apache.kafka.common.errors.TopicAuthorizationException) Pair(io.confluent.ksql.util.Pair)

Aggregations

KafkaDeleteTopicsException (io.confluent.ksql.exception.KafkaDeleteTopicsException)1 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)1 KsqlException (io.confluent.ksql.util.KsqlException)1 KsqlServerException (io.confluent.ksql.util.KsqlServerException)1 Pair (io.confluent.ksql.util.Pair)1 Map (java.util.Map)1 ExecutionException (java.util.concurrent.ExecutionException)1 DeleteTopicsResult (org.apache.kafka.clients.admin.DeleteTopicsResult)1 KafkaFuture (org.apache.kafka.common.KafkaFuture)1 TopicAuthorizationException (org.apache.kafka.common.errors.TopicAuthorizationException)1 TopicDeletionDisabledException (org.apache.kafka.common.errors.TopicDeletionDisabledException)1 TopicExistsException (org.apache.kafka.common.errors.TopicExistsException)1 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)1 UnsupportedVersionException (org.apache.kafka.common.errors.UnsupportedVersionException)1