@Test public void testHadoopFsPath() { try { TempletonUtils.hadoopFsPath(null, null, null); TempletonUtils.hadoopFsPath(tmpFile.toURI().toString(), null, null); TempletonUtils.hadoopFsPath(tmpFile.toURI().toString(), new Configuration(), null); } catch (FileNotFoundException e) { Assert.fail("Couldn't find " + tmpFile.toURI().toString()); } catch (Exception e) { e.printStackTrace(); } try { TempletonUtils.hadoopFsPath("/scoobydoo/teddybear", new Configuration(), null); Assert.fail("Should not have found /scoobydoo/teddybear"); } catch (FileNotFoundException e) { } catch (Exception e) { 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) { e.printStackTrace(); Assert.fail("Get wrong exception: " + e.getMessage()); } }
public static Path hadoopFsPath(String fname, final Configuration conf, String user) throws URISyntaxException, IOException, InterruptedException { if (fname == null || conf == null) { return null; } UserGroupInformation ugi; if (user!=null) { ugi = UgiFactory.getUgi(user); } else { ugi = UserGroupInformation.getLoginUser(); } final String finalFName = new String(fname); final FileSystem defaultFs = ugi.doAs(new PrivilegedExceptionAction<FileSystem>() { public FileSystem run() throws URISyntaxException, IOException, InterruptedException { return FileSystem.get(new URI(finalFName), conf); } }); fname = addUserHomeDirectoryIfApplicable(fname, user); URI u = new URI(fname); Path p = new Path(u).makeQualified(defaultFs); if (hadoopFsIsMissing(defaultFs, p)) throw new FileNotFoundException("File " + fname + " does not exist."); return p; }
TempletonUtils { public static Path hadoopFsPath(String fname, final Configuration conf, String user) throws URISyntaxException, IOException, InterruptedException { if (fname == null || conf == null) { return null; } UserGroupInformation ugi; if (user!=null) { ugi = UgiFactory.getUgi(user); } else { ugi = UserGroupInformation.getLoginUser(); } final String finalFName = new String(fname); final FileSystem defaultFs = ugi.doAs(new PrivilegedExceptionAction<FileSystem>() { public FileSystem run() throws URISyntaxException, IOException, InterruptedException { return FileSystem.get(new URI(finalFName), conf); } }); fname = addUserHomeDirectoryIfApplicable(fname, user); URI u = new URI(fname); Path p = new Path(u).makeQualified(defaultFs); if (hadoopFsIsMissing(defaultFs, p)) throw new FileNotFoundException("File " + fname + " does not exist."); return p; } }
TempletonUtils { public static Path hadoopFsPath(String fname, final Configuration conf, String user) throws URISyntaxException, IOException, InterruptedException { if (fname == null || conf == null) { return null; } UserGroupInformation ugi; if (user!=null) { ugi = UgiFactory.getUgi(user); } else { ugi = UserGroupInformation.getLoginUser(); } final String finalFName = new String(fname); final FileSystem defaultFs = ugi.doAs(new PrivilegedExceptionAction<FileSystem>() { public FileSystem run() throws URISyntaxException, IOException, InterruptedException { return FileSystem.get(new URI(finalFName), conf); } }); fname = addUserHomeDirectoryIfApplicable(fname, user); URI u = new URI(fname); Path p = new Path(u).makeQualified(defaultFs); if (hadoopFsIsMissing(defaultFs, p)) throw new FileNotFoundException("File " + fname + " does not exist."); return p; }  }
TempletonUtils { public static Path hadoopFsPath(String fname, final Configuration conf, String user) throws URISyntaxException, IOException, InterruptedException { if (fname == null || conf == null) { return null; } UserGroupInformation ugi; if (user!=null) { ugi = UgiFactory.getUgi(user); } else { ugi = UserGroupInformation.getLoginUser(); } final String finalFName = new String(fname); final FileSystem defaultFs = ugi.doAs(new PrivilegedExceptionAction<FileSystem>() { public FileSystem run() throws URISyntaxException, IOException, InterruptedException { return FileSystem.get(new URI(finalFName), conf); } }); fname = addUserHomeDirectoryIfApplicable(fname, user); URI u = new URI(fname); Path p = new Path(u).makeQualified(defaultFs); if (hadoopFsIsMissing(defaultFs, p)) throw new FileNotFoundException("File " + fname + " does not exist."); return p; }  static boolean isset(String s); static boolean isset(char ch); static boolean isset(T[] a); static boolean isset(Collection<T> col); static boolean isset(Map<K, V> col); static String extractPercentComplete(String line); static String extractChildJobId(String line); static String encodeArray(String[] plain); static String encodeArray(List<String> list); static String[] decodeArray(String s); static String[] hadoopFsListAsArray(String files, Configuration conf,
                         String user); static String hadoopFsListAsString(String files, Configuration conf,
                        String user); static String hadoopFsFilename(String fname, Configuration conf, String user); static boolean hadoopFsIsMissing(FileSystem fs, Path p); static String addUserHomeDirectoryIfApplicable(String origPathStr, String user); static Path hadoopFsPath(String fname, final Configuration conf, String user); static int fetchUrl(URL url); static Map<String, String> hadoopUserEnv(String user,
                          String overrideClasspath); static String quoteForWindows(String param); static void addCmdForWindows(ArrayList<String> args); }
TempletonUtils { public static Path hadoopFsPath(String fname, final Configuration conf, String user) throws URISyntaxException, IOException, InterruptedException { if (fname == null || conf == null) { return null; } UserGroupInformation ugi; if (user!=null) { ugi = UgiFactory.getUgi(user); } else { ugi = UserGroupInformation.getLoginUser(); } final String finalFName = new String(fname); final FileSystem defaultFs = ugi.doAs(new PrivilegedExceptionAction<FileSystem>() { public FileSystem run() throws URISyntaxException, IOException, InterruptedException { return FileSystem.get(new URI(finalFName), conf); } }); fname = addUserHomeDirectoryIfApplicable(fname, user); URI u = new URI(fname); Path p = new Path(u).makeQualified(defaultFs); if (hadoopFsIsMissing(defaultFs, p)) throw new FileNotFoundException("File " + fname + " does not exist."); return p; }  static boolean isset(String s); static boolean isset(char ch); static boolean isset(T[] a); static boolean isset(Collection<T> col); static boolean isset(Map<K, V> col); static String extractPercentComplete(String line); static String extractChildJobId(String line); static String encodeArray(String[] plain); static String encodeArray(List<String> list); static String[] decodeArray(String s); static String[] hadoopFsListAsArray(String files, Configuration conf,
                         String user); static String hadoopFsListAsString(String files, Configuration conf,
                        String user); static String hadoopFsFilename(String fname, Configuration conf, String user); static boolean hadoopFsIsMissing(FileSystem fs, Path p); static String addUserHomeDirectoryIfApplicable(String origPathStr, String user); static Path hadoopFsPath(String fname, final Configuration conf, String user); static int fetchUrl(URL url); static Map<String, String> hadoopUserEnv(String user,
                          String overrideClasspath); static String quoteForWindows(String param); static void addCmdForWindows(ArrayList<String> args); static final Pattern JAR_COMPLETE; static final Pattern PIG_COMPLETE; static final Pattern JAR_ID; static final Pattern PIG_ID; static final Pattern[] ID_PATTERNS; }