From a8e7b87e7b91a5ecfcdb96eea0777a6545d8d93d Mon Sep 17 00:00:00 2001 From: Peter Kolloch Date: Mon, 20 Jul 2015 15:58:21 +0200 Subject: [PATCH] Fixes #1829 - Only override acceptedResourceRoles when supplied in update --- .../scala/mesosphere/marathon/api/v2/AppUpdate.scala | 2 +- .../mesosphere/marathon/api/v2/AppUpdateTest.scala | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/scala/mesosphere/marathon/api/v2/AppUpdate.scala b/src/main/scala/mesosphere/marathon/api/v2/AppUpdate.scala index 4619f91d2ed..08d9fd94736 100644 --- a/src/main/scala/mesosphere/marathon/api/v2/AppUpdate.scala +++ b/src/main/scala/mesosphere/marathon/api/v2/AppUpdate.scala @@ -108,7 +108,7 @@ case class AppUpdate( dependencies.map(_.map(_.canonicalPath(app.id))).getOrElse(app.dependencies), upgradeStrategy.getOrElse(app.upgradeStrategy), labels.getOrElse(app.labels), - acceptedResourceRoles, + acceptedResourceRoles.orElse(app.acceptedResourceRoles), version.getOrElse(Timestamp.now()) ) diff --git a/src/test/scala/mesosphere/marathon/api/v2/AppUpdateTest.scala b/src/test/scala/mesosphere/marathon/api/v2/AppUpdateTest.scala index 7761b8c896c..6b06e74b458 100644 --- a/src/test/scala/mesosphere/marathon/api/v2/AppUpdateTest.scala +++ b/src/test/scala/mesosphere/marathon/api/v2/AppUpdateTest.scala @@ -5,7 +5,7 @@ import javax.validation.Validation import mesosphere.marathon.MarathonSpec import mesosphere.marathon.health.HealthCheck import mesosphere.marathon.state.Container._ -import mesosphere.marathon.state.{ Container, PathId, Timestamp, UpgradeStrategy } +import mesosphere.marathon.state.{ AppDefinition, Container, PathId, Timestamp, UpgradeStrategy } import mesosphere.marathon.state.PathId._ import org.apache.mesos.{ Protos => mesos } @@ -140,4 +140,14 @@ class AppUpdateTest extends MarathonSpec { AppUpdate(cmd = Some("foo"), version = Some(Timestamp.now())) } } + + test("acceptedResourceRoles of update is only applied when != None") { + val app = AppDefinition(id = PathId("withAcceptedRoles"), acceptedResourceRoles = Some(Set("a"))) + + val unchanged = AppUpdate().apply(app).copy(version = app.version) + assert(unchanged == app) + + val changed = AppUpdate(acceptedResourceRoles = Some(Set("b"))).apply(app).copy(version = app.version) + assert(changed == app.copy(acceptedResourceRoles = Some(Set("b")))) + } }