Search in sources :

Example 31 with DeleteTopicsResult

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

the class StreamsResetter method doDelete.

// visible for testing
public void doDelete(final List<String> topicsToDelete, final Admin adminClient) {
    boolean hasDeleteErrors = false;
    final DeleteTopicsResult deleteTopicsResult = adminClient.deleteTopics(topicsToDelete);
    final Map<String, KafkaFuture<Void>> results = deleteTopicsResult.topicNameValues();
    for (final Map.Entry<String, KafkaFuture<Void>> entry : results.entrySet()) {
        try {
            entry.getValue().get(30, TimeUnit.SECONDS);
        } catch (final 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) OptionException(joptsimple.OptionException) ParseException(java.text.ParseException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 32 with DeleteTopicsResult

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

the class IntegrationTestHarness method deleteTopics.

protected boolean deleteTopics(Collection<String> topics) {
    boolean deleteStatus = true;
    try {
        DeleteTopicsResult resultFutures = adminClient.deleteTopics(topics);
        resultFutures.all().get(ADMIN_OPERATION_WAIT_DURATION_MS, TimeUnit.MILLISECONDS);
    } catch (Exception e) {
        LOG.error("Error deleting topics: {}", StringUtils.join(topics, ","), e);
        deleteStatus = false;
    }
    return deleteStatus;
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult)

Example 33 with DeleteTopicsResult

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

the class Kafka method destroyTmp.

@Override
public void destroyTmp() {
    // TODO Auto-generated method stub
    Properties config = new Properties();
    config.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "192.168.122.219:9092");
    AdminClient admin = AdminClient.create(config);
    List<String> list = new ArrayList<>();
    list.add(getReceiveService());
    DeleteTopicsResult deleteTopicsResult = admin.deleteTopics(list);
}
Also used : DeleteTopicsResult(org.apache.kafka.clients.admin.DeleteTopicsResult) ArrayList(java.util.ArrayList) Properties(java.util.Properties) AdminClient(org.apache.kafka.clients.admin.AdminClient)

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