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

Commit

Permalink
Back port of Pass killGracePeriodSeconds value to Mesos for pods (#5823)
Browse files Browse the repository at this point in the history
Backport Of: c80cd98

JIRA Issues: MARATHON-7962
  • Loading branch information
timcharper authored Dec 14, 2017
1 parent d419a6e commit c0eb0e3
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/main/scala/mesosphere/mesos/TaskGroupBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ import mesosphere.marathon.raml.Endpoint
import mesosphere.marathon.state.{ EnvVarString, PathId, PortAssignment, Timestamp }
import mesosphere.marathon.stream._
import mesosphere.marathon.tasks.PortsMatch
import org.apache.mesos.Protos.{ DurationInfo, KillPolicy }
import org.apache.mesos.{ Protos => mesos }

import java.util.concurrent.TimeUnit.SECONDS
import scala.collection.immutable.Seq

object TaskGroupBuilder extends StrictLogging {
Expand Down Expand Up @@ -156,6 +158,15 @@ object TaskGroupBuilder extends StrictLogging {
builder.setHealthCheck(computeHealthCheck(healthCheck, portAssignments))
}

for {
lc <- container.lifecycle
killGracePeriodSeconds <- lc.killGracePeriodSeconds
} {
val durationInfo = DurationInfo.newBuilder.setNanoseconds((killGracePeriodSeconds * SECONDS.toNanos(1)).toLong)
builder.setKillPolicy(
KillPolicy.newBuilder.setGracePeriod(durationInfo))
}

builder
}

Expand Down
38 changes: 33 additions & 5 deletions src/test/scala/mesosphere/mesos/TaskGroupBuilderTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,25 @@ import mesosphere.marathon.core.pod._
import mesosphere.marathon.core.task.Task
import mesosphere.marathon.plugin.task.RunSpecTaskProcessor
import mesosphere.marathon.plugin.{ ApplicationSpec, PodSpec }
import mesosphere.marathon.raml
import mesosphere.marathon.raml.Resources
import mesosphere.marathon.{ AllConf, raml }
import mesosphere.marathon.raml.{ Lifecycle, Resources }
import mesosphere.marathon.state.PathId._
import mesosphere.marathon.state.{ Command, EnvVarString, ResourceRole }
import mesosphere.marathon.state._
import mesosphere.marathon.stream._
import mesosphere.marathon.test.MarathonTestHelper
import mesosphere.marathon.test.{ MarathonTestHelper, SettableClock }
import org.apache.mesos.Protos.{ ExecutorInfo, TaskGroupInfo, TaskInfo }
import org.apache.mesos.{ Protos => mesos }
import org.scalatest.Inside

import scala.collection.immutable.Seq
import scala.collection.breakOut
import scala.concurrent.duration._

class TaskGroupBuilderTest extends UnitTest with Inside {

implicit val clock = new SettableClock()
val config = AllConf.withTestConfig()

class TaskGroupBuilderTest extends UnitTest {
val defaultBuilderConfig = TaskGroupBuilder.BuilderConfig(
acceptedResourceRoles = Set(ResourceRole.Unreserved),
envVarsPrefix = None)
Expand Down Expand Up @@ -887,5 +893,27 @@ class TaskGroupBuilderTest extends UnitTest {
taskGroupInfo.getTasksCount should be(1)
taskGroupInfo.getTasks(0).getName should be(s"${container.name}-extended")
}

"killPolicy is specified correctly" in {
val killDuration = 3.seconds
val offer = MarathonTestHelper.makeBasicOffer(cpus = 3.1, mem = 416.0, disk = 10.0, beginPort = 8000, endPort = 9000).build
val container = MesosContainer(
name = "withTTY",
resources = Resources(),
lifecycle = Some(Lifecycle(Some(killDuration.toSeconds.toDouble))))

val podSpec = PodDefinition(id = PathId("/tty"), containers = Seq(container))
val resourceMatch = RunSpecOfferMatcher.matchOffer(podSpec, offer, Seq.empty, defaultBuilderConfig.acceptedResourceRoles)
val (_, taskGroupInfo, _, _) = TaskGroupBuilder.build(
podSpec,
offer,
s => Instance.Id.forRunSpec(s),
defaultBuilderConfig,
RunSpecTaskProcessor.empty,
resourceMatch.asInstanceOf[ResourceMatchResponse.Match].resourceMatch
)

taskGroupInfo.getTasks(0).getKillPolicy.getGracePeriod.getNanoseconds shouldBe (killDuration.toNanos)
}
}
}

0 comments on commit c0eb0e3

Please sign in to comment.