@Test public void testGenerateDumpScript() throws IOException { Path dumpScript = new Path(TEST_DIR, SCRIPT_NAME); HeapDumpForTaskUtils.generateDumpScript(dumpScript, this.fs, "test.hprof", "chmod 777 "); Assert.assertEquals(true, this.fs.exists(dumpScript)); Assert.assertEquals(true, this.fs.exists(new Path(dumpScript.getParent(), "dumps"))); Closer closer = Closer.create(); try { BufferedReader scriptReader = closer.register(new BufferedReader(new InputStreamReader(this.fs.open(dumpScript)))); Assert.assertEquals("#!/bin/sh", scriptReader.readLine()); Assert.assertEquals("if [ -n \"$HADOOP_PREFIX\" ]; then", scriptReader.readLine()); Assert.assertEquals(" ${HADOOP_PREFIX}/bin/hadoop dfs -put test.hprof dumpScript/dumps/${PWD scriptReader.readLine()); Assert.assertEquals("else", scriptReader.readLine()); Assert.assertEquals(" ${HADOOP_HOME}/bin/hadoop dfs -put test.hprof dumpScript/dumps/${PWD scriptReader.readLine()); Assert.assertEquals("fi", scriptReader.readLine()); } catch (Throwable t) { closer.rethrow(t); } finally { closer.close(); } }
public static void generateDumpScript(Path dumpScript, FileSystem fs, String heapFileName, String chmod) throws IOException { if (fs.exists(dumpScript)) { LOG.info("Heap dump script already exists: " + dumpScript); return; } try (BufferedWriter scriptWriter = new BufferedWriter(new OutputStreamWriter(fs.create(dumpScript), ConfigurationKeys.DEFAULT_CHARSET_ENCODING))) { Path dumpDir = new Path(dumpScript.getParent(), DUMP_FOLDER); if (!fs.exists(dumpDir)) { fs.mkdirs(dumpDir); } scriptWriter.write("#!/bin/sh\n"); scriptWriter.write("if [ -n \"$HADOOP_PREFIX\" ]; then\n"); scriptWriter .write(" ${HADOOP_PREFIX}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("else\n"); scriptWriter .write(" ${HADOOP_HOME}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("fi\n"); } catch (IOException ioe) { LOG.error("Heap dump script is not generated successfully."); if (fs.exists(dumpScript)) { fs.delete(dumpScript, true); } throw ioe; } Runtime.getRuntime().exec(chmod + " " + dumpScript); }
HeapDumpForTaskUtils { public static void generateDumpScript(Path dumpScript, FileSystem fs, String heapFileName, String chmod) throws IOException { if (fs.exists(dumpScript)) { LOG.info("Heap dump script already exists: " + dumpScript); return; } try (BufferedWriter scriptWriter = new BufferedWriter(new OutputStreamWriter(fs.create(dumpScript), ConfigurationKeys.DEFAULT_CHARSET_ENCODING))) { Path dumpDir = new Path(dumpScript.getParent(), DUMP_FOLDER); if (!fs.exists(dumpDir)) { fs.mkdirs(dumpDir); } scriptWriter.write("#!/bin/sh\n"); scriptWriter.write("if [ -n \"$HADOOP_PREFIX\" ]; then\n"); scriptWriter .write(" ${HADOOP_PREFIX}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("else\n"); scriptWriter .write(" ${HADOOP_HOME}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("fi\n"); } catch (IOException ioe) { LOG.error("Heap dump script is not generated successfully."); if (fs.exists(dumpScript)) { fs.delete(dumpScript, true); } throw ioe; } Runtime.getRuntime().exec(chmod + " " + dumpScript); } }
HeapDumpForTaskUtils { public static void generateDumpScript(Path dumpScript, FileSystem fs, String heapFileName, String chmod) throws IOException { if (fs.exists(dumpScript)) { LOG.info("Heap dump script already exists: " + dumpScript); return; } try (BufferedWriter scriptWriter = new BufferedWriter(new OutputStreamWriter(fs.create(dumpScript), ConfigurationKeys.DEFAULT_CHARSET_ENCODING))) { Path dumpDir = new Path(dumpScript.getParent(), DUMP_FOLDER); if (!fs.exists(dumpDir)) { fs.mkdirs(dumpDir); } scriptWriter.write("#!/bin/sh\n"); scriptWriter.write("if [ -n \"$HADOOP_PREFIX\" ]; then\n"); scriptWriter .write(" ${HADOOP_PREFIX}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("else\n"); scriptWriter .write(" ${HADOOP_HOME}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("fi\n"); } catch (IOException ioe) { LOG.error("Heap dump script is not generated successfully."); if (fs.exists(dumpScript)) { fs.delete(dumpScript, true); } throw ioe; } Runtime.getRuntime().exec(chmod + " " + dumpScript); }  }
HeapDumpForTaskUtils { public static void generateDumpScript(Path dumpScript, FileSystem fs, String heapFileName, String chmod) throws IOException { if (fs.exists(dumpScript)) { LOG.info("Heap dump script already exists: " + dumpScript); return; } try (BufferedWriter scriptWriter = new BufferedWriter(new OutputStreamWriter(fs.create(dumpScript), ConfigurationKeys.DEFAULT_CHARSET_ENCODING))) { Path dumpDir = new Path(dumpScript.getParent(), DUMP_FOLDER); if (!fs.exists(dumpDir)) { fs.mkdirs(dumpDir); } scriptWriter.write("#!/bin/sh\n"); scriptWriter.write("if [ -n \"$HADOOP_PREFIX\" ]; then\n"); scriptWriter .write(" ${HADOOP_PREFIX}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("else\n"); scriptWriter .write(" ${HADOOP_HOME}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("fi\n"); } catch (IOException ioe) { LOG.error("Heap dump script is not generated successfully."); if (fs.exists(dumpScript)) { fs.delete(dumpScript, true); } throw ioe; } Runtime.getRuntime().exec(chmod + " " + dumpScript); }  static void generateDumpScript(Path dumpScript, FileSystem fs, String heapFileName, String chmod); }
HeapDumpForTaskUtils { public static void generateDumpScript(Path dumpScript, FileSystem fs, String heapFileName, String chmod) throws IOException { if (fs.exists(dumpScript)) { LOG.info("Heap dump script already exists: " + dumpScript); return; } try (BufferedWriter scriptWriter = new BufferedWriter(new OutputStreamWriter(fs.create(dumpScript), ConfigurationKeys.DEFAULT_CHARSET_ENCODING))) { Path dumpDir = new Path(dumpScript.getParent(), DUMP_FOLDER); if (!fs.exists(dumpDir)) { fs.mkdirs(dumpDir); } scriptWriter.write("#!/bin/sh\n"); scriptWriter.write("if [ -n \"$HADOOP_PREFIX\" ]; then\n"); scriptWriter .write(" ${HADOOP_PREFIX}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("else\n"); scriptWriter .write(" ${HADOOP_HOME}/bin/hadoop dfs -put " + heapFileName + " " + dumpDir + "/${PWD scriptWriter.write("fi\n"); } catch (IOException ioe) { LOG.error("Heap dump script is not generated successfully."); if (fs.exists(dumpScript)) { fs.delete(dumpScript, true); } throw ioe; } Runtime.getRuntime().exec(chmod + " " + dumpScript); }  static void generateDumpScript(Path dumpScript, FileSystem fs, String heapFileName, String chmod);  }