You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mapreduce-commits@hadoop.apache.org by ac...@apache.org on 2011/09/27 08:56:50 UTC

svn commit: r1176235 - in /hadoop/common/trunk/hadoop-mapreduce-project: ./ hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/ hadoop-yarn/hadoop-yarn-server...

Author: acmurthy
Date: Tue Sep 27 06:56:50 2011
New Revision: 1176235

URL: http://svn.apache.org/viewvc?rev=1176235&view=rev
Log:
MAPREDUCE-3067. Ensure exit-code is set correctly for containers. Contributed by Hitesh Shah.

Modified:
    hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt
    hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/ContainerImpl.java
    hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerManagerWithLCE.java
    hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManager.java

Modified: hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt?rev=1176235&r1=1176234&r2=1176235&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt (original)
+++ hadoop/common/trunk/hadoop-mapreduce-project/CHANGES.txt Tue Sep 27 06:56:50 2011
@@ -1438,6 +1438,9 @@ Release 0.23.0 - Unreleased
     MAPREDUCE-3071. app master configuration web UI link under the Job menu 
     opens up application menu. (thomas graves  via mahadev)
 
+    MAPREDUCE-3067. Ensure exit-code is set correctly for containers. (Hitesh
+    Shah via acmurthy)
+
 Release 0.22.0 - Unreleased
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/ContainerImpl.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/ContainerImpl.java?rev=1176235&r1=1176234&r2=1176235&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/ContainerImpl.java (original)
+++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/container/ContainerImpl.java Tue Sep 27 06:56:50 2011
@@ -567,6 +567,9 @@ public class ContainerImpl implements Co
 
     @Override
     public void transition(ContainerImpl container, ContainerEvent event) {
+      // Set exit code to 0 on success    	
+      container.exitCode = 0;
+    	
       // TODO: Add containerWorkDir to the deletion service.
 
       if (clCleanupRequired) {

Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerManagerWithLCE.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerManagerWithLCE.java?rev=1176235&r1=1176234&r2=1176235&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerManagerWithLCE.java (original)
+++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/TestContainerManagerWithLCE.java Tue Sep 27 06:56:50 2011
@@ -105,8 +105,32 @@ public class TestContainerManagerWithLCE
     LOG.info("Running testContainerLaunchAndStop");
     super.testContainerLaunchAndStop();
   }
+  
+  @Override
+  public void testContainerLaunchAndExitSuccess() throws IOException,
+      InterruptedException {
+    // Don't run the test if the binary is not available.
+    if (!shouldRunTest()) {
+      LOG.info("LCE binary path is not passed. Not running the test");
+      return;
+    }
+    LOG.info("Running testContainerLaunchAndExitSuccess");
+    super.testContainerLaunchAndExitSuccess();
+  }
 
   @Override
+  public void testContainerLaunchAndExitFailure() throws IOException,
+      InterruptedException {
+    // Don't run the test if the binary is not available.
+    if (!shouldRunTest()) {
+      LOG.info("LCE binary path is not passed. Not running the test");
+      return;
+    }
+    LOG.info("Running testContainerLaunchAndExitFailure");
+    super.testContainerLaunchAndExitFailure();
+  }
+  
+  @Override
   public void testLocalFilesCleanup() throws InterruptedException,
       IOException {
     // Don't run the test if the binary is not available.

Modified: hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManager.java
URL: http://svn.apache.org/viewvc/hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManager.java?rev=1176235&r1=1176234&r2=1176235&view=diff
==============================================================================
--- hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManager.java (original)
+++ hadoop/common/trunk/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/containermanager/TestContainerManager.java Tue Sep 27 06:56:50 2011
@@ -287,7 +287,95 @@ public class TestContainerManager extend
         exec.signalContainer(user,
             pid, Signal.NULL));
   }
+  
+  private void testContainerLaunchAndExit(int exitCode) throws IOException, InterruptedException {
 
+	  File scriptFile = new File(tmpDir, "scriptFile.sh");
+	  PrintWriter fileWriter = new PrintWriter(scriptFile);
+	  File processStartFile =
+			  new File(tmpDir, "start_file.txt").getAbsoluteFile();
+	  fileWriter.write("\numask 0"); // So that start file is readable by the test
+	  fileWriter.write("\necho Hello World! > " + processStartFile);
+	  fileWriter.write("\necho $$ >> " + processStartFile); 
+
+	  // Have script throw an exit code at the end
+	  if (exitCode != 0) {
+		  fileWriter.write("\nexit "+exitCode);
+	  }
+	  
+	  fileWriter.close();
+
+	  ContainerLaunchContext containerLaunchContext = 
+			  recordFactory.newRecordInstance(ContainerLaunchContext.class);
+
+	  // ////// Construct the Container-id
+	  ContainerId cId = createContainerId();
+	  containerLaunchContext.setContainerId(cId);
+
+	  containerLaunchContext.setUser(user);
+
+	  URL resource_alpha =
+			  ConverterUtils.getYarnUrlFromPath(localFS
+					  .makeQualified(new Path(scriptFile.getAbsolutePath())));
+	  LocalResource rsrc_alpha =
+			  recordFactory.newRecordInstance(LocalResource.class);
+	  rsrc_alpha.setResource(resource_alpha);
+	  rsrc_alpha.setSize(-1);
+	  rsrc_alpha.setVisibility(LocalResourceVisibility.APPLICATION);
+	  rsrc_alpha.setType(LocalResourceType.FILE);
+	  rsrc_alpha.setTimestamp(scriptFile.lastModified());
+	  String destinationFile = "dest_file";
+	  Map<String, LocalResource> localResources = 
+			  new HashMap<String, LocalResource>();
+	  localResources.put(destinationFile, rsrc_alpha);
+	  containerLaunchContext.setLocalResources(localResources);
+	  containerLaunchContext.setUser(containerLaunchContext.getUser());
+	  List<String> commands = new ArrayList<String>();
+	  commands.add("/bin/bash");
+	  commands.add(scriptFile.getAbsolutePath());
+	  containerLaunchContext.setCommands(commands);
+	  containerLaunchContext.setResource(recordFactory
+			  .newRecordInstance(Resource.class));
+	  containerLaunchContext.getResource().setMemory(100 * 1024 * 1024);
+
+	  StartContainerRequest startRequest = recordFactory.newRecordInstance(StartContainerRequest.class);
+	  startRequest.setContainerLaunchContext(containerLaunchContext);
+	  containerManager.startContainer(startRequest);
+
+	  BaseContainerManagerTest.waitForContainerState(containerManager, cId,
+			  ContainerState.COMPLETE);
+
+	  GetContainerStatusRequest gcsRequest = 
+			  recordFactory.newRecordInstance(GetContainerStatusRequest.class);
+	  gcsRequest.setContainerId(cId);
+	  ContainerStatus containerStatus = 
+			  containerManager.getContainerStatus(gcsRequest).getStatus();
+
+	  // Verify exit status matches exit state of script
+	  Assert.assertEquals(exitCode,
+			  containerStatus.getExitStatus());	    
+  }
+  
+  @Test
+  public void testContainerLaunchAndExitSuccess() throws IOException, InterruptedException {
+	  containerManager.start();
+	  int exitCode = 0; 
+
+	  // launch context for a command that will return exit code 0 
+	  // and verify exit code returned 
+	  testContainerLaunchAndExit(exitCode);	  
+  }
+
+  @Test
+  public void testContainerLaunchAndExitFailure() throws IOException, InterruptedException {
+	  containerManager.start();
+	  int exitCode = 50; 
+
+	  // launch context for a command that will return exit code 0 
+	  // and verify exit code returned 
+	  testContainerLaunchAndExit(exitCode);	  
+  }
+  
   @Test
   public void testLocalFilesCleanup() throws InterruptedException,
       IOException {