|
@@ -29,7 +29,10 @@ import java.io.OutputStream;
|
|
import java.io.PipedInputStream;
|
|
import java.io.PipedInputStream;
|
|
import java.io.PipedOutputStream;
|
|
import java.io.PipedOutputStream;
|
|
import java.io.PrintStream;
|
|
import java.io.PrintStream;
|
|
|
|
+import java.util.Arrays;
|
|
|
|
|
|
|
|
+import org.apache.hadoop.fs.LocatedFileStatus;
|
|
|
|
+import org.apache.hadoop.fs.RemoteIterator;
|
|
import org.codehaus.jettison.json.JSONException;
|
|
import org.codehaus.jettison.json.JSONException;
|
|
import org.codehaus.jettison.json.JSONObject;
|
|
import org.codehaus.jettison.json.JSONObject;
|
|
import org.junit.Assert;
|
|
import org.junit.Assert;
|
|
@@ -83,6 +86,7 @@ public class TestMRJobClient extends ClusterMapReduceTestCase {
|
|
|
|
|
|
public static int runTool(Configuration conf, Tool tool, String[] args,
|
|
public static int runTool(Configuration conf, Tool tool, String[] args,
|
|
OutputStream out) throws Exception {
|
|
OutputStream out) throws Exception {
|
|
|
|
+ LOG.info("args = " + Arrays.toString(args));
|
|
PrintStream oldOut = System.out;
|
|
PrintStream oldOut = System.out;
|
|
PrintStream newOut = new PrintStream(out, true);
|
|
PrintStream newOut = new PrintStream(out, true);
|
|
try {
|
|
try {
|
|
@@ -140,7 +144,7 @@ public class TestMRJobClient extends ClusterMapReduceTestCase {
|
|
// test list of events
|
|
// test list of events
|
|
testJobEvents(jobId, conf);
|
|
testJobEvents(jobId, conf);
|
|
// test job history
|
|
// test job history
|
|
- testJobHistory(conf);
|
|
|
|
|
|
+ testJobHistory(jobId, conf);
|
|
// test tracker list
|
|
// test tracker list
|
|
testListTrackers(conf);
|
|
testListTrackers(conf);
|
|
// attempts list
|
|
// attempts list
|
|
@@ -354,111 +358,127 @@ public class TestMRJobClient extends ClusterMapReduceTestCase {
|
|
/**
|
|
/**
|
|
* print job history from file
|
|
* print job history from file
|
|
*/
|
|
*/
|
|
- private void testJobHistory(Configuration conf) throws Exception {
|
|
|
|
|
|
+ private void testJobHistory(String jobId, Configuration conf)
|
|
|
|
+ throws Exception {
|
|
CLI jc = createJobClient();
|
|
CLI jc = createJobClient();
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
|
- File f = new File("src/test/resources/job_1329348432655_0001-10.jhist");
|
|
|
|
- FileSystem localFs = FileSystem.getLocal(conf);
|
|
|
|
- String historyFileUri = new Path(f.getAbsolutePath())
|
|
|
|
- .makeQualified(localFs.getUri(), localFs.getWorkingDirectory()).toUri()
|
|
|
|
- .toString();
|
|
|
|
|
|
|
|
- // Try a bunch of different valid combinations of the command to test
|
|
|
|
- // argument parsing
|
|
|
|
- int exitCode = runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- "all",
|
|
|
|
- historyFileUri,
|
|
|
|
|
|
+ // Find jhist file
|
|
|
|
+ String historyFileUri = null;
|
|
|
|
+ RemoteIterator<LocatedFileStatus> it =
|
|
|
|
+ getFileSystem().listFiles(new Path("/"), true);
|
|
|
|
+ while (it.hasNext() && historyFileUri == null) {
|
|
|
|
+ LocatedFileStatus file = it.next();
|
|
|
|
+ if (file.getPath().getName().endsWith(".jhist")) {
|
|
|
|
+ historyFileUri = file.getPath().toUri().toString();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ assertNotNull("Could not find jhist file", historyFileUri);
|
|
|
|
+
|
|
|
|
+ for (String historyFileOrJobId : new String[]{historyFileUri, jobId}) {
|
|
|
|
+ // Try a bunch of different valid combinations of the command
|
|
|
|
+ int exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ "all",
|
|
|
|
+ historyFileOrJobId,
|
|
}, out);
|
|
}, out);
|
|
- assertEquals("Exit code", 0, exitCode);
|
|
|
|
- checkHistoryHumanOutput(out);
|
|
|
|
- File outFile = File.createTempFile("myout", ".txt");
|
|
|
|
- exitCode = runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- "all",
|
|
|
|
- historyFileUri,
|
|
|
|
- "-outfile",
|
|
|
|
- outFile.getAbsolutePath()
|
|
|
|
|
|
+ assertEquals("Exit code", 0, exitCode);
|
|
|
|
+ checkHistoryHumanOutput(jobId, out);
|
|
|
|
+ File outFile = File.createTempFile("myout", ".txt");
|
|
|
|
+ exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ "all",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "-outfile",
|
|
|
|
+ outFile.getAbsolutePath()
|
|
}, out);
|
|
}, out);
|
|
- assertEquals("Exit code", 0, exitCode);
|
|
|
|
- checkHistoryHumanFileOutput(out, outFile);
|
|
|
|
- outFile = File.createTempFile("myout", ".txt");
|
|
|
|
- exitCode = runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- "all",
|
|
|
|
- historyFileUri,
|
|
|
|
- "-outfile",
|
|
|
|
- outFile.getAbsolutePath(),
|
|
|
|
- "-format",
|
|
|
|
- "human"
|
|
|
|
|
|
+ assertEquals("Exit code", 0, exitCode);
|
|
|
|
+ checkHistoryHumanFileOutput(jobId, out, outFile);
|
|
|
|
+ outFile = File.createTempFile("myout", ".txt");
|
|
|
|
+ exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ "all",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "-outfile",
|
|
|
|
+ outFile.getAbsolutePath(),
|
|
|
|
+ "-format",
|
|
|
|
+ "human"
|
|
}, out);
|
|
}, out);
|
|
- assertEquals("Exit code", 0, exitCode);
|
|
|
|
- checkHistoryHumanFileOutput(out, outFile);
|
|
|
|
-
|
|
|
|
- exitCode = runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- historyFileUri,
|
|
|
|
- "-format",
|
|
|
|
- "human"
|
|
|
|
|
|
+ assertEquals("Exit code", 0, exitCode);
|
|
|
|
+ checkHistoryHumanFileOutput(jobId, out, outFile);
|
|
|
|
+ exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "-format",
|
|
|
|
+ "human"
|
|
}, out);
|
|
}, out);
|
|
- assertEquals("Exit code", 0, exitCode);
|
|
|
|
- checkHistoryHumanOutput(out);
|
|
|
|
-
|
|
|
|
- exitCode = runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- "all",
|
|
|
|
- historyFileUri,
|
|
|
|
- "-format",
|
|
|
|
- "json"
|
|
|
|
|
|
+ assertEquals("Exit code", 0, exitCode);
|
|
|
|
+ checkHistoryHumanOutput(jobId, out);
|
|
|
|
+ exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ "all",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "-format",
|
|
|
|
+ "json"
|
|
}, out);
|
|
}, out);
|
|
- assertEquals("Exit code", 0, exitCode);
|
|
|
|
- checkHistoryJSONOutput(out);
|
|
|
|
- outFile = File.createTempFile("myout", ".txt");
|
|
|
|
- exitCode = runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- "all",
|
|
|
|
- historyFileUri,
|
|
|
|
- "-outfile",
|
|
|
|
- outFile.getAbsolutePath(),
|
|
|
|
- "-format",
|
|
|
|
- "json"
|
|
|
|
|
|
+ assertEquals("Exit code", 0, exitCode);
|
|
|
|
+ checkHistoryJSONOutput(jobId, out);
|
|
|
|
+ outFile = File.createTempFile("myout", ".txt");
|
|
|
|
+ exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ "all",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "-outfile",
|
|
|
|
+ outFile.getAbsolutePath(),
|
|
|
|
+ "-format",
|
|
|
|
+ "json"
|
|
}, out);
|
|
}, out);
|
|
- assertEquals("Exit code", 0, exitCode);
|
|
|
|
- checkHistoryJSONFileOutput(out, outFile);
|
|
|
|
- exitCode = runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- historyFileUri,
|
|
|
|
- "-format",
|
|
|
|
- "json"
|
|
|
|
|
|
+ assertEquals("Exit code", 0, exitCode);
|
|
|
|
+ checkHistoryJSONFileOutput(jobId, out, outFile);
|
|
|
|
+ exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "-format",
|
|
|
|
+ "json"
|
|
}, out);
|
|
}, out);
|
|
- assertEquals("Exit code", 0, exitCode);
|
|
|
|
- checkHistoryJSONOutput(out);
|
|
|
|
-
|
|
|
|
- // Check some bad arguments
|
|
|
|
- exitCode = runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- historyFileUri,
|
|
|
|
- "foo"
|
|
|
|
- }, out);
|
|
|
|
- assertEquals("Exit code", -1, exitCode);
|
|
|
|
- exitCode = runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- historyFileUri,
|
|
|
|
- "-format"
|
|
|
|
|
|
+ assertEquals("Exit code", 0, exitCode);
|
|
|
|
+ checkHistoryJSONOutput(jobId, out);
|
|
|
|
+
|
|
|
|
+ // Check some bad arguments
|
|
|
|
+ exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "foo"
|
|
}, out);
|
|
}, out);
|
|
- assertEquals("Exit code", -1, exitCode);
|
|
|
|
- runTool(conf, jc, new String[] {
|
|
|
|
- "-history",
|
|
|
|
- historyFileUri,
|
|
|
|
- "-outfile",
|
|
|
|
- }, out);
|
|
|
|
- assertEquals("Exit code", -1, exitCode);
|
|
|
|
|
|
+ assertEquals("Exit code", -1, exitCode);
|
|
|
|
+ exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "-format"
|
|
|
|
+ }, out);
|
|
|
|
+ assertEquals("Exit code", -1, exitCode);
|
|
|
|
+ exitCode = runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "-outfile",
|
|
|
|
+ }, out);
|
|
|
|
+ assertEquals("Exit code", -1, exitCode);
|
|
|
|
+ try {
|
|
|
|
+ runTool(conf, jc, new String[]{
|
|
|
|
+ "-history",
|
|
|
|
+ historyFileOrJobId,
|
|
|
|
+ "-format",
|
|
|
|
+ "foo"
|
|
|
|
+ }, out);
|
|
|
|
+ fail();
|
|
|
|
+ } catch (IllegalArgumentException e) {
|
|
|
|
+ // Expected
|
|
|
|
+ }
|
|
|
|
+ }
|
|
try {
|
|
try {
|
|
runTool(conf, jc, new String[]{
|
|
runTool(conf, jc, new String[]{
|
|
"-history",
|
|
"-history",
|
|
- historyFileUri,
|
|
|
|
- "-format",
|
|
|
|
- "foo"
|
|
|
|
|
|
+ "not_a_valid_history_file_or_job_id",
|
|
}, out);
|
|
}, out);
|
|
fail();
|
|
fail();
|
|
} catch (IllegalArgumentException e) {
|
|
} catch (IllegalArgumentException e) {
|
|
@@ -466,45 +486,47 @@ public class TestMRJobClient extends ClusterMapReduceTestCase {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void checkHistoryHumanOutput(ByteArrayOutputStream out)
|
|
|
|
|
|
+ private void checkHistoryHumanOutput(String jobId, ByteArrayOutputStream out)
|
|
throws IOException, JSONException {
|
|
throws IOException, JSONException {
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(
|
|
new ByteArrayInputStream(out.toByteArray())));
|
|
new ByteArrayInputStream(out.toByteArray())));
|
|
br.readLine();
|
|
br.readLine();
|
|
String line = br.readLine();
|
|
String line = br.readLine();
|
|
br.close();
|
|
br.close();
|
|
- assertEquals("Hadoop job: job_1329348432655_0001", line);
|
|
|
|
|
|
+ assertEquals("Hadoop job: " + jobId, line);
|
|
out.reset();
|
|
out.reset();
|
|
}
|
|
}
|
|
|
|
|
|
- private void checkHistoryJSONOutput(ByteArrayOutputStream out)
|
|
|
|
|
|
+ private void checkHistoryJSONOutput(String jobId, ByteArrayOutputStream out)
|
|
throws IOException, JSONException {
|
|
throws IOException, JSONException {
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(
|
|
BufferedReader br = new BufferedReader(new InputStreamReader(
|
|
new ByteArrayInputStream(out.toByteArray())));
|
|
new ByteArrayInputStream(out.toByteArray())));
|
|
String line = org.apache.commons.io.IOUtils.toString(br);
|
|
String line = org.apache.commons.io.IOUtils.toString(br);
|
|
br.close();
|
|
br.close();
|
|
JSONObject json = new JSONObject(line);
|
|
JSONObject json = new JSONObject(line);
|
|
- assertEquals("job_1329348432655_0001", json.getString("hadoopJob"));
|
|
|
|
|
|
+ assertEquals(jobId, json.getString("hadoopJob"));
|
|
out.reset();
|
|
out.reset();
|
|
}
|
|
}
|
|
|
|
|
|
- private void checkHistoryHumanFileOutput(ByteArrayOutputStream out,
|
|
|
|
- File outFile) throws IOException, JSONException {
|
|
|
|
|
|
+ private void checkHistoryHumanFileOutput(String jobId,
|
|
|
|
+ ByteArrayOutputStream out, File outFile)
|
|
|
|
+ throws IOException, JSONException {
|
|
BufferedReader br = new BufferedReader(new FileReader(outFile));
|
|
BufferedReader br = new BufferedReader(new FileReader(outFile));
|
|
br.readLine();
|
|
br.readLine();
|
|
String line = br.readLine();
|
|
String line = br.readLine();
|
|
br.close();
|
|
br.close();
|
|
- assertEquals("Hadoop job: job_1329348432655_0001", line);
|
|
|
|
|
|
+ assertEquals("Hadoop job: " + jobId, line);
|
|
assertEquals(0, out.size());
|
|
assertEquals(0, out.size());
|
|
}
|
|
}
|
|
|
|
|
|
- private void checkHistoryJSONFileOutput(ByteArrayOutputStream out,
|
|
|
|
- File outFile) throws IOException, JSONException {
|
|
|
|
|
|
+ private void checkHistoryJSONFileOutput(String jobId,
|
|
|
|
+ ByteArrayOutputStream out, File outFile)
|
|
|
|
+ throws IOException, JSONException {
|
|
BufferedReader br = new BufferedReader(new FileReader(outFile));
|
|
BufferedReader br = new BufferedReader(new FileReader(outFile));
|
|
String line = org.apache.commons.io.IOUtils.toString(br);
|
|
String line = org.apache.commons.io.IOUtils.toString(br);
|
|
br.close();
|
|
br.close();
|
|
JSONObject json = new JSONObject(line);
|
|
JSONObject json = new JSONObject(line);
|
|
- assertEquals("job_1329348432655_0001", json.getString("hadoopJob"));
|
|
|
|
|
|
+ assertEquals(jobId, json.getString("hadoopJob"));
|
|
assertEquals(0, out.size());
|
|
assertEquals(0, out.size());
|
|
}
|
|
}
|
|
|
|
|