jobfailures.jsp
上传用户:quxuerui
上传日期:2018-01-08
资源大小:41811k
文件大小:6k
源码类别:

网格计算

开发平台:

Java

  1. <%@ page
  2.   contentType="text/html; charset=UTF-8"
  3.   import="javax.servlet.*"
  4.   import="javax.servlet.http.*"
  5.   import="java.io.*"
  6.   import="java.util.*"
  7.   import="org.apache.hadoop.mapred.*"
  8.   import="org.apache.hadoop.util.*"
  9. %>
  10. <%
  11.   JobTracker tracker = (JobTracker) application.getAttribute("job.tracker");
  12.   String trackerName = 
  13.            StringUtils.simpleHostname(tracker.getJobTrackerMachine());
  14. %>
  15. <%! 
  16.   private void printFailedAttempts(JspWriter out,
  17.                                    JobTracker tracker,
  18.                                    JobID jobId,
  19.                                    TaskInProgress tip,
  20.                                    TaskStatus.State failState) throws IOException {
  21.     TaskStatus[] statuses = tip.getTaskStatuses();
  22.     TaskID tipId = tip.getTIPId();
  23.     for(int i=0; i < statuses.length; ++i) {
  24.       TaskStatus.State taskState = statuses[i].getRunState();
  25.       if ((failState == null && (taskState == TaskStatus.State.FAILED || 
  26.           taskState == TaskStatus.State.KILLED)) || taskState == failState) {
  27.         String taskTrackerName = statuses[i].getTaskTracker();
  28.         TaskTrackerStatus taskTracker = tracker.getTaskTracker(taskTrackerName);
  29.         out.print("<tr><td>" + statuses[i].getTaskID() +
  30.                   "</td><td><a href="taskdetails.jsp?jobid="+ jobId + 
  31.                   "&tipid=" + tipId + "">" + tipId +
  32.                   "</a></td>");
  33.         if (taskTracker == null) {
  34.           out.print("<td>" + taskTrackerName + "</td>");
  35.         } else {
  36.           out.print("<td><a href="http://" + taskTracker.getHost() + ":" +
  37.                     taskTracker.getHttpPort() + "">" +  taskTracker.getHost() + 
  38.                     "</a></td>");
  39.         }
  40.         out.print("<td>" + taskState + "</td>");
  41.         out.print("<td><pre>");
  42.         String[] failures = 
  43.                      tracker.getTaskDiagnostics(statuses[i].getTaskID());
  44.         if (failures == null) {
  45.           out.print("&nbsp;");
  46.         } else {
  47.           for(int j = 0 ; j < failures.length ; j++){
  48.             out.print(failures[j]);
  49.             if (j < (failures.length - 1)) {
  50.               out.print("n-------n");
  51.             }
  52.           }
  53.         }
  54.         out.print("</pre></td>");
  55.         
  56.         out.print("<td>");
  57.         String taskLogUrl = null;
  58.         if (taskTracker != null) {
  59.           taskLogUrl = TaskLogServlet.getTaskLogUrl(taskTracker.getHost(),
  60.                                 String.valueOf(taskTracker.getHttpPort()),
  61.                                 statuses[i].getTaskID().toString());
  62.         }
  63.         if (taskLogUrl != null) {
  64.           String tailFourKBUrl = taskLogUrl + "&start=-4097";
  65.           String tailEightKBUrl = taskLogUrl + "&start=-8193";
  66.           String entireLogUrl = taskLogUrl;
  67.           out.print("<a href="" + tailFourKBUrl + "">Last 4KB</a><br/>");
  68.           out.print("<a href="" + tailEightKBUrl + "">Last 8KB</a><br/>");
  69.           out.print("<a href="" + entireLogUrl + "">All</a><br/>");
  70.         } else { 
  71.           out.print("n/a"); // task tracker was lost
  72.         }
  73.         out.print("</td>");
  74.         
  75.         out.print("</tr>n");
  76.        }
  77.     }
  78.   }
  79.              
  80.   private void printFailures(JspWriter out, 
  81.                              JobTracker tracker,
  82.                              JobID jobId,
  83.                              String kind, 
  84.                              String cause) throws IOException {
  85.     JobInProgress job = (JobInProgress) tracker.getJob(jobId);
  86.     if (job == null) {
  87.       out.print("<b>Job " + jobId + " not found.</b><br>n");
  88.       return;
  89.     }
  90.     
  91.     boolean includeMap = false;
  92.     boolean includeReduce = false;
  93.     if (kind == null) {
  94.       includeMap = true;
  95.       includeReduce = true;
  96.     } else if ("map".equals(kind)) {
  97.       includeMap = true;
  98.     } else if ("reduce".equals(kind)) {
  99.       includeReduce = true;
  100.     } else if ("all".equals(kind)) {
  101.       includeMap = true;
  102.       includeReduce = true;
  103.     } else {
  104.       out.print("<b>Kind " + kind + " not supported.</b><br>n");
  105.       return;
  106.     }
  107.     
  108.     TaskStatus.State state = null;
  109.     try {
  110.       if (cause != null) {
  111.         state = TaskStatus.State.valueOf(cause.toUpperCase());
  112.         if (state != TaskStatus.State.FAILED && state != TaskStatus.State.KILLED) {
  113.           out.print("<b>Cause '" + cause + 
  114.               "' is not an 'unsuccessful' state.</b><br>n");
  115.           return;
  116.         }
  117.       }
  118.     } catch (IllegalArgumentException e) {
  119.       out.print("<b>Cause '" + cause + "' not supported.</b><br>n");
  120.       return;
  121.     }
  122.     
  123.     out.print("<table border=2 cellpadding="5" cellspacing="2">");
  124.     out.print("<tr><th>Attempt</th><th>Task</th><th>Machine</th><th>State</th>" +
  125.               "<th>Error</th><th>Logs</th></tr>n");
  126.     if (includeMap) {
  127.       TaskInProgress[] tips = job.getMapTasks();
  128.       for(int i=0; i < tips.length; ++i) {
  129.         printFailedAttempts(out, tracker, jobId, tips[i], state);
  130.       }
  131.     }
  132.     if (includeReduce) {
  133.       TaskInProgress[] tips = job.getReduceTasks();
  134.       for(int i=0; i < tips.length; ++i) {
  135.         printFailedAttempts(out, tracker, jobId, tips[i], state);
  136.       }
  137.     }
  138.     out.print("</table>n");
  139.   }
  140. %>
  141. <%
  142.     String jobId = request.getParameter("jobid");
  143.     if (jobId == null) {
  144.       out.println("<h2>Missing 'jobid'!</h2>");
  145.       return;
  146.     }
  147.     JobID jobIdObj = JobID.forName(jobId);
  148.     String kind = request.getParameter("kind");
  149.     String cause = request.getParameter("cause");
  150. %>
  151. <html>
  152. <title>Hadoop <%=jobId%> failures on <%=trackerName%></title>
  153. <body>
  154. <h1>Hadoop <a href="jobdetails.jsp?jobid=<%=jobId%>"><%=jobId%></a>
  155. failures on <a href="jobtracker.jsp"><%=trackerName%></a></h1>
  156. <% 
  157.     printFailures(out, tracker, jobIdObj, kind, cause); 
  158. %>
  159. <hr>
  160. <a href="jobtracker.jsp">Go back to JobTracker</a><br>
  161. <%
  162. out.println(ServletUtil.htmlFooter());
  163. %>