hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s..@apache.org
Subject svn commit: r627927 - in /hadoop/core/trunk: ./ src/java/org/apache/hadoop/dfs/ src/java/org/apache/hadoop/ipc/ src/java/org/apache/hadoop/security/ src/test/org/apache/hadoop/dfs/ src/test/org/apache/hadoop/security/
Date Fri, 15 Feb 2008 01:49:00 GMT
Author: shv
Date: Thu Feb 14 17:48:42 2008
New Revision: 627927

URL: http://svn.apache.org/viewvc?rev=627927&view=rev
Log:
HADOOP-2683. Moving UGI out of the RPC Server. Contributed by Tsz Wo (Nicholas), SZE.

Modified:
    hadoop/core/trunk/CHANGES.txt
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
    hadoop/core/trunk/src/java/org/apache/hadoop/dfs/PermissionChecker.java
    hadoop/core/trunk/src/java/org/apache/hadoop/ipc/Server.java
    hadoop/core/trunk/src/java/org/apache/hadoop/security/UnixUserGroupInformation.java
    hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java
    hadoop/core/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java
    hadoop/core/trunk/src/test/org/apache/hadoop/dfs/NNThroughputBenchmark.java
    hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java

Modified: hadoop/core/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=627927&r1=627926&r2=627927&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Thu Feb 14 17:48:42 2008
@@ -88,6 +88,9 @@
     HADOOP-2808. Minor fix to FileUtil::copy to mind the overwrite
     formal. (cdouglas)
 
+		HADOOP-2683. Moving UGI out of the RPC Server.
+		(Tsz Wo (Nicholas), SZE via shv)
+
 Release 0.16.0 - 2008-02-07
 
   INCOMPATIBLE CHANGES

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java?rev=627927&r1=627926&r2=627927&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/NameNode.java Thu Feb 14 17:48:42 2008
@@ -27,6 +27,7 @@
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.net.NetUtils;
 import org.apache.hadoop.net.NetworkTopology;
+import org.apache.hadoop.security.UserGroupInformation;
 
 import java.io.*;
 import java.net.*;
@@ -278,7 +279,8 @@
                             + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
     }
     namesystem.startFile(src,
-        new PermissionStatus(Server.getUserInfo().getUserName(), null, masked),
+        new PermissionStatus(UserGroupInformation.getCurrentUGI().getUserName(),
+            null, masked),
         clientName, clientMachine, overwrite, replication, blockSize);
     myMetrics.numFilesCreated.inc();
   }
@@ -418,7 +420,8 @@
                             + MAX_PATH_LENGTH + " characters, " + MAX_PATH_DEPTH + " levels.");
     }
     return namesystem.mkdirs(src,
-        new PermissionStatus(Server.getUserInfo().getUserName(), null, masked));
+        new PermissionStatus(UserGroupInformation.getCurrentUGI().getUserName(),
+            null, masked));
   }
 
   /**

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/dfs/PermissionChecker.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/PermissionChecker.java?rev=627927&r1=627926&r2=627927&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/PermissionChecker.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/PermissionChecker.java Thu Feb 14 17:48:42
2008
@@ -35,8 +35,10 @@
 
   PermissionChecker(String fsOwner, String supergroup
       ) throws AccessControlException{
-    UserGroupInformation ugi = Server.getUserInfo();
-    LOG.debug("ugi=" + ugi);
+    UserGroupInformation ugi = UserGroupInformation.getCurrentUGI();
+    if (LOG.isDebugEnabled()) {
+      LOG.debug("ugi=" + ugi);
+    }
 
     if (ugi != null) {
       user = ugi.getUserName();

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/ipc/Server.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/ipc/Server.java?rev=627927&r1=627926&r2=627927&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/ipc/Server.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/ipc/Server.java Thu Feb 14 17:48:42 2008
@@ -46,8 +46,6 @@
 import java.util.Iterator;
 import java.util.Random;
 
-import javax.security.auth.login.LoginException;
-
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
@@ -58,7 +56,6 @@
 import org.apache.hadoop.util.StringUtils;
 import org.apache.hadoop.ipc.metrics.RpcMetrics;
 import org.apache.hadoop.security.UserGroupInformation;
-import org.apache.hadoop.security.UnixUserGroupInformation;
 
 /** An abstract IPC service.  IPC calls take a single {@link Writable} as a
  * parameter, and return a {@link Writable} as their value.  A service runs on
@@ -126,19 +123,11 @@
 
   /** Returns {@link UserGroupInformation} associated with current RPC.
    *  returns null if user information is not available.
+   *  @deprecated should use {@link UserGroupInformation#getCurrentUGI()}
    */
