{"action":"created","comment":{"url":"https://api.github.com/repos/apache/kafka/pulls/comments/71525529","id":71525529,"diff_hunk":"@@ -0,0 +1,208 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE\n+ * file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file\n+ * to You under the Apache License, Version 2.0 (the \"License\"); you may not use this file except in compliance with the\n+ * License. You may obtain a copy of the License at\n+ *\n+ * http://www.apache.org/licenses/LICENSE-2.0\n+ *\n+ * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on\n+ * an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the\n+ * specific language governing permissions and limitations under the License.\n+ */\n+package org.apache.kafka.tools;\n+\n+import joptsimple.OptionException;\n+import joptsimple.OptionParser;\n+import joptsimple.OptionSet;\n+import joptsimple.OptionSpec;\n+import kafka.admin.TopicCommand;\n+import kafka.utils.ZkUtils;\n+import org.apache.kafka.clients.consumer.ConsumerConfig;\n+import org.apache.kafka.clients.consumer.KafkaConsumer;\n+import org.apache.kafka.common.TopicPartition;\n+import org.apache.kafka.common.security.JaasUtils;\n+import org.apache.kafka.common.serialization.ByteArrayDeserializer;\n+\n+import java.io.IOException;\n+import java.util.Collections;\n+import java.util.LinkedList;\n+import java.util.List;\n+import java.util.Properties;\n+import java.util.Set;\n+\n+/**\n+ * {@link StreamsCleanupClient} resets a Kafka Streams application to the very beginning. Thus, an application can\n+ * reprocess the whole input from scratch.\n+ * <p>\n+ * This includes, setting source topic offsets to zero, skipping over all intermediate user topics,\n+ * and deleting all internally created topics.\n+ */\n+public class StreamsCleanupClient {\n+    private static OptionSpec<String> bootstrapServerOption;\n+    private static OptionSpec<String> zookeeperOption;\n+    private static OptionSpec<String> applicationIdOption;\n+    private static OptionSpec<String> sourceTopicsOption;\n+    private static OptionSpec<String> intermediateTopicsOption;\n+\n+    private OptionSet options = null;\n+\n+    public void run(String[] args) {\n+        ZkUtils zkUtils = null;\n+\n+        int exitCode = 0;\n+        try {\n+            parseArguments(args);\n+\n+            zkUtils = ZkUtils.apply(options.valueOf(zookeeperOption),\n+                    30000,\n+                    30000,\n+                    JaasUtils.isZkSecurityEnabled());\n+\n+            final List<String> allTopics = scala.collection.JavaConversions.seqAsJavaList(zkUtils.getAllTopics());\n+\n+            resetSourceTopicOffsets();\n+            seekToEndIntermediateTopics(zkUtils, allTopics);\n+            deleteInternalTopics(zkUtils, allTopics);\n+        } catch (Exception e) {\n+            exitCode = -1;\n+            System.err.println(e.getMessage());\n+        } finally {\n+            if (zkUtils != null) {\n+                zkUtils.close();\n+            }\n+            System.exit(exitCode);\n+        }\n+    }\n+\n+    private void parseArguments(final String[] args) throws IOException {\n+        final OptionParser optionParser = new OptionParser();\n+        applicationIdOption = optionParser.accepts(\"application-id\", \"The Kafka Streams application ID (application.id)\")\n+                .withRequiredArg()\n+                .describedAs(\"id\")\n+                .ofType(String.class)\n+                .required();\n+        bootstrapServerOption = optionParser.accepts(\"bootstrap-server\", \"Format: <host:port>\")\n+                .withRequiredArg()\n+                .describedAs(\"url\")\n+                .defaultsTo(\"localhost:9092\")\n+                .ofType(String.class);\n+        zookeeperOption = optionParser.accepts(\"zookeeper\", \"Format: <host:port>\")\n+                .withRequiredArg()\n+                .describedAs(\"url\")\n+                .defaultsTo(\"localhost:2181\")\n+                .ofType(String.class);\n+        sourceTopicsOption = optionParser.accepts(\"source-topics\", \"Comma separated list of user source topics\")\n+                .withRequiredArg()\n+                .describedAs(\"list\")\n+                .ofType(String.class);\n+        intermediateTopicsOption = optionParser.accepts(\"intermediate-topics\", \"Comma separated list of intermediate user topics\")","path":"tools/src/main/java/org/apache/kafka/tools/StreamsCleanupClient.java","position":99,"original_position":99,"commit_id":"eeacd3a2f812395ead416412ccb7e5fe842543f1","original_commit_id":"eeacd3a2f812395ead416412ccb7e5fe842543f1","user":{"login":"mjsax","id":8959638,"avatar_url":"https://avatars.githubusercontent.com/u/8959638?v=3","gravatar_id":"","url":"https://api.github.com/users/mjsax","html_url":"https://github.com/mjsax","followers_url":"https://api.github.com/users/mjsax/followers","following_url":"https://api.github.com/users/mjsax/following{/other_user}","gists_url":"https://api.github.com/users/mjsax/gists{/gist_id}","starred_url":"https://api.github.com/users/mjsax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjsax/subscriptions","organizations_url":"https://api.github.com/users/mjsax/orgs","repos_url":"https://api.github.com/users/mjsax/repos","events_url":"https://api.github.com/users/mjsax/events{/privacy}","received_events_url":"https://api.github.com/users/mjsax/received_events","type":"User","site_admin":false},"body":"We will have a wiki page explaining the differences.\r\n(Using option `--intermediate--topics` will not be recommended there -- for intermediate user topics, we suggest to delete and recreate them manually. For development, this option is still useful.)\r\n\r\nIn general, users are responsible to specify the correct values -- otherwise, they mess up the application state.","created_at":"2016-07-20T13:40:04Z","updated_at":"2016-07-20T13:40:04Z","html_url":"https://github.com/apache/kafka/pull/1636#discussion_r71525529","pull_request_url":"https://api.github.com/repos/apache/kafka/pulls/1636","_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments/71525529"},"html":{"href":"https://github.com/apache/kafka/pull/1636#discussion_r71525529"},"pull_request":{"href":"https://api.github.com/repos/apache/kafka/pulls/1636"}}},"pull_request":{"url":"https://api.github.com/repos/apache/kafka/pulls/1636","id":77965160,"html_url":"https://github.com/apache/kafka/pull/1636","diff_url":"https://github.com/apache/kafka/pull/1636.diff","patch_url":"https://github.com/apache/kafka/pull/1636.patch","issue_url":"https://api.github.com/repos/apache/kafka/issues/1636","number":1636,"state":"open","locked":false,"title":"KAFKA-3185: Allow users to cleanup internal Kafka Streams data","user":{"login":"mjsax","id":8959638,"avatar_url":"https://avatars.githubusercontent.com/u/8959638?v=3","gravatar_id":"","url":"https://api.github.com/users/mjsax","html_url":"https://github.com/mjsax","followers_url":"https://api.github.com/users/mjsax/followers","following_url":"https://api.github.com/users/mjsax/following{/other_user}","gists_url":"https://api.github.com/users/mjsax/gists{/gist_id}","starred_url":"https://api.github.com/users/mjsax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjsax/subscriptions","organizations_url":"https://api.github.com/users/mjsax/orgs","repos_url":"https://api.github.com/users/mjsax/repos","events_url":"https://api.github.com/users/mjsax/events{/privacy}","received_events_url":"https://api.github.com/users/mjsax/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-19T12:14:12Z","updated_at":"2016-07-20T13:40:04Z","closed_at":null,"merged_at":null,"merge_commit_sha":"07db26eb035264d1c1b92998c6482d7292e3ceb1","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/kafka/pulls/1636/commits","review_comments_url":"https://api.github.com/repos/apache/kafka/pulls/1636/comments","review_comment_url":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/kafka/issues/1636/comments","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/eeacd3a2f812395ead416412ccb7e5fe842543f1","head":{"label":"mjsax:kafka-3185","ref":"kafka-3185","sha":"eeacd3a2f812395ead416412ccb7e5fe842543f1","user":{"login":"mjsax","id":8959638,"avatar_url":"https://avatars.githubusercontent.com/u/8959638?v=3","gravatar_id":"","url":"https://api.github.com/users/mjsax","html_url":"https://github.com/mjsax","followers_url":"https://api.github.com/users/mjsax/followers","following_url":"https://api.github.com/users/mjsax/following{/other_user}","gists_url":"https://api.github.com/users/mjsax/gists{/gist_id}","starred_url":"https://api.github.com/users/mjsax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjsax/subscriptions","organizations_url":"https://api.github.com/users/mjsax/orgs","repos_url":"https://api.github.com/users/mjsax/repos","events_url":"https://api.github.com/users/mjsax/events{/privacy}","received_events_url":"https://api.github.com/users/mjsax/received_events","type":"User","site_admin":false},"repo":{"id":50839421,"name":"kafka","full_name":"mjsax/kafka","owner":{"login":"mjsax","id":8959638,"avatar_url":"https://avatars.githubusercontent.com/u/8959638?v=3","gravatar_id":"","url":"https://api.github.com/users/mjsax","html_url":"https://github.com/mjsax","followers_url":"https://api.github.com/users/mjsax/followers","following_url":"https://api.github.com/users/mjsax/following{/other_user}","gists_url":"https://api.github.com/users/mjsax/gists{/gist_id}","starred_url":"https://api.github.com/users/mjsax/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mjsax/subscriptions","organizations_url":"https://api.github.com/users/mjsax/orgs","repos_url":"https://api.github.com/users/mjsax/repos","events_url":"https://api.github.com/users/mjsax/events{/privacy}","received_events_url":"https://api.github.com/users/mjsax/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mjsax/kafka","description":"Mirror of Apache Kafka","fork":true,"url":"https://api.github.com/repos/mjsax/kafka","forks_url":"https://api.github.com/repos/mjsax/kafka/forks","keys_url":"https://api.github.com/repos/mjsax/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mjsax/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mjsax/kafka/teams","hooks_url":"https://api.github.com/repos/mjsax/kafka/hooks","issue_events_url":"https://api.github.com/repos/mjsax/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/mjsax/kafka/events","assignees_url":"https://api.github.com/repos/mjsax/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/mjsax/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/mjsax/kafka/tags","blobs_url":"https://api.github.com/repos/mjsax/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mjsax/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mjsax/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/mjsax/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mjsax/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/mjsax/kafka/languages","stargazers_url":"https://api.github.com/repos/mjsax/kafka/stargazers","contributors_url":"https://api.github.com/repos/mjsax/kafka/contributors","subscribers_url":"https://api.github.com/repos/mjsax/kafka/subscribers","subscription_url":"https://api.github.com/repos/mjsax/kafka/subscription","commits_url":"https://api.github.com/repos/mjsax/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/mjsax/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/mjsax/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/mjsax/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/mjsax/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/mjsax/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mjsax/kafka/merges","archive_url":"https://api.github.com/repos/mjsax/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mjsax/kafka/downloads","issues_url":"https://api.github.com/repos/mjsax/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/mjsax/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/mjsax/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/mjsax/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mjsax/kafka/labels{/name}","releases_url":"https://api.github.com/repos/mjsax/kafka/releases{/id}","deployments_url":"https://api.github.com/repos/mjsax/kafka/deployments","created_at":"2016-02-01T12:57:30Z","updated_at":"2016-02-01T12:57:34Z","pushed_at":"2016-07-19T12:16:08Z","git_url":"git://github.com/mjsax/kafka.git","ssh_url":"git@github.com:mjsax/kafka.git","clone_url":"https://github.com/mjsax/kafka.git","svn_url":"https://github.com/mjsax/kafka","homepage":null,"size":32589,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"trunk"}},"base":{"label":"apache:trunk","ref":"trunk","sha":"0744449eaa0f80827b60f2be3a5a2cc306360ce7","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":2211243,"name":"kafka","full_name":"apache/kafka","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/kafka","description":"Mirror of Apache Kafka","fork":false,"url":"https://api.github.com/repos/apache/kafka","forks_url":"https://api.github.com/repos/apache/kafka/forks","keys_url":"https://api.github.com/repos/apache/kafka/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/kafka/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/kafka/teams","hooks_url":"https://api.github.com/repos/apache/kafka/hooks","issue_events_url":"https://api.github.com/repos/apache/kafka/issues/events{/number}","events_url":"https://api.github.com/repos/apache/kafka/events","assignees_url":"https://api.github.com/repos/apache/kafka/assignees{/user}","branches_url":"https://api.github.com/repos/apache/kafka/branches{/branch}","tags_url":"https://api.github.com/repos/apache/kafka/tags","blobs_url":"https://api.github.com/repos/apache/kafka/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/kafka/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/kafka/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/kafka/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/kafka/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/kafka/languages","stargazers_url":"https://api.github.com/repos/apache/kafka/stargazers","contributors_url":"https://api.github.com/repos/apache/kafka/contributors","subscribers_url":"https://api.github.com/repos/apache/kafka/subscribers","subscription_url":"https://api.github.com/repos/apache/kafka/subscription","commits_url":"https://api.github.com/repos/apache/kafka/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/kafka/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/kafka/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/kafka/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/kafka/contents/{+path}","compare_url":"https://api.github.com/repos/apache/kafka/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/kafka/merges","archive_url":"https://api.github.com/repos/apache/kafka/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/kafka/downloads","issues_url":"https://api.github.com/repos/apache/kafka/issues{/number}","pulls_url":"https://api.github.com/repos/apache/kafka/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/kafka/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/kafka/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/kafka/labels{/name}","releases_url":"https://api.github.com/repos/apache/kafka/releases{/id}","deployments_url":"https://api.github.com/repos/apache/kafka/deployments","created_at":"2011-08-15T18:06:16Z","updated_at":"2016-07-20T12:10:36Z","pushed_at":"2016-07-20T13:38:57Z","git_url":"git://github.com/apache/kafka.git","ssh_url":"git@github.com:apache/kafka.git","clone_url":"https://github.com/apache/kafka.git","svn_url":"https://github.com/apache/kafka","homepage":null,"size":45993,"stargazers_count":3472,"watchers_count":3472,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":2130,"mirror_url":"git://git.apache.org/kafka.git","open_issues_count":221,"forks":2130,"open_issues":221,"watchers":3472,"default_branch":"trunk"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/kafka/pulls/1636"},"html":{"href":"https://github.com/apache/kafka/pull/1636"},"issue":{"href":"https://api.github.com/repos/apache/kafka/issues/1636"},"comments":{"href":"https://api.github.com/repos/apache/kafka/issues/1636/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/kafka/pulls/1636/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/kafka/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/kafka/pulls/1636/commits"},"statuses":{"href":"https://api.github.com/repos/apache/kafka/statuses/eeacd3a2f812395ead416412ccb7e5fe842543f1"}}}}
{"actor":{"display_login":"mjsax"}}