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

网格计算

开发平台:

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.lang.String"
  7.   import="java.util.*"
  8.   import="org.apache.hadoop.mapred.*"
  9.   import="org.apache.hadoop.util.*"
  10.   import="java.text.SimpleDateFormat"  
  11.   import="org.apache.hadoop.util.*"
  12. %>
  13. <%!static SimpleDateFormat dateFormat = new SimpleDateFormat(
  14.       "d-MMM-yyyy HH:mm:ss");
  15.   private static final String PRIVATE_ACTIONS_KEY = "webinterface.private.actions";%>
  16. <%!private void printConfirm(JspWriter out, String jobid, String tipid,
  17.       String taskid, String action) throws IOException {
  18.     String url = "taskdetails.jsp?jobid=" + jobid + "&tipid=" + tipid
  19.         + "&taskid=" + taskid;
  20.     out.print("<html><head><META http-equiv="refresh" content="15;URL="
  21.         + url + ""></head>" + "<body><h3> Are you sure you want to kill/fail "
  22.         + taskid + " ?<h3><br><table border="0"><tr><td width="100">"
  23.         + "<form action="" + url + "" method="post">"
  24.         + "<input type="hidden" name="action" value="" + action + "" />"
  25.         + "<input type="submit" name="Kill/Fail" value="Kill/Fail" />"
  26.         + "</form>"
  27.         + "</td><td width="100"><form method="post" action="" + url
  28.         + ""><input type="submit" value="Cancel" name="Cancel""
  29.         + "/></form></td></tr></table></body></html>");
  30.   }%>
  31. <%
  32.     JobTracker tracker = (JobTracker) application.getAttribute("job.tracker");
  33.     String jobid = request.getParameter("jobid");
  34.     String tipid = request.getParameter("tipid");
  35.     String taskid = request.getParameter("taskid");
  36.     JobID jobidObj = JobID.forName(jobid);
  37.     TaskID tipidObj = TaskID.forName(tipid);
  38.     TaskAttemptID taskidObj = TaskAttemptID.forName(taskid);
  39.     
  40.     JobInProgress job = (JobInProgress) tracker.getJob(jobidObj);
  41.     
  42.     boolean privateActions = JSPUtil.conf.getBoolean(PRIVATE_ACTIONS_KEY,
  43.         false);
  44.     if (privateActions) {
  45.       String action = request.getParameter("action");
  46.       if (action != null) {
  47.         if (action.equalsIgnoreCase("confirm")) {
  48.           String subAction = request.getParameter("subaction");
  49.           if (subAction == null)
  50.             subAction = "fail-task";
  51.           printConfirm(out, jobid, tipid, taskid, subAction);
  52.           return;
  53.         }
  54.         else if (action.equalsIgnoreCase("kill-task") 
  55.             && request.getMethod().equalsIgnoreCase("POST")) {
  56.           tracker.killTask(taskidObj, false);
  57.           //redirect again so that refreshing the page will not attempt to rekill the task
  58.           response.sendRedirect("/taskdetails.jsp?" + "&subaction=kill-task"
  59.               + "&jobid=" + jobid + "&tipid=" + tipid);
  60.         }
  61.         else if (action.equalsIgnoreCase("fail-task")
  62.             && request.getMethod().equalsIgnoreCase("POST")) {
  63.           tracker.killTask(taskidObj, true);
  64.           response.sendRedirect("/taskdetails.jsp?" + "&subaction=fail-task"
  65.               + "&jobid=" + jobid + "&tipid=" + tipid);
  66.         }
  67.       }
  68.     }
  69.     TaskInProgress tip = null;
  70.     if (job != null && tipidObj != null) {
  71.       tip = job.getTaskInProgress(tipidObj);
  72.     }
  73.     TaskStatus[] ts = null;
  74.     if (tip != null) { 
  75.       ts = tip.getTaskStatuses();
  76.     }
  77.     boolean isCleanupOrSetup = false;
  78.     if ( tip != null) {
  79.       isCleanupOrSetup = tip.isJobCleanupTask();
  80.       if (!isCleanupOrSetup) {
  81.         isCleanupOrSetup = tip.isJobSetupTask();
  82.       }
  83.     }
  84. %>
  85. <html>
  86. <head>
  87.   <link rel="stylesheet" type="text/css" href="/static/hadoop.css">
  88.   <title>Hadoop Task Details</title>
  89. </head>
  90. <body>
  91. <h1>Job <a href="/jobdetails.jsp?jobid=<%=jobid%>"><%=jobid%></a></h1>
  92. <hr>
  93. <h2>All Task Attempts</h2>
  94. <center>
  95. <%
  96.     if (ts == null || ts.length == 0) {
  97. %>
  98. <h3>No Task Attempts found</h3>
  99. <%
  100.     } else {
  101. %>
  102. <table border=2 cellpadding="5" cellspacing="2">
  103. <tr><td align="center">Task Attempts</td><td>Machine</td><td>Status</td><td>Progress</td><td>Start Time</td> 
  104.   <%
  105.    if (!ts[0].getIsMap() && !isCleanupOrSetup) {
  106.    %>
  107. <td>Shuffle Finished</td><td>Sort Finished</td>
  108.   <%
  109.   }
  110.   %>
  111. <td>Finish Time</td><td>Errors</td><td>Task Logs</td><td>Counters</td><td>Actions</td></tr>
  112.   <%
  113.     for (int i = 0; i < ts.length; i++) {
  114.       TaskStatus status = ts[i];
  115.       String taskTrackerName = status.getTaskTracker();
  116.       TaskTrackerStatus taskTracker = tracker.getTaskTracker(taskTrackerName);
  117.       out.print("<tr><td>" + status.getTaskID() + "</td>");
  118.       String taskAttemptTracker = null;
  119.       String cleanupTrackerName = null;
  120.       TaskTrackerStatus cleanupTracker = null;
  121.       String cleanupAttemptTracker = null;
  122.       boolean hasCleanupAttempt = false;
  123.       if (tip != null && tip.isCleanupAttempt(status.getTaskID())) {
  124.         cleanupTrackerName = tip.machineWhereCleanupRan(status.getTaskID());
  125.         cleanupTracker = tracker.getTaskTracker(cleanupTrackerName);
  126.         if (cleanupTracker != null) {
  127.           cleanupAttemptTracker = "http://" + cleanupTracker.getHost() + ":"
  128.             + cleanupTracker.getHttpPort();
  129.         }
  130.         hasCleanupAttempt = true;
  131.       }
  132.       out.print("<td>");
  133.       if (hasCleanupAttempt) {
  134.         out.print("Task attempt: ");
  135.       }
  136.       if (taskTracker == null) {
  137.         out.print(taskTrackerName);
  138.       } else {
  139.         taskAttemptTracker = "http://" + taskTracker.getHost() + ":"
  140.           + taskTracker.getHttpPort();
  141.         out.print("<a href="" + taskAttemptTracker + "">"
  142.           + tracker.getNode(taskTracker.getHost()) + "</a>");
  143.       }
  144.       if (hasCleanupAttempt) {
  145.         out.print("<br/>Cleanup Attempt: ");
  146.         if (cleanupAttemptTracker == null ) {
  147.           out.print(cleanupTrackerName);
  148.         } else {
  149.           out.print("<a href="" + cleanupAttemptTracker + "">"
  150.             + tracker.getNode(cleanupTracker.getHost()) + "</a>");
  151.         }
  152.       }
  153.       out.print("</td>");
  154.         out.print("<td>" + status.getRunState() + "</td>");
  155.         out.print("<td>" + StringUtils.formatPercent(status.getProgress(), 2)
  156.           + ServletUtil.percentageGraph(status.getProgress() * 100f, 80) + "</td>");
  157.         out.print("<td>"
  158.           + StringUtils.getFormattedTimeWithDiff(dateFormat, status
  159.           .getStartTime(), 0) + "</td>");
  160.         if (!ts[i].getIsMap() && !isCleanupOrSetup) {
  161.           out.print("<td>"
  162.           + StringUtils.getFormattedTimeWithDiff(dateFormat, status
  163.           .getShuffleFinishTime(), status.getStartTime()) + "</td>");
  164.         out.println("<td>"
  165.           + StringUtils.getFormattedTimeWithDiff(dateFormat, status
  166.           .getSortFinishTime(), status.getShuffleFinishTime())
  167.           + "</td>");
  168.         }
  169.         out.println("<td>"
  170.           + StringUtils.getFormattedTimeWithDiff(dateFormat, status
  171.           .getFinishTime(), status.getStartTime()) + "</td>");
  172.         out.print("<td><pre>");
  173.         String [] failures = tracker.getTaskDiagnostics(status.getTaskID());
  174.         if (failures == null) {
  175.           out.print("&nbsp;");
  176.         } else {
  177.           for(int j = 0 ; j < failures.length ; j++){
  178.             out.print(failures[j]);
  179.             if (j < (failures.length - 1)) {
  180.               out.print("n-------n");
  181.             }
  182.           }
  183.         }
  184.         out.print("</pre></td>");
  185.         out.print("<td>");
  186.         String taskLogUrl = null;
  187.         if (taskTracker != null ) {
  188.          taskLogUrl = TaskLogServlet.getTaskLogUrl(taskTracker.getHost(),
  189.          String.valueOf(taskTracker.getHttpPort()),
  190.          status.getTaskID().toString());
  191.        }
  192.         if (hasCleanupAttempt) {
  193.           out.print("Task attempt: <br/>");
  194.         }
  195.         if (taskLogUrl == null) {
  196.           out.print("n/a");
  197.         } else {
  198.           String tailFourKBUrl = taskLogUrl + "&start=-4097";
  199.           String tailEightKBUrl = taskLogUrl + "&start=-8193";
  200.           String entireLogUrl = taskLogUrl + "&all=true";
  201.           out.print("<a href="" + tailFourKBUrl + "">Last 4KB</a><br/>");
  202.           out.print("<a href="" + tailEightKBUrl + "">Last 8KB</a><br/>");
  203.           out.print("<a href="" + entireLogUrl + "">All</a><br/>");
  204.         }
  205.         if (hasCleanupAttempt) {
  206.           out.print("Cleanup attempt: <br/>");
  207.           taskLogUrl = null;
  208.           if (cleanupTracker != null ) {
  209.          taskLogUrl = TaskLogServlet.getTaskLogUrl(cleanupTracker.getHost(),
  210.                                 String.valueOf(cleanupTracker.getHttpPort()),
  211.                                 status.getTaskID().toString());
  212.          }
  213.           if (taskLogUrl == null) {
  214.             out.print("n/a");
  215.           } else {
  216.             String tailFourKBUrl = taskLogUrl + "&start=-4097&cleanup=true";
  217.             String tailEightKBUrl = taskLogUrl + "&start=-8193&cleanup=true";
  218.             String entireLogUrl = taskLogUrl + "&all=true&cleanup=true";
  219.             out.print("<a href="" + tailFourKBUrl + "">Last 4KB</a><br/>");
  220.             out.print("<a href="" + tailEightKBUrl + "">Last 8KB</a><br/>");
  221.             out.print("<a href="" + entireLogUrl + "">All</a><br/>");
  222.           }
  223.         }
  224.         out.print("</td><td>" + "<a href="/taskstats.jsp?jobid=" + jobid
  225.           + "&tipid=" + tipid + "&taskid=" + status.getTaskID() + "">"
  226.           + ((status.getCounters() != null) ? status.getCounters().size() : 0) + "</a></td>");
  227.         out.print("<td>");
  228.         if (privateActions
  229.           && status.getRunState() == TaskStatus.State.RUNNING) {
  230.         out.print("<a href="/taskdetails.jsp?action=confirm"
  231.           + "&subaction=kill-task" + "&jobid=" + jobid + "&tipid="
  232.           + tipid + "&taskid=" + status.getTaskID() + "" > Kill </a>");
  233.         out.print("<br><a href="/taskdetails.jsp?action=confirm"
  234.           + "&subaction=fail-task" + "&jobid=" + jobid + "&tipid="
  235.           + tipid + "&taskid=" + status.getTaskID() + "" > Fail </a>");
  236.         }
  237.         else
  238.           out.print("<pre>&nbsp;</pre>");
  239.         out.println("</td></tr>");
  240.       }
  241.   %>
  242. </table>
  243. </center>
  244. <%
  245.       if (ts[0].getIsMap()) {
  246. %>
  247. <h3>Input Split Locations</h3>
  248. <table border=2 cellpadding="5" cellspacing="2">
  249. <%
  250.         for (String split: StringUtils.split(tracker.getTip(
  251.                                          tipidObj).getSplitNodes())) {
  252.           out.println("<tr><td>" + split + "</td></tr>");
  253.         }
  254. %>
  255. </table>
  256. <%    
  257.       }
  258.     }
  259. %>
  260. <hr>
  261. <a href="jobdetails.jsp?jobid=<%=jobid%>">Go back to the job</a><br>
  262. <a href="jobtracker.jsp">Go back to JobTracker</a><br>
  263. <%
  264. out.println(ServletUtil.htmlFooter());
  265. %>