Skip to content
This repository has been archived by the owner on Oct 23, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3052 from mesosphere/gk/fixes_#3051
Browse files Browse the repository at this point in the history
Fixes #3051 - Improve service ports allocation
  • Loading branch information
aquamatthias committed Jan 21, 2016
2 parents 1f178d0 + f85cc33 commit c0e3753
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ class GroupManager @Singleton @Inject() (
//scalastyle:off method.length
private[state] def assignDynamicServicePorts(from: Group, to: Group): Group = {
val portRange = Range(config.localPortMin(), config.localPortMax())
var taken = to.transitiveApps.flatMap(_.ports)
var taken = from.transitiveApps.flatMap(_.ports) ++ to.transitiveApps.flatMap(_.ports)

def nextGlobalFreePort: JInt = synchronized {
val port = portRange.find(!taken.contains(_))
Expand Down
15 changes: 15 additions & 0 deletions src/test/scala/mesosphere/marathon/state/GroupManagerTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ class GroupManagerTest extends MarathonActorSupport with MockitoSugar with Match
assignedPorts should have size 2
}

test("Assign unique service ports also when adding a dynamic service port to an app") {
val originalGroup = Group(PathId.empty, Set(
AppDefinition("/app1".toPath, ports = Seq(10, 11))
))

val updatedGroup = Group(PathId.empty, Set(
AppDefinition("/app1".toPath, ports = Seq(0, 0, 0))
))
val result = manager(10, 20).assignDynamicServicePorts(originalGroup, updatedGroup)

val assignedPorts: Set[Integer] = result.transitiveApps.flatMap(_.ports)
println(assignedPorts.mkString((",")))
assignedPorts should have size 3
}

test("If there are not enough ports, a PortExhausted exception is thrown") {
val group = Group(PathId.empty, Set(
AppDefinition("/app1".toPath, ports = Seq(0, 0, 0)),
Expand Down

0 comments on commit c0e3753

Please sign in to comment.