hadoop-mapreduce-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From vino...@apache.org
Subject svn commit: r1189815 - in /hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src: main/java/org/apache/hadoop/yarn/server/nodemanager/util/ test/java/org/apache/hadoop/yarn/server/...
Date Thu, 27 Oct 2011 15:52:43 GMT
Author: vinodkv
Date: Thu Oct 27 15:52:43 2011
New Revision: 1189815

URL: http://svn.apache.org/viewvc?rev=1189815&view=rev
Log:
MAPREDUCE-3240. Fixed NodeManager to be able to forcefully cleanup its containers (process-trees)
irrespective of whether the container succeeded, or killed. Contributed by Hitesh Shah.
Added the new files which I missed earlier.

Added:
    hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/util/
    hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/util/ProcessIdFileReader.java
    hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/
    hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestProcessIdFileReader.java

Added: hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/util/ProcessIdFileReader.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/util/ProcessIdFileReader.java?rev=1189815&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/util/ProcessIdFileReader.java
(added)
+++ hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/main/java/org/apache/hadoop/yarn/server/nodemanager/util/ProcessIdFileReader.java
Thu Oct 27 15:52:43 2011
@@ -0,0 +1,74 @@
+package org.apache.hadoop.yarn.server.nodemanager.util;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.fs.Path;
+
+/**
+ * Helper functionality to read the pid from a file.
+ */
+public class ProcessIdFileReader {
+
+  private static final Log LOG = LogFactory.getLog(ProcessIdFileReader.class);
+  
+  /**
+   * Get the process id from specified file path.
+   * Parses each line to find a valid number
+   * and returns the first one found.
+   * @return Process Id if obtained from path specified else null
+   * @throws IOException
+   */
+  public static String getProcessId(Path path) throws IOException {
+    if (path == null) {
+      throw new IOException("Trying to access process id from a null path");
+    }
+    
+    LOG.debug("Accessing pid from pid file " + path);
+    String processId = null;
+    FileReader fileReader = null;
+    BufferedReader bufReader = null;
+
+    try {
+      File file = new File(path.toString());
+      if (file.exists()) {
+        fileReader = new FileReader(file);
+        bufReader = new BufferedReader(fileReader);
+        while (true) {
+          String line = bufReader.readLine();
+          if (line == null) {
+            break;
+          }
+          String temp = line.trim(); 
+          if (!temp.isEmpty()) {
+            try {
+              Long pid = Long.valueOf(temp);
+              if (pid > 0) {
+                processId = temp;
+                break;
+              }
+            } catch (Exception e) {
+              // do nothing
+            }
+          }
+        }
+      }
+    } finally {
+      if (fileReader != null) {
+        fileReader.close();
+      }
+      if (bufReader != null) {
+        bufReader.close();
+      }
+    }
+    LOG.debug("Got pid " 
+        + (processId != null? processId : "null")  
+        + " from path " + path);
+    return processId;
+  }
+
+}

Added: hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestProcessIdFileReader.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestProcessIdFileReader.java?rev=1189815&view=auto
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestProcessIdFileReader.java
(added)
+++ hadoop/common/branches/branch-0.23/hadoop-mapreduce-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-nodemanager/src/test/java/org/apache/hadoop/yarn/server/nodemanager/util/TestProcessIdFileReader.java
Thu Oct 27 15:52:43 2011
@@ -0,0 +1,86 @@
+package org.apache.hadoop.yarn.server.nodemanager.util;
+
+import static org.junit.Assert.*;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.PrintWriter;
+
+import junit.framework.Assert;
+
+import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.yarn.server.nodemanager.util.ProcessIdFileReader;
+import org.junit.Test;
+
+public class TestProcessIdFileReader {
+
+  
+  @Test
+  public void testNullPath() {
+    String pid = null;
+    try {
+      pid = ProcessIdFileReader.getProcessId(null);
+      fail("Expected an error to be thrown for null path");
+    } catch (Exception e) {
+      // expected
+    }
+    assert(pid == null);
+  }
+  
+  @Test 
+  public void testSimpleGet() throws IOException {
+    String rootDir = new File(System.getProperty(
+        "test.build.data", "/tmp")).getAbsolutePath();
+    File testFile = null;
+    
+    try {
+      testFile = new File(rootDir, "temp.txt");
+      PrintWriter fileWriter = new PrintWriter(testFile);
+      fileWriter.println("56789");
+      fileWriter.close();      
+      String processId = null; 
+                  
+      processId = ProcessIdFileReader.getProcessId(
+          new Path(rootDir + Path.SEPARATOR + "temp.txt"));
+      Assert.assertEquals("56789", processId);      
+      
+    } finally {
+      if (testFile != null
+          && testFile.exists()) {
+        testFile.delete();
+      }
+    }
+  }
+
+    
+  @Test
+  public void testComplexGet() throws IOException {
+    String rootDir = new File(System.getProperty(
+        "test.build.data", "/tmp")).getAbsolutePath();
+    File testFile = null;
+    
+    try {
+      testFile = new File(rootDir, "temp.txt");
+      PrintWriter fileWriter = new PrintWriter(testFile);
+      fileWriter.println("   ");
+      fileWriter.println("");
+      fileWriter.println("abc");
+      fileWriter.println("-123");
+      fileWriter.println("-123 ");
+      fileWriter.println(" 23 ");
+      fileWriter.println("6236");
+      fileWriter.close();      
+      String processId = null; 
+                  
+      processId = ProcessIdFileReader.getProcessId(
+          new Path(rootDir + Path.SEPARATOR + "temp.txt"));
+      Assert.assertEquals("23", processId);      
+      
+    } finally {
+      if (testFile != null
+          && testFile.exists()) {
+        testFile.delete();
+      }
+    }
+  }
+}



Mime
View raw message