This repository has been archived by the owner on Oct 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migration to fix unreachable strategy for resident apps.
Summary: fixes #5209 forward port 809b9f9 Also-By: tharper@mesosphere.com Test Plan: with older version of marathon, create resident app. Upgrade. Check that resident app unreachable strategy is disabled. Modify app and see if there are validation issues Reviewers: jasongilanfarr, aquamatthias, jenkins Reviewed By: jasongilanfarr, aquamatthias, jenkins Subscribers: marathon-team Differential Revision: https://phabricator.mesosphere.com/D557
- Loading branch information
1 parent
efdb865
commit 9451cf8
Showing
5 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/scala/mesosphere/marathon/storage/migration/legacy/MigrationTo_1_4_2.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package mesosphere.marathon | ||
package storage.migration.legacy | ||
|
||
import akka.Done | ||
import akka.stream.Materializer | ||
import akka.stream.scaladsl.{ Flow, Keep, Sink } | ||
import com.typesafe.scalalogging.StrictLogging | ||
import mesosphere.marathon.state._ | ||
import mesosphere.marathon.storage.repository.AppRepository | ||
|
||
import scala.concurrent.{ ExecutionContext, Future } | ||
|
||
@SuppressWarnings(Array("ClassNames")) | ||
class MigrationTo_1_4_2(appRepository: AppRepository)(implicit | ||
ctx: ExecutionContext, | ||
mat: Materializer) extends StrictLogging { | ||
|
||
import MigrationTo_1_4_2.migrationFlow | ||
val sink = | ||
Flow[AppDefinition] | ||
.mapAsync(Int.MaxValue)(appRepository.store) | ||
.toMat(Sink.ignore)(Keep.right) | ||
|
||
def migrate(): Future[Done] = { | ||
logger.info("Starting migration to 1.4.2") | ||
|
||
appRepository.all() | ||
.via(migrationFlow) | ||
.runWith(sink) | ||
.andThen { | ||
case _ => | ||
logger.info("Finished 1.4.2 migration") | ||
} | ||
} | ||
} | ||
|
||
object MigrationTo_1_4_2 extends StrictLogging { | ||
private def fixResidentApp(app: AppDefinition): AppDefinition = { | ||
if (app.isResident) | ||
app.copy(unreachableStrategy = UnreachableDisabled) | ||
else | ||
app | ||
} | ||
|
||
val migrationFlow = | ||
Flow[AppDefinition] | ||
.filter(_.isResident) | ||
.map { app => | ||
logger.info(s"Disable Unreachable strategy for resident app: ${app.id}") | ||
fixResidentApp(app) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/test/scala/mesosphere/marathon/storage/migration/legacy/MigrationTo_1_4_2Test.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package mesosphere.marathon | ||
package storage.migration.legacy | ||
|
||
import akka.stream.scaladsl.Source | ||
import mesosphere.AkkaUnitTest | ||
import mesosphere.marathon.Protos.ResidencyDefinition.TaskLostBehavior | ||
import mesosphere.marathon.state.{ AppDefinition, PathId, Residency, UnreachableDisabled, UnreachableStrategy } | ||
import mesosphere.marathon.stream.Sink | ||
import mesosphere.marathon.test.GroupCreation | ||
|
||
class MigrationTo_1_4_2Test extends AkkaUnitTest with GroupCreation { | ||
import MigrationTo_1_4_2.migrationFlow | ||
|
||
"Migration to 1.4.2" should { | ||
"do nothing if there are no resident apps" in { | ||
val result = Source.single(AppDefinition(id = PathId("abc"))) | ||
.via(migrationFlow) | ||
.runWith(Sink.seq) | ||
.futureValue | ||
|
||
result.shouldBe(Nil) | ||
} | ||
|
||
"fix wrong UnreachableStrategy for resident apps" in { | ||
val badApp = AppDefinition( | ||
id = PathId("/badApp"), | ||
residency = Some(Residency(23L, TaskLostBehavior.WAIT_FOREVER)), | ||
unreachableStrategy = UnreachableStrategy.default(resident = false)) | ||
val goodApp = AppDefinition(id = PathId("/goodApp")) | ||
val fixedApp = badApp.copy(unreachableStrategy = UnreachableDisabled) | ||
|
||
val result = Source(Seq(badApp, goodApp)) | ||
.via(migrationFlow) | ||
.runWith(Sink.seq) | ||
.futureValue | ||
|
||
result shouldBe (Seq(fixedApp)) | ||
} | ||
} | ||
} |