{"action":"created","comment":{"url":"https://api.github.com/repos/apache/storm/pulls/comments/52340405","id":52340405,"diff_hunk":"@@ -0,0 +1,247 @@\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.container.cgroup;\n+\n+import org.apache.storm.container.cgroup.core.CgroupCore;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import java.io.File;\n+import java.io.IOException;\n+import java.util.HashSet;\n+import java.util.List;\n+import java.util.Map;\n+import java.util.Set;\n+\n+public class CgroupCommon implements CgroupCommonOperation {\n+\n+    public static final String TASKS = \"/tasks\";\n+    public static final String NOTIFY_ON_RELEASE = \"/notify_on_release\";\n+    public static final String RELEASE_AGENT = \"/release_agent\";\n+    public static final String CGROUP_CLONE_CHILDREN = \"/cgroup.clone_children\";\n+    public static final String CGROUP_EVENT_CONTROL = \"/cgroup.event_control\";\n+    public static final String CGROUP_PROCS = \"/cgroup.procs\";\n+\n+    private final Hierarchy hierarchy;\n+\n+    private final String name;\n+\n+    private final String dir;\n+\n+    private final CgroupCommon parent;\n+\n+    //private final Map<SubSystemType, CgroupCore> cores;\n+\n+    private final boolean isRoot;\n+\n+    //private final Set<CgroupCommon> children = new HashSet<CgroupCommon>();\n+\n+    private static final Logger LOG = LoggerFactory.getLogger(CgroupCommon.class);\n+\n+    public CgroupCommon(String name, Hierarchy hierarchy, CgroupCommon parent) {\n+        this.name = parent.getName() + \"/\" + name;\n+        this.hierarchy = hierarchy;\n+        this.parent = parent;\n+        this.dir = parent.getDir() + \"/\" + name;\n+        this.isRoot = false;\n+    }\n+\n+    /**\n+     * rootCgroup\n+     */\n+    public CgroupCommon(Hierarchy hierarchy, String dir) {\n+        this.name = \"\";\n+        this.hierarchy = hierarchy;\n+        this.parent = null;\n+        this.dir = dir;\n+        this.isRoot = true;\n+    }\n+\n+    @Override\n+    public void addTask(int taskId) throws IOException {\n+        CgroupUtils.writeFileByLine(CgroupUtils.getDir(this.dir, TASKS), String.valueOf(taskId));\n+    }\n+\n+    @Override\n+    public Set<Integer> getTasks() throws IOException {\n+        List<String> stringTasks = CgroupUtils.readFileByLine(CgroupUtils.getDir(this.dir, TASKS));\n+        Set<Integer> tasks = new HashSet<Integer>();\n+        for (String task : stringTasks) {\n+            tasks.add(Integer.valueOf(task));\n+        }\n+        return tasks;\n+    }\n+\n+    @Override\n+    public void addProcs(int pid) throws IOException {\n+        CgroupUtils.writeFileByLine(CgroupUtils.getDir(this.dir, CGROUP_PROCS), String.valueOf(pid));\n+    }\n+\n+    @Override\n+    public Set<Integer> getPids() throws IOException {\n+        List<String> stringPids = CgroupUtils.readFileByLine(CgroupUtils.getDir(this.dir, CGROUP_PROCS));\n+        Set<Integer> pids = new HashSet<Integer>();\n+        for (String task : stringPids) {\n+            pids.add(Integer.valueOf(task));\n+        }\n+        return pids;\n+    }\n+\n+    @Override\n+    public void setNotifyOnRelease(boolean flag) throws IOException {\n+\n+        CgroupUtils.writeFileByLine(CgroupUtils.getDir(this.dir, NOTIFY_ON_RELEASE), flag ? \"1\" : \"0\");\n+    }\n+\n+    @Override\n+    public boolean getNotifyOnRelease() throws IOException {\n+        return CgroupUtils.readFileByLine(CgroupUtils.getDir(this.dir, NOTIFY_ON_RELEASE)).get(0).equals(\"1\") ? true : false;\n+    }\n+\n+    @Override\n+    public void setReleaseAgent(String command) throws IOException {\n+        if (!this.isRoot) {\n+            return;\n+        }\n+        CgroupUtils.writeFileByLine(CgroupUtils.getDir(this.dir, RELEASE_AGENT), command);\n+    }\n+\n+    @Override\n+    public String getReleaseAgent() throws IOException {\n+        if (!this.isRoot) {\n+            return null;\n+        }\n+        return CgroupUtils.readFileByLine(CgroupUtils.getDir(this.dir, RELEASE_AGENT)).get(0);","path":"storm-core/src/jvm/org/apache/storm/container/cgroup/CgroupCommon.java","position":129,"original_position":129,"commit_id":"05e37d32f287df5bff358ef1a3b6b847bbfdaa4c","original_commit_id":"05e37d32f287df5bff358ef1a3b6b847bbfdaa4c","user":{"login":"jerrypeng","id":3613359,"avatar_url":"https://avatars.githubusercontent.com/u/3613359?v=3","gravatar_id":"","url":"https://api.github.com/users/jerrypeng","html_url":"https://github.com/jerrypeng","followers_url":"https://api.github.com/users/jerrypeng/followers","following_url":"https://api.github.com/users/jerrypeng/following{/other_user}","gists_url":"https://api.github.com/users/jerrypeng/gists{/gist_id}","starred_url":"https://api.github.com/users/jerrypeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerrypeng/subscriptions","organizations_url":"https://api.github.com/users/jerrypeng/orgs","repos_url":"https://api.github.com/users/jerrypeng/repos","events_url":"https://api.github.com/users/jerrypeng/events{/privacy}","received_events_url":"https://api.github.com/users/jerrypeng/received_events","type":"User","site_admin":false},"body":"not necessary, see previous comment","created_at":"2016-02-09T17:15:47Z","updated_at":"2016-02-09T17:15:47Z","html_url":"https://github.com/apache/storm/pull/1053#discussion_r52340405","pull_request_url":"https://api.github.com/repos/apache/storm/pulls/1053","_links":{"self":{"href":"https://api.github.com/repos/apache/storm/pulls/comments/52340405"},"html":{"href":"https://github.com/apache/storm/pull/1053#discussion_r52340405"},"pull_request":{"href":"https://api.github.com/repos/apache/storm/pulls/1053"}}},"pull_request":{"url":"https://api.github.com/repos/apache/storm/pulls/1053","id":57439071,"html_url":"https://github.com/apache/storm/pull/1053","diff_url":"https://github.com/apache/storm/pull/1053.diff","patch_url":"https://github.com/apache/storm/pull/1053.patch","issue_url":"https://api.github.com/repos/apache/storm/issues/1053","number":1053,"state":"open","locked":false,"title":"[STORM-1336] - Evalute/Port JStorm cgroup support and implement cgroup support for RAS","user":{"login":"jerrypeng","id":3613359,"avatar_url":"https://avatars.githubusercontent.com/u/3613359?v=3","gravatar_id":"","url":"https://api.github.com/users/jerrypeng","html_url":"https://github.com/jerrypeng","followers_url":"https://api.github.com/users/jerrypeng/followers","following_url":"https://api.github.com/users/jerrypeng/following{/other_user}","gists_url":"https://api.github.com/users/jerrypeng/gists{/gist_id}","starred_url":"https://api.github.com/users/jerrypeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerrypeng/subscriptions","organizations_url":"https://api.github.com/users/jerrypeng/orgs","repos_url":"https://api.github.com/users/jerrypeng/repos","events_url":"https://api.github.com/users/jerrypeng/events{/privacy}","received_events_url":"https://api.github.com/users/jerrypeng/received_events","type":"User","site_admin":false},"body":"Documentation in PR\r\n\r\nhttps://github.com/apache/storm/pull/1054","created_at":"2016-01-27T23:15:03Z","updated_at":"2016-02-09T17:15:48Z","closed_at":null,"merged_at":null,"merge_commit_sha":"4682c96bdd5af414776b121375724b162c450c1e","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/storm/pulls/1053/commits","review_comments_url":"https://api.github.com/repos/apache/storm/pulls/1053/comments","review_comment_url":"https://api.github.com/repos/apache/storm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/storm/issues/1053/comments","statuses_url":"https://api.github.com/repos/apache/storm/statuses/05e37d32f287df5bff358ef1a3b6b847bbfdaa4c","head":{"label":"jerrypeng:STORM-1336","ref":"STORM-1336","sha":"05e37d32f287df5bff358ef1a3b6b847bbfdaa4c","user":{"login":"jerrypeng","id":3613359,"avatar_url":"https://avatars.githubusercontent.com/u/3613359?v=3","gravatar_id":"","url":"https://api.github.com/users/jerrypeng","html_url":"https://github.com/jerrypeng","followers_url":"https://api.github.com/users/jerrypeng/followers","following_url":"https://api.github.com/users/jerrypeng/following{/other_user}","gists_url":"https://api.github.com/users/jerrypeng/gists{/gist_id}","starred_url":"https://api.github.com/users/jerrypeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerrypeng/subscriptions","organizations_url":"https://api.github.com/users/jerrypeng/orgs","repos_url":"https://api.github.com/users/jerrypeng/repos","events_url":"https://api.github.com/users/jerrypeng/events{/privacy}","received_events_url":"https://api.github.com/users/jerrypeng/received_events","type":"User","site_admin":false},"repo":{"id":37741458,"name":"storm","full_name":"jerrypeng/storm","owner":{"login":"jerrypeng","id":3613359,"avatar_url":"https://avatars.githubusercontent.com/u/3613359?v=3","gravatar_id":"","url":"https://api.github.com/users/jerrypeng","html_url":"https://github.com/jerrypeng","followers_url":"https://api.github.com/users/jerrypeng/followers","following_url":"https://api.github.com/users/jerrypeng/following{/other_user}","gists_url":"https://api.github.com/users/jerrypeng/gists{/gist_id}","starred_url":"https://api.github.com/users/jerrypeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jerrypeng/subscriptions","organizations_url":"https://api.github.com/users/jerrypeng/orgs","repos_url":"https://api.github.com/users/jerrypeng/repos","events_url":"https://api.github.com/users/jerrypeng/events{/privacy}","received_events_url":"https://api.github.com/users/jerrypeng/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jerrypeng/storm","description":"Mirror of Apache Storm","fork":true,"url":"https://api.github.com/repos/jerrypeng/storm","forks_url":"https://api.github.com/repos/jerrypeng/storm/forks","keys_url":"https://api.github.com/repos/jerrypeng/storm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jerrypeng/storm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jerrypeng/storm/teams","hooks_url":"https://api.github.com/repos/jerrypeng/storm/hooks","issue_events_url":"https://api.github.com/repos/jerrypeng/storm/issues/events{/number}","events_url":"https://api.github.com/repos/jerrypeng/storm/events","assignees_url":"https://api.github.com/repos/jerrypeng/storm/assignees{/user}","branches_url":"https://api.github.com/repos/jerrypeng/storm/branches{/branch}","tags_url":"https://api.github.com/repos/jerrypeng/storm/tags","blobs_url":"https://api.github.com/repos/jerrypeng/storm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jerrypeng/storm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jerrypeng/storm/git/refs{/sha}","trees_url":"https://api.github.com/repos/jerrypeng/storm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jerrypeng/storm/statuses/{sha}","languages_url":"https://api.github.com/repos/jerrypeng/storm/languages","stargazers_url":"https://api.github.com/repos/jerrypeng/storm/stargazers","contributors_url":"https://api.github.com/repos/jerrypeng/storm/contributors","subscribers_url":"https://api.github.com/repos/jerrypeng/storm/subscribers","subscription_url":"https://api.github.com/repos/jerrypeng/storm/subscription","commits_url":"https://api.github.com/repos/jerrypeng/storm/commits{/sha}","git_commits_url":"https://api.github.com/repos/jerrypeng/storm/git/commits{/sha}","comments_url":"https://api.github.com/repos/jerrypeng/storm/comments{/number}","issue_comment_url":"https://api.github.com/repos/jerrypeng/storm/issues/comments{/number}","contents_url":"https://api.github.com/repos/jerrypeng/storm/contents/{+path}","compare_url":"https://api.github.com/repos/jerrypeng/storm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jerrypeng/storm/merges","archive_url":"https://api.github.com/repos/jerrypeng/storm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jerrypeng/storm/downloads","issues_url":"https://api.github.com/repos/jerrypeng/storm/issues{/number}","pulls_url":"https://api.github.com/repos/jerrypeng/storm/pulls{/number}","milestones_url":"https://api.github.com/repos/jerrypeng/storm/milestones{/number}","notifications_url":"https://api.github.com/repos/jerrypeng/storm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jerrypeng/storm/labels{/name}","releases_url":"https://api.github.com/repos/jerrypeng/storm/releases{/id}","deployments_url":"https://api.github.com/repos/jerrypeng/storm/deployments","created_at":"2015-06-19T19:23:06Z","updated_at":"2016-02-08T22:07:32Z","pushed_at":"2016-02-09T15:42:07Z","git_url":"git://github.com/jerrypeng/storm.git","ssh_url":"git@github.com:jerrypeng/storm.git","clone_url":"https://github.com/jerrypeng/storm.git","svn_url":"https://github.com/jerrypeng/storm","homepage":null,"size":101459,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":3,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"00c18c988f7b4cf98635e43ce5af6ed13ecc08d0","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-02-09T16:00:01Z","pushed_at":"2016-02-09T15:55:35Z","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":158329,"stargazers_count":2837,"watchers_count":2837,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":2115,"mirror_url":"git://git.apache.org/storm.git","open_issues_count":81,"forks":2115,"open_issues":81,"watchers":2837,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/storm/pulls/1053"},"html":{"href":"https://github.com/apache/storm/pull/1053"},"issue":{"href":"https://api.github.com/repos/apache/storm/issues/1053"},"comments":{"href":"https://api.github.com/repos/apache/storm/issues/1053/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/storm/pulls/1053/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/storm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/storm/pulls/1053/commits"},"statuses":{"href":"https://api.github.com/repos/apache/storm/statuses/05e37d32f287df5bff358ef1a3b6b847bbfdaa4c"}}}}