From 084e453629865ced18ec72721d67291623ed21d3 Mon Sep 17 00:00:00 2001 From: Ravi Prakash Date: Tue, 19 May 2015 10:28:11 -0700 Subject: [PATCH] YARN-3302. TestDockerContainerExecutor should run automatically if it can detect docker in the usual place (Ravindra Kumar Naik via raviprak) (cherry picked from commit c97f32e7b9d9e1d4c80682cc01741579166174d1) --- hadoop-yarn-project/CHANGES.txt | 3 +++ .../TestDockerContainerExecutor.java | 27 ++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/hadoop-yarn-project/CHANGES.txt b/hadoop-yarn-project/CHANGES.txt index eb5c18342b2..c97df938c81 100644 --- a/hadoop-yarn-project/CHANGES.txt +++ b/hadoop-yarn-project/CHANGES.txt @@ -372,6 +372,9 @@ Release 2.8.0 - UNRELEASED YARN-2421. RM still allocates containers to an app in the FINISHING 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 INCOMPATIBLE CHANGES diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDockerContainerExecutor.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDockerContainerExecutor.java index 65e381c5265..93868971b24 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDockerContainerExecutor.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestDockerContainerExecutor.java @@ -51,10 +51,11 @@ * This is intended to test the DockerContainerExecutor code, but it requires * docker to be installed. *
    - *
  1. Install docker, and Compile the code with docker-service-url set to the - * host and port where docker service is running. + *
  2. To run the tests, set the docker-service-url to the host and port where + * docker service is running (If docker-service-url is not specified then the + * local daemon will be used). *
    
    - * > 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
      * 
    */ public class TestDockerContainerExecutor { @@ -98,10 +99,13 @@ public void setup() { dockerUrl = System.getProperty("docker-service-url"); LOG.info("dockerUrl: " + dockerUrl); - if (Strings.isNullOrEmpty(dockerUrl)) { + if (!Strings.isNullOrEmpty(dockerUrl)) { + dockerUrl = " -H " + dockerUrl; + } else if(isDockerDaemonRunningLocally()) { + dockerUrl = ""; + } else { return; } - dockerUrl = " -H " + dockerUrl; dockerExec = "docker " + dockerUrl; conf.set( YarnConfiguration.NM_DOCKER_CONTAINER_EXECUTOR_IMAGE_NAME, yarnImage); @@ -136,6 +140,17 @@ private boolean shouldRun() { 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 * @param cId a fake ContainerID @@ -200,7 +215,7 @@ public void tearDown() { * Test that a touch command can be launched successfully in a docker * container */ - @Test + @Test(timeout=1000000) public void testLaunchContainer() throws IOException { if (!shouldRun()) { LOG.warn("Docker not installed, aborting test.");