{"action":"created","comment":{"url":"https://api.github.com/repos/taskgraph/taskgraph/pulls/comments/26274288","id":26274288,"diff_hunk":"@@ -0,0 +1,165 @@\n+package filesystem\n+\n+import (\n+\t\"bytes\"\n+\t\"encoding/json\"\n+\t\"io\"\n+\t\"io/ioutil\"\n+\t\"log\"\n+\t\"net/http\"\n+\t\"net/url\"\n+\t\"os\"\n+\t\"path\"\n+\t\"regexp\"\n+\n+\t\"github.com/colinmarc/hdfs\"\n+)\n+\n+// Requirement:\n+//   hadoop version:\n+//   HDFS version:\n+//   REST API version:\n+\n+type hdfsConfig struct {\n+\tnamenodeAddr string\n+\twebHdfsAddr  string\n+\tuser         string\n+}\n+\n+type HdfsClient struct {\n+\tclient *hdfs.Client\n+\thdfsConfig\n+}\n+\n+func NewHdfsClient(namenodeAddr, webHdfsAddr, user string) (Client, error) {\n+\tclient, err := hdfs.NewForUser(namenodeAddr, user)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\t// client.Remove(\"/tmp/logs/testing\")\n+\treturn &HdfsClient{\n+\t\tclient: client,\n+\t\thdfsConfig: hdfsConfig{\n+\t\t\tnamenodeAddr: namenodeAddr,\n+\t\t\twebHdfsAddr:  webHdfsAddr,\n+\t\t\tuser:         user,\n+\t\t},\n+\t}, nil\n+}\n+\n+func (c *HdfsClient) OpenReadCloser(name string) (io.ReadCloser, error) {\n+\treturn c.client.Open(name)\n+}\n+\n+func (c *HdfsClient) OpenWriteCloser(name string) (io.WriteCloser, error) {\n+\texist, err := c.Exists(name)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tif !exist {\n+\t\terr := c.client.CreateEmptyFile(name)\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t}\n+\treturn &HdfsFile{\n+\t\tpath:       name,\n+\t\tlogger:     log.New(os.Stdout, \"\", log.Lshortfile|log.LstdFlags),\n+\t\thdfsConfig: c.hdfsConfig,\n+\t}, nil\n+}\n+\n+func (c *HdfsClient) Exists(name string) (bool, error) {\n+\t_, err := c.client.Stat(name)\n+\treturn existCommon(err)\n+}\n+\n+func (c *HdfsClient) Rename(oldpath, newpath string) error {\n+\treturn c.client.Rename(oldpath, newpath)\n+}\n+\n+func (c *HdfsClient) Glob(dirname, pattern string) ([]string, error) {\n+\tfileInfoList, err := c.client.ReadDir(dirname)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tres := make([]string, 0)\n+\tfor _, fi := range fileInfoList {\n+\t\tmatched, err := regexp.MatchString(pattern, fi.Name())\n+\t\tif err != nil {\n+\t\t\treturn nil, err\n+\t\t}\n+\t\tif matched {\n+\t\t\tres = append(res, fi.Name())\n+\t\t}\n+\t}\n+\treturn res, nil\n+}\n+\n+type HdfsFile struct {\n+\tpath   string\n+\tlogger *log.Logger\n+\thdfsConfig\n+\t// buffer\n+}\n+\n+// REST docs:\n+// http://hadoop.apache.org/docs/stable/hadoop-project-dist/hadoop-hdfs/WebHDFS.html#Append_to_a_File\n+func (f *HdfsFile) Write(b []byte) (int, error) {","path":"filesystem/hdfs.go","position":108,"original_position":108,"commit_id":"17d7e32a890c6846c4c4d7db4e2a735cd8c7db9e","original_commit_id":"17d7e32a890c6846c4c4d7db4e2a735cd8c7db9e","user":{"login":"fengjingchao","id":920884,"avatar_url":"https://avatars.githubusercontent.com/u/920884?v=3","gravatar_id":"","url":"https://api.github.com/users/fengjingchao","html_url":"https://github.com/fengjingchao","followers_url":"https://api.github.com/users/fengjingchao/followers","following_url":"https://api.github.com/users/fengjingchao/following{/other_user}","gists_url":"https://api.github.com/users/fengjingchao/gists{/gist_id}","starred_url":"https://api.github.com/users/fengjingchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengjingchao/subscriptions","organizations_url":"https://api.github.com/users/fengjingchao/orgs","repos_url":"https://api.github.com/users/fengjingchao/repos","events_url":"https://api.github.com/users/fengjingchao/events{/privacy}","received_events_url":"https://api.github.com/users/fengjingchao/received_events","type":"User","site_admin":false},"body":"Right. I've implemented Write() using HDFS REST api. Xiang is talking about another go native hdfs client project.","created_at":"2015-03-12T02:29:58Z","updated_at":"2015-03-12T02:29:58Z","html_url":"https://github.com/taskgraph/taskgraph/pull/18#discussion_r26274288","pull_request_url":"https://api.github.com/repos/taskgraph/taskgraph/pulls/18","_links":{"self":{"href":"https://api.github.com/repos/taskgraph/taskgraph/pulls/comments/26274288"},"html":{"href":"https://github.com/taskgraph/taskgraph/pull/18#discussion_r26274288"},"pull_request":{"href":"https://api.github.com/repos/taskgraph/taskgraph/pulls/18"}}},"pull_request":{"url":"https://api.github.com/repos/taskgraph/taskgraph/pulls/18","id":30664447,"html_url":"https://github.com/taskgraph/taskgraph/pull/18","diff_url":"https://github.com/taskgraph/taskgraph/pull/18.diff","patch_url":"https://github.com/taskgraph/taskgraph/pull/18.patch","issue_url":"https://api.github.com/repos/taskgraph/taskgraph/issues/18","number":18,"state":"open","locked":false,"title":"FileSystem","user":{"login":"fengjingchao","id":920884,"avatar_url":"https://avatars.githubusercontent.com/u/920884?v=3","gravatar_id":"","url":"https://api.github.com/users/fengjingchao","html_url":"https://github.com/fengjingchao","followers_url":"https://api.github.com/users/fengjingchao/followers","following_url":"https://api.github.com/users/fengjingchao/following{/other_user}","gists_url":"https://api.github.com/users/fengjingchao/gists{/gist_id}","starred_url":"https://api.github.com/users/fengjingchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengjingchao/subscriptions","organizations_url":"https://api.github.com/users/fengjingchao/orgs","repos_url":"https://api.github.com/users/fengjingchao/repos","events_url":"https://api.github.com/users/fengjingchao/events{/privacy}","received_events_url":"https://api.github.com/users/fengjingchao/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-03-06T17:44:23Z","updated_at":"2015-03-12T02:29:58Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5cf86832e3bc636bcfa09c9cc6a5afd0d9f31bfe","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/taskgraph/taskgraph/pulls/18/commits","review_comments_url":"https://api.github.com/repos/taskgraph/taskgraph/pulls/18/comments","review_comment_url":"https://api.github.com/repos/taskgraph/taskgraph/pulls/comments{/number}","comments_url":"https://api.github.com/repos/taskgraph/taskgraph/issues/18/comments","statuses_url":"https://api.github.com/repos/taskgraph/taskgraph/statuses/17d7e32a890c6846c4c4d7db4e2a735cd8c7db9e","head":{"label":"fengjingchao:master","ref":"master","sha":"17d7e32a890c6846c4c4d7db4e2a735cd8c7db9e","user":{"login":"fengjingchao","id":920884,"avatar_url":"https://avatars.githubusercontent.com/u/920884?v=3","gravatar_id":"","url":"https://api.github.com/users/fengjingchao","html_url":"https://github.com/fengjingchao","followers_url":"https://api.github.com/users/fengjingchao/followers","following_url":"https://api.github.com/users/fengjingchao/following{/other_user}","gists_url":"https://api.github.com/users/fengjingchao/gists{/gist_id}","starred_url":"https://api.github.com/users/fengjingchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengjingchao/subscriptions","organizations_url":"https://api.github.com/users/fengjingchao/orgs","repos_url":"https://api.github.com/users/fengjingchao/repos","events_url":"https://api.github.com/users/fengjingchao/events{/privacy}","received_events_url":"https://api.github.com/users/fengjingchao/received_events","type":"User","site_admin":false},"repo":{"id":30481726,"name":"taskgraph","full_name":"fengjingchao/taskgraph","owner":{"login":"fengjingchao","id":920884,"avatar_url":"https://avatars.githubusercontent.com/u/920884?v=3","gravatar_id":"","url":"https://api.github.com/users/fengjingchao","html_url":"https://github.com/fengjingchao","followers_url":"https://api.github.com/users/fengjingchao/followers","following_url":"https://api.github.com/users/fengjingchao/following{/other_user}","gists_url":"https://api.github.com/users/fengjingchao/gists{/gist_id}","starred_url":"https://api.github.com/users/fengjingchao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fengjingchao/subscriptions","organizations_url":"https://api.github.com/users/fengjingchao/orgs","repos_url":"https://api.github.com/users/fengjingchao/repos","events_url":"https://api.github.com/users/fengjingchao/events{/privacy}","received_events_url":"https://api.github.com/users/fengjingchao/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fengjingchao/taskgraph","description":"A fault tolerant, distributed task driven framework","fork":true,"url":"https://api.github.com/repos/fengjingchao/taskgraph","forks_url":"https://api.github.com/repos/fengjingchao/taskgraph/forks","keys_url":"https://api.github.com/repos/fengjingchao/taskgraph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fengjingchao/taskgraph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fengjingchao/taskgraph/teams","hooks_url":"https://api.github.com/repos/fengjingchao/taskgraph/hooks","issue_events_url":"https://api.github.com/repos/fengjingchao/taskgraph/issues/events{/number}","events_url":"https://api.github.com/repos/fengjingchao/taskgraph/events","assignees_url":"https://api.github.com/repos/fengjingchao/taskgraph/assignees{/user}","branches_url":"https://api.github.com/repos/fengjingchao/taskgraph/branches{/branch}","tags_url":"https://api.github.com/repos/fengjingchao/taskgraph/tags","blobs_url":"https://api.github.com/repos/fengjingchao/taskgraph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fengjingchao/taskgraph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fengjingchao/taskgraph/git/refs{/sha}","trees_url":"https://api.github.com/repos/fengjingchao/taskgraph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fengjingchao/taskgraph/statuses/{sha}","languages_url":"https://api.github.com/repos/fengjingchao/taskgraph/languages","stargazers_url":"https://api.github.com/repos/fengjingchao/taskgraph/stargazers","contributors_url":"https://api.github.com/repos/fengjingchao/taskgraph/contributors","subscribers_url":"https://api.github.com/repos/fengjingchao/taskgraph/subscribers","subscription_url":"https://api.github.com/repos/fengjingchao/taskgraph/subscription","commits_url":"https://api.github.com/repos/fengjingchao/taskgraph/commits{/sha}","git_commits_url":"https://api.github.com/repos/fengjingchao/taskgraph/git/commits{/sha}","comments_url":"https://api.github.com/repos/fengjingchao/taskgraph/comments{/number}","issue_comment_url":"https://api.github.com/repos/fengjingchao/taskgraph/issues/comments{/number}","contents_url":"https://api.github.com/repos/fengjingchao/taskgraph/contents/{+path}","compare_url":"https://api.github.com/repos/fengjingchao/taskgraph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fengjingchao/taskgraph/merges","archive_url":"https://api.github.com/repos/fengjingchao/taskgraph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fengjingchao/taskgraph/downloads","issues_url":"https://api.github.com/repos/fengjingchao/taskgraph/issues{/number}","pulls_url":"https://api.github.com/repos/fengjingchao/taskgraph/pulls{/number}","milestones_url":"https://api.github.com/repos/fengjingchao/taskgraph/milestones{/number}","notifications_url":"https://api.github.com/repos/fengjingchao/taskgraph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fengjingchao/taskgraph/labels{/name}","releases_url":"https://api.github.com/repos/fengjingchao/taskgraph/releases{/id}","created_at":"2015-02-08T05:18:21Z","updated_at":"2015-03-08T23:59:47Z","pushed_at":"2015-03-08T23:59:47Z","git_url":"git://github.com/fengjingchao/taskgraph.git","ssh_url":"git@github.com:fengjingchao/taskgraph.git","clone_url":"https://github.com/fengjingchao/taskgraph.git","svn_url":"https://github.com/fengjingchao/taskgraph","homepage":null,"size":4177,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"taskgraph:master","ref":"master","sha":"2fc637e91daea2e34a0bed94db63c34d5f5a13e5","user":{"login":"taskgraph","id":9723611,"avatar_url":"https://avatars.githubusercontent.com/u/9723611?v=3","gravatar_id":"","url":"https://api.github.com/users/taskgraph","html_url":"https://github.com/taskgraph","followers_url":"https://api.github.com/users/taskgraph/followers","following_url":"https://api.github.com/users/taskgraph/following{/other_user}","gists_url":"https://api.github.com/users/taskgraph/gists{/gist_id}","starred_url":"https://api.github.com/users/taskgraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taskgraph/subscriptions","organizations_url":"https://api.github.com/users/taskgraph/orgs","repos_url":"https://api.github.com/users/taskgraph/repos","events_url":"https://api.github.com/users/taskgraph/events{/privacy}","received_events_url":"https://api.github.com/users/taskgraph/received_events","type":"Organization","site_admin":false},"repo":{"id":30477948,"name":"taskgraph","full_name":"taskgraph/taskgraph","owner":{"login":"taskgraph","id":9723611,"avatar_url":"https://avatars.githubusercontent.com/u/9723611?v=3","gravatar_id":"","url":"https://api.github.com/users/taskgraph","html_url":"https://github.com/taskgraph","followers_url":"https://api.github.com/users/taskgraph/followers","following_url":"https://api.github.com/users/taskgraph/following{/other_user}","gists_url":"https://api.github.com/users/taskgraph/gists{/gist_id}","starred_url":"https://api.github.com/users/taskgraph/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/taskgraph/subscriptions","organizations_url":"https://api.github.com/users/taskgraph/orgs","repos_url":"https://api.github.com/users/taskgraph/repos","events_url":"https://api.github.com/users/taskgraph/events{/privacy}","received_events_url":"https://api.github.com/users/taskgraph/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/taskgraph/taskgraph","description":"A fault tolerant, distributed task driven framework","fork":false,"url":"https://api.github.com/repos/taskgraph/taskgraph","forks_url":"https://api.github.com/repos/taskgraph/taskgraph/forks","keys_url":"https://api.github.com/repos/taskgraph/taskgraph/keys{/key_id}","collaborators_url":"https://api.github.com/repos/taskgraph/taskgraph/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/taskgraph/taskgraph/teams","hooks_url":"https://api.github.com/repos/taskgraph/taskgraph/hooks","issue_events_url":"https://api.github.com/repos/taskgraph/taskgraph/issues/events{/number}","events_url":"https://api.github.com/repos/taskgraph/taskgraph/events","assignees_url":"https://api.github.com/repos/taskgraph/taskgraph/assignees{/user}","branches_url":"https://api.github.com/repos/taskgraph/taskgraph/branches{/branch}","tags_url":"https://api.github.com/repos/taskgraph/taskgraph/tags","blobs_url":"https://api.github.com/repos/taskgraph/taskgraph/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/taskgraph/taskgraph/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/taskgraph/taskgraph/git/refs{/sha}","trees_url":"https://api.github.com/repos/taskgraph/taskgraph/git/trees{/sha}","statuses_url":"https://api.github.com/repos/taskgraph/taskgraph/statuses/{sha}","languages_url":"https://api.github.com/repos/taskgraph/taskgraph/languages","stargazers_url":"https://api.github.com/repos/taskgraph/taskgraph/stargazers","contributors_url":"https://api.github.com/repos/taskgraph/taskgraph/contributors","subscribers_url":"https://api.github.com/repos/taskgraph/taskgraph/subscribers","subscription_url":"https://api.github.com/repos/taskgraph/taskgraph/subscription","commits_url":"https://api.github.com/repos/taskgraph/taskgraph/commits{/sha}","git_commits_url":"https://api.github.com/repos/taskgraph/taskgraph/git/commits{/sha}","comments_url":"https://api.github.com/repos/taskgraph/taskgraph/comments{/number}","issue_comment_url":"https://api.github.com/repos/taskgraph/taskgraph/issues/comments{/number}","contents_url":"https://api.github.com/repos/taskgraph/taskgraph/contents/{+path}","compare_url":"https://api.github.com/repos/taskgraph/taskgraph/compare/{base}...{head}","merges_url":"https://api.github.com/repos/taskgraph/taskgraph/merges","archive_url":"https://api.github.com/repos/taskgraph/taskgraph/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/taskgraph/taskgraph/downloads","issues_url":"https://api.github.com/repos/taskgraph/taskgraph/issues{/number}","pulls_url":"https://api.github.com/repos/taskgraph/taskgraph/pulls{/number}","milestones_url":"https://api.github.com/repos/taskgraph/taskgraph/milestones{/number}","notifications_url":"https://api.github.com/repos/taskgraph/taskgraph/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/taskgraph/taskgraph/labels{/name}","releases_url":"https://api.github.com/repos/taskgraph/taskgraph/releases{/id}","created_at":"2015-02-08T02:19:17Z","updated_at":"2015-03-11T12:51:49Z","pushed_at":"2015-03-11T12:51:48Z","git_url":"git://github.com/taskgraph/taskgraph.git","ssh_url":"git@github.com:taskgraph/taskgraph.git","clone_url":"https://github.com/taskgraph/taskgraph.git","svn_url":"https://github.com/taskgraph/taskgraph","homepage":null,"size":4713,"stargazers_count":20,"watchers_count":20,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":5,"forks":6,"open_issues":5,"watchers":20,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/taskgraph/taskgraph/pulls/18"},"html":{"href":"https://github.com/taskgraph/taskgraph/pull/18"},"issue":{"href":"https://api.github.com/repos/taskgraph/taskgraph/issues/18"},"comments":{"href":"https://api.github.com/repos/taskgraph/taskgraph/issues/18/comments"},"review_comments":{"href":"https://api.github.com/repos/taskgraph/taskgraph/pulls/18/comments"},"review_comment":{"href":"https://api.github.com/repos/taskgraph/taskgraph/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/taskgraph/taskgraph/pulls/18/commits"},"statuses":{"href":"https://api.github.com/repos/taskgraph/taskgraph/statuses/17d7e32a890c6846c4c4d7db4e2a735cd8c7db9e"}}}}