+  @Deprecated
   public static UserGroupInformation getUserInfo() {
-    Call call = CurCall.get();
-    if (call != null)
-      return call.connection.ticket;
-    // This is to support local calls (as opposed to rpc ones) to the name-node.
-    // Currently it is name-node specific and should be placed somewhere else.
-    try {
-      return UnixUserGroupInformation.login();
-    } catch(LoginException le) {
-      LOG.info(StringUtils.stringifyException(le));
-      return null;
-    }
+    return UserGroupInformation.getCurrentUGI();
   }
   
   private String bindAddress; 
@@ -904,6 +893,8 @@
           Writable value = null;
           
           CurCall.set(call);
+          UserGroupInformation previous = UserGroupInformation.getCurrentUGI();
+          UserGroupInformation.setCurrentUGI(call.connection.ticket);
           try {
             value = call(call.param, call.receivedTime);             // make the call
           } catch (Throwable e) {
@@ -911,6 +902,7 @@
             errorClass = e.getClass().getName();
             error = StringUtils.stringifyException(e);
           }
+          UserGroupInformation.setCurrentUGI(previous);
           CurCall.set(null);
 
           buf.reset();

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/security/UnixUserGroupInformation.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/security/UnixUserGroupInformation.java?rev=627927&r1=627926&r2=627927&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/security/UnixUserGroupInformation.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/security/UnixUserGroupInformation.java Thu
Feb 14 17:48:42 2008
@@ -34,7 +34,7 @@
 import org.apache.hadoop.io.WritableUtils;
 
 /** An implementation of UserGroupInformation in the Unix system */
