From 6a0e7dd454d587266a6020f83c6d07efb946d6ce Mon Sep 17 00:00:00 2001 From: Giovanni Matteo Fumarola Date: Thu, 23 May 2019 13:27:52 -0700 Subject: [PATCH] YARN-9482. DistributedShell job with localization fails in unsecure cluster. Contributed by Prabhu Joseph. --- .../distributedshell/ApplicationMaster.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java index 56664cea2d..c30dc4dc01 100644 --- a/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java +++ b/hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java @@ -774,17 +774,27 @@ private void printUsage(Options opts) { } private void cleanup() { - Path dst = null; try { - FileSystem fs = FileSystem.get(conf); - dst = new Path(fs.getHomeDirectory(), getRelativePath(appName, - appId.toString(), "")); - fs.delete(dst, true); - } catch(IOException e) { - LOG.warn("Failed to remove application staging directory {}", dst); + appSubmitterUgi.doAs(new PrivilegedExceptionAction() { + @Override + public Void run() throws IOException { + FileSystem fs = FileSystem.get(conf); + Path dst = new Path(getAppSubmitterHomeDir(), + getRelativePath(appName, appId.toString(), "")); + fs.delete(dst, true); + return null; + } + }); + } catch(Exception e) { + LOG.warn("Failed to remove application staging directory", e); } } + private Path getAppSubmitterHomeDir() { + return new Path("/user/" + + System.getenv(ApplicationConstants.Environment.USER.name())); + } + /** * Main run function for the application master * @@ -1485,7 +1495,7 @@ public void run() { String relativePath = getRelativePath(appName, appId.toString(), fileName); Path dst = - new Path(fs.getHomeDirectory(), relativePath); + new Path(getAppSubmitterHomeDir(), relativePath); FileStatus fileStatus = fs.getFileStatus(dst); LocalResource localRes = LocalResource.newInstance( URL.fromURI(dst.toUri()),