{"action":"created","comment":{"url":"https://api.github.com/repos/alde/eremetic/pulls/comments/45862231","id":45862231,"diff_hunk":"@@ -0,0 +1,73 @@\n+package scheduler\n+\n+import (\n+\t\"errors\"\n+\t\"fmt\"\n+\n+\t\"github.com/alde/eremetic/types\"\n+\tlog \"github.com/dmuth/google-go-log4go\"\n+\togle \"github.com/jacobsa/oglematchers\"\n+\tmesos \"github.com/mesos/mesos-go/mesosproto\"\n+)\n+\n+type resourceMatcher struct {\n+\tname  string\n+\tvalue float64\n+}\n+\n+func (m *resourceMatcher) Matches(o interface{}) error {\n+\toffer := o.(*mesos.Offer)\n+\terr := errors.New(\"\")\n+\n+\tfor _, res := range offer.Resources {\n+\t\tif res.GetName() == m.name {\n+\t\t\tif res.GetType() != mesos.Value_SCALAR {\n+\t\t\t\treturn err\n+\t\t\t}\n+\n+\t\t\tif res.Scalar.GetValue() >= m.value {\n+\t\t\t\treturn nil\n+\t\t\t}\n+\n+\t\t\treturn err\n+\t\t}\n+\t}\n+\treturn err\n+}\n+\n+func (m *resourceMatcher) Description() string {\n+\treturn fmt.Sprintf(\"%f of scalar resource %s\", m.value, m.name)\n+}\n+\n+func CPUAvailable(v float64) ogle.Matcher {\n+\treturn &resourceMatcher{\"cpus\", v}\n+}\n+\n+func MemoryAvailable(v float64) ogle.Matcher {\n+\treturn &resourceMatcher{\"mem\", v}\n+}\n+\n+func makeMatcher(task types.EremeticTask) ogle.Matcher {\n+\treturn ogle.AllOf(\n+\t\tCPUAvailable(task.TaskCPUs),\n+\t\tMemoryAvailable(task.TaskMem))\n+}\n+\n+func matches(matcher ogle.Matcher, o interface{}) bool {\n+\terr := matcher.Matches(o)\n+\treturn err == nil\n+}\n+\n+func matchOffer(task types.EremeticTask, offers []*mesos.Offer) (*mesos.Offer, []*mesos.Offer) {\n+\tvar matcher = makeMatcher(task)","path":"scheduler/match.go","position":62,"original_position":62,"commit_id":"48d3502c344edd1f0a08a55bb64d74be510bc3f5","original_commit_id":"48d3502c344edd1f0a08a55bb64d74be510bc3f5","user":{"login":"alde","id":350296,"avatar_url":"https://avatars.githubusercontent.com/u/350296?v=3","gravatar_id":"","url":"https://api.github.com/users/alde","html_url":"https://github.com/alde","followers_url":"https://api.github.com/users/alde/followers","following_url":"https://api.github.com/users/alde/following{/other_user}","gists_url":"https://api.github.com/users/alde/gists{/gist_id}","starred_url":"https://api.github.com/users/alde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alde/subscriptions","organizations_url":"https://api.github.com/users/alde/orgs","repos_url":"https://api.github.com/users/alde/repos","events_url":"https://api.github.com/users/alde/events{/privacy}","received_events_url":"https://api.github.com/users/alde/received_events","type":"User","site_admin":false},"body":"think I'd prefer createMatcher instead of makeMatcher\r\n\r\nmakeMatcher sounds weird in my head","created_at":"2015-11-25T12:43:42Z","updated_at":"2015-11-25T12:43:42Z","html_url":"https://github.com/alde/eremetic/pull/31#discussion_r45862231","pull_request_url":"https://api.github.com/repos/alde/eremetic/pulls/31","_links":{"self":{"href":"https://api.github.com/repos/alde/eremetic/pulls/comments/45862231"},"html":{"href":"https://github.com/alde/eremetic/pull/31#discussion_r45862231"},"pull_request":{"href":"https://api.github.com/repos/alde/eremetic/pulls/31"}}},"pull_request":{"url":"https://api.github.com/repos/alde/eremetic/pulls/31","id":51788098,"html_url":"https://github.com/alde/eremetic/pull/31","diff_url":"https://github.com/alde/eremetic/pull/31.diff","patch_url":"https://github.com/alde/eremetic/pull/31.patch","issue_url":"https://api.github.com/repos/alde/eremetic/issues/31","number":31,"state":"open","locked":false,"title":"Filter offers","user":{"login":"keis","id":125062,"avatar_url":"https://avatars.githubusercontent.com/u/125062?v=3","gravatar_id":"","url":"https://api.github.com/users/keis","html_url":"https://github.com/keis","followers_url":"https://api.github.com/users/keis/followers","following_url":"https://api.github.com/users/keis/following{/other_user}","gists_url":"https://api.github.com/users/keis/gists{/gist_id}","starred_url":"https://api.github.com/users/keis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keis/subscriptions","organizations_url":"https://api.github.com/users/keis/orgs","repos_url":"https://api.github.com/users/keis/repos","events_url":"https://api.github.com/users/keis/events{/privacy}","received_events_url":"https://api.github.com/users/keis/received_events","type":"User","site_admin":false},"body":"This should stop eremetic from trying to launch tasks on offers without enough resources.\r\n\r\nFuture improvements are to perhaps give up on a task if we can't launch it after X minutes. Also right now it freaks out and rejects all offers when a task can't be launched","created_at":"2015-11-25T12:29:04Z","updated_at":"2015-11-25T12:43:42Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e008f68e4b3462c2b0c03b9608b912ccec17aeae","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/alde/eremetic/pulls/31/commits","review_comments_url":"https://api.github.com/repos/alde/eremetic/pulls/31/comments","review_comment_url":"https://api.github.com/repos/alde/eremetic/pulls/comments{/number}","comments_url":"https://api.github.com/repos/alde/eremetic/issues/31/comments","statuses_url":"https://api.github.com/repos/alde/eremetic/statuses/48d3502c344edd1f0a08a55bb64d74be510bc3f5","head":{"label":"keis:filter-offers","ref":"filter-offers","sha":"48d3502c344edd1f0a08a55bb64d74be510bc3f5","user":{"login":"keis","id":125062,"avatar_url":"https://avatars.githubusercontent.com/u/125062?v=3","gravatar_id":"","url":"https://api.github.com/users/keis","html_url":"https://github.com/keis","followers_url":"https://api.github.com/users/keis/followers","following_url":"https://api.github.com/users/keis/following{/other_user}","gists_url":"https://api.github.com/users/keis/gists{/gist_id}","starred_url":"https://api.github.com/users/keis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keis/subscriptions","organizations_url":"https://api.github.com/users/keis/orgs","repos_url":"https://api.github.com/users/keis/repos","events_url":"https://api.github.com/users/keis/events{/privacy}","received_events_url":"https://api.github.com/users/keis/received_events","type":"User","site_admin":false},"repo":{"id":44615832,"name":"eremetic","full_name":"keis/eremetic","owner":{"login":"keis","id":125062,"avatar_url":"https://avatars.githubusercontent.com/u/125062?v=3","gravatar_id":"","url":"https://api.github.com/users/keis","html_url":"https://github.com/keis","followers_url":"https://api.github.com/users/keis/followers","following_url":"https://api.github.com/users/keis/following{/other_user}","gists_url":"https://api.github.com/users/keis/gists{/gist_id}","starred_url":"https://api.github.com/users/keis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keis/subscriptions","organizations_url":"https://api.github.com/users/keis/orgs","repos_url":"https://api.github.com/users/keis/repos","events_url":"https://api.github.com/users/keis/events{/privacy}","received_events_url":"https://api.github.com/users/keis/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/keis/eremetic","description":"A Framework for Mesos to run one-off tasks in docker","fork":true,"url":"https://api.github.com/repos/keis/eremetic","forks_url":"https://api.github.com/repos/keis/eremetic/forks","keys_url":"https://api.github.com/repos/keis/eremetic/keys{/key_id}","collaborators_url":"https://api.github.com/repos/keis/eremetic/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/keis/eremetic/teams","hooks_url":"https://api.github.com/repos/keis/eremetic/hooks","issue_events_url":"https://api.github.com/repos/keis/eremetic/issues/events{/number}","events_url":"https://api.github.com/repos/keis/eremetic/events","assignees_url":"https://api.github.com/repos/keis/eremetic/assignees{/user}","branches_url":"https://api.github.com/repos/keis/eremetic/branches{/branch}","tags_url":"https://api.github.com/repos/keis/eremetic/tags","blobs_url":"https://api.github.com/repos/keis/eremetic/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/keis/eremetic/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/keis/eremetic/git/refs{/sha}","trees_url":"https://api.github.com/repos/keis/eremetic/git/trees{/sha}","statuses_url":"https://api.github.com/repos/keis/eremetic/statuses/{sha}","languages_url":"https://api.github.com/repos/keis/eremetic/languages","stargazers_url":"https://api.github.com/repos/keis/eremetic/stargazers","contributors_url":"https://api.github.com/repos/keis/eremetic/contributors","subscribers_url":"https://api.github.com/repos/keis/eremetic/subscribers","subscription_url":"https://api.github.com/repos/keis/eremetic/subscription","commits_url":"https://api.github.com/repos/keis/eremetic/commits{/sha}","git_commits_url":"https://api.github.com/repos/keis/eremetic/git/commits{/sha}","comments_url":"https://api.github.com/repos/keis/eremetic/comments{/number}","issue_comment_url":"https://api.github.com/repos/keis/eremetic/issues/comments{/number}","contents_url":"https://api.github.com/repos/keis/eremetic/contents/{+path}","compare_url":"https://api.github.com/repos/keis/eremetic/compare/{base}...{head}","merges_url":"https://api.github.com/repos/keis/eremetic/merges","archive_url":"https://api.github.com/repos/keis/eremetic/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/keis/eremetic/downloads","issues_url":"https://api.github.com/repos/keis/eremetic/issues{/number}","pulls_url":"https://api.github.com/repos/keis/eremetic/pulls{/number}","milestones_url":"https://api.github.com/repos/keis/eremetic/milestones{/number}","notifications_url":"https://api.github.com/repos/keis/eremetic/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/keis/eremetic/labels{/name}","releases_url":"https://api.github.com/repos/keis/eremetic/releases{/id}","created_at":"2015-10-20T15:28:06Z","updated_at":"2015-10-20T15:28:06Z","pushed_at":"2015-11-25T12:20:56Z","git_url":"git://github.com/keis/eremetic.git","ssh_url":"git@github.com:keis/eremetic.git","clone_url":"https://github.com/keis/eremetic.git","svn_url":"https://github.com/keis/eremetic","homepage":null,"size":727,"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":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"alde:master","ref":"master","sha":"3a88a5890284df4c5cea57ffb16c6ee4206415ba","user":{"login":"alde","id":350296,"avatar_url":"https://avatars.githubusercontent.com/u/350296?v=3","gravatar_id":"","url":"https://api.github.com/users/alde","html_url":"https://github.com/alde","followers_url":"https://api.github.com/users/alde/followers","following_url":"https://api.github.com/users/alde/following{/other_user}","gists_url":"https://api.github.com/users/alde/gists{/gist_id}","starred_url":"https://api.github.com/users/alde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alde/subscriptions","organizations_url":"https://api.github.com/users/alde/orgs","repos_url":"https://api.github.com/users/alde/repos","events_url":"https://api.github.com/users/alde/events{/privacy}","received_events_url":"https://api.github.com/users/alde/received_events","type":"User","site_admin":false},"repo":{"id":44609170,"name":"eremetic","full_name":"alde/eremetic","owner":{"login":"alde","id":350296,"avatar_url":"https://avatars.githubusercontent.com/u/350296?v=3","gravatar_id":"","url":"https://api.github.com/users/alde","html_url":"https://github.com/alde","followers_url":"https://api.github.com/users/alde/followers","following_url":"https://api.github.com/users/alde/following{/other_user}","gists_url":"https://api.github.com/users/alde/gists{/gist_id}","starred_url":"https://api.github.com/users/alde/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alde/subscriptions","organizations_url":"https://api.github.com/users/alde/orgs","repos_url":"https://api.github.com/users/alde/repos","events_url":"https://api.github.com/users/alde/events{/privacy}","received_events_url":"https://api.github.com/users/alde/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/alde/eremetic","description":"A Framework for Mesos to run one-off tasks in docker","fork":false,"url":"https://api.github.com/repos/alde/eremetic","forks_url":"https://api.github.com/repos/alde/eremetic/forks","keys_url":"https://api.github.com/repos/alde/eremetic/keys{/key_id}","collaborators_url":"https://api.github.com/repos/alde/eremetic/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/alde/eremetic/teams","hooks_url":"https://api.github.com/repos/alde/eremetic/hooks","issue_events_url":"https://api.github.com/repos/alde/eremetic/issues/events{/number}","events_url":"https://api.github.com/repos/alde/eremetic/events","assignees_url":"https://api.github.com/repos/alde/eremetic/assignees{/user}","branches_url":"https://api.github.com/repos/alde/eremetic/branches{/branch}","tags_url":"https://api.github.com/repos/alde/eremetic/tags","blobs_url":"https://api.github.com/repos/alde/eremetic/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/alde/eremetic/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/alde/eremetic/git/refs{/sha}","trees_url":"https://api.github.com/repos/alde/eremetic/git/trees{/sha}","statuses_url":"https://api.github.com/repos/alde/eremetic/statuses/{sha}","languages_url":"https://api.github.com/repos/alde/eremetic/languages","stargazers_url":"https://api.github.com/repos/alde/eremetic/stargazers","contributors_url":"https://api.github.com/repos/alde/eremetic/contributors","subscribers_url":"https://api.github.com/repos/alde/eremetic/subscribers","subscription_url":"https://api.github.com/repos/alde/eremetic/subscription","commits_url":"https://api.github.com/repos/alde/eremetic/commits{/sha}","git_commits_url":"https://api.github.com/repos/alde/eremetic/git/commits{/sha}","comments_url":"https://api.github.com/repos/alde/eremetic/comments{/number}","issue_comment_url":"https://api.github.com/repos/alde/eremetic/issues/comments{/number}","contents_url":"https://api.github.com/repos/alde/eremetic/contents/{+path}","compare_url":"https://api.github.com/repos/alde/eremetic/compare/{base}...{head}","merges_url":"https://api.github.com/repos/alde/eremetic/merges","archive_url":"https://api.github.com/repos/alde/eremetic/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/alde/eremetic/downloads","issues_url":"https://api.github.com/repos/alde/eremetic/issues{/number}","pulls_url":"https://api.github.com/repos/alde/eremetic/pulls{/number}","milestones_url":"https://api.github.com/repos/alde/eremetic/milestones{/number}","notifications_url":"https://api.github.com/repos/alde/eremetic/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/alde/eremetic/labels{/name}","releases_url":"https://api.github.com/repos/alde/eremetic/releases{/id}","created_at":"2015-10-20T13:45:17Z","updated_at":"2015-10-22T22:29:02Z","pushed_at":"2015-11-25T12:29:04Z","git_url":"git://github.com/alde/eremetic.git","ssh_url":"git@github.com:alde/eremetic.git","clone_url":"https://github.com/alde/eremetic.git","svn_url":"https://github.com/alde/eremetic","homepage":null,"size":725,"stargazers_count":7,"watchers_count":7,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":2,"mirror_url":null,"open_issues_count":3,"forks":2,"open_issues":3,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/alde/eremetic/pulls/31"},"html":{"href":"https://github.com/alde/eremetic/pull/31"},"issue":{"href":"https://api.github.com/repos/alde/eremetic/issues/31"},"comments":{"href":"https://api.github.com/repos/alde/eremetic/issues/31/comments"},"review_comments":{"href":"https://api.github.com/repos/alde/eremetic/pulls/31/comments"},"review_comment":{"href":"https://api.github.com/repos/alde/eremetic/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/alde/eremetic/pulls/31/commits"},"statuses":{"href":"https://api.github.com/repos/alde/eremetic/statuses/48d3502c344edd1f0a08a55bb64d74be510bc3f5"}}}}