HadoopArchiveLogs implements Tool { @VisibleForTesting void generateScript(File localScript, Path workingDir, Path remoteRootLogDir, String suffix) 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 app : eligibleApplications) { fw.write("if [ \"$YARN_SHELL_ID\" == \""); fw.write(Integer.toString(containerCount)); fw.write("\" ]; then\n\tappId=\""); fw.write(app.getAppId()); fw.write("\"\n\tuser=\""); fw.write(app.getUser()); 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_PREFIX\"/bin/hadoop "); fw.write(HadoopArchiveLogsRunner.class.getName()); fw.write(" -appId \"$appId\" -user \"$user\" -workingDir "); fw.write(workingDir.toString()); fw.write(" -remoteRootLogDir "); fw.write(remoteRootLogDir.toString()); 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); }