{"action":"created","comment":{"url":"https://api.github.com/repos/apache/storm/pulls/comments/57447253","id":57447253,"diff_hunk":"@@ -0,0 +1,110 @@\n+/**\n+ * Licensed to the Apache Software Foundation (ASF) under one\n+ * or more contributor license agreements.  See the NOTICE file\n+ * distributed with this work for additional information\n+ * regarding copyright ownership.  The ASF licenses this file\n+ * to you under the Apache License, Version 2.0 (the\n+ * \"License\"); you may not use this file except in compliance\n+ * with the 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\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+package org.apache.storm.daemon;\n+\n+import com.google.common.collect.Ordering;\n+import com.google.common.collect.Sets;\n+\n+import org.apache.storm.Thrift;\n+import org.apache.storm.generated.Grouping;\n+import org.apache.storm.grouping.CustomStreamGrouping;\n+import org.apache.storm.grouping.LoadMapping;\n+import org.apache.storm.task.WorkerTopologyContext;\n+import org.apache.storm.tuple.Fields;\n+import org.apache.storm.utils.Utils;\n+\n+import java.util.ArrayList;\n+import java.util.Collections;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Random;\n+import java.util.Set;\n+\n+public class GrouperFactory {\n+\n+    // A no-op grouper\n+    public static Grouper DIRECT = new Grouper() {\n+        @Override\n+        public List<Integer> outTasks(Integer taskId, List<Object> values, LoadMapping load) {\n+            return null;\n+        }\n+    };\n+\n+    public static Grouper mkGrouper(WorkerTopologyContext context, String componentId, String streamId, Fields outFields,\n+                                    Grouping thriftGrouping,\n+                                    List<Integer> unsortedTargetTasks,\n+                                    Map topoConf) {\n+        final Random random = new Random();\n+        final List<Integer> targetTasks = Ordering.natural().sortedCopy(unsortedTargetTasks);\n+        final int numTasks = targetTasks.size();\n+        switch (Thrift.groupingType(thriftGrouping)) {\n+            case FIELDS:\n+                if (Thrift.isGlobalGrouping(thriftGrouping)) {\n+                    return new Grouper() {\n+                        @Override\n+                        public List<Integer> outTasks(Integer taskId, List value, LoadMapping load) {\n+                            if (targetTasks.isEmpty()) {\n+                                return null;\n+                            }\n+                            // It's possible for target to have multiple tasks if it reads multiple sources\n+                            return Collections.singletonList(targetTasks.get(0));\n+                        }\n+                    };\n+                }\n+                return new Grouper.FieldsGrouper(outFields, thriftGrouping, targetTasks);\n+            case SHUFFLE:\n+                return new Grouper.ShuffleGrouper(context, componentId, streamId, targetTasks, topoConf);\n+            case ALL:\n+                return new Grouper() {\n+                    @Override\n+                    public List<Integer> outTasks(Integer taskId, List<Object> values, LoadMapping load) {\n+                        return targetTasks;\n+                    }\n+                };\n+            case LOCAL_OR_SHUFFLE:\n+                Set<Integer> sameTasks = Sets.intersection(Sets.newHashSet(targetTasks), Sets.newHashSet(context.getThisWorkerTasks()));\n+                if (sameTasks.isEmpty()) {\n+                    return new Grouper.ShuffleGrouper(context, componentId, streamId, targetTasks, topoConf);\n+                } else {\n+                    return new Grouper.ShuffleGrouper(context, componentId, streamId, new ArrayList<>(sameTasks), topoConf);\n+                }\n+            case NONE:\n+                return new Grouper() {\n+                    @Override\n+                    public List<Integer> outTasks(Integer taskId, List<Object> values, LoadMapping load) {\n+                        int index = random.nextInt(numTasks);\n+                        return Collections.singletonList(targetTasks.get(index));\n+                    }\n+                };\n+            case CUSTOM_OBJECT:\n+                CustomStreamGrouping customObject =\n+                    (CustomStreamGrouping) Thrift.instantiateJavaObject(thriftGrouping.get_custom_object());\n+                return new Grouper.CustomGrouper(customObject, context, componentId, streamId, targetTasks);\n+            case CUSTOM_SERIALIZED:\n+                CustomStreamGrouping\n+                    customSerialized =\n+                    Utils.javaDeserialize(thriftGrouping.get_custom_serialized(), CustomStreamGrouping.class);\n+                return new Grouper.CustomGrouper(customSerialized, context, componentId, streamId, targetTasks);","path":"storm-core/src/jvm/org/apache/storm/daemon/GrouperFactory.java","position":102,"original_position":102,"commit_id":"66e33349ce76a37ed82aab7784c3155fd3c7d6ae","original_commit_id":"66e33349ce76a37ed82aab7784c3155fd3c7d6ae","user":{"login":"revans2","id":3441321,"avatar_url":"https://avatars.githubusercontent.com/u/3441321?v=3","gravatar_id":"","url":"https://api.github.com/users/revans2","html_url":"https://github.com/revans2","followers_url":"https://api.github.com/users/revans2/followers","following_url":"https://api.github.com/users/revans2/following{/other_user}","gists_url":"https://api.github.com/users/revans2/gists{/gist_id}","starred_url":"https://api.github.com/users/revans2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/revans2/subscriptions","organizations_url":"https://api.github.com/users/revans2/orgs","repos_url":"https://api.github.com/users/revans2/repos","events_url":"https://api.github.com/users/revans2/events{/privacy}","received_events_url":"https://api.github.com/users/revans2/received_events","type":"User","site_admin":false},"body":"If someone created a CustormStreamGrouping that was also LoadAwareCustomStreamGrouping the LoadAware portion would never be called, because we are now using constructors instead of the builder pattern.  This really should be.\r\n\r\n```\r\ncase CUSTOM_SERIALIZED:\r\n  CustomStreamGrouping\r\n    customGrouping =\r\n      Utils.javaDeserialize(thriftGrouping.get_custom_serialized(), CustomStreamGrouping.class);\r\n    if (customGrouping instanceof CustomLoadAwareStreamGrouping) {\r\n      return new Grouper.LoadAwareCustomGrouper(customSerialized, context, componentId, streamId, targetTasks);\r\n    }\r\n    return new Grouper.CustomGrouper(customSerialized, context, componentId, streamId, targetTasks);\r\n```","created_at":"2016-03-25T14:16:43Z","updated_at":"2016-03-25T14:16:43Z","html_url":"https://github.com/apache/storm/pull/1249#discussion_r57447253","pull_request_url":"https://api.github.com/repos/apache/storm/pulls/1249","_links":{"self":{"href":"https://api.github.com/repos/apache/storm/pulls/comments/57447253"},"html":{"href":"https://github.com/apache/storm/pull/1249#discussion_r57447253"},"pull_request":{"href":"https://api.github.com/repos/apache/storm/pulls/1249"}}},"pull_request":{"url":"https://api.github.com/repos/apache/storm/pulls/1249","id":63867373,"html_url":"https://github.com/apache/storm/pull/1249","diff_url":"https://github.com/apache/storm/pull/1249.diff","patch_url":"https://github.com/apache/storm/pull/1249.patch","issue_url":"https://api.github.com/repos/apache/storm/issues/1249","number":1249,"state":"open","locked":false,"title":"STORM-1271: Port backtype.storm.daemon.task to java","user":{"login":"abhishekagarwal87","id":1477457,"avatar_url":"https://avatars.githubusercontent.com/u/1477457?v=3","gravatar_id":"","url":"https://api.github.com/users/abhishekagarwal87","html_url":"https://github.com/abhishekagarwal87","followers_url":"https://api.github.com/users/abhishekagarwal87/followers","following_url":"https://api.github.com/users/abhishekagarwal87/following{/other_user}","gists_url":"https://api.github.com/users/abhishekagarwal87/gists{/gist_id}","starred_url":"https://api.github.com/users/abhishekagarwal87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhishekagarwal87/subscriptions","organizations_url":"https://api.github.com/users/abhishekagarwal87/orgs","repos_url":"https://api.github.com/users/abhishekagarwal87/repos","events_url":"https://api.github.com/users/abhishekagarwal87/events{/privacy}","received_events_url":"https://api.github.com/users/abhishekagarwal87/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-03-23T11:29:31Z","updated_at":"2016-03-25T14:16:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9abfed29d456cab7a24c2a2a6baad5fbfd064a31","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/storm/pulls/1249/commits","review_comments_url":"https://api.github.com/repos/apache/storm/pulls/1249/comments","review_comment_url":"https://api.github.com/repos/apache/storm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/storm/issues/1249/comments","statuses_url":"https://api.github.com/repos/apache/storm/statuses/66e33349ce76a37ed82aab7784c3155fd3c7d6ae","head":{"label":"abhishekagarwal87:task","ref":"task","sha":"66e33349ce76a37ed82aab7784c3155fd3c7d6ae","user":{"login":"abhishekagarwal87","id":1477457,"avatar_url":"https://avatars.githubusercontent.com/u/1477457?v=3","gravatar_id":"","url":"https://api.github.com/users/abhishekagarwal87","html_url":"https://github.com/abhishekagarwal87","followers_url":"https://api.github.com/users/abhishekagarwal87/followers","following_url":"https://api.github.com/users/abhishekagarwal87/following{/other_user}","gists_url":"https://api.github.com/users/abhishekagarwal87/gists{/gist_id}","starred_url":"https://api.github.com/users/abhishekagarwal87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhishekagarwal87/subscriptions","organizations_url":"https://api.github.com/users/abhishekagarwal87/orgs","repos_url":"https://api.github.com/users/abhishekagarwal87/repos","events_url":"https://api.github.com/users/abhishekagarwal87/events{/privacy}","received_events_url":"https://api.github.com/users/abhishekagarwal87/received_events","type":"User","site_admin":false},"repo":{"id":41912769,"name":"storm","full_name":"abhishekagarwal87/storm","owner":{"login":"abhishekagarwal87","id":1477457,"avatar_url":"https://avatars.githubusercontent.com/u/1477457?v=3","gravatar_id":"","url":"https://api.github.com/users/abhishekagarwal87","html_url":"https://github.com/abhishekagarwal87","followers_url":"https://api.github.com/users/abhishekagarwal87/followers","following_url":"https://api.github.com/users/abhishekagarwal87/following{/other_user}","gists_url":"https://api.github.com/users/abhishekagarwal87/gists{/gist_id}","starred_url":"https://api.github.com/users/abhishekagarwal87/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/abhishekagarwal87/subscriptions","organizations_url":"https://api.github.com/users/abhishekagarwal87/orgs","repos_url":"https://api.github.com/users/abhishekagarwal87/repos","events_url":"https://api.github.com/users/abhishekagarwal87/events{/privacy}","received_events_url":"https://api.github.com/users/abhishekagarwal87/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/abhishekagarwal87/storm","description":"Mirror of Apache Storm","fork":true,"url":"https://api.github.com/repos/abhishekagarwal87/storm","forks_url":"https://api.github.com/repos/abhishekagarwal87/storm/forks","keys_url":"https://api.github.com/repos/abhishekagarwal87/storm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/abhishekagarwal87/storm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/abhishekagarwal87/storm/teams","hooks_url":"https://api.github.com/repos/abhishekagarwal87/storm/hooks","issue_events_url":"https://api.github.com/repos/abhishekagarwal87/storm/issues/events{/number}","events_url":"https://api.github.com/repos/abhishekagarwal87/storm/events","assignees_url":"https://api.github.com/repos/abhishekagarwal87/storm/assignees{/user}","branches_url":"https://api.github.com/repos/abhishekagarwal87/storm/branches{/branch}","tags_url":"https://api.github.com/repos/abhishekagarwal87/storm/tags","blobs_url":"https://api.github.com/repos/abhishekagarwal87/storm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/abhishekagarwal87/storm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/abhishekagarwal87/storm/git/refs{/sha}","trees_url":"https://api.github.com/repos/abhishekagarwal87/storm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/abhishekagarwal87/storm/statuses/{sha}","languages_url":"https://api.github.com/repos/abhishekagarwal87/storm/languages","stargazers_url":"https://api.github.com/repos/abhishekagarwal87/storm/stargazers","contributors_url":"https://api.github.com/repos/abhishekagarwal87/storm/contributors","subscribers_url":"https://api.github.com/repos/abhishekagarwal87/storm/subscribers","subscription_url":"https://api.github.com/repos/abhishekagarwal87/storm/subscription","commits_url":"https://api.github.com/repos/abhishekagarwal87/storm/commits{/sha}","git_commits_url":"https://api.github.com/repos/abhishekagarwal87/storm/git/commits{/sha}","comments_url":"https://api.github.com/repos/abhishekagarwal87/storm/comments{/number}","issue_comment_url":"https://api.github.com/repos/abhishekagarwal87/storm/issues/comments{/number}","contents_url":"https://api.github.com/repos/abhishekagarwal87/storm/contents/{+path}","compare_url":"https://api.github.com/repos/abhishekagarwal87/storm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/abhishekagarwal87/storm/merges","archive_url":"https://api.github.com/repos/abhishekagarwal87/storm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/abhishekagarwal87/storm/downloads","issues_url":"https://api.github.com/repos/abhishekagarwal87/storm/issues{/number}","pulls_url":"https://api.github.com/repos/abhishekagarwal87/storm/pulls{/number}","milestones_url":"https://api.github.com/repos/abhishekagarwal87/storm/milestones{/number}","notifications_url":"https://api.github.com/repos/abhishekagarwal87/storm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/abhishekagarwal87/storm/labels{/name}","releases_url":"https://api.github.com/repos/abhishekagarwal87/storm/releases{/id}","deployments_url":"https://api.github.com/repos/abhishekagarwal87/storm/deployments","created_at":"2015-09-04T11:42:14Z","updated_at":"2015-09-04T11:42:17Z","pushed_at":"2016-03-25T07:25:51Z","git_url":"git://github.com/abhishekagarwal87/storm.git","ssh_url":"git@github.com:abhishekagarwal87/storm.git","clone_url":"https://github.com/abhishekagarwal87/storm.git","svn_url":"https://github.com/abhishekagarwal87/storm","homepage":null,"size":102225,"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":"master"}},"base":{"label":"apache:master","ref":"master","sha":"4264bfc2a93a49f535fcad5fe8e871161ed13048","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":14135470,"name":"storm","full_name":"apache/storm","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/storm","description":"Mirror of Apache Storm","fork":false,"url":"https://api.github.com/repos/apache/storm","forks_url":"https://api.github.com/repos/apache/storm/forks","keys_url":"https://api.github.com/repos/apache/storm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/storm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/storm/teams","hooks_url":"https://api.github.com/repos/apache/storm/hooks","issue_events_url":"https://api.github.com/repos/apache/storm/issues/events{/number}","events_url":"https://api.github.com/repos/apache/storm/events","assignees_url":"https://api.github.com/repos/apache/storm/assignees{/user}","branches_url":"https://api.github.com/repos/apache/storm/branches{/branch}","tags_url":"https://api.github.com/repos/apache/storm/tags","blobs_url":"https://api.github.com/repos/apache/storm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/storm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/storm/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/storm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/storm/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/storm/languages","stargazers_url":"https://api.github.com/repos/apache/storm/stargazers","contributors_url":"https://api.github.com/repos/apache/storm/contributors","subscribers_url":"https://api.github.com/repos/apache/storm/subscribers","subscription_url":"https://api.github.com/repos/apache/storm/subscription","commits_url":"https://api.github.com/repos/apache/storm/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/storm/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/storm/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/storm/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/storm/contents/{+path}","compare_url":"https://api.github.com/repos/apache/storm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/storm/merges","archive_url":"https://api.github.com/repos/apache/storm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/storm/downloads","issues_url":"https://api.github.com/repos/apache/storm/issues{/number}","pulls_url":"https://api.github.com/repos/apache/storm/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/storm/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/storm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/storm/labels{/name}","releases_url":"https://api.github.com/repos/apache/storm/releases{/id}","deployments_url":"https://api.github.com/repos/apache/storm/deployments","created_at":"2013-11-05T08:00:14Z","updated_at":"2016-03-25T06:31:40Z","pushed_at":"2016-03-25T09:24:36Z","git_url":"git://github.com/apache/storm.git","ssh_url":"git@github.com:apache/storm.git","clone_url":"https://github.com/apache/storm.git","svn_url":"https://github.com/apache/storm","homepage":null,"size":162973,"stargazers_count":2982,"watchers_count":2982,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":2246,"mirror_url":"git://git.apache.org/storm.git","open_issues_count":85,"forks":2246,"open_issues":85,"watchers":2982,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/storm/pulls/1249"},"html":{"href":"https://github.com/apache/storm/pull/1249"},"issue":{"href":"https://api.github.com/repos/apache/storm/issues/1249"},"comments":{"href":"https://api.github.com/repos/apache/storm/issues/1249/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/storm/pulls/1249/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/storm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/storm/pulls/1249/commits"},"statuses":{"href":"https://api.github.com/repos/apache/storm/statuses/66e33349ce76a37ed82aab7784c3155fd3c7d6ae"}}}}