%@ page
contentType="text/html; charset=UTF-8"
import="javax.servlet.*"
import="javax.servlet.http.*"
import="java.io.*"
import="java.util.*"
import="org.apache.hadoop.mapred.*"
import="org.apache.hadoop.util.*"
%>
<%
JobTracker tracker = (JobTracker) application.getAttribute("job.tracker");
String trackerName =
StringUtils.simpleHostname(tracker.getJobTrackerMachine());
%>
<%!
private void printFailedAttempts(JspWriter out,
JobTracker tracker,
JobID jobId,
TaskInProgress tip,
TaskStatus.State failState) throws IOException {
TaskStatus[] statuses = tip.getTaskStatuses();
TaskID tipId = tip.getTIPId();
for(int i=0; i < statuses.length; ++i) {
TaskStatus.State taskState = statuses[i].getRunState();
if ((failState == null && (taskState == TaskStatus.State.FAILED ||
taskState == TaskStatus.State.KILLED)) || taskState == failState) {
String taskTrackerName = statuses[i].getTaskTracker();
TaskTrackerStatus taskTracker = tracker.getTaskTracker(taskTrackerName);
out.print("
" + statuses[i].getTaskID() +
" | " + tipId +
" | ");
if (taskTracker == null) {
out.print("" + taskTrackerName + " | ");
} else {
out.print("" + taskTracker.getHost() +
" | ");
}
out.print("" + taskState + " | ");
out.print("");
String[] failures =
tracker.getTaskDiagnostics(statuses[i].getTaskID());
if (failures == null) {
out.print(" ");
} else {
for(int j = 0 ; j < failures.length ; j++){
out.print(failures[j]);
if (j < (failures.length - 1)) {
out.print("\n-------\n");
}
}
}
out.print(" | ");
out.print("");
String taskLogUrl = null;
if (taskTracker != null) {
taskLogUrl = TaskLogServlet.getTaskLogUrl(taskTracker.getHost(),
String.valueOf(taskTracker.getHttpPort()),
statuses[i].getTaskID().toString());
}
if (taskLogUrl != null) {
String tailFourKBUrl = taskLogUrl + "&start=-4097";
String tailEightKBUrl = taskLogUrl + "&start=-8193";
String entireLogUrl = taskLogUrl;
out.print("Last 4KB ");
out.print("Last 8KB ");
out.print("All ");
} else {
out.print("n/a"); // task tracker was lost
}
out.print(" | ");
out.print("
\n");
}
}
}
private void printFailures(JspWriter out,
JobTracker tracker,
JobID jobId,
String kind,
String cause) throws IOException {
JobInProgress job = (JobInProgress) tracker.getJob(jobId);
if (job == null) {
out.print("Job " + jobId + " not found.
\n");
return;
}
boolean includeMap = false;
boolean includeReduce = false;
if (kind == null) {
includeMap = true;
includeReduce = true;
} else if ("map".equals(kind)) {
includeMap = true;
} else if ("reduce".equals(kind)) {
includeReduce = true;
} else if ("all".equals(kind)) {
includeMap = true;
includeReduce = true;
} else {
out.print("Kind " + kind + " not supported.
\n");
return;
}
TaskStatus.State state = null;
try {
if (cause != null) {
state = TaskStatus.State.valueOf(cause.toUpperCase());
if (state != TaskStatus.State.FAILED && state != TaskStatus.State.KILLED) {
out.print("Cause '" + cause +
"' is not an 'unsuccessful' state.
\n");
return;
}
}
} catch (IllegalArgumentException e) {
out.print("Cause '" + cause + "' not supported.
\n");
return;
}
out.print("");
out.print("Attempt | Task | Machine | State | " +
"Error | Logs |
\n");
if (includeMap) {
TaskInProgress[] tips = job.getMapTasks();
for(int i=0; i < tips.length; ++i) {
printFailedAttempts(out, tracker, jobId, tips[i], state);
}
}
if (includeReduce) {
TaskInProgress[] tips = job.getReduceTasks();
for(int i=0; i < tips.length; ++i) {
printFailedAttempts(out, tracker, jobId, tips[i], state);
}
}
out.print("
\n");
}
%>
<%
String jobId = request.getParameter("jobid");
if (jobId == null) {
out.println("Missing 'jobid'!
");
return;
}
JobID jobIdObj = JobID.forName(jobId);
String kind = request.getParameter("kind");
String cause = request.getParameter("cause");
%>
Hadoop <%=jobId%> failures on <%=trackerName%>
<%
printFailures(out, tracker, jobIdObj, kind, cause);
%>
Go back to JobTracker
<%
out.println(ServletUtil.htmlFooter());
%>