HadoopArchiveLogs implements Tool { @VisibleForTesting void generateScript(File localScript) throws IOException { if (verbose) { LOG.info("Generating script at: " + localScript.getAbsolutePath()); } String halrJarPath = HadoopArchiveLogsRunner.class.getProtectionDomain() .getCodeSource().getLocation().getPath(); String harJarPath = HadoopArchives.class.getProtectionDomain() .getCodeSource().getLocation().getPath(); String classpath = halrJarPath + File.pathSeparator + harJarPath; FileWriterWithEncoding fw = null; try { fw = new FileWriterWithEncoding(localScript, "UTF-8"); fw.write("#!/bin/bash\nset -e\nset -x\n"); int containerCount = 1; for (AppInfo context : eligibleApplications) { fw.write("if [ \"$YARN_SHELL_ID\" == \""); fw.write(Integer.toString(containerCount)); fw.write("\" ]; then\n\tappId=\""); fw.write(context.getAppId()); fw.write("\"\n\tuser=\""); fw.write(context.getUser()); fw.write("\"\n\tworkingDir=\""); fw.write(context.getWorkingDir().toString()); fw.write("\"\n\tremoteRootLogDir=\""); fw.write(context.getRemoteRootLogDir().toString()); fw.write("\"\n\tsuffix=\""); fw.write(context.getSuffix()); fw.write("\"\nel"); containerCount++; } fw.write("se\n\techo \"Unknown Mapping!\"\n\texit 1\nfi\n"); fw.write("export HADOOP_CLIENT_OPTS=\"-Xmx"); fw.write(Long.toString(memory)); fw.write("m\"\n"); fw.write("export HADOOP_CLASSPATH="); fw.write(classpath); fw.write("\n\"$HADOOP_HOME\"/bin/hadoop "); fw.write(HadoopArchiveLogsRunner.class.getName()); fw.write(" -appId \"$appId\" -user \"$user\" -workingDir "); fw.write("\"$workingDir\""); fw.write(" -remoteRootLogDir "); fw.write("\"$remoteRootLogDir\""); fw.write(" -suffix "); fw.write("\"$suffix\""); if (!proxy) { fw.write(" -noProxy\n"); } fw.write("\n"); } finally { if (fw != null) { fw.close(); } } } HadoopArchiveLogs(Configuration conf); static void main(String[] args); @Override int run(String[] args); @Override void setConf(Configuration conf); @Override Configuration getConf();  }
@Test(timeout = 10000) public void testGenerateScript() throws Exception { _testGenerateScript(false); _testGenerateScript(true); }