diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java index 88ae207..92d8d68 100644 --- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java +++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-applications/hadoop-yarn-applications-distributedshell/src/main/java/org/apache/hadoop/yarn/applications/distributedshell/ApplicationMaster.java @@ -27,6 +27,7 @@ import java.net.URI; import java.net.URISyntaxException; import java.nio.ByteBuffer; +import java.security.PrivilegedAction; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; @@ -908,13 +909,8 @@ public void run() { } else { renamedSchellScriptPath = new Path(shellScriptPath + ".sh"); } - try { - FileSystem fs = renamedSchellScriptPath.getFileSystem(conf); - fs.rename(new Path(shellScriptPath), renamedSchellScriptPath); - } catch (IOException e) { - LOG.warn("Not able to add suffix (.bat/.sh) to the shell script filename"); - throw new YarnRuntimeException(e); - } + // rename the script file based on the underlying OS syntax. + renameScriptFile(renamedSchellScriptPath); LocalResource shellRsrc = Records.newRecord(LocalResource.class); shellRsrc.setType(LocalResourceType.FILE); @@ -983,6 +979,34 @@ public void run() { } } + private void renameScriptFile(final Path renamedSchellScriptPath) { + UserGroupInformation jobSubmitter = null; + try { + jobSubmitter = UserGroupInformation.getCurrentUser(); + } catch (IOException e) { + LOG.warn("Not able to get current user from UserGroupInformation."); + throw new YarnRuntimeException(e); + } + + jobSubmitter.doAs(new PrivilegedAction() { + @Override + public Void run() { + try { + FileSystem fs = renamedSchellScriptPath.getFileSystem(conf); + fs.rename(new Path(shellScriptPath), renamedSchellScriptPath); + } catch (IOException e) { + LOG.warn("Not able to add suffix (.bat/.sh) to the shell script filename"); + throw new YarnRuntimeException(e); + } + return null; + } + }); + LOG.info("User " + jobSubmitter + + " added suffix(.sh/.bat) to script file as " + + renamedSchellScriptPath); + } + + /** * Setup the request that will be sent to the RM for the container ask. *