Author: eli Date: Wed Sep 26 21:26:54 2012 New Revision: 1390730 URL: http://svn.apache.org/viewvc?rev=1390730&view=rev Log: HDFS-3972. Trash emptier fails in secure HA cluster. Contributed by Todd Lipcon
Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SecurityUtil.java Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java?rev=1390730&r1=1390729&r2=1390730&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/TrashPolicyDefault.java Wed Sep 26 21:26:54 2012 @@ -72,8 +72,9 @@ public class TrashPolicyDefault extends public TrashPolicyDefault() { } - private TrashPolicyDefault(Path home, Configuration conf) throws IOException { - initialize(conf, home.getFileSystem(conf), home); + private TrashPolicyDefault(FileSystem fs, Path home, Configuration conf) + throws IOException { + initialize(conf, fs, home); } @Override @@ -279,7 +280,8 @@ public class TrashPolicyDefault extends if (!home.isDirectory()) continue; try { - TrashPolicyDefault trash = new TrashPolicyDefault(home.getPath(), conf); + TrashPolicyDefault trash = new TrashPolicyDefault( + fs, home.getPath(), conf); trash.deleteCheckpoint(); trash.createCheckpoint(); } catch (IOException e) { Modified: hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SecurityUtil.java URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SecurityUtil.java?rev=1390730&r1=1390729&r2=1390730&view=diff ============================================================================== --- hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SecurityUtil.java (original) +++ hadoop/common/branches/branch-2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/SecurityUtil.java Wed Sep 26 21:26:54 2012 @@ -25,6 +25,7 @@ import java.net.URLConnection; import java.net.UnknownHostException; import java.security.AccessController; import java.security.PrivilegedAction; +import java.security.PrivilegedExceptionAction; import java.util.Arrays; import java.util.List; import java.util.ServiceLoader; @@ -451,6 +452,41 @@ public class SecurityUtil { return action.run(); } } + + /** + * Perform the given action as the daemon's login user. If an + * InterruptedException is thrown, it is converted to an IOException. + * + * @param action the action to perform + * @return the result of the action + * @throws IOException in the event of error + */ + public static <T> T doAsLoginUser(PrivilegedExceptionAction<T> action) + throws IOException { + return doAsUser(UserGroupInformation.getLoginUser(), action); + } + + /** + * Perform the given action as the daemon's current user. If an + * InterruptedException is thrown, it is converted to an IOException. + * + * @param action the action to perform + * @return the result of the action + * @throws IOException in the event of error + */ + public static <T> T doAsCurrentUser(PrivilegedExceptionAction<T> action) + throws IOException { + return doAsUser(UserGroupInformation.getCurrentUser(), action); + } + + private static <T> T doAsUser(UserGroupInformation ugi, + PrivilegedExceptionAction<T> action) throws IOException { + try { + return ugi.doAs(action); + } catch (InterruptedException ie) { + throw new IOException(ie); + } + } /** * Open a (if need be) secure connection to a URL in a secure environment