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 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 starlight-for-kafka by datastax.
the class KafkaAuthorizationTestBase method testDeleteTopicFailed.
@Test(timeOut = 20000)
public void testDeleteTopicFailed() throws PulsarAdminException, InterruptedException {
String newTopic = "testDeleteTopicFailed";
String fullNewTopicName = "persistent://" + TENANT + "/" + NAMESPACE + "/" + newTopic;
admin.topics().createPartitionedTopic(fullNewTopicName, 1);
@Cleanup AdminClient adminClient = createAdminClient(TENANT + "/" + NAMESPACE, userToken);
DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(Collections.singletonList(newTopic));
try {
deleteTopicsResult.all().get();
fail("Should delete failed!");
} catch (ExecutionException ex) {
assertTrue(ex.getMessage().contains("TopicAuthorizationException"));
}
try {
admin.topics().createPartitionedTopic(fullNewTopicName, 1);
} catch (PulsarAdminException exception) {
assertTrue(exception.getMessage().contains("This topic already exists"));
}
admin.topics().deletePartitionedTopic(fullNewTopicName);
adminClient.close();
}
use of org.apache.kafka.clients.admin.DeleteTopicsResult in project starlight-for-kafka by datastax.
the class KafkaAuthorizationTestBase method testDeleteTopicSuccess.
@Test(timeOut = 20000)
public void testDeleteTopicSuccess() throws PulsarAdminException, InterruptedException {
String newTopic = "testDeleteTopicSuccess";
String fullNewTopicName = "persistent://" + TENANT + "/" + NAMESPACE + "/" + newTopic;
admin.topics().createPartitionedTopic(fullNewTopicName, 1);
@Cleanup AdminClient adminClient = createAdminClient(TENANT + "/" + NAMESPACE, adminToken);
DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(Collections.singletonList(newTopic));
try {
deleteTopicsResult.all().get();
} catch (ExecutionException ex) {
fail("Should success but have : " + ex.getMessage());
}
List<String> topicList = admin.topics().getList(TENANT + "/" + NAMESPACE);
topicList.forEach(topic -> {
if (topic.startsWith(fullNewTopicName)) {
fail("Delete topic failed!");
}
});
adminClient.close();
}
use of org.apache.kafka.clients.admin.DeleteTopicsResult in project kop by streamnative.
the class KafkaAuthorizationTestBase method testDeleteTopicFailed.
@Test(timeOut = 20000)
public void testDeleteTopicFailed() throws PulsarAdminException, InterruptedException {
String newTopic = "testDeleteTopicFailed";
String fullNewTopicName = "persistent://" + TENANT + "/" + NAMESPACE + "/" + newTopic;
admin.topics().createPartitionedTopic(fullNewTopicName, 1);
AdminClient adminClient = createAdminClient(TENANT + "/" + NAMESPACE, userToken);
DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(Collections.singletonList(newTopic));
try {
deleteTopicsResult.all().get();
fail("Should delete failed!");
} catch (ExecutionException ex) {
log.info("Test delete topic failed", ex);
assertTrue(ex.getMessage().contains("TopicAuthorizationException"));
}
try {
admin.topics().createPartitionedTopic(fullNewTopicName, 1);
} catch (PulsarAdminException exception) {
assertTrue(exception.getMessage().contains("This topic already exists"));
}
admin.topics().deletePartitionedTopic(fullNewTopicName);
adminClient.close();
}
Aggregations