public static void main(final String[] args) { System.exit(new StreamsResetter().run(args)); }
private void maybeDeleteInternalTopics(final KafkaAdminClient adminClient, final boolean dryRun) { System.out.println("Deleting all internal/auto-created topics for application " + options.valueOf(applicationIdOption)); List<String> topicsToDelete = new ArrayList<>(); for (final String listing : allTopics) { if (isInternalTopic(listing)) { if (!dryRun) { topicsToDelete.add(listing); } else { System.out.println("Topic: " + listing); } } } if (!dryRun) { doDelete(topicsToDelete, adminClient); } System.out.println("Done."); }
public void resetOffsetsTo(Consumer<byte[], byte[]> client, Set<TopicPartition> inputTopicPartitions, Long offset) { final Map<TopicPartition, Long> endOffsets = client.endOffsets(inputTopicPartitions); final Map<TopicPartition, Long> beginningOffsets = client.beginningOffsets(inputTopicPartitions); final Map<TopicPartition, Long> topicPartitionsAndOffset = new HashMap<>(inputTopicPartitions.size()); for (final TopicPartition topicPartition : inputTopicPartitions) { topicPartitionsAndOffset.put(topicPartition, offset); } final Map<TopicPartition, Long> validatedTopicPartitionsAndOffset = checkOffsetRange(topicPartitionsAndOffset, beginningOffsets, endOffsets); for (final TopicPartition topicPartition : inputTopicPartitions) { client.seek(topicPartition, validatedTopicPartitionsAndOffset.get(topicPartition)); } }
System.out.println("Following input topics offsets will be reset to (for consumer group " + groupId + ")"); if (options.has(toOffsetOption)) { resetOffsetsTo(client, inputTopicPartitions, options.valueOf(toOffsetOption)); } else if (options.has(toEarliestOption)) { client.seekToBeginning(inputTopicPartitions); client.seekToEnd(inputTopicPartitions); } else if (options.has(shiftByOption)) { shiftOffsetsBy(client, inputTopicPartitions, options.valueOf(shiftByOption)); } else if (options.has(toDatetimeOption)) { final String ts = options.valueOf(toDatetimeOption); final long timestamp = getDateTime(ts); resetToDatetime(client, inputTopicPartitions, timestamp); } else if (options.has(byDurationOption)) { final String duration = options.valueOf(byDurationOption); final Duration durationParsed = DatatypeFactory.newInstance().newDuration(duration); resetByDuration(client, inputTopicPartitions, durationParsed); } else if (options.has(fromFileOption)) { final String resetPlanPath = options.valueOf(fromFileOption); final Map<TopicPartition, Long> topicPartitionsAndOffset = getTopicPartitionOffsetFromResetPlan(resetPlanPath); resetOffsetsFromResetPlan(client, inputTopicPartitions, topicPartitionsAndOffset); } else { client.seekToBeginning(inputTopicPartitions);
if (isInputTopic(topic)) { inputTopicPartitions.add(p); } else if (isIntermediateTopic(topic)) { intermediateTopicPartitions.add(p); } else { maybeReset(groupId, client, inputTopicPartitions); maybeSeekToEnd(groupId, client, intermediateTopicPartitions);
parseArguments(args); validateNoActiveConsumers(groupId, kafkaAdminClient); exitCode = maybeResetInputAndSeekToEndIntermediateTopicOffsets(consumerConfig, dryRun); maybeDeleteInternalTopics(kafkaAdminClient, dryRun);
if (isInternalTopic(topic)) { topicsToSubscribe.add(topic); if (isInputTopic(topic) || isInternalTopic(topic)) { inputAndInternalTopicPartitions.add(p); } else if (isIntermediateTopic(topic)) { intermediateTopicPartitions.add(p); } else {
public int run(final String[] args) { return run(args, new Properties()); }
ZkUtils zkUtils = null; try { parseArguments(args); allTopics.addAll(scala.collection.JavaConversions.seqAsJavaList(zkUtils.getAllTopics())); resetInputAndInternalAndSeekToEndIntermediateTopicOffsets(); deleteInternalTopics(zkUtils); } catch (final Throwable e) { exitCode = EXIT_CODE_ERROR;
private void deleteInternalTopics(final ZkUtils zkUtils) { System.out.println("Deleting all internal/auto-created topics for application " + options.valueOf(applicationIdOption)); for (final String topic : allTopics) { if (isInternalTopic(topic)) { final TopicCommand.TopicCommandOptions commandOptions = new TopicCommand.TopicCommandOptions(new String[]{ "--zookeeper", options.valueOf(zookeeperOption), "--delete", "--topic", topic}); try { TopicCommand.deleteTopic(zkUtils, commandOptions); } catch (final RuntimeException e) { System.err.println("ERROR: Deleting topic " + topic + " failed."); throw e; } } } System.out.println("Done."); }
System.out.println("Following input topics offsets will be reset to (for consumer group " + groupId + ")"); if (options.has(toOffsetOption)) { resetOffsetsTo(client, inputTopicPartitions, options.valueOf(toOffsetOption)); } else if (options.has(toEarliestOption)) { client.seekToBeginning(inputTopicPartitions); client.seekToEnd(inputTopicPartitions); } else if (options.has(shiftByOption)) { shiftOffsetsBy(client, inputTopicPartitions, options.valueOf(shiftByOption)); } else if (options.has(toDatetimeOption)) { final String ts = options.valueOf(toDatetimeOption); final long timestamp = getDateTime(ts); resetToDatetime(client, inputTopicPartitions, timestamp); } else if (options.has(byDurationOption)) { final String duration = options.valueOf(byDurationOption); final Duration durationParsed = DatatypeFactory.newInstance().newDuration(duration); resetByDuration(client, inputTopicPartitions, durationParsed); } else if (options.has(fromFileOption)) { final String resetPlanPath = options.valueOf(fromFileOption); final Map<TopicPartition, Long> topicPartitionsAndOffset = getTopicPartitionOffsetFromResetPlan(resetPlanPath); resetOffsetsFromResetPlan(client, inputTopicPartitions, topicPartitionsAndOffset); } else { client.seekToBeginning(inputTopicPartitions);
if (isInputTopic(topic)) { inputTopicPartitions.add(p); } else if (isIntermediateTopic(topic)) { intermediateTopicPartitions.add(p); } else { maybeReset(groupId, client, inputTopicPartitions); maybeSeekToEnd(groupId, client, intermediateTopicPartitions);
parseArguments(args); validateNoActiveConsumers(groupId, kafkaAdminClient); exitCode = maybeResetInputAndSeekToEndIntermediateTopicOffsets(consumerConfig, dryRun); maybeDeleteInternalTopics(kafkaAdminClient, dryRun);
public int run(final String[] args) { return run(args, new Properties()); }
System.out.println("Following input topics offsets will be reset to (for consumer group " + groupId + ")"); if (options.has(toOffsetOption)) { resetOffsetsTo(client, inputTopicPartitions, options.valueOf(toOffsetOption)); } else if (options.has(toEarliestOption)) { client.seekToBeginning(inputTopicPartitions); client.seekToEnd(inputTopicPartitions); } else if (options.has(shiftByOption)) { shiftOffsetsBy(client, inputTopicPartitions, options.valueOf(shiftByOption)); } else if (options.has(toDatetimeOption)) { final String ts = options.valueOf(toDatetimeOption); final long timestamp = getDateTime(ts); resetToDatetime(client, inputTopicPartitions, timestamp); } else if (options.has(byDurationOption)) { final String duration = options.valueOf(byDurationOption); final Duration durationParsed = DatatypeFactory.newInstance().newDuration(duration); resetByDuration(client, inputTopicPartitions, durationParsed); } else if (options.has(fromFileOption)) { final String resetPlanPath = options.valueOf(fromFileOption); final Map<TopicPartition, Long> topicPartitionsAndOffset = getTopicPartitionOffsetFromResetPlan(resetPlanPath); resetOffsetsFromResetPlan(client, inputTopicPartitions, topicPartitionsAndOffset); } else { client.seekToBeginning(inputTopicPartitions);
if (isInputTopic(topic)) { inputTopicPartitions.add(p); } else if (isIntermediateTopic(topic)) { intermediateTopicPartitions.add(p); } else { maybeReset(groupId, client, inputTopicPartitions); maybeSeekToEnd(groupId, client, intermediateTopicPartitions);
parseArguments(args); validateNoActiveConsumers(groupId, kafkaAdminClient); exitCode = maybeResetInputAndSeekToEndIntermediateTopicOffsets(consumerConfig, dryRun); maybeDeleteInternalTopics(kafkaAdminClient, dryRun);
public static void main(final String[] args) { Exit.exit(new StreamsResetter().run(args)); }
private void maybeDeleteInternalTopics(final KafkaAdminClient adminClient, final boolean dryRun) { System.out.println("Deleting all internal/auto-created topics for application " + options.valueOf(applicationIdOption)); List<String> topicsToDelete = new ArrayList<>(); for (final String listing : allTopics) { if (isInternalTopic(listing)) { if (!dryRun) { topicsToDelete.add(listing); } else { System.out.println("Topic: " + listing); } } } if (!dryRun) { doDelete(topicsToDelete, adminClient); } System.out.println("Done."); }
public void resetOffsetsTo(Consumer<byte[], byte[]> client, Set<TopicPartition> inputTopicPartitions, Long offset) { final Map<TopicPartition, Long> endOffsets = client.endOffsets(inputTopicPartitions); final Map<TopicPartition, Long> beginningOffsets = client.beginningOffsets(inputTopicPartitions); final Map<TopicPartition, Long> topicPartitionsAndOffset = new HashMap<>(inputTopicPartitions.size()); for (final TopicPartition topicPartition : inputTopicPartitions) { topicPartitionsAndOffset.put(topicPartition, offset); } final Map<TopicPartition, Long> validatedTopicPartitionsAndOffset = checkOffsetRange(topicPartitionsAndOffset, beginningOffsets, endOffsets); for (final TopicPartition topicPartition : inputTopicPartitions) { client.seek(topicPartition, validatedTopicPartitionsAndOffset.get(topicPartition)); } }