{"action":"created","comment":{"url":"https://api.github.com/repos/apache/spark/pulls/comments/33274248","id":33274248,"diff_hunk":"@@ -86,10 +89,106 @@ private[mesos] trait MesosSchedulerUtils extends Logging {\n   /**\n    * Get the amount of resources for the specified type from the resource list\n    */\n-  protected def getResource(res: List[Resource], name: String): Double = {\n+  protected def getResource(res: JList[Resource], name: String): Double = {\n     for (r <- res if r.getName == name) {\n       return r.getScalar.getValue\n     }\n     0.0\n   }\n+\n+\n+  /** Helper method to get the key,value-set pair for a Mesos Attribute protobuf */\n+  private[mesos] def getAttribute(attr: Attribute): (String, Set[String]) =\n+    (attr.getName, attr.getText.getValue.split(',').toSet)\n+\n+\n+  /** Build a Mesos resource protobuf object */\n+  private[mesos] def createResource(resourceName: String, quantity: Double): Protos.Resource = {\n+    Resource.newBuilder()\n+      .setName(resourceName)\n+      .setType(Value.Type.SCALAR)\n+      .setScalar(Value.Scalar.newBuilder().setValue(quantity).build())\n+      .build()\n+  }\n+\n+\n+  /**\n+   * Match the requirements (if any) to the offer attributes.\n+   * if attribute requirements are not specified - return true\n+   * else if attribute is defined and no values are given, simple attribute presence is preformed\n+   * else if attribute name and value is specified, subset match is performed on slave attributes\n+   */\n+  private[mesos] def matchesAttributeRequirements(\n+      slaveOfferConstraints: Map[String, Set[String]],\n+      offerAttributes: Map[String, Set[String]]): Boolean =\n+    if (slaveOfferConstraints.isEmpty) {\n+      true\n+    } else {\n+      slaveOfferConstraints.forall {","path":"core/src/main/scala/org/apache/spark/scheduler/cluster/mesos/MesosSchedulerUtils.scala","position":63,"original_position":63,"commit_id":"97d55e1193fb30e5faa077bb1244959545475f7d","original_commit_id":"97d55e1193fb30e5faa077bb1244959545475f7d","user":{"login":"squito","id":71240,"avatar_url":"https://avatars.githubusercontent.com/u/71240?v=3","gravatar_id":"","url":"https://api.github.com/users/squito","html_url":"https://github.com/squito","followers_url":"https://api.github.com/users/squito/followers","following_url":"https://api.github.com/users/squito/following{/other_user}","gists_url":"https://api.github.com/users/squito/gists{/gist_id}","starred_url":"https://api.github.com/users/squito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/squito/subscriptions","organizations_url":"https://api.github.com/users/squito/orgs","repos_url":"https://api.github.com/users/squito/repos","events_url":"https://api.github.com/users/squito/events{/privacy}","received_events_url":"https://api.github.com/users/squito/received_events","type":"User","site_admin":false},"body":"I think dragos mentioned this for another case earlier -- I don't think you need the `if (slaveOfferConstraints.isEmpty)` since `forall` takes care of it for you\r\n```scala\r\nscala> List().forall{_ => 1 > 2}\r\nres0: Boolean = true\r\n```","created_at":"2015-06-25T16:24:07Z","updated_at":"2015-06-25T16:24:07Z","html_url":"https://github.com/apache/spark/pull/5563#discussion_r33274248","pull_request_url":"https://api.github.com/repos/apache/spark/pulls/5563","_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/comments/33274248"},"html":{"href":"https://github.com/apache/spark/pull/5563#discussion_r33274248"},"pull_request":{"href":"https://api.github.com/repos/apache/spark/pulls/5563"}}},"pull_request":{"url":"https://api.github.com/repos/apache/spark/pulls/5563","id":33582727,"html_url":"https://github.com/apache/spark/pull/5563","diff_url":"https://github.com/apache/spark/pull/5563.diff","patch_url":"https://github.com/apache/spark/pull/5563.patch","issue_url":"https://api.github.com/repos/apache/spark/issues/5563","number":5563,"state":"open","locked":false,"title":"[SPARK-6707] [CORE][MESOS]: Mesos Scheduler should allow the user to specify constraints based on slave attributes","user":{"login":"ankurcha","id":124104,"avatar_url":"https://avatars.githubusercontent.com/u/124104?v=3","gravatar_id":"","url":"https://api.github.com/users/ankurcha","html_url":"https://github.com/ankurcha","followers_url":"https://api.github.com/users/ankurcha/followers","following_url":"https://api.github.com/users/ankurcha/following{/other_user}","gists_url":"https://api.github.com/users/ankurcha/gists{/gist_id}","starred_url":"https://api.github.com/users/ankurcha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankurcha/subscriptions","organizations_url":"https://api.github.com/users/ankurcha/orgs","repos_url":"https://api.github.com/users/ankurcha/repos","events_url":"https://api.github.com/users/ankurcha/events{/privacy}","received_events_url":"https://api.github.com/users/ankurcha/received_events","type":"User","site_admin":false},"body":"Currently, the mesos scheduler only looks at the 'cpu' and 'mem' resources when trying to determine the usablility of a resource offer from a mesos slave node. It may be preferable for the user to be able to ensure that the spark jobs are only started on a certain set of nodes (based on attributes). \r\n\r\nFor example, If the user sets a property, let's say `spark.mesos.constraints` is set to `tachyon=true;us-east-1=false`, then the resource offers will be checked to see if they meet both these constraints and only then will be accepted to start new executors.","created_at":"2015-04-17T21:10:07Z","updated_at":"2015-06-25T16:24:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"027ab432992d7191b21e3102af6bb4d9d3e4e416","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/apache/spark/pulls/5563/commits","review_comments_url":"https://api.github.com/repos/apache/spark/pulls/5563/comments","review_comment_url":"https://api.github.com/repos/apache/spark/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/spark/issues/5563/comments","statuses_url":"https://api.github.com/repos/apache/spark/statuses/97d55e1193fb30e5faa077bb1244959545475f7d","head":{"label":"ankurcha:mesos_attribs","ref":"mesos_attribs","sha":"97d55e1193fb30e5faa077bb1244959545475f7d","user":{"login":"ankurcha","id":124104,"avatar_url":"https://avatars.githubusercontent.com/u/124104?v=3","gravatar_id":"","url":"https://api.github.com/users/ankurcha","html_url":"https://github.com/ankurcha","followers_url":"https://api.github.com/users/ankurcha/followers","following_url":"https://api.github.com/users/ankurcha/following{/other_user}","gists_url":"https://api.github.com/users/ankurcha/gists{/gist_id}","starred_url":"https://api.github.com/users/ankurcha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankurcha/subscriptions","organizations_url":"https://api.github.com/users/ankurcha/orgs","repos_url":"https://api.github.com/users/ankurcha/repos","events_url":"https://api.github.com/users/ankurcha/events{/privacy}","received_events_url":"https://api.github.com/users/ankurcha/received_events","type":"User","site_admin":false},"repo":{"id":34135789,"name":"spark","full_name":"ankurcha/spark","owner":{"login":"ankurcha","id":124104,"avatar_url":"https://avatars.githubusercontent.com/u/124104?v=3","gravatar_id":"","url":"https://api.github.com/users/ankurcha","html_url":"https://github.com/ankurcha","followers_url":"https://api.github.com/users/ankurcha/followers","following_url":"https://api.github.com/users/ankurcha/following{/other_user}","gists_url":"https://api.github.com/users/ankurcha/gists{/gist_id}","starred_url":"https://api.github.com/users/ankurcha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ankurcha/subscriptions","organizations_url":"https://api.github.com/users/ankurcha/orgs","repos_url":"https://api.github.com/users/ankurcha/repos","events_url":"https://api.github.com/users/ankurcha/events{/privacy}","received_events_url":"https://api.github.com/users/ankurcha/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ankurcha/spark","description":"Mirror of Apache Spark","fork":true,"url":"https://api.github.com/repos/ankurcha/spark","forks_url":"https://api.github.com/repos/ankurcha/spark/forks","keys_url":"https://api.github.com/repos/ankurcha/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ankurcha/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ankurcha/spark/teams","hooks_url":"https://api.github.com/repos/ankurcha/spark/hooks","issue_events_url":"https://api.github.com/repos/ankurcha/spark/issues/events{/number}","events_url":"https://api.github.com/repos/ankurcha/spark/events","assignees_url":"https://api.github.com/repos/ankurcha/spark/assignees{/user}","branches_url":"https://api.github.com/repos/ankurcha/spark/branches{/branch}","tags_url":"https://api.github.com/repos/ankurcha/spark/tags","blobs_url":"https://api.github.com/repos/ankurcha/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ankurcha/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ankurcha/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/ankurcha/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ankurcha/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/ankurcha/spark/languages","stargazers_url":"https://api.github.com/repos/ankurcha/spark/stargazers","contributors_url":"https://api.github.com/repos/ankurcha/spark/contributors","subscribers_url":"https://api.github.com/repos/ankurcha/spark/subscribers","subscription_url":"https://api.github.com/repos/ankurcha/spark/subscription","commits_url":"https://api.github.com/repos/ankurcha/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/ankurcha/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/ankurcha/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/ankurcha/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/ankurcha/spark/contents/{+path}","compare_url":"https://api.github.com/repos/ankurcha/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ankurcha/spark/merges","archive_url":"https://api.github.com/repos/ankurcha/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ankurcha/spark/downloads","issues_url":"https://api.github.com/repos/ankurcha/spark/issues{/number}","pulls_url":"https://api.github.com/repos/ankurcha/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/ankurcha/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/ankurcha/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ankurcha/spark/labels{/name}","releases_url":"https://api.github.com/repos/ankurcha/spark/releases{/id}","created_at":"2015-04-17T19:25:53Z","updated_at":"2015-05-08T17:52:46Z","pushed_at":"2015-06-24T23:20:53Z","git_url":"git://github.com/ankurcha/spark.git","ssh_url":"git@github.com:ankurcha/spark.git","clone_url":"https://github.com/ankurcha/spark.git","svn_url":"https://github.com/ankurcha/spark","homepage":null,"size":108867,"stargazers_count":0,"watchers_count":0,"language":"Scala","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":0,"default_branch":"master"}},"base":{"label":"apache:master","ref":"master","sha":"7daa70292e47be6a944351ef00c770ad4bcb0877","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":17165658,"name":"spark","full_name":"apache/spark","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/spark","description":"Mirror of Apache Spark","fork":false,"url":"https://api.github.com/repos/apache/spark","forks_url":"https://api.github.com/repos/apache/spark/forks","keys_url":"https://api.github.com/repos/apache/spark/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/spark/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/spark/teams","hooks_url":"https://api.github.com/repos/apache/spark/hooks","issue_events_url":"https://api.github.com/repos/apache/spark/issues/events{/number}","events_url":"https://api.github.com/repos/apache/spark/events","assignees_url":"https://api.github.com/repos/apache/spark/assignees{/user}","branches_url":"https://api.github.com/repos/apache/spark/branches{/branch}","tags_url":"https://api.github.com/repos/apache/spark/tags","blobs_url":"https://api.github.com/repos/apache/spark/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/spark/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/spark/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/spark/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/spark/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/spark/languages","stargazers_url":"https://api.github.com/repos/apache/spark/stargazers","contributors_url":"https://api.github.com/repos/apache/spark/contributors","subscribers_url":"https://api.github.com/repos/apache/spark/subscribers","subscription_url":"https://api.github.com/repos/apache/spark/subscription","commits_url":"https://api.github.com/repos/apache/spark/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/spark/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/spark/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/spark/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/spark/contents/{+path}","compare_url":"https://api.github.com/repos/apache/spark/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/spark/merges","archive_url":"https://api.github.com/repos/apache/spark/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/spark/downloads","issues_url":"https://api.github.com/repos/apache/spark/issues{/number}","pulls_url":"https://api.github.com/repos/apache/spark/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/spark/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/spark/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/spark/labels{/name}","releases_url":"https://api.github.com/repos/apache/spark/releases{/id}","created_at":"2014-02-25T08:00:08Z","updated_at":"2015-06-25T15:33:43Z","pushed_at":"2015-06-25T16:21:43Z","git_url":"git://github.com/apache/spark.git","ssh_url":"git@github.com:apache/spark.git","clone_url":"https://github.com/apache/spark.git","svn_url":"https://github.com/apache/spark","homepage":null,"size":1514733,"stargazers_count":4531,"watchers_count":4531,"language":"Scala","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":3996,"mirror_url":"git://git.apache.org/spark.git","open_issues_count":354,"forks":3996,"open_issues":354,"watchers":4531,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/spark/pulls/5563"},"html":{"href":"https://github.com/apache/spark/pull/5563"},"issue":{"href":"https://api.github.com/repos/apache/spark/issues/5563"},"comments":{"href":"https://api.github.com/repos/apache/spark/issues/5563/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/spark/pulls/5563/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/spark/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/spark/pulls/5563/commits"},"statuses":{"href":"https://api.github.com/repos/apache/spark/statuses/97d55e1193fb30e5faa077bb1244959545475f7d"}}}}