You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by ji...@apache.org on 2011/04/22 20:09:50 UTC

svn commit: r1095975 - in /hadoop/common/branches/yahoo-merge: CHANGES.txt src/java/org/apache/hadoop/fs/FileContext.java

Author: jitendra
Date: Fri Apr 22 18:09:50 2011
New Revision: 1095975

URL: http://svn.apache.org/viewvc?rev=1095975&view=rev
Log:
Merging change r1092832 from trunk to yahoo-merge.

Modified:
    hadoop/common/branches/yahoo-merge/CHANGES.txt   (contents, props changed)
    hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java

Modified: hadoop/common/branches/yahoo-merge/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/CHANGES.txt?rev=1095975&r1=1095974&r2=1095975&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/CHANGES.txt (original)
+++ hadoop/common/branches/yahoo-merge/CHANGES.txt Fri Apr 22 18:09:50 2011
@@ -8,6 +8,8 @@ Trunk (unreleased changes)
 
     HADOOP-6994. Api to get delegation token in AbstractFileSystem. (jitendra)
 
+    HADOOP-7171. Support UGI in FileContext API. (jitendra)
+
   IMPROVEMENTS
 
     HADOOP-7133. Batch the calls in DataStorage to FileUtil.createHardLink().

Propchange: hadoop/common/branches/yahoo-merge/CHANGES.txt
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Fri Apr 22 18:09:50 2011
@@ -1,4 +1,4 @@
-/hadoop/common/trunk/CHANGES.txt:1080396,1091618
+/hadoop/common/trunk/CHANGES.txt:1080396,1091618,1092832
 /hadoop/core/branches/branch-0.18/CHANGES.txt:727226
 /hadoop/core/branches/branch-0.19/CHANGES.txt:713112
 /hadoop/core/trunk/CHANGES.txt:776175-785643,785929-786278

Modified: hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java?rev=1095975&r1=1095974&r2=1095975&view=diff
==============================================================================
--- hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java (original)
+++ hadoop/common/branches/yahoo-merge/src/java/org/apache/hadoop/fs/FileContext.java Fri Apr 22 18:09:50 2011
@@ -208,9 +208,9 @@ public final class FileContext {
     try {
       ugi = UserGroupInformation.getCurrentUser();
     } catch (IOException e) {
-      LOG.error("Exception in getCurrentUser: "+e);
+      LOG.error("Exception in getCurrentUser: ",e);
       throw new RuntimeException("Failed to get the current user " +
-      		"while creating a FileContext");
+      		"while creating a FileContext", e);
     }
     /*
      * Init the wd.
@@ -286,9 +286,11 @@ public final class FileContext {
    * 
    * @throws UnsupportedFileSystemException If the file system for
    *           <code>absOrFqPath</code> is not supported.
+   * @throws IOExcepton If the file system for <code>absOrFqPath</code> could
+   *         not be instantiated.
    */
   private AbstractFileSystem getFSofPath(final Path absOrFqPath)
-      throws UnsupportedFileSystemException {
+      throws UnsupportedFileSystemException, IOException {
     checkNotSchemeWithRelative(absOrFqPath);
     if (!absOrFqPath.isAbsolute() && absOrFqPath.toUri().getScheme() == null) {
       throw new HadoopIllegalArgumentException(
@@ -300,28 +302,25 @@ public final class FileContext {
       defaultFS.checkPath(absOrFqPath);
       return defaultFS;
     } catch (Exception e) { // it is different FileSystem
-      try {
-        return ugi.doAs(new PrivilegedExceptionAction<AbstractFileSystem>() {
-
-          public AbstractFileSystem run() throws UnsupportedFileSystemException {
-            return AbstractFileSystem.get(absOrFqPath.toUri(), conf);
-          }
-
-        });
-      } catch (InterruptedException ex) {
-        LOG.error(ex);
-        throw new RuntimeException(
-            "Failed to get the AbstractFileSystem for path: " + absOrFqPath);
-      } catch (UnsupportedFileSystemException ex) {
-        throw ex;
-      } catch (IOException ex) {
-        LOG.error("IOException in doAs: " + ex);
-        throw new RuntimeException(
-            "Failed to get the AbstractFileSystem for path: " + absOrFqPath);
-      }
+      return getAbstractFileSystem(ugi, absOrFqPath.toUri(), conf);
     }
   }
   
+  private static AbstractFileSystem getAbstractFileSystem(
+      UserGroupInformation user, final URI uri, final Configuration conf)
+      throws UnsupportedFileSystemException, IOException {
+    try {
+      return user.doAs(new PrivilegedExceptionAction<AbstractFileSystem>() {
+        public AbstractFileSystem run() throws UnsupportedFileSystemException {
+          return AbstractFileSystem.get(uri, conf);
+        }
+      });
+    } catch (InterruptedException ex) {
+      LOG.error(ex);
+      throw new IOException("Failed to get the AbstractFileSystem for path: "
+          + uri, ex);
+    }
+  }
   
   /**
    * Protected Static Factory methods for getting a FileContexts
@@ -418,10 +417,23 @@ public final class FileContext {
    * @return new FileContext for specified uri
    * @throws UnsupportedFileSystemException If the file system with specified is
    *           not supported
+   * @throws RuntimeException If the file system specified is supported but
+   *         could not be instantiated, or if login fails.
    */
   public static FileContext getFileContext(final URI defaultFsUri,
       final Configuration aConf) throws UnsupportedFileSystemException {
-    return getFileContext(AbstractFileSystem.get(defaultFsUri,  aConf), aConf);
+    UserGroupInformation currentUser = null;
+    AbstractFileSystem defaultAfs = null;
+    try {
+      currentUser = UserGroupInformation.getCurrentUser();
+      defaultAfs = getAbstractFileSystem(currentUser, defaultFsUri, aConf);
+    } catch (UnsupportedFileSystemException ex) {
+      throw ex;
+    } catch (IOException ex) {
+      LOG.error(ex);
+      throw new RuntimeException(ex);
+    }
+    return getFileContext(defaultAfs, aConf);
   }
 
   /**