{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/comments/45349579","id":45349579,"diff_hunk":"@@ -0,0 +1,146 @@\n+package vnidallocator\n+\n+import (\n+\t\"errors\"\n+\t\"fmt\"\n+\n+\t\"github.com/golang/glog\"\n+\n+\tkapi \"k8s.io/kubernetes/pkg/api\"\n+\t\"k8s.io/kubernetes/pkg/registry/service/allocator\"\n+\n+\t\"github.com/openshift/openshift-sdn/plugins/osdn/util\"\n+)\n+\n+// Interface manages the allocation of VNIDs out of a range.\n+// Interface should be threadsafe.\n+type Interface interface {\n+\tAllocate(uint) error\n+\tAllocateNext() (uint, error)\n+\tRelease(uint) error\n+}\n+\n+var (\n+\tErrFull            = errors.New(\"range is full\")\n+\tErrNotInRange      = errors.New(\"provided VNID is not in the valid range\")\n+\tErrAllocated       = errors.New(\"provided VNID is already allocated\")\n+\tErrMismatchedRange = errors.New(\"the provided VNID range does not match the current VNID range\")\n+)\n+\n+type Allocator struct {\n+\tvnidRange util.VNIDRange\n+\n+\talloc allocator.Interface\n+}\n+\n+// Allocator implements Interface and Snapshottable\n+var _ Interface = &Allocator{}\n+\n+// NewAllocatorCustom creates a Allocator over a VNID Range, calling allocatorFactory to construct the backing store.\n+func NewAllocatorCustom(vr util.VNIDRange, allocatorFactory allocator.AllocatorFactory) *Allocator {\n+\treturn &Allocator{\n+\t\tvnidRange: vr,\n+\t\talloc:     allocatorFactory(int(vr.Size), vr.String()),\n+\t}\n+}\n+\n+// Helper that wraps NewAllocatorCustom, for creating a range backed by an in-memory store.\n+func NewInMemoryAllocator(vr util.VNIDRange) *Allocator {\n+\treturn NewAllocatorCustom(vr, allocator.NewContiguousAllocationInterface)\n+}\n+\n+// Free returns the count of VNID left in the range.\n+func (r *Allocator) Free() int {\n+\treturn r.alloc.Free()\n+}\n+\n+// Allocate attempts to reserve the provided VNID. ErrNotInRange or\n+// ErrAllocated will be returned if the VNID is not valid for this range\n+// or has already been reserved. ErrFull will be returned if there\n+// are no VNIDs left.","path":"plugins/osdn/vnidallocator/allocator.go","position":60,"original_position":60,"commit_id":"f18599c0997ade3800d7e4ef5b25933bdc4bd9f8","original_commit_id":"f18599c0997ade3800d7e4ef5b25933bdc4bd9f8","user":{"login":"danwinship","id":96040,"avatar_url":"https://avatars.githubusercontent.com/u/96040?v=3","gravatar_id":"","url":"https://api.github.com/users/danwinship","html_url":"https://github.com/danwinship","followers_url":"https://api.github.com/users/danwinship/followers","following_url":"https://api.github.com/users/danwinship/following{/other_user}","gists_url":"https://api.github.com/users/danwinship/gists{/gist_id}","starred_url":"https://api.github.com/users/danwinship/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/danwinship/subscriptions","organizations_url":"https://api.github.com/users/danwinship/orgs","repos_url":"https://api.github.com/users/danwinship/repos","events_url":"https://api.github.com/users/danwinship/events{/privacy}","received_events_url":"https://api.github.com/users/danwinship/received_events","type":"User","site_admin":false},"body":"Either (a) vnid is out of range, in which case ErrNotInRange, or (b) it's in range but already used, in which case ErrAllocated, or (c) it's in range and not already used, in which case Allocate() will succeed. It shouldn't be possible to get ErrFull.","created_at":"2015-11-19T14:53:23Z","updated_at":"2015-11-19T14:53:23Z","html_url":"https://github.com/openshift/openshift-sdn/pull/210#discussion_r45349579","pull_request_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/210","_links":{"self":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/comments/45349579"},"html":{"href":"https://github.com/openshift/openshift-sdn/pull/210#discussion_r45349579"},"pull_request":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/210"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/210","id":51124541,"html_url":"https://github.com/openshift/openshift-sdn/pull/210","diff_url":"https://github.com/openshift/openshift-sdn/pull/210.diff","patch_url":"https://github.com/openshift/openshift-sdn/pull/210.patch","issue_url":"https://api.github.com/repos/openshift/openshift-sdn/issues/210","number":210,"state":"open","locked":false,"title":"Refactor VNID allocator","user":{"login":"pravisankar","id":1258630,"avatar_url":"https://avatars.githubusercontent.com/u/1258630?v=3","gravatar_id":"","url":"https://api.github.com/users/pravisankar","html_url":"https://github.com/pravisankar","followers_url":"https://api.github.com/users/pravisankar/followers","following_url":"https://api.github.com/users/pravisankar/following{/other_user}","gists_url":"https://api.github.com/users/pravisankar/gists{/gist_id}","starred_url":"https://api.github.com/users/pravisankar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pravisankar/subscriptions","organizations_url":"https://api.github.com/users/pravisankar/orgs","repos_url":"https://api.github.com/users/pravisankar/repos","events_url":"https://api.github.com/users/pravisankar/events{/privacy}","received_events_url":"https://api.github.com/users/pravisankar/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-18T18:45:42Z","updated_at":"2015-11-19T14:53:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f7451dafdc2866cdfbbb02ffd462a2cd1f76a80f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/210/commits","review_comments_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/210/comments","review_comment_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/openshift-sdn/issues/210/comments","statuses_url":"https://api.github.com/repos/openshift/openshift-sdn/statuses/f18599c0997ade3800d7e4ef5b25933bdc4bd9f8","head":{"label":"pravisankar:vnid-allocators","ref":"vnid-allocators","sha":"f18599c0997ade3800d7e4ef5b25933bdc4bd9f8","user":{"login":"pravisankar","id":1258630,"avatar_url":"https://avatars.githubusercontent.com/u/1258630?v=3","gravatar_id":"","url":"https://api.github.com/users/pravisankar","html_url":"https://github.com/pravisankar","followers_url":"https://api.github.com/users/pravisankar/followers","following_url":"https://api.github.com/users/pravisankar/following{/other_user}","gists_url":"https://api.github.com/users/pravisankar/gists{/gist_id}","starred_url":"https://api.github.com/users/pravisankar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pravisankar/subscriptions","organizations_url":"https://api.github.com/users/pravisankar/orgs","repos_url":"https://api.github.com/users/pravisankar/repos","events_url":"https://api.github.com/users/pravisankar/events{/privacy}","received_events_url":"https://api.github.com/users/pravisankar/received_events","type":"User","site_admin":false},"repo":{"id":39804494,"name":"openshift-sdn","full_name":"pravisankar/openshift-sdn","owner":{"login":"pravisankar","id":1258630,"avatar_url":"https://avatars.githubusercontent.com/u/1258630?v=3","gravatar_id":"","url":"https://api.github.com/users/pravisankar","html_url":"https://github.com/pravisankar","followers_url":"https://api.github.com/users/pravisankar/followers","following_url":"https://api.github.com/users/pravisankar/following{/other_user}","gists_url":"https://api.github.com/users/pravisankar/gists{/gist_id}","starred_url":"https://api.github.com/users/pravisankar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pravisankar/subscriptions","organizations_url":"https://api.github.com/users/pravisankar/orgs","repos_url":"https://api.github.com/users/pravisankar/repos","events_url":"https://api.github.com/users/pravisankar/events{/privacy}","received_events_url":"https://api.github.com/users/pravisankar/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pravisankar/openshift-sdn","description":"","fork":true,"url":"https://api.github.com/repos/pravisankar/openshift-sdn","forks_url":"https://api.github.com/repos/pravisankar/openshift-sdn/forks","keys_url":"https://api.github.com/repos/pravisankar/openshift-sdn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pravisankar/openshift-sdn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pravisankar/openshift-sdn/teams","hooks_url":"https://api.github.com/repos/pravisankar/openshift-sdn/hooks","issue_events_url":"https://api.github.com/repos/pravisankar/openshift-sdn/issues/events{/number}","events_url":"https://api.github.com/repos/pravisankar/openshift-sdn/events","assignees_url":"https://api.github.com/repos/pravisankar/openshift-sdn/assignees{/user}","branches_url":"https://api.github.com/repos/pravisankar/openshift-sdn/branches{/branch}","tags_url":"https://api.github.com/repos/pravisankar/openshift-sdn/tags","blobs_url":"https://api.github.com/repos/pravisankar/openshift-sdn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pravisankar/openshift-sdn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pravisankar/openshift-sdn/git/refs{/sha}","trees_url":"https://api.github.com/repos/pravisankar/openshift-sdn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pravisankar/openshift-sdn/statuses/{sha}","languages_url":"https://api.github.com/repos/pravisankar/openshift-sdn/languages","stargazers_url":"https://api.github.com/repos/pravisankar/openshift-sdn/stargazers","contributors_url":"https://api.github.com/repos/pravisankar/openshift-sdn/contributors","subscribers_url":"https://api.github.com/repos/pravisankar/openshift-sdn/subscribers","subscription_url":"https://api.github.com/repos/pravisankar/openshift-sdn/subscription","commits_url":"https://api.github.com/repos/pravisankar/openshift-sdn/commits{/sha}","git_commits_url":"https://api.github.com/repos/pravisankar/openshift-sdn/git/commits{/sha}","comments_url":"https://api.github.com/repos/pravisankar/openshift-sdn/comments{/number}","issue_comment_url":"https://api.github.com/repos/pravisankar/openshift-sdn/issues/comments{/number}","contents_url":"https://api.github.com/repos/pravisankar/openshift-sdn/contents/{+path}","compare_url":"https://api.github.com/repos/pravisankar/openshift-sdn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pravisankar/openshift-sdn/merges","archive_url":"https://api.github.com/repos/pravisankar/openshift-sdn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pravisankar/openshift-sdn/downloads","issues_url":"https://api.github.com/repos/pravisankar/openshift-sdn/issues{/number}","pulls_url":"https://api.github.com/repos/pravisankar/openshift-sdn/pulls{/number}","milestones_url":"https://api.github.com/repos/pravisankar/openshift-sdn/milestones{/number}","notifications_url":"https://api.github.com/repos/pravisankar/openshift-sdn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pravisankar/openshift-sdn/labels{/name}","releases_url":"https://api.github.com/repos/pravisankar/openshift-sdn/releases{/id}","created_at":"2015-07-28T00:23:09Z","updated_at":"2015-07-28T00:23:09Z","pushed_at":"2015-11-19T02:58:58Z","git_url":"git://github.com/pravisankar/openshift-sdn.git","ssh_url":"git@github.com:pravisankar/openshift-sdn.git","clone_url":"https://github.com/pravisankar/openshift-sdn.git","svn_url":"https://github.com/pravisankar/openshift-sdn","homepage":null,"size":710,"stargazers_count":0,"watchers_count":0,"language":"Go","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":"openshift:master","ref":"master","sha":"ffa994725b5f60a0767698dc359d8a7783abb9a8","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":29500061,"name":"openshift-sdn","full_name":"openshift/openshift-sdn","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/openshift-sdn","description":"","fork":false,"url":"https://api.github.com/repos/openshift/openshift-sdn","forks_url":"https://api.github.com/repos/openshift/openshift-sdn/forks","keys_url":"https://api.github.com/repos/openshift/openshift-sdn/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/openshift-sdn/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/openshift-sdn/teams","hooks_url":"https://api.github.com/repos/openshift/openshift-sdn/hooks","issue_events_url":"https://api.github.com/repos/openshift/openshift-sdn/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/openshift-sdn/events","assignees_url":"https://api.github.com/repos/openshift/openshift-sdn/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/openshift-sdn/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/openshift-sdn/tags","blobs_url":"https://api.github.com/repos/openshift/openshift-sdn/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/openshift-sdn/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/openshift-sdn/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/openshift-sdn/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/openshift-sdn/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/openshift-sdn/languages","stargazers_url":"https://api.github.com/repos/openshift/openshift-sdn/stargazers","contributors_url":"https://api.github.com/repos/openshift/openshift-sdn/contributors","subscribers_url":"https://api.github.com/repos/openshift/openshift-sdn/subscribers","subscription_url":"https://api.github.com/repos/openshift/openshift-sdn/subscription","commits_url":"https://api.github.com/repos/openshift/openshift-sdn/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/openshift-sdn/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/openshift-sdn/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/openshift-sdn/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/openshift-sdn/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/openshift-sdn/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/openshift-sdn/merges","archive_url":"https://api.github.com/repos/openshift/openshift-sdn/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/openshift-sdn/downloads","issues_url":"https://api.github.com/repos/openshift/openshift-sdn/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/openshift-sdn/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/openshift-sdn/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/openshift-sdn/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/openshift-sdn/labels{/name}","releases_url":"https://api.github.com/repos/openshift/openshift-sdn/releases{/id}","created_at":"2015-01-19T22:32:20Z","updated_at":"2015-11-04T13:54:35Z","pushed_at":"2015-11-19T02:58:58Z","git_url":"git://github.com/openshift/openshift-sdn.git","ssh_url":"git@github.com:openshift/openshift-sdn.git","clone_url":"https://github.com/openshift/openshift-sdn.git","svn_url":"https://github.com/openshift/openshift-sdn","homepage":null,"size":790,"stargazers_count":26,"watchers_count":26,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":29,"mirror_url":null,"open_issues_count":14,"forks":29,"open_issues":14,"watchers":26,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/210"},"html":{"href":"https://github.com/openshift/openshift-sdn/pull/210"},"issue":{"href":"https://api.github.com/repos/openshift/openshift-sdn/issues/210"},"comments":{"href":"https://api.github.com/repos/openshift/openshift-sdn/issues/210/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/210/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/openshift-sdn/pulls/210/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/openshift-sdn/statuses/f18599c0997ade3800d7e4ef5b25933bdc4bd9f8"}}}}