YARN-3302. TestDockerContainerExecutor should run automatically if it can detect docker in the usual place (Ravindra Kumar Naik via raviprak)

(cherry picked from commit c97f32e7b9)
This commit is contained in:
Ravi Prakash 2015-05-19 10:28:11 -07:00
parent d39039d54d
commit 084e453629
2 changed files with 24 additions and 6 deletions

View File

@ -372,6 +372,9 @@ Release 2.8.0 - UNRELEASED
YARN-2421. RM still allocates containers to an app in the FINISHING YARN-2421. RM still allocates containers to an app in the FINISHING
state (Chang Li via jlowe) state (Chang Li via jlowe)
YARN-3302. TestDockerContainerExecutor should run automatically if it can
detect docker in the usual place (Ravindra Kumar Naik via raviprak)
Release 2.7.1 - UNRELEASED Release 2.7.1 - UNRELEASED
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -51,10 +51,11 @@ import com.google.common.base.Strings;
* This is intended to test the DockerContainerExecutor code, but it requires * This is intended to test the DockerContainerExecutor code, but it requires
* docker to be installed. * docker to be installed.
* <br><ol> * <br><ol>
* <li>Install docker, and Compile the code with docker-service-url set to the * <li>To run the tests, set the docker-service-url to the host and port where
* host and port where docker service is running. * docker service is running (If docker-service-url is not specified then the
* local daemon will be used).
* <br><pre><code> * <br><pre><code>
* > mvn clean install -Ddocker-service-url=tcp://0.0.0.0:4243 -DskipTests * mvn test -Ddocker-service-url=tcp://0.0.0.0:4243 -Dtest=TestDockerContainerExecutor
* </code></pre> * </code></pre>
*/ */
public class TestDockerContainerExecutor { public class TestDockerContainerExecutor {
@ -98,10 +99,13 @@ public class TestDockerContainerExecutor {
dockerUrl = System.getProperty("docker-service-url"); dockerUrl = System.getProperty("docker-service-url");
LOG.info("dockerUrl: " + dockerUrl); LOG.info("dockerUrl: " + dockerUrl);
if (Strings.isNullOrEmpty(dockerUrl)) { if (!Strings.isNullOrEmpty(dockerUrl)) {
dockerUrl = " -H " + dockerUrl;
} else if(isDockerDaemonRunningLocally()) {
dockerUrl = "";
} else {
return; return;
} }
dockerUrl = " -H " + dockerUrl;
dockerExec = "docker " + dockerUrl; dockerExec = "docker " + dockerUrl;
conf.set( conf.set(
YarnConfiguration.NM_DOCKER_CONTAINER_EXECUTOR_IMAGE_NAME, yarnImage); YarnConfiguration.NM_DOCKER_CONTAINER_EXECUTOR_IMAGE_NAME, yarnImage);
@ -136,6 +140,17 @@ public class TestDockerContainerExecutor {
return exec != null; return exec != null;
} }
private boolean isDockerDaemonRunningLocally() {
boolean dockerDaemonRunningLocally = true;
try {
shellExec("docker info");
} catch (Exception e) {
LOG.info("docker daemon is not running on local machine.");
dockerDaemonRunningLocally = false;
}
return dockerDaemonRunningLocally;
}
/** /**
* Test that a docker container can be launched to run a command * Test that a docker container can be launched to run a command
* @param cId a fake ContainerID * @param cId a fake ContainerID
@ -200,7 +215,7 @@ public class TestDockerContainerExecutor {
* Test that a touch command can be launched successfully in a docker * Test that a touch command can be launched successfully in a docker
* container * container
*/ */
@Test @Test(timeout=1000000)
public void testLaunchContainer() throws IOException { public void testLaunchContainer() throws IOException {
if (!shouldRun()) { if (!shouldRun()) {
LOG.warn("Docker not installed, aborting test."); LOG.warn("Docker not installed, aborting test.");