Search in sources :

Example 16 with DeleteTopicsResult

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

the class ControllerIT method deleteTopic.

private void deleteTopic(TestContext context, String topicName, String configMapName) throws InterruptedException, ExecutionException {
    LOGGER.info("Deleting topic {} (ConfigMap {})", topicName, configMapName);
    // Now we can delete the topic
    DeleteTopicsResult dlt = adminClient.deleteTopics(singletonList(topicName));
    dlt.all().get();
    LOGGER.info("Deleted topic {}", topicName);
    // Wait for the configmap to be deleted
    waitFor(context, () -> {
        ConfigMap cm = kubeClient.configMaps().inNamespace(NAMESPACE).withName(configMapName).get();
        LOGGER.info("Polled configmap {}, got {}, waiting for deletion", configMapName, cm);
        return cm == null;
    }, timeout, "Expected the configmap to have been deleted by now");
}
Also used : ConfigMap(io.fabric8.kubernetes.api.model.ConfigMap) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 17 with DeleteTopicsResult

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

the class TopicOperatorBaseIT method deleteTopicInKafka.

protected void deleteTopicInKafka(String topicName, String resourceName) throws InterruptedException, ExecutionException {
    LOGGER.info("Deleting topic {} (KafkaTopic {})", topicName, resourceName);
    // Now we can delete the topic
    DeleteTopicsResult dlt = adminClient.deleteTopics(singletonList(topicName));
    dlt.all().get();
    LOGGER.info("Deleted topic {}", topicName);
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 18 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult 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)

Example 19 with DeleteTopicsResult

use of org.apache.kafka.clients.admin.DeleteTopicsResult in project druid by apache.

the class KafkaAdminClient method deleteStream.

@Override
public void deleteStream(String streamName) throws Exception {
    DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(ImmutableList.of(streamName));
    deleteTopicsResult.values().get(streamName).get();
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 20 with DeleteTopicsResult

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

the class StreamsResetter method doDelete.

// visible for testing
public void doDelete(final List<String> topicsToDelete, final AdminClient adminClient) {
    boolean hasDeleteErrors = false;
    final DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(topicsToDelete);
    final Map<String, KafkaFuture<Void>> results = deleteTopicsResult.values();
    for (final Map.Entry<String, KafkaFuture<Void>> entry : results.entrySet()) {
        try {
            entry.getValue().get(30, TimeUnit.SECONDS);
        } catch (Exception e) {
            System.err.println("ERROR: deleting topic " + entry.getKey());
            e.printStackTrace(System.err);
            hasDeleteErrors = true;
        }
    }
    if (hasDeleteErrors) {
        throw new RuntimeException("Encountered an error deleting one or more topics");
    }
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) HashMap(java.util.HashMap) Map(java.util.Map) DatatypeConfigurationException(javax.xml.datatype.DatatypeConfigurationException) OptionException(joptsimple.OptionException) ParseException(java.text.ParseException) IOException(java.io.IOException)

Aggregations

DeleteTopicsResult (org.apache.kafka.clients.admin.DeleteTopicsResult)33 ExecutionException (java.util.concurrent.ExecutionException)12 AdminClient (org.apache.kafka.clients.admin.AdminClient)6 KafkaFuture (org.apache.kafka.common.KafkaFuture)6 IOException (java.io.IOException)4 Map (java.util.Map)4 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)3 ListTopicsResult (org.apache.kafka.clients.admin.ListTopicsResult)3 TopicExistsException (org.apache.kafka.common.errors.TopicExistsException)3 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)3 ByteArrayDeserializer (org.apache.kafka.common.serialization.ByteArrayDeserializer)3 ByteArraySerializer (org.apache.kafka.common.serialization.ByteArraySerializer)3 StringDeserializer (org.apache.kafka.common.serialization.StringDeserializer)3 StringSerializer (org.apache.kafka.common.serialization.StringSerializer)3 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)2 StringReader (java.io.StringReader)2 ParseException (java.text.ParseException)2 OptionException (joptsimple.OptionException)2 Cleanup (lombok.Cleanup)2