Search in sources :

Example 1 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 List<String> topicsToDelete) {
    if (!isDeleteTopicEnabled) {
        log.info("Cannot delete topics since 'delete.topic.enable' is false. ");
        return;
    }
    final DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(topicsToDelete);
    final Map<String, KafkaFuture<Void>> results = deleteTopicsResult.values();
    List<String> failList = Lists.newArrayList();
    for (final Map.Entry<String, KafkaFuture<Void>> entry : results.entrySet()) {
        try {
            entry.getValue().get(30, TimeUnit.SECONDS);
        } catch (Exception e) {
            failList.add(entry.getKey());
        }
    }
    if (!failList.isEmpty()) {
        throw new KsqlException("Failed to clean up topics: " + failList.stream().collect(Collectors.joining(",")));
    }
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) Map(java.util.Map) KafkaTopicException(io.confluent.ksql.exception.KafkaTopicException) RetriableException(org.apache.kafka.common.errors.RetriableException) KafkaResponseGetFailedException(io.confluent.ksql.exception.KafkaResponseGetFailedException) ExecutionException(java.util.concurrent.ExecutionException) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException)

Example 2 with DeleteTopicsResult

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

the class KafkaTopicClientImplTest method getDeleteTopicsResult.

private DeleteTopicsResult getDeleteTopicsResult() {
    DeleteTopicsResult deleteTopicsResult = mock(DeleteTopicsResult.class);
    expect(deleteTopicsResult.values()).andReturn(Collections.singletonMap(topicName1, KafkaFuture.allOf()));
    replay(deleteTopicsResult);
    return deleteTopicsResult;
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 3 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 4 with DeleteTopicsResult

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

the class KafkaSystemAdmin method clearStream.

@Override
public boolean clearStream(StreamSpec streamSpec) {
    LOG.info("Creating Kafka topic: {} on system: {}", streamSpec.getPhysicalName(), streamSpec.getSystemName());
    String topicName = streamSpec.getPhysicalName();
    try {
        DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(ImmutableSet.of(topicName));
        deleteTopicsResult.all().get(KAFKA_ADMIN_OPS_TIMEOUT_MS, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        LOG.error("Failed to delete topic {} with exception {}.", topicName, e);
        return false;
    }
    return true;
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) TopicExistsException(org.apache.kafka.common.errors.TopicExistsException) NotImplementedException(org.apache.commons.lang3.NotImplementedException) StreamValidationException(org.apache.samza.system.StreamValidationException) SamzaException(org.apache.samza.SamzaException)

Example 5 with DeleteTopicsResult

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

the class KafkaSinkITCase method deleteTestTopic.

private void deleteTestTopic(String topic) throws ExecutionException, InterruptedException, TimeoutException {
    final DeleteTopicsResult result = admin.deleteTopics(Collections.singletonList(topic));
    result.all().get(1, TimeUnit.MINUTES);
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Aggregations

DeleteTopicsResult (org.apache.kafka.clients.admin.DeleteTopicsResult)11 KafkaFuture (org.apache.kafka.common.KafkaFuture)5 HashMap (java.util.HashMap)3 Map (java.util.Map)3 ExecutionException (java.util.concurrent.ExecutionException)3 IOException (java.io.IOException)2 ParseException (java.text.ParseException)2 OptionException (joptsimple.OptionException)2 TopicExistsException (org.apache.kafka.common.errors.TopicExistsException)2 KafkaResponseGetFailedException (io.confluent.ksql.exception.KafkaResponseGetFailedException)1 KafkaTopicException (io.confluent.ksql.exception.KafkaTopicException)1 ConfigMap (io.fabric8.kubernetes.api.model.ConfigMap)1 HashSet (java.util.HashSet)1 DatatypeConfigurationException (javax.xml.datatype.DatatypeConfigurationException)1 NotImplementedException (org.apache.commons.lang3.NotImplementedException)1 InterruptException (org.apache.kafka.common.errors.InterruptException)1 LeaderNotAvailableException (org.apache.kafka.common.errors.LeaderNotAvailableException)1 RetriableException (org.apache.kafka.common.errors.RetriableException)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)1