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");
}
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);
}
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);
}
}
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();
}
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");
}
}
Aggregations