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 1928003..302e2f3 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 @@ -307,6 +307,9 @@ public boolean init(String[] args) throws ParseException, IOException { Options opts = new Options(); opts.addOption("app_attempt_id", true, "App Attempt ID. Not to be used unless for testing purposes"); + opts.addOption("shell_command", true, + "Shell command to be executed if shell command file does not " + + "exists, this is usually because AM started alone without client"); opts.addOption("shell_script", true, "Location of the shell script to be executed"); opts.addOption("shell_args", true, "Command line args for the shell script"); @@ -389,17 +392,22 @@ public boolean init(String[] args) throws ParseException, IOException { File shellCommandFile = new File(shellCommandPath); if (!shellCommandFile.exists()) { - throw new IllegalArgumentException( - "No shell command specified to be executed by application master"); - } - FileInputStream fs = null; - DataInputStream ds = null; - try { - ds = new DataInputStream(new FileInputStream(shellCommandFile)); - shellCommand = ds.readUTF(); - } finally { - org.apache.commons.io.IOUtils.closeQuietly(ds); - org.apache.commons.io.IOUtils.closeQuietly(fs); + if (cliParser.hasOption("shell_command")) { + shellCommand = cliParser.getOptionValue("shell_command"); + } else { + throw new IllegalArgumentException( + "No shell command specified to be executed by application master"); + } + } else { + FileInputStream fs = null; + DataInputStream ds = null; + try { + ds = new DataInputStream(new FileInputStream(shellCommandFile)); + shellCommand = ds.readUTF(); + } finally { + org.apache.commons.io.IOUtils.closeQuietly(ds); + org.apache.commons.io.IOUtils.closeQuietly(fs); + } } if (cliParser.hasOption("shell_args")) {