GitHub PullRequestReviewCommentEvent at 2014-09-11 10:19:18
Repository: juju
Actor: tasdomas
Payload: {"action":"created","comment":{"url":"https://api.github.com/repos/juju/juju/pulls/comments/17413738","id":17413738,"diff_hunk":"@@ -379,86 +446,101 @@ func (p *Ports) removeOps() []txn.Op {\n \t}}\n }\n \n-// OpenedPorts returns ports documents associated with specified machine.\n-func (m *Machine) OpenedPorts(st *State) ([]*Ports, error) {\n+// OpenedPorts returns this machine ports document for the given\n+// network.\n+func (m *Machine) OpenedPorts(networkName string) (*Ports, error) {\n+\tkey := portsGlobalKey(m.Id(), networkName)\n+\tports, err := m.st.Ports(key)\n+\tif err != nil && !errors.IsNotFound(err) {\n+\t\treturn nil, errors.Trace(err)\n+\t}\n+\treturn ports, nil\n+}\n+\n+// AllPorts returns all opened ports for this machine (regardless of\n+// network).\n+func (m *Machine) AllPorts() ([]*Ports, error) {\n \topenedPorts, closer := m.st.getCollection(openedPortsC)\n \tdefer closer()\n \n \tidRegex := fmt.Sprintf(\"m#%s#n#.*\", m.Id())\n \tdocs := []portsDoc{}\n-\terr := openedPorts.Find(bson.M{\"_id\": bson.M{\"$regex\": idRegex}}).All(&docs)\n+\tquery := bson.M{\"_id\": bson.M{\"$regex\": idRegex}}\n+\terr := openedPorts.Find(query).All(&docs)\n \tif err != nil {\n-\t\treturn nil, err\n+\t\treturn nil, errors.Trace(err)\n \t}\n \tresults := make([]*Ports, len(docs))\n \tfor i, doc := range docs {\n-\t\tresults[i] = &Ports{st: st, doc: doc}\n+\t\tresults[i] = &Ports{st: m.st, doc: doc}\n \t}\n \treturn results, nil\n }\n \n-// portsDocId generates the id of a ports document given the machine id and network name.\n-func portsDocId(machineId string, networkName string) string {\n-\treturn fmt.Sprintf(\"m#%s#n#%s\", machineId, networkName)\n-}\n+// Ports returns the opened ports document with the given global key.\n+func (st *State) Ports(key string) (*Ports, error) {\n+\topenedPorts, closer := st.getCollection(openedPortsC)\n+\tdefer closer()\n \n-func addPortsDocOps(st *State,\n-\t// TODO(domas) 2014-07-04 bug #1337804: network id is hard-coded until multiple network support lands.\n-\t//network string,\n-\tmachineId string,\n-\tports ...PortRange) []txn.Op {\n+\tvar doc portsDoc\n+\terr := openedPorts.FindId(key).One(&doc)\n+\tif err == mgo.ErrNotFound {\n+\t\treturn nil, errors.NotFoundf(\"ports document %v\", key)\n+\t}\n+\tif err != nil {\n+\t\treturn nil, errors.Annotatef(err, \"cannot get ports document %v\", key)\n+\t}\n \n-\tid := portsDocId(machineId, network.DefaultPublic)\n+\treturn &Ports{st, doc, false}, nil\n+}\n \n-\tops := []txn.Op{{\n+func addPortsDocOps(st *State, machineId, networkName string, ports ...PortRange) []txn.Op {\n+\tkey := portsGlobalKey(machineId, networkName)\n+\tpdoc := &portsDoc{\n+\t\tId:    key,\n+\t\tPorts: ports,\n+\t}\n+\treturn []txn.Op{{\n \t\tC:      machinesC,\n \t\tId:     machineId,\n \t\tAssert: notDeadDoc,\n \t}, {\n \t\tC:      openedPortsC,\n-\t\tId:     id,\n+\t\tId:     key,\n \t\tAssert: txn.DocMissing,\n-\t\tInsert: portsDoc{Id: id, Ports: ports},\n+\t\tInsert: pdoc,\n \t}}\n-\treturn ops\n }\n \n-// getPorts returns the ports document for the specified\n-// machine and network.\n-func getPorts(st *State,\n-\t// TODO(domas) 2014-07-04 bug #1337804: network is hardcoded until multiple network support lands.\n-\t// networkName string,\n-\tmachineId string) (*Ports, error) {\n+// getPorts returns the ports document for the specified machine and\n+// network.\n+func getPorts(st *State, machineId, networkName string) (*Ports, error) {\n \topenedPorts, closer := st.getCollection(openedPortsC)\n \tdefer closer()\n \n \tvar doc portsDoc\n-\tid := portsDocId(machineId, network.DefaultPublic)\n-\terr := openedPorts.FindId(id).One(&doc)\n+\tkey := portsGlobalKey(machineId, networkName)\n+\terr := openedPorts.FindId(key).One(&doc)\n \tif err == mgo.ErrNotFound {\n-\t\treturn nil, errors.NotFoundf(\"ports document for machine %v\", machineId)\n+\t\treturn nil, errors.NotFoundf(\"ports document %v\", key)","path":"state/ports.go","position":474,"original_position":474,"commit_id":"9be175d187c3559667bc154f314096ccceb76001","original_commit_id":"9be175d187c3559667bc154f314096ccceb76001","user":{"login":"tasdomas","id":119220,"avatar_url":"https://avatars.githubusercontent.com/u/119220?v=2","gravatar_id":"3c92b82c3b671a25df1bd0477dfb27b8","url":"https://api.github.com/users/tasdomas","html_url":"https://github.com/tasdomas","followers_url":"https://api.github.com/users/tasdomas/followers","following_url":"https://api.github.com/users/tasdomas/following{/other_user}","gists_url":"https://api.github.com/users/tasdomas/gists{/gist_id}","starred_url":"https://api.github.com/users/tasdomas/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tasdomas/subscriptions","organizations_url":"https://api.github.com/users/tasdomas/orgs","repos_url":"https://api.github.com/users/tasdomas/repos","events_url":"https://api.github.com/users/tasdomas/events{/privacy}","received_events_url":"https://api.github.com/users/tasdomas/received_events","type":"User","site_admin":false},"body":"Do we really want to expose the actual ports document key here?","created_at":"2014-09-11T10:19:18Z","updated_at":"2014-09-11T10:19:18Z","html_url":"https://github.com/juju/juju/pull/739#discussion_r17413738","pull_request_url":"https://api.github.com/repos/juju/juju/pulls/739","_links":{"self":{"href":"https://api.github.com/repos/juju/juju/pulls/comments/17413738"},"html":{"href":"https://github.com/juju/juju/pull/739#discussion_r17413738"},"pull_request":{"href":"https://api.github.com/repos/juju/juju/pulls/739"}}},"pull_request":{"url":"https://api.github.com/repos/juju/juju/pulls/739","id":21075657,"html_url":"https://github.com/juju/juju/pull/739","diff_url":"https://github.com/juju/juju/pull/739.diff","patch_url":"https://github.com/juju/juju/pull/739.patch","issue_url":"https://api.github.com/repos/juju/juju/issues/739","number":739,"state":"open","locked":false,"title":"Added state opened ports watcher; allow opening/closing port ranges on units","user":{"login":"dimitern","id":619986,"avatar_url":"https://avatars.githubusercontent.com/u/619986?v=2","gravatar_id":"6889e0065cf206ab0e4b3873576b5026","url":"https://api.github.com/users/dimitern","html_url":"https://github.com/dimitern","followers_url":"https://api.github.com/users/dimitern/followers","following_url":"https://api.github.com/users/dimitern/following{/other_user}","gists_url":"https://api.github.com/users/dimitern/gists{/gist_id}","starred_url":"https://api.github.com/users/dimitern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimitern/subscriptions","organizations_url":"https://api.github.com/users/dimitern/orgs","repos_url":"https://api.github.com/users/dimitern/repos","events_url":"https://api.github.com/users/dimitern/events{/privacy}","received_events_url":"https://api.github.com/users/dimitern/received_events","type":"User","site_admin":false},"body":"Taking over the work Domas did in https://github.com/juju/juju/pull/517 and splitting this, \r\nas requested by reviewers in 4 chunks. This is 1/4 and is only\r\nabout changes in the state package.\r\n\r\nPorts opened on a unit are now migrated to the openedPorts collection\r\non subsequent OpenPort/ClosePort calls, but the Ports list on the\r\nunit document is not reset yet, as it's better done in a follow-up\r\none in an upgrade step.\r\n\r\nNext: 2/4: upgrade step to migrate ports from units to openedPorts\r\ncollection; 3/4: firewaller api changes to enable watching ports;\r\n4/4: firewaller worker using the new api.","created_at":"2014-09-11T09:25:47Z","updated_at":"2014-09-11T10:19:18Z","closed_at":null,"merged_at":null,"merge_commit_sha":"3d54613752da214d4d08d9c7dd3f874ab466eae7","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/juju/juju/pulls/739/commits","review_comments_url":"https://api.github.com/repos/juju/juju/pulls/739/comments","review_comment_url":"https://api.github.com/repos/juju/juju/pulls/comments/{number}","comments_url":"https://api.github.com/repos/juju/juju/issues/739/comments","statuses_url":"https://api.github.com/repos/juju/juju/statuses/9be175d187c3559667bc154f314096ccceb76001","head":{"label":"dimitern:state-openedports-watcher","ref":"state-openedports-watcher","sha":"9be175d187c3559667bc154f314096ccceb76001","user":{"login":"dimitern","id":619986,"avatar_url":"https://avatars.githubusercontent.com/u/619986?v=2","gravatar_id":"6889e0065cf206ab0e4b3873576b5026","url":"https://api.github.com/users/dimitern","html_url":"https://github.com/dimitern","followers_url":"https://api.github.com/users/dimitern/followers","following_url":"https://api.github.com/users/dimitern/following{/other_user}","gists_url":"https://api.github.com/users/dimitern/gists{/gist_id}","starred_url":"https://api.github.com/users/dimitern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimitern/subscriptions","organizations_url":"https://api.github.com/users/dimitern/orgs","repos_url":"https://api.github.com/users/dimitern/repos","events_url":"https://api.github.com/users/dimitern/events{/privacy}","received_events_url":"https://api.github.com/users/dimitern/received_events","type":"User","site_admin":false},"repo":{"id":20473382,"name":"juju","full_name":"dimitern/juju","owner":{"login":"dimitern","id":619986,"avatar_url":"https://avatars.githubusercontent.com/u/619986?v=2","gravatar_id":"6889e0065cf206ab0e4b3873576b5026","url":"https://api.github.com/users/dimitern","html_url":"https://github.com/dimitern","followers_url":"https://api.github.com/users/dimitern/followers","following_url":"https://api.github.com/users/dimitern/following{/other_user}","gists_url":"https://api.github.com/users/dimitern/gists{/gist_id}","starred_url":"https://api.github.com/users/dimitern/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dimitern/subscriptions","organizations_url":"https://api.github.com/users/dimitern/orgs","repos_url":"https://api.github.com/users/dimitern/repos","events_url":"https://api.github.com/users/dimitern/events{/privacy}","received_events_url":"https://api.github.com/users/dimitern/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/dimitern/juju","description":"juju is devops distilled","fork":true,"url":"https://api.github.com/repos/dimitern/juju","forks_url":"https://api.github.com/repos/dimitern/juju/forks","keys_url":"https://api.github.com/repos/dimitern/juju/keys{/key_id}","collaborators_url":"https://api.github.com/repos/dimitern/juju/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/dimitern/juju/teams","hooks_url":"https://api.github.com/repos/dimitern/juju/hooks","issue_events_url":"https://api.github.com/repos/dimitern/juju/issues/events{/number}","events_url":"https://api.github.com/repos/dimitern/juju/events","assignees_url":"https://api.github.com/repos/dimitern/juju/assignees{/user}","branches_url":"https://api.github.com/repos/dimitern/juju/branches{/branch}","tags_url":"https://api.github.com/repos/dimitern/juju/tags","blobs_url":"https://api.github.com/repos/dimitern/juju/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/dimitern/juju/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/dimitern/juju/git/refs{/sha}","trees_url":"https://api.github.com/repos/dimitern/juju/git/trees{/sha}","statuses_url":"https://api.github.com/repos/dimitern/juju/statuses/{sha}","languages_url":"https://api.github.com/repos/dimitern/juju/languages","stargazers_url":"https://api.github.com/repos/dimitern/juju/stargazers","contributors_url":"https://api.github.com/repos/dimitern/juju/contributors","subscribers_url":"https://api.github.com/repos/dimitern/juju/subscribers","subscription_url":"https://api.github.com/repos/dimitern/juju/subscription","commits_url":"https://api.github.com/repos/dimitern/juju/commits{/sha}","git_commits_url":"https://api.github.com/repos/dimitern/juju/git/commits{/sha}","comments_url":"https://api.github.com/repos/dimitern/juju/comments{/number}","issue_comment_url":"https://api.github.com/repos/dimitern/juju/issues/comments/{number}","contents_url":"https://api.github.com/repos/dimitern/juju/contents/{+path}","compare_url":"https://api.github.com/repos/dimitern/juju/compare/{base}...{head}","merges_url":"https://api.github.com/repos/dimitern/juju/merges","archive_url":"https://api.github.com/repos/dimitern/juju/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/dimitern/juju/downloads","issues_url":"https://api.github.com/repos/dimitern/juju/issues{/number}","pulls_url":"https://api.github.com/repos/dimitern/juju/pulls{/number}","milestones_url":"https://api.github.com/repos/dimitern/juju/milestones{/number}","notifications_url":"https://api.github.com/repos/dimitern/juju/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/dimitern/juju/labels{/name}","releases_url":"https://api.github.com/repos/dimitern/juju/releases{/id}","created_at":"2014-06-04T06:58:49Z","updated_at":"2014-06-30T08:05:50Z","pushed_at":"2014-09-11T09:22:08Z","git_url":"git://github.com/dimitern/juju.git","ssh_url":"git@github.com:dimitern/juju.git","clone_url":"https://github.com/dimitern/juju.git","svn_url":"https://github.com/dimitern/juju","homepage":null,"size":29142,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"juju:master","ref":"master","sha":"270a9f96ca51a26812932a798fdc178ce80aa48a","user":{"login":"juju","id":4604548,"avatar_url":"https://avatars.githubusercontent.com/u/4604548?v=2","gravatar_id":"b095d1e26e5705abe0ad2de7d87aac2e","url":"https://api.github.com/users/juju","html_url":"https://github.com/juju","followers_url":"https://api.github.com/users/juju/followers","following_url":"https://api.github.com/users/juju/following{/other_user}","gists_url":"https://api.github.com/users/juju/gists{/gist_id}","starred_url":"https://api.github.com/users/juju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juju/subscriptions","organizations_url":"https://api.github.com/users/juju/orgs","repos_url":"https://api.github.com/users/juju/repos","events_url":"https://api.github.com/users/juju/events{/privacy}","received_events_url":"https://api.github.com/users/juju/received_events","type":"Organization","site_admin":false},"repo":{"id":20445947,"name":"juju","full_name":"juju/juju","owner":{"login":"juju","id":4604548,"avatar_url":"https://avatars.githubusercontent.com/u/4604548?v=2","gravatar_id":"b095d1e26e5705abe0ad2de7d87aac2e","url":"https://api.github.com/users/juju","html_url":"https://github.com/juju","followers_url":"https://api.github.com/users/juju/followers","following_url":"https://api.github.com/users/juju/following{/other_user}","gists_url":"https://api.github.com/users/juju/gists{/gist_id}","starred_url":"https://api.github.com/users/juju/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/juju/subscriptions","organizations_url":"https://api.github.com/users/juju/orgs","repos_url":"https://api.github.com/users/juju/repos","events_url":"https://api.github.com/users/juju/events{/privacy}","received_events_url":"https://api.github.com/users/juju/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/juju/juju","description":"juju is devops distilled","fork":false,"url":"https://api.github.com/repos/juju/juju","forks_url":"https://api.github.com/repos/juju/juju/forks","keys_url":"https://api.github.com/repos/juju/juju/keys{/key_id}","collaborators_url":"https://api.github.com/repos/juju/juju/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/juju/juju/teams","hooks_url":"https://api.github.com/repos/juju/juju/hooks","issue_events_url":"https://api.github.com/repos/juju/juju/issues/events{/number}","events_url":"https://api.github.com/repos/juju/juju/events","assignees_url":"https://api.github.com/repos/juju/juju/assignees{/user}","branches_url":"https://api.github.com/repos/juju/juju/branches{/branch}","tags_url":"https://api.github.com/repos/juju/juju/tags","blobs_url":"https://api.github.com/repos/juju/juju/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/juju/juju/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/juju/juju/git/refs{/sha}","trees_url":"https://api.github.com/repos/juju/juju/git/trees{/sha}","statuses_url":"https://api.github.com/repos/juju/juju/statuses/{sha}","languages_url":"https://api.github.com/repos/juju/juju/languages","stargazers_url":"https://api.github.com/repos/juju/juju/stargazers","contributors_url":"https://api.github.com/repos/juju/juju/contributors","subscribers_url":"https://api.github.com/repos/juju/juju/subscribers","subscription_url":"https://api.github.com/repos/juju/juju/subscription","commits_url":"https://api.github.com/repos/juju/juju/commits{/sha}","git_commits_url":"https://api.github.com/repos/juju/juju/git/commits{/sha}","comments_url":"https://api.github.com/repos/juju/juju/comments{/number}","issue_comment_url":"https://api.github.com/repos/juju/juju/issues/comments/{number}","contents_url":"https://api.github.com/repos/juju/juju/contents/{+path}","compare_url":"https://api.github.com/repos/juju/juju/compare/{base}...{head}","merges_url":"https://api.github.com/repos/juju/juju/merges","archive_url":"https://api.github.com/repos/juju/juju/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/juju/juju/downloads","issues_url":"https://api.github.com/repos/juju/juju/issues{/number}","pulls_url":"https://api.github.com/repos/juju/juju/pulls{/number}","milestones_url":"https://api.github.com/repos/juju/juju/milestones{/number}","notifications_url":"https://api.github.com/repos/juju/juju/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/juju/juju/labels{/name}","releases_url":"https://api.github.com/repos/juju/juju/releases{/id}","created_at":"2014-06-03T14:28:10Z","updated_at":"2014-09-10T19:46:10Z","pushed_at":"2014-09-11T04:14:13Z","git_url":"git://github.com/juju/juju.git","ssh_url":"git@github.com:juju/juju.git","clone_url":"https://github.com/juju/juju.git","svn_url":"https://github.com/juju/juju","homepage":"juju.ubuntu.com","size":45311,"stargazers_count":204,"watchers_count":204,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"forks_count":56,"mirror_url":null,"open_issues_count":50,"forks":56,"open_issues":50,"watchers":204,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/juju/juju/pulls/739"},"html":{"href":"https://github.com/juju/juju/pull/739"},"issue":{"href":"https://api.github.com/repos/juju/juju/issues/739"},"comments":{"href":"https://api.github.com/repos/juju/juju/issues/739/comments"},"review_comments":{"href":"https://api.github.com/repos/juju/juju/pulls/739/comments"},"review_comment":{"href":"https://api.github.com/repos/juju/juju/pulls/comments/{number}"},"commits":{"href":"https://api.github.com/repos/juju/juju/pulls/739/commits"},"statuses":{"href":"https://api.github.com/repos/juju/juju/statuses/9be175d187c3559667bc154f314096ccceb76001"}}}}