diff --git a/src/main/scala/mesosphere/marathon/core/instance/update/InstanceUpdateOpResolver.scala b/src/main/scala/mesosphere/marathon/core/instance/update/InstanceUpdateOpResolver.scala index c3c34b615da..e14053d5016 100644 --- a/src/main/scala/mesosphere/marathon/core/instance/update/InstanceUpdateOpResolver.scala +++ b/src/main/scala/mesosphere/marathon/core/instance/update/InstanceUpdateOpResolver.scala @@ -46,13 +46,20 @@ private[marathon] class InstanceUpdateOpResolver( createInstance(op.instanceId)(updater.reserve(op, clock.now())) case op: ForceExpunge => - updateExistingInstance(op.instanceId)(updater.forceExpunge(_, clock.now())) + updateExistingInstance(op.instanceId)( + applyOperation = updater.forceExpunge(_, clock.now() ), + ifNotExist = InstanceUpdateEffect.Noop(_)) case op: Revert => Future.successful(updater.revert(op.instance)) } } + private[this] def failIfNotExist(id: Instance.Id): InstanceUpdateEffect = { + InstanceUpdateEffect.Failure( + new IllegalStateException(s"$id of app [${id.runSpecId}] does not exist")) + } + /** * Helper method that verifies that an instance already exists. If it does, it will apply the given function and * return the resulting effect; otherwise this will result in a. [[InstanceUpdateEffect.Failure]]. @@ -60,14 +67,15 @@ private[marathon] class InstanceUpdateOpResolver( * @param applyOperation the operation that shall be applied to the instance * @return The [[InstanceUpdateEffect]] that results from applying the given operation. */ - private[this] def updateExistingInstance(id: Instance.Id)(applyOperation: Instance => InstanceUpdateEffect)(implicit ec: ExecutionContext): Future[InstanceUpdateEffect] = { + private[this] def updateExistingInstance(id: Instance.Id)( + applyOperation: Instance => InstanceUpdateEffect, + ifNotExist: Instance.Id => InstanceUpdateEffect = failIfNotExist(_))(implicit ec: ExecutionContext): Future[InstanceUpdateEffect] = { directInstanceTracker.instance(id).map { case Some(existingInstance) => applyOperation(existingInstance) case None => - InstanceUpdateEffect.Failure( - new IllegalStateException(s"$id of app [${id.runSpecId}] does not exist")) + ifNotExist(id) } } diff --git a/src/test/scala/mesosphere/marathon/core/instance/update/InstanceUpdateOpResolverTest.scala b/src/test/scala/mesosphere/marathon/core/instance/update/InstanceUpdateOpResolverTest.scala index 9b3fde14664..293ab95f290 100644 --- a/src/test/scala/mesosphere/marathon/core/instance/update/InstanceUpdateOpResolverTest.scala +++ b/src/test/scala/mesosphere/marathon/core/instance/update/InstanceUpdateOpResolverTest.scala @@ -32,8 +32,8 @@ class InstanceUpdateOpResolverTest extends UnitTest { When("call taskTracker.task") verify(instanceTracker).instance(notExistingInstanceId) - Then("result in a Failure") - stateChange shouldBe a[InstanceUpdateEffect.Failure] + Then("result in a Noop") + stateChange shouldBe a[InstanceUpdateEffect.Noop] verifyNoMoreInteractions() }