YARN-7667. Docker Stop grace period should be configurable. Contributed by Eric Badger

This commit is contained in:
Jason Lowe 2018-04-09 17:19:21 -05:00
parent 9059376785
commit 907919d28c
4 changed files with 40 additions and 4 deletions

View File

@ -1951,6 +1951,20 @@ public class YarnConfiguration extends Configuration {
*/
public static final boolean DEFAULT_NM_DOCKER_ALLOW_DELAYED_REMOVAL = false;
/**
* A configurable value to pass to the Docker Stop command. This value
* defines the number of seconds between the docker stop command sending
* a SIGTERM and a SIGKILL.
*/
public static final String NM_DOCKER_STOP_GRACE_PERIOD =
DOCKER_CONTAINER_RUNTIME_PREFIX + "stop.grace-period";
/**
* The default value for the grace period between the SIGTERM and the
* SIGKILL in the Docker Stop command.
*/
public static final int DEFAULT_NM_DOCKER_STOP_GRACE_PERIOD = 10;
/** The mode in which the Java Container Sandbox should run detailed by
* the JavaSandboxLinuxContainerRuntime. */
public static final String YARN_CONTAINER_SANDBOX =

View File

@ -1786,6 +1786,14 @@
<value>false</value>
</property>
<property>
<description>A configurable value to pass to the Docker Stop command. This value
defines the number of seconds between the docker stop command sending
a SIGTERM and a SIGKILL.</description>
<name>yarn.nodemanager.runtime.linux.docker.stop.grace-period</name>
<value>10</value>
</property>
<property>
<description>The mode in which the Java Container Sandbox should run detailed by
the JavaSandboxLinuxContainerRuntime.</description>

View File

@ -245,6 +245,7 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
private int userRemappingGidThreshold;
private Set<String> capabilities;
private boolean delayedRemovalAllowed;
private int dockerStopGracePeriod;
/**
* Return whether the given environment variables indicate that the operation
@ -348,6 +349,10 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
delayedRemovalAllowed = conf.getBoolean(
YarnConfiguration.NM_DOCKER_ALLOW_DELAYED_REMOVAL,
YarnConfiguration.DEFAULT_NM_DOCKER_ALLOW_DELAYED_REMOVAL);
dockerStopGracePeriod = conf.getInt(
YarnConfiguration.NM_DOCKER_STOP_GRACE_PERIOD,
YarnConfiguration.DEFAULT_NM_DOCKER_STOP_GRACE_PERIOD);
}
private Set<String> getDockerCapabilitiesFromConf() throws
@ -1138,7 +1143,8 @@ public class DockerLinuxContainerRuntime implements LinuxContainerRuntime {
DockerCommandExecutor.getContainerStatus(containerId, conf,
privilegedOperationExecutor);
if (DockerCommandExecutor.isStoppable(containerStatus)) {
DockerStopCommand dockerStopCommand = new DockerStopCommand(containerId);
DockerStopCommand dockerStopCommand = new DockerStopCommand(
containerId).setGracePeriod(dockerStopGracePeriod);
DockerCommandExecutor.executeDockerCommand(dockerStopCommand, containerId,
env, conf, privilegedOperationExecutor, false);
} else {

View File

@ -146,6 +146,7 @@ public class TestDockerContainerRuntime {
private final String whitelistedUser = "yoda";
private String[] testCapabilities;
private final String signalPid = "1234";
private int dockerStopGracePeriod;
@Before
public void setup() {
@ -166,6 +167,10 @@ public class TestDockerContainerRuntime {
env.put("FROM_CLIENT", "1");
image = "busybox:latest";
dockerStopGracePeriod = conf.getInt(
YarnConfiguration.NM_DOCKER_STOP_GRACE_PERIOD,
YarnConfiguration.DEFAULT_NM_DOCKER_STOP_GRACE_PERIOD);
env.put(DockerLinuxContainerRuntime.ENV_DOCKER_CONTAINER_IMAGE, image);
when(container.getContainerId()).thenReturn(cId);
when(cId.toString()).thenReturn(containerId);
@ -1308,10 +1313,11 @@ public class TestDockerContainerRuntime {
List<String> dockerCommands = getDockerCommandsForSignal(
ContainerExecutor.Signal.TERM,
DockerCommandExecutor.DockerContainerStatus.RUNNING);
Assert.assertEquals(3, dockerCommands.size());
Assert.assertEquals(4, dockerCommands.size());
Assert.assertEquals("[docker-command-execution]", dockerCommands.get(0));
Assert.assertEquals(" docker-command=stop", dockerCommands.get(1));
Assert.assertEquals(" name=container_id", dockerCommands.get(2));
Assert.assertEquals(" time=10", dockerCommands.get(3));
}
@Test
@ -1321,10 +1327,11 @@ public class TestDockerContainerRuntime {
List<String> dockerCommands = getDockerCommandsForSignal(
ContainerExecutor.Signal.KILL,
DockerCommandExecutor.DockerContainerStatus.RUNNING);
Assert.assertEquals(3, dockerCommands.size());
Assert.assertEquals(4, dockerCommands.size());
Assert.assertEquals("[docker-command-execution]", dockerCommands.get(0));
Assert.assertEquals(" docker-command=stop", dockerCommands.get(1));
Assert.assertEquals(" name=container_id", dockerCommands.get(2));
Assert.assertEquals(" time=10", dockerCommands.get(3));
}
@Test
@ -1884,7 +1891,8 @@ public class TestDockerContainerRuntime {
|| ContainerExecutor.Signal.TERM.equals(signal)) {
if (DockerCommandExecutor.isStoppable(containerStatus)) {
DockerStopCommand dockerStopCommand =
new DockerStopCommand(containerName);
new DockerStopCommand(containerName)
.setGracePeriod(dockerStopGracePeriod);
DockerCommandExecutor.executeDockerCommand(dockerStopCommand,
containerName, environment, conf, mockExecutor, false);
}