-public class UnixUserGroupInformation implements UserGroupInformation {
+public class UnixUserGroupInformation extends UserGroupInformation {
   final static public String UGI_PROPERTY_NAME = "hadoop.job.ugi";
   final static private HashMap<String, UnixUserGroupInformation> user2UGIMap =
     new HashMap<String, UnixUserGroupInformation>();

Modified: hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java?rev=627927&r1=627926&r2=627927&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/security/UserGroupInformation.java Thu Feb
14 17:48:42 2008
@@ -21,20 +21,36 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.io.Writable;
 
-/** A {@link Writable} interface for storing user and groups information.
+/** A {@link Writable} abstract class for storing user and groups information.
  */
-public interface UserGroupInformation extends Writable {
+public abstract class UserGroupInformation implements Writable {
   public static final Log LOG = LogFactory.getLog(UserGroupInformation.class);
 
+  private static final ThreadLocal<UserGroupInformation> currentUGI
+    = new ThreadLocal<UserGroupInformation>();
+
+  /** @return the {@link UserGroupInformation} for the current thread */ 
+  public static UserGroupInformation getCurrentUGI() {
+    return currentUGI.get();
+  }
+
+  /** Set the {@link UserGroupInformation} for the current thread */ 
+  public static void setCurrentUGI(UserGroupInformation ugi) {
+    if (LOG.isDebugEnabled()) {
+      LOG.debug(Thread.currentThread().getName() + ", ugi=" + ugi);
+    }
+    currentUGI.set(ugi);
+  }
+
   /** Get username
    * 
    * @return the user's name
    */
-  public String getUserName();
+  public abstract String getUserName();
   
   /** Get the name of the groups that the user belong to
    * 
    * @return an array of group names
    */
-  public String[] getGroupNames();
+  public abstract String[] getGroupNames();
 }

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java?rev=627927&r1=627926&r2=627927&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/dfs/MiniDFSCluster.java Thu Feb 14 17:48:42
2008
@@ -22,13 +22,15 @@
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Random;
+
+import javax.security.auth.login.LoginException;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.dfs.FSConstants.DatanodeReportType;
 import org.apache.hadoop.dfs.FSConstants.StartupOption;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.FileUtil;
+import org.apache.hadoop.security.*;
 import org.apache.hadoop.util.ToolRunner;
 
 /**
@@ -163,6 +165,13 @@
                         String[] racks,
                         long[] simulatedCapacities) throws IOException {
     this.conf = conf;
+    try {
+      UserGroupInformation.setCurrentUGI(UnixUserGroupInformation.login(conf));
+    } catch (LoginException e) {
+      IOException ioe = new IOException();
+      ioe.initCause(e);
+      throw ioe;
+    }
     base_dir = new File(System.getProperty("test.build.data"), "dfs/");
     data_dir = new File(base_dir, "data");
     

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/dfs/NNThroughputBenchmark.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/dfs/NNThroughputBenchmark.java?rev=627927&r1=627926&r2=627927&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/dfs/NNThroughputBenchmark.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/dfs/NNThroughputBenchmark.java Thu Feb 14
17:48:42 2008
@@ -22,6 +22,8 @@
 import java.util.List;
 import java.util.ArrayList;
 
+import javax.security.auth.login.LoginException;
+
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.commons.logging.impl.Log4JLogger;
@@ -30,6 +32,7 @@
 import org.apache.hadoop.net.DNS;
 import org.apache.hadoop.net.NetworkTopology;
 import org.apache.hadoop.util.StringUtils;
+import org.apache.hadoop.security.*;
 import org.apache.log4j.Level;
 
 /**
@@ -64,8 +67,13 @@
   static Configuration config;
   static NameNode nameNode;
 
-  NNThroughputBenchmark(Configuration conf) throws IOException {
+  private final UserGroupInformation ugi;
+
+  NNThroughputBenchmark(Configuration conf) throws IOException, LoginException {
     config = conf;
+    ugi = UnixUserGroupInformation.login(config);
+    UserGroupInformation.setCurrentUGI(ugi);
+
     // We do not need many handlers, since each thread simulates a handler
     // by calling name-node methods directly
     config.setInt("dfs.namenode.handler.count", 1);
@@ -273,7 +281,7 @@
   /**
    * One of the threads that perform stats operations.
    */
-  private static class StatsDaemon extends Thread {
+  private class StatsDaemon extends Thread {
     private int daemonId;
     private int opsPerThread;
     private String arg1;      // argument passed to executeOp()
@@ -290,6 +298,7 @@
     }
 
     public void run() {
+      UserGroupInformation.setCurrentUGI(ugi);
       localNumOpsExecuted = 0;
       localCumulativeTime = 0;
       arg1 = statsOp.getExecutionArgument(daemonId);

Modified: hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java
URL: http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java?rev=627927&r1=627926&r2=627927&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java (original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/security/TestPermission.java Thu Feb 14 17:48:42
2008
@@ -22,17 +22,23 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.commons.logging.impl.Log4JLogger;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.dfs.MiniDFSCluster;
 import org.apache.hadoop.fs.*;
 import org.apache.hadoop.fs.permission.*;
 import org.apache.hadoop.ipc.RemoteException;
+import org.apache.log4j.Level;
 
 import junit.framework.TestCase;
 
 /** Unit tests for permission */
 public class TestPermission extends TestCase {
   public static final Log LOG = LogFactory.getLog(TestPermission.class);
+
+  {
+    ((Log4JLogger)UserGroupInformation.LOG).getLogger().setLevel(Level.ALL);
+  }
 
   final private static Path ROOT_PATH = new Path("/data");
   final private static Path CHILD_DIR1 = new Path(ROOT_PATH, "web1");



Mime
View raw message