{"action":"created","comment":{"url":"https://api.github.com/repos/mesosphere/marathon/pulls/comments/73292828","id":73292828,"diff_hunk":"@@ -321,7 +321,65 @@ object DeploymentPlan {\n \n     validator[DeploymentPlan] { plan =>\n       plan.createdOrUpdatedApps as \"app\" is every(valid(AppDefinition.updateIsValid(plan.original)))\n-      plan should notBeTooBig\n+      plan should notBeTooBig and haveValidPorts\n+    }\n+  }\n+\n+  private def haveValidPorts: Validator[DeploymentPlan] = {\n+    new Validator[DeploymentPlan] {\n+      override def apply(plan: DeploymentPlan): Result = {\n+        // Each service port should be unique across a cluster. We\n+        // want to report conflicts if the same service port is used\n+        // by multiple apps.\n+\n+        // This validation rule is only applied for newly created or\n+        // updated applications (within this deployment plan),\n+        // not for all applications.\n+\n+        // We construct the mapping servicePort <- Set[AppKey]. This\n+        // allows us to report any service port that has more than 1\n+        // application using the same port.\n+\n+        // We keep track of the total number of ports to support an\n+        // early exit condition.\n+\n+        val createdOrUpdatedApps = plan.createdOrUpdatedApps.map(app => app.id).toSet\n+        var ports: Int = 0\n+        val merged =\n+          new mutable.HashMap[Int, mutable.Set[AppDefinition.AppKey]] with mutable.MultiMap[Int, AppDefinition.AppKey]\n+\n+        // Add each servicePort <- Application to the map.\n+        for {\n+          app <- plan.target.transitiveApps\n+          // We ignore randomly assigned ports identified by `0`.\n+          port <- app.servicePorts if port != 0\n+        } {\n+          ports += 1\n+          merged.addBinding(port, app.id)\n+        }\n+\n+        // If the total number of unique ports is equal to the number\n+        // of requested ports then we know there are no conflicts.\n+        if (merged.size == ports) {\n+          Success\n+        } else {\n+          // Otherwise we find all ports that have more than 1 app\n+          // interested in them.\n+\n+          // We report all the conflicting apps along with which other\n+          // apps they conflict with.\n+          val violations = for {\n+            // only yield port as conflict if createdOrUpdatedApps are involved and therefore in the intersection set\n+            (port, apps) <- merged if apps.size > 1 && apps.intersect(createdOrUpdatedApps).nonEmpty","path":"src/main/scala/mesosphere/marathon/upgrade/DeploymentPlan.scala","position":63,"original_position":63,"commit_id":"54d47be0530368e0ed467c4e2983214ce796e614","original_commit_id":"54d47be0530368e0ed467c4e2983214ce796e614","user":{"login":"aquamatthias","id":330485,"avatar_url":"https://avatars.githubusercontent.com/u/330485?v=3","gravatar_id":"","url":"https://api.github.com/users/aquamatthias","html_url":"https://github.com/aquamatthias","followers_url":"https://api.github.com/users/aquamatthias/followers","following_url":"https://api.github.com/users/aquamatthias/following{/other_user}","gists_url":"https://api.github.com/users/aquamatthias/gists{/gist_id}","starred_url":"https://api.github.com/users/aquamatthias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aquamatthias/subscriptions","organizations_url":"https://api.github.com/users/aquamatthias/orgs","repos_url":"https://api.github.com/users/aquamatthias/repos","events_url":"https://api.github.com/users/aquamatthias/events{/privacy}","received_events_url":"https://api.github.com/users/aquamatthias/received_events","type":"User","site_admin":false},"body":"This will filter the list of `(port, apps)`. It could lead to an empty array for violations, which still would cause a Failure - or (the filter is applied in the else/failure branch)? ","created_at":"2016-08-03T07:36:24Z","updated_at":"2016-08-03T07:36:24Z","html_url":"https://github.com/mesosphere/marathon/pull/4172#discussion_r73292828","pull_request_url":"https://api.github.com/repos/mesosphere/marathon/pulls/4172","_links":{"self":{"href":"https://api.github.com/repos/mesosphere/marathon/pulls/comments/73292828"},"html":{"href":"https://github.com/mesosphere/marathon/pull/4172#discussion_r73292828"},"pull_request":{"href":"https://api.github.com/repos/mesosphere/marathon/pulls/4172"}}},"pull_request":{"url":"https://api.github.com/repos/mesosphere/marathon/pulls/4172","id":79811306,"html_url":"https://github.com/mesosphere/marathon/pull/4172","diff_url":"https://github.com/mesosphere/marathon/pull/4172.diff","patch_url":"https://github.com/mesosphere/marathon/pull/4172.patch","issue_url":"https://api.github.com/repos/mesosphere/marathon/issues/4172","number":4172,"state":"open","locked":false,"title":"Moved unique port validation from Group to DeploymentPlan","user":{"login":"unterstein","id":904420,"avatar_url":"https://avatars.githubusercontent.com/u/904420?v=3","gravatar_id":"","url":"https://api.github.com/users/unterstein","html_url":"https://github.com/unterstein","followers_url":"https://api.github.com/users/unterstein/followers","following_url":"https://api.github.com/users/unterstein/following{/other_user}","gists_url":"https://api.github.com/users/unterstein/gists{/gist_id}","starred_url":"https://api.github.com/users/unterstein/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/unterstein/subscriptions","organizations_url":"https://api.github.com/users/unterstein/orgs","repos_url":"https://api.github.com/users/unterstein/repos","events_url":"https://api.github.com/users/unterstein/events{/privacy}","received_events_url":"https://api.github.com/users/unterstein/received_events","type":"User","site_admin":false},"body":"Like we discussed today:\r\nMoved unique port validation from Group to DeploymentPlan, like requested in https://github.com/mesosphere/marathon/issues/4167","created_at":"2016-08-02T21:22:15Z","updated_at":"2016-08-03T07:36:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"9214cccddb633106b29ea142f22c8387df44738e","assignee":{"login":"aquamatthias","id":330485,"avatar_url":"https://avatars.githubusercontent.com/u/330485?v=3","gravatar_id":"","url":"https://api.github.com/users/aquamatthias","html_url":"https://github.com/aquamatthias","followers_url":"https://api.github.com/users/aquamatthias/followers","following_url":"https://api.github.com/users/aquamatthias/following{/other_user}","gists_url":"https://api.github.com/users/aquamatthias/gists{/gist_id}","starred_url":"https://api.github.com/users/aquamatthias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aquamatthias/subscriptions","organizations_url":"https://api.github.com/users/aquamatthias/orgs","repos_url":"https://api.github.com/users/aquamatthias/repos","events_url":"https://api.github.com/users/aquamatthias/events{/privacy}","received_events_url":"https://api.github.com/users/aquamatthias/received_events","type":"User","site_admin":false},"assignees":[{"login":"aquamatthias","id":330485,"avatar_url":"https://avatars.githubusercontent.com/u/330485?v=3","gravatar_id":"","url":"https://api.github.com/users/aquamatthias","html_url":"https://github.com/aquamatthias","followers_url":"https://api.github.com/users/aquamatthias/followers","following_url":"https://api.github.com/users/aquamatthias/following{/other_user}","gists_url":"https://api.github.com/users/aquamatthias/gists{/gist_id}","starred_url":"https://api.github.com/users/aquamatthias/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aquamatthias/subscriptions","organizations_url":"https://api.github.com/users/aquamatthias/orgs","repos_url":"https://api.github.com/users/aquamatthias/repos","events_url":"https://api.github.com/users/aquamatthias/events{/privacy}","received_events_url":"https://api.github.com/users/aquamatthias/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/mesosphere/marathon/pulls/4172/commits","review_comments_url":"https://api.github.com/repos/mesosphere/marathon/pulls/4172/comments","review_comment_url":"https://api.github.com/repos/mesosphere/marathon/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mesosphere/marathon/issues/4172/comments","statuses_url":"https://api.github.com/repos/mesosphere/marathon/statuses/54d47be0530368e0ed467c4e2983214ce796e614","head":{"label":"mesosphere:ju/4167-move-port-validation","ref":"ju/4167-move-port-validation","sha":"54d47be0530368e0ed467c4e2983214ce796e614","user":{"login":"mesosphere","id":3458585,"avatar_url":"https://avatars.githubusercontent.com/u/3458585?v=3","gravatar_id":"","url":"https://api.github.com/users/mesosphere","html_url":"https://github.com/mesosphere","followers_url":"https://api.github.com/users/mesosphere/followers","following_url":"https://api.github.com/users/mesosphere/following{/other_user}","gists_url":"https://api.github.com/users/mesosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/mesosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mesosphere/subscriptions","organizations_url":"https://api.github.com/users/mesosphere/orgs","repos_url":"https://api.github.com/users/mesosphere/repos","events_url":"https://api.github.com/users/mesosphere/events{/privacy}","received_events_url":"https://api.github.com/users/mesosphere/received_events","type":"Organization","site_admin":false},"repo":{"id":10941409,"name":"marathon","full_name":"mesosphere/marathon","owner":{"login":"mesosphere","id":3458585,"avatar_url":"https://avatars.githubusercontent.com/u/3458585?v=3","gravatar_id":"","url":"https://api.github.com/users/mesosphere","html_url":"https://github.com/mesosphere","followers_url":"https://api.github.com/users/mesosphere/followers","following_url":"https://api.github.com/users/mesosphere/following{/other_user}","gists_url":"https://api.github.com/users/mesosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/mesosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mesosphere/subscriptions","organizations_url":"https://api.github.com/users/mesosphere/orgs","repos_url":"https://api.github.com/users/mesosphere/repos","events_url":"https://api.github.com/users/mesosphere/events{/privacy}","received_events_url":"https://api.github.com/users/mesosphere/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mesosphere/marathon","description":"Deploy and manage containers (including Docker) on top of Apache Mesos at scale.","fork":false,"url":"https://api.github.com/repos/mesosphere/marathon","forks_url":"https://api.github.com/repos/mesosphere/marathon/forks","keys_url":"https://api.github.com/repos/mesosphere/marathon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mesosphere/marathon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mesosphere/marathon/teams","hooks_url":"https://api.github.com/repos/mesosphere/marathon/hooks","issue_events_url":"https://api.github.com/repos/mesosphere/marathon/issues/events{/number}","events_url":"https://api.github.com/repos/mesosphere/marathon/events","assignees_url":"https://api.github.com/repos/mesosphere/marathon/assignees{/user}","branches_url":"https://api.github.com/repos/mesosphere/marathon/branches{/branch}","tags_url":"https://api.github.com/repos/mesosphere/marathon/tags","blobs_url":"https://api.github.com/repos/mesosphere/marathon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mesosphere/marathon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mesosphere/marathon/git/refs{/sha}","trees_url":"https://api.github.com/repos/mesosphere/marathon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mesosphere/marathon/statuses/{sha}","languages_url":"https://api.github.com/repos/mesosphere/marathon/languages","stargazers_url":"https://api.github.com/repos/mesosphere/marathon/stargazers","contributors_url":"https://api.github.com/repos/mesosphere/marathon/contributors","subscribers_url":"https://api.github.com/repos/mesosphere/marathon/subscribers","subscription_url":"https://api.github.com/repos/mesosphere/marathon/subscription","commits_url":"https://api.github.com/repos/mesosphere/marathon/commits{/sha}","git_commits_url":"https://api.github.com/repos/mesosphere/marathon/git/commits{/sha}","comments_url":"https://api.github.com/repos/mesosphere/marathon/comments{/number}","issue_comment_url":"https://api.github.com/repos/mesosphere/marathon/issues/comments{/number}","contents_url":"https://api.github.com/repos/mesosphere/marathon/contents/{+path}","compare_url":"https://api.github.com/repos/mesosphere/marathon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mesosphere/marathon/merges","archive_url":"https://api.github.com/repos/mesosphere/marathon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mesosphere/marathon/downloads","issues_url":"https://api.github.com/repos/mesosphere/marathon/issues{/number}","pulls_url":"https://api.github.com/repos/mesosphere/marathon/pulls{/number}","milestones_url":"https://api.github.com/repos/mesosphere/marathon/milestones{/number}","notifications_url":"https://api.github.com/repos/mesosphere/marathon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mesosphere/marathon/labels{/name}","releases_url":"https://api.github.com/repos/mesosphere/marathon/releases{/id}","deployments_url":"https://api.github.com/repos/mesosphere/marathon/deployments","created_at":"2013-06-25T14:56:34Z","updated_at":"2016-08-02T23:25:37Z","pushed_at":"2016-08-03T00:32:43Z","git_url":"git://github.com/mesosphere/marathon.git","ssh_url":"git@github.com:mesosphere/marathon.git","clone_url":"https://github.com/mesosphere/marathon.git","svn_url":"https://github.com/mesosphere/marathon","homepage":"https://mesosphere.github.io/marathon/","size":28435,"stargazers_count":2685,"watchers_count":2685,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":597,"mirror_url":null,"open_issues_count":626,"forks":597,"open_issues":626,"watchers":2685,"default_branch":"master"}},"base":{"label":"mesosphere:master","ref":"master","sha":"ff17d28e5f7ad4226a54d06b9d0a101e9c5d3cb2","user":{"login":"mesosphere","id":3458585,"avatar_url":"https://avatars.githubusercontent.com/u/3458585?v=3","gravatar_id":"","url":"https://api.github.com/users/mesosphere","html_url":"https://github.com/mesosphere","followers_url":"https://api.github.com/users/mesosphere/followers","following_url":"https://api.github.com/users/mesosphere/following{/other_user}","gists_url":"https://api.github.com/users/mesosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/mesosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mesosphere/subscriptions","organizations_url":"https://api.github.com/users/mesosphere/orgs","repos_url":"https://api.github.com/users/mesosphere/repos","events_url":"https://api.github.com/users/mesosphere/events{/privacy}","received_events_url":"https://api.github.com/users/mesosphere/received_events","type":"Organization","site_admin":false},"repo":{"id":10941409,"name":"marathon","full_name":"mesosphere/marathon","owner":{"login":"mesosphere","id":3458585,"avatar_url":"https://avatars.githubusercontent.com/u/3458585?v=3","gravatar_id":"","url":"https://api.github.com/users/mesosphere","html_url":"https://github.com/mesosphere","followers_url":"https://api.github.com/users/mesosphere/followers","following_url":"https://api.github.com/users/mesosphere/following{/other_user}","gists_url":"https://api.github.com/users/mesosphere/gists{/gist_id}","starred_url":"https://api.github.com/users/mesosphere/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mesosphere/subscriptions","organizations_url":"https://api.github.com/users/mesosphere/orgs","repos_url":"https://api.github.com/users/mesosphere/repos","events_url":"https://api.github.com/users/mesosphere/events{/privacy}","received_events_url":"https://api.github.com/users/mesosphere/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mesosphere/marathon","description":"Deploy and manage containers (including Docker) on top of Apache Mesos at scale.","fork":false,"url":"https://api.github.com/repos/mesosphere/marathon","forks_url":"https://api.github.com/repos/mesosphere/marathon/forks","keys_url":"https://api.github.com/repos/mesosphere/marathon/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mesosphere/marathon/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mesosphere/marathon/teams","hooks_url":"https://api.github.com/repos/mesosphere/marathon/hooks","issue_events_url":"https://api.github.com/repos/mesosphere/marathon/issues/events{/number}","events_url":"https://api.github.com/repos/mesosphere/marathon/events","assignees_url":"https://api.github.com/repos/mesosphere/marathon/assignees{/user}","branches_url":"https://api.github.com/repos/mesosphere/marathon/branches{/branch}","tags_url":"https://api.github.com/repos/mesosphere/marathon/tags","blobs_url":"https://api.github.com/repos/mesosphere/marathon/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mesosphere/marathon/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mesosphere/marathon/git/refs{/sha}","trees_url":"https://api.github.com/repos/mesosphere/marathon/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mesosphere/marathon/statuses/{sha}","languages_url":"https://api.github.com/repos/mesosphere/marathon/languages","stargazers_url":"https://api.github.com/repos/mesosphere/marathon/stargazers","contributors_url":"https://api.github.com/repos/mesosphere/marathon/contributors","subscribers_url":"https://api.github.com/repos/mesosphere/marathon/subscribers","subscription_url":"https://api.github.com/repos/mesosphere/marathon/subscription","commits_url":"https://api.github.com/repos/mesosphere/marathon/commits{/sha}","git_commits_url":"https://api.github.com/repos/mesosphere/marathon/git/commits{/sha}","comments_url":"https://api.github.com/repos/mesosphere/marathon/comments{/number}","issue_comment_url":"https://api.github.com/repos/mesosphere/marathon/issues/comments{/number}","contents_url":"https://api.github.com/repos/mesosphere/marathon/contents/{+path}","compare_url":"https://api.github.com/repos/mesosphere/marathon/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mesosphere/marathon/merges","archive_url":"https://api.github.com/repos/mesosphere/marathon/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mesosphere/marathon/downloads","issues_url":"https://api.github.com/repos/mesosphere/marathon/issues{/number}","pulls_url":"https://api.github.com/repos/mesosphere/marathon/pulls{/number}","milestones_url":"https://api.github.com/repos/mesosphere/marathon/milestones{/number}","notifications_url":"https://api.github.com/repos/mesosphere/marathon/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mesosphere/marathon/labels{/name}","releases_url":"https://api.github.com/repos/mesosphere/marathon/releases{/id}","deployments_url":"https://api.github.com/repos/mesosphere/marathon/deployments","created_at":"2013-06-25T14:56:34Z","updated_at":"2016-08-02T23:25:37Z","pushed_at":"2016-08-03T00:32:43Z","git_url":"git://github.com/mesosphere/marathon.git","ssh_url":"git@github.com:mesosphere/marathon.git","clone_url":"https://github.com/mesosphere/marathon.git","svn_url":"https://github.com/mesosphere/marathon","homepage":"https://mesosphere.github.io/marathon/","size":28435,"stargazers_count":2685,"watchers_count":2685,"language":"Scala","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":597,"mirror_url":null,"open_issues_count":626,"forks":597,"open_issues":626,"watchers":2685,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mesosphere/marathon/pulls/4172"},"html":{"href":"https://github.com/mesosphere/marathon/pull/4172"},"issue":{"href":"https://api.github.com/repos/mesosphere/marathon/issues/4172"},"comments":{"href":"https://api.github.com/repos/mesosphere/marathon/issues/4172/comments"},"review_comments":{"href":"https://api.github.com/repos/mesosphere/marathon/pulls/4172/comments"},"review_comment":{"href":"https://api.github.com/repos/mesosphere/marathon/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mesosphere/marathon/pulls/4172/commits"},"statuses":{"href":"https://api.github.com/repos/mesosphere/marathon/statuses/54d47be0530368e0ed467c4e2983214ce796e614"}}}}
{"actor":{"display_login":"aquamatthias"}}