Author: daijy Date: Tue Sep 3 22:56:58 2013 New Revision: 1519881 URL: http://svn.apache.org/r1519881 Log: WebHCat does not honor user home directory (Daniel Dai)
Modified: hive/trunk/RELEASE_NOTES.txt hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonControllerJob.java hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonUtils.java hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hcatalog/templeton/tool/TestTempletonUtils.java Modified: hive/trunk/RELEASE_NOTES.txt URL: http://svn.apache.org/viewvc/hive/trunk/RELEASE_NOTES.txt?rev=1519881&r1=1519880&r2=1519881&view=diff ============================================================================== --- hive/trunk/RELEASE_NOTES.txt (original) +++ hive/trunk/RELEASE_NOTES.txt Tue Sep 3 22:56:58 2013 @@ -15,6 +15,7 @@ Release Notes - Hive - Version 0.11.0 * [HIVE-4326] - Clean up remaining items in hive/hcatalog/historical/trunk ** Bug + * [HIVE-4441] - WebHCat does not honor user home directory * [HIVE-4442] - WebHCat should not override user.name parameter for Queue call * [HIVE-4586] - WebHCat should return 404 error for undefined resource * [HIVE-4820] - webhcat_config.sh should set default values for HIVE_HOME and HCAT_PREFIX that work with default build tree structure Modified: hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonControllerJob.java URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonControllerJob.java?rev=1519881&r1=1519880&r2=1519881&view=diff ============================================================================== --- hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonControllerJob.java (original) +++ hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonControllerJob.java Tue Sep 3 22:56:58 2013 @@ -154,6 +154,10 @@ public class TempletonControllerJob exte String statusdir = conf.get(STATUSDIR_NAME); + if (statusdir != null) { + statusdir = TempletonUtils.addUserHomeDirectoryIfApplicable(statusdir, conf.get("user.name"), conf); + } + ExecutorService pool = Executors.newCachedThreadPool(); executeWatcher(pool, conf, context.getJobID(), proc.getInputStream(), statusdir, STDOUT_FNAME); Modified: hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonUtils.java URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonUtils.java?rev=1519881&r1=1519880&r2=1519881&view=diff ============================================================================== --- hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonUtils.java (original) +++ hive/trunk/hcatalog/webhcat/svr/src/main/java/org/apache/hcatalog/templeton/tool/TempletonUtils.java Tue Sep 3 22:56:58 2013 @@ -36,6 +36,7 @@ import java.util.regex.Pattern; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; +import org.apache.hadoop.hdfs.DistributedFileSystem; import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.util.StringUtils; import org.apache.hcatalog.templeton.UgiFactory; @@ -210,6 +211,23 @@ public class TempletonUtils { return false; } } + + public static String addUserHomeDirectoryIfApplicable(String origPathStr, String user, Configuration conf) throws IOException { + Path path = new Path(origPathStr); + String result = origPathStr; + + // shortcut for s3/asv + // If path contains scheme, user should mean an absolute path, + // However, path.isAbsolute tell us otherwise. + // So we skip conversion for non-hdfs. + if (!(path.getFileSystem(conf) instanceof DistributedFileSystem)) { + return result; + } + if (!path.isAbsolute()) { + result = "/user/" + user + "/" + origPathStr; + } + return result; + } public static Path hadoopFsPath(final String fname, final Configuration conf, String user) throws URISyntaxException, IOException, @@ -227,6 +245,7 @@ public class TempletonUtils { } }); + fname = addUserHomeDirectoryIfApplicable(fname, user, conf); URI u = new URI(fname); Path p = new Path(u).makeQualified(defaultFs); Modified: hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hcatalog/templeton/tool/TestTempletonUtils.java URL: http://svn.apache.org/viewvc/hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hcatalog/templeton/tool/TestTempletonUtils.java?rev=1519881&r1=1519880&r2=1519881&view=diff ============================================================================== --- hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hcatalog/templeton/tool/TestTempletonUtils.java (original) +++ hive/trunk/hcatalog/webhcat/svr/src/test/java/org/apache/hcatalog/templeton/tool/TestTempletonUtils.java Tue Sep 3 22:56:58 2013 @@ -118,6 +118,16 @@ public class TestTempletonUtils { // This is our problem -- it means the configuration was wrong. e.printStackTrace(); } + try { + TempletonUtils.hadoopFsPath("a", new Configuration(), "teddybear"); + Assert.fail("Should not have found /user/teddybear/a"); + } catch (FileNotFoundException e) { + Assert.assertTrue(e.getMessage().contains("/user/teddybear/a")); + } catch (Exception e) { + // This is our problem -- it means the configuration was wrong. + e.printStackTrace(); + Assert.fail("Get wrong exception: " + e.getMessage()); + } } @Test