Search in sources :

Example 1 with KafkaAdminClient

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

the class StreamsResetter method run.

public int run(final String[] args, final Properties config) {
    int exitCode = EXIT_CODE_SUCCESS;
    KafkaAdminClient kafkaAdminClient = null;
    try {
        parseArguments(args);
        final boolean dryRun = options.has(dryRunOption);
        final String groupId = options.valueOf(applicationIdOption);
        final Properties properties = new Properties();
        if (options.has(commandConfigOption)) {
            properties.putAll(Utils.loadProps(options.valueOf(commandConfigOption)));
        }
        properties.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, options.valueOf(bootstrapServerOption));
        validateNoActiveConsumers(groupId, properties);
        kafkaAdminClient = (KafkaAdminClient) AdminClient.create(properties);
        allTopics.clear();
        allTopics.addAll(kafkaAdminClient.listTopics().names().get(60, TimeUnit.SECONDS));
        if (dryRun) {
            System.out.println("----Dry run displays the actions which will be performed when running Streams Reset Tool----");
        }
        final HashMap<Object, Object> consumerConfig = new HashMap<>(config);
        consumerConfig.putAll(properties);
        exitCode = maybeResetInputAndSeekToEndIntermediateTopicOffsets(consumerConfig, dryRun);
        maybeDeleteInternalTopics(kafkaAdminClient, dryRun);
    } catch (final Throwable e) {
        exitCode = EXIT_CODE_ERROR;
        System.err.println("ERROR: " + e);
        e.printStackTrace(System.err);
    } finally {
        if (kafkaAdminClient != null) {
            kafkaAdminClient.close(60, TimeUnit.SECONDS);
        }
    }
    return exitCode;
}
Also used : KafkaAdminClient(org.apache.kafka.clients.admin.KafkaAdminClient) HashMap(java.util.HashMap) Properties(java.util.Properties)

Aggregations

HashMap (java.util.HashMap)1 Properties (java.util.Properties)1 KafkaAdminClient (org.apache.kafka.clients.admin.KafkaAdminClient)1