Explorar el Código

HADOOP-2833. Do not use "Dr. Who" as the default user in JobClient.
A valid user name is required. (Tsz Wo (Nicholas), SZE via rangadi)


git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@633257 13f79535-47bb-0310-9956-ffa450edef68

Raghu Angadi hace 17 años
padre
commit
4545f7af3f

+ 3 - 0
CHANGES.txt

@@ -40,6 +40,9 @@ Trunk (unreleased changes)
 
 
   IMPROVEMENTS
   IMPROVEMENTS
 
 
+    HADOOP-2833. Do not use "Dr. Who" as the default user in JobClient. 
+    A valid user name is required. (Tsz Wo (Nicholas), SZE via rangadi)
+
     HADOOP-2655. Copy on write for data and metadata files in the 
     HADOOP-2655. Copy on write for data and metadata files in the 
     presence of snapshots. Needed for supporting appends to HDFS
     presence of snapshots. Needed for supporting appends to HDFS
     files. (dhruba) 
     files. (dhruba) 

+ 9 - 1
src/java/org/apache/hadoop/dfs/DFSClient.java

@@ -56,10 +56,11 @@ import javax.security.auth.login.LoginException;
  *
  *
  ********************************************************/
  ********************************************************/
 class DFSClient implements FSConstants {
 class DFSClient implements FSConstants {
-  public static final Log LOG = LogFactory.getLog("org.apache.hadoop.fs.DFSClient");
+  public static final Log LOG = LogFactory.getLog(DFSClient.class);
   static final int MAX_BLOCK_ACQUIRE_FAILURES = 3;
   static final int MAX_BLOCK_ACQUIRE_FAILURES = 3;
   private static final int TCP_WINDOW_SIZE = 128 * 1024; // 128 KB
   private static final int TCP_WINDOW_SIZE = 128 * 1024; // 128 KB
   ClientProtocol namenode;
   ClientProtocol namenode;
+  final UnixUserGroupInformation ugi;
   volatile boolean clientRunning = true;
   volatile boolean clientRunning = true;
   Random r = new Random();
   Random r = new Random();
   String clientName;
   String clientName;
@@ -140,6 +141,13 @@ class DFSClient implements FSConstants {
     this.socketTimeout = conf.getInt("dfs.socket.timeout", 
     this.socketTimeout = conf.getInt("dfs.socket.timeout", 
                                      FSConstants.READ_TIMEOUT);
                                      FSConstants.READ_TIMEOUT);
     this.socketFactory = NetUtils.getSocketFactory(conf, ClientProtocol.class);
     this.socketFactory = NetUtils.getSocketFactory(conf, ClientProtocol.class);
+
+    try {
+      this.ugi = UnixUserGroupInformation.login(conf, true);
+    } catch (LoginException e) {
+      throw (IOException)(new IOException().initCause(e));
+    }
+
     this.namenode = createNamenode(nameNodeAddr, conf);
     this.namenode = createNamenode(nameNodeAddr, conf);
     String taskId = conf.get("mapred.task.id");
     String taskId = conf.get("mapred.task.id");
     if (taskId != null) {
     if (taskId != null) {

+ 5 - 0
src/java/org/apache/hadoop/dfs/DistributedFileSystem.java

@@ -100,6 +100,11 @@ public class DistributedFileSystem extends FileSystem {
     workingDir = makeAbsolute(dir);
     workingDir = makeAbsolute(dir);
   }
   }
 
 
+  /** {@inheritDoc} */
+  public Path getHomeDirectory() {
+    return new Path("/user/" + dfs.ugi.getUserName()).makeQualified(this);
+  }
+
   private String getPathName(Path file) {
   private String getPathName(Path file) {
     checkPath(file);
     checkPath(file);
     String result = makeAbsolute(file).toUri().getPath();
     String result = makeAbsolute(file).toUri().getPath();

+ 5 - 7
src/java/org/apache/hadoop/mapred/JobClient.java

@@ -458,13 +458,12 @@ public class JobClient extends Configured implements MRConstants, Tool  {
      * set this user's id in job configuration, so later job files can be
      * set this user's id in job configuration, so later job files can be
      * accessed using this user's id
      * accessed using this user's id
      */
      */
+    UnixUserGroupInformation ugi = null;
     try {
     try {
-      UnixUserGroupInformation.saveToConf(job,
-          UnixUserGroupInformation.UGI_PROPERTY_NAME, UnixUserGroupInformation
-          .login(job));
+      ugi = UnixUserGroupInformation.login(job, true);
     } catch (LoginException e) {
     } catch (LoginException e) {
-      throw new IOException("Failed to get the current user's information: "
-          + e.getMessage());
+      throw (IOException)(new IOException(
+          "Failed to get the current user's information.").initCause(e));
     }
     }
       
       
     //
     //
@@ -527,8 +526,7 @@ public class JobClient extends Configured implements MRConstants, Tool  {
     }
     }
 
 
     // Set the user's name and working directory
     // Set the user's name and working directory
-    String user = System.getProperty("user.name");
-    job.setUser(user != null ? user : "Dr Who");
+    job.setUser(ugi.getUserName());
     if (job.getWorkingDirectory() == null) {
     if (job.getWorkingDirectory() == null) {
       job.setWorkingDirectory(fs.getWorkingDirectory());          
       job.setWorkingDirectory(fs.getWorkingDirectory());          
     }
     }

+ 13 - 3
src/java/org/apache/hadoop/security/UnixUserGroupInformation.java

@@ -251,6 +251,12 @@ public class UnixUserGroupInformation extends UserGroupInformation {
     }
     }
   }
   }
 
 
+  /** Equivalent to login(conf, false). */
+  public static UnixUserGroupInformation login(Configuration conf)
+    throws LoginException {
+    return login(conf, false);
+  }
+  
   /** Get a user's name & its group names from the given configuration; 
   /** Get a user's name & its group names from the given configuration; 
    * If it is not defined in the configuration, get the current user's
    * If it is not defined in the configuration, get the current user's
    * information from Unix.
    * information from Unix.
@@ -258,16 +264,20 @@ public class UnixUserGroupInformation extends UserGroupInformation {
    * the UGI map.
    * the UGI map.
    * 
    * 
    *  @param conf either a job configuration or client's configuration
    *  @param conf either a job configuration or client's configuration
+   *  @param save saving it to conf?
    *  @return UnixUserGroupInformation a user/group information
    *  @return UnixUserGroupInformation a user/group information
    *  @exception LoginException if not able to get the user/group information
    *  @exception LoginException if not able to get the user/group information
    */
    */
-  public static UnixUserGroupInformation login(Configuration conf) 
-   throws LoginException {
+  public static UnixUserGroupInformation login(Configuration conf, boolean save
+      ) throws LoginException {
     UnixUserGroupInformation ugi = readFromConf(conf, UGI_PROPERTY_NAME);
     UnixUserGroupInformation ugi = readFromConf(conf, UGI_PROPERTY_NAME);
     if (ugi == null) {
     if (ugi == null) {
       ugi = login();
       ugi = login();
       LOG.debug("Unix Login: " + ugi);
       LOG.debug("Unix Login: " + ugi);
-    } 
+      if (save) {
+        saveToConf(conf, UGI_PROPERTY_NAME, ugi);
+      }
+    }
     return ugi;
     return ugi;
   }
   }