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

网格计算

开发平台:

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.text.*"
  7.   import="java.util.*"
  8.   import="java.text.DecimalFormat"
  9.   import="org.apache.hadoop.mapred.*"
  10.   import="org.apache.hadoop.util.*"
  11. %>
  12. <%
  13.   JobTracker tracker = (JobTracker) application.getAttribute("job.tracker");
  14.   String trackerName = 
  15.            StringUtils.simpleHostname(tracker.getJobTrackerMachine());
  16. %>
  17. <%!
  18.   private static final String PRIVATE_ACTIONS_KEY 
  19. = "webinterface.private.actions";
  20.  
  21.   private void printTaskSummary(JspWriter out,
  22.                                 String jobId,
  23.                                 String kind,
  24.                                 double completePercent,
  25.                                 TaskInProgress[] tasks
  26.                                ) throws IOException {
  27.     int totalTasks = tasks.length;
  28.     int runningTasks = 0;
  29.     int finishedTasks = 0;
  30.     int killedTasks = 0;
  31.     int failedTaskAttempts = 0;
  32.     int killedTaskAttempts = 0;
  33.     for(int i=0; i < totalTasks; ++i) {
  34.       TaskInProgress task = tasks[i];
  35.       if (task.isComplete()) {
  36.         finishedTasks += 1;
  37.       } else if (task.isRunning()) {
  38.         runningTasks += 1;
  39.       } else if (task.wasKilled()) {
  40.         killedTasks += 1;
  41.       }
  42.       failedTaskAttempts += task.numTaskFailures();
  43.       killedTaskAttempts += task.numKilledTasks();
  44.     }
  45.     int pendingTasks = totalTasks - runningTasks - killedTasks - finishedTasks; 
  46.     out.print("<tr><th><a href="jobtasks.jsp?jobid=" + jobId + 
  47.               "&type="+ kind + "&pagenum=1">" + kind + 
  48.               "</a></th><td align="right">" + 
  49.               StringUtils.formatPercent(completePercent, 2) +
  50.               ServletUtil.percentageGraph((int)(completePercent * 100), 80) +
  51.               "</td><td align="right">" + 
  52.               totalTasks + 
  53.               "</td><td align="right">" + 
  54.               ((pendingTasks > 0) 
  55.                ? "<a href="jobtasks.jsp?jobid=" + jobId + "&type="+ kind + 
  56.                  "&pagenum=1" + "&state=pending">" + pendingTasks + "</a>"
  57.                : "0") + 
  58.               "</td><td align="right">" + 
  59.               ((runningTasks > 0) 
  60.                ? "<a href="jobtasks.jsp?jobid=" + jobId + "&type="+ kind + 
  61.                  "&pagenum=1" + "&state=running">" + runningTasks + "</a>" 
  62.                : "0") + 
  63.               "</td><td align="right">" + 
  64.               ((finishedTasks > 0) 
  65.                ?"<a href="jobtasks.jsp?jobid=" + jobId + "&type="+ kind + 
  66.                 "&pagenum=1" + "&state=completed">" + finishedTasks + "</a>" 
  67.                : "0") + 
  68.               "</td><td align="right">" + 
  69.               ((killedTasks > 0) 
  70.                ?"<a href="jobtasks.jsp?jobid=" + jobId + "&type="+ kind +
  71.                 "&pagenum=1" + "&state=killed">" + killedTasks + "</a>"
  72.                : "0") + 
  73.               "</td><td align="right">" + 
  74.               ((failedTaskAttempts > 0) ? 
  75.                   ("<a href="jobfailures.jsp?jobid=" + jobId + 
  76.                    "&kind=" + kind + "&cause=failed">" + failedTaskAttempts + 
  77.                    "</a>") : 
  78.                   "0"
  79.                   ) + 
  80.               " / " +
  81.               ((killedTaskAttempts > 0) ? 
  82.                   ("<a href="jobfailures.jsp?jobid=" + jobId + 
  83.                    "&kind=" + kind + "&cause=killed">" + killedTaskAttempts + 
  84.                    "</a>") : 
  85.                   "0"
  86.                   ) + 
  87.               "</td></tr>n");
  88.   }
  89.   private void printJobLevelTaskSummary(JspWriter out,
  90.                                 String jobId,
  91.                                 String kind,
  92.                                 TaskInProgress[] tasks
  93.                                ) throws IOException {
  94.     int totalTasks = tasks.length;
  95.     int runningTasks = 0;
  96.     int finishedTasks = 0;
  97.     int killedTasks = 0;
  98.     for(int i=0; i < totalTasks; ++i) {
  99.       TaskInProgress task = tasks[i];
  100.       if (task.isComplete()) {
  101.         finishedTasks += 1;
  102.       } else if (task.isRunning()) {
  103.         runningTasks += 1;
  104.       } else if (task.isFailed()) {
  105.         killedTasks += 1;
  106.       }
  107.     }
  108.     int pendingTasks = totalTasks - runningTasks - killedTasks - finishedTasks; 
  109.     out.print(((runningTasks > 0)  
  110.                ? "<a href="jobtasks.jsp?jobid=" + jobId + "&type="+ kind + 
  111.                  "&pagenum=1" + "&state=running">" + " Running" + 
  112.                  "</a>" 
  113.                : ((pendingTasks > 0) ? " Pending" :
  114.                  ((finishedTasks > 0) 
  115.                ?"<a href="jobtasks.jsp?jobid=" + jobId + "&type="+ kind + 
  116.                 "&pagenum=1" + "&state=completed">" + " Successful"
  117.                  + "</a>" 
  118.                : ((killedTasks > 0) 
  119.                ?"<a href="jobtasks.jsp?jobid=" + jobId + "&type="+ kind +
  120.                 "&pagenum=1" + "&state=killed">" + " Failed" 
  121.                 + "</a>" : "None")))));
  122.   }
  123.   
  124.   private void printConfirm(JspWriter out, String jobId) throws IOException{
  125.     String url = "jobdetails.jsp?jobid=" + jobId;
  126.     out.print("<html><head><META http-equiv="refresh" content="15;URL="
  127.         + url+""></head>"
  128.         + "<body><h3> Are you sure you want to kill " + jobId
  129.         + " ?<h3><br><table border="0"><tr><td width="100">"
  130.         + "<form action="" + url + "" method="post">"
  131.         + "<input type="hidden" name="action" value="kill" />"
  132.         + "<input type="submit" name="kill" value="Kill" />"
  133.         + "</form>"
  134.         + "</td><td width="100"><form method="post" action="" + url
  135.         + ""><input type="submit" value="Cancel" name="Cancel""
  136.         + "/></form></td></tr></table></body></html>");
  137.   }
  138.   
  139. %>       
  140. <%   
  141.     String jobId = request.getParameter("jobid"); 
  142.     String refreshParam = request.getParameter("refresh");
  143.     if (jobId == null) {
  144.       out.println("<h2>Missing 'jobid'!</h2>");
  145.       return;
  146.     }
  147.     
  148.     int refresh = 60; // refresh every 60 seconds by default
  149.     if (refreshParam != null) {
  150.         try {
  151.             refresh = Integer.parseInt(refreshParam);
  152.         }
  153.         catch (NumberFormatException ignored) {
  154.         }
  155.     }
  156.     JobID jobIdObj = JobID.forName(jobId);
  157.     JobInProgress job = (JobInProgress) tracker.getJob(jobIdObj);
  158.     
  159.     String action = request.getParameter("action");
  160.     if(JSPUtil.conf.getBoolean(PRIVATE_ACTIONS_KEY, false) && 
  161.         "changeprio".equalsIgnoreCase(action) 
  162.         && request.getMethod().equalsIgnoreCase("POST")) {
  163.       tracker.setJobPriority(jobIdObj, 
  164.                              JobPriority.valueOf(request.getParameter("prio")));
  165.     }
  166.     
  167.     if(JSPUtil.conf.getBoolean(PRIVATE_ACTIONS_KEY, false)) {
  168.         action = request.getParameter("action");
  169.     if(action!=null && action.equalsIgnoreCase("confirm")) {
  170.          printConfirm(out, jobId);
  171.          return;
  172.     }
  173.        else if(action != null && action.equalsIgnoreCase("kill") && 
  174.            request.getMethod().equalsIgnoreCase("POST")) {
  175.       tracker.killJob(jobIdObj);
  176.     }
  177.     }
  178. %>
  179. <%@page import="org.apache.hadoop.mapred.TaskGraphServlet"%>
  180. <html>
  181. <head>
  182.   <% 
  183.   if (refresh != 0) {
  184.       %>
  185.       <meta http-equiv="refresh" content="<%=refresh%>">
  186.       <%
  187.   }
  188.   %>
  189. <title>Hadoop <%=jobId%> on <%=trackerName%></title>
  190. <link rel="stylesheet" type="text/css" href="/static/hadoop.css">
  191. </head>
  192. <body>
  193. <h1>Hadoop <%=jobId%> on <a href="jobtracker.jsp"><%=trackerName%></a></h1>
  194. <% 
  195.     if (job == null) {
  196.       out.print("<b>Job " + jobId + " not found.</b><br>n");
  197.       return;
  198.     }
  199.     JobProfile profile = job.getProfile();
  200.     JobStatus status = job.getStatus();
  201.     int runState = status.getRunState();
  202.     int flakyTaskTrackers = job.getNoOfBlackListedTrackers();
  203.     out.print("<b>User:</b> " + profile.getUser() + "<br>n");
  204.     out.print("<b>Job Name:</b> " + profile.getJobName() + "<br>n");
  205.     out.print("<b>Job File:</b> <a href="jobconf.jsp?jobid=" + jobId + "">" 
  206.               + profile.getJobFile() + "</a><br>n");
  207.     out.print("<b>Job Setup:</b>");
  208.     printJobLevelTaskSummary(out, jobId, "setup", job.getSetupTasks());
  209.     out.print("<br>n");
  210.     if (runState == JobStatus.RUNNING) {
  211.       out.print("<b>Status:</b> Running<br>n");
  212.       out.print("<b>Started at:</b> " + new Date(job.getStartTime()) + "<br>n");
  213.       out.print("<b>Running for:</b> " + StringUtils.formatTimeDiff(
  214.           System.currentTimeMillis(), job.getStartTime()) + "<br>n");
  215.     } else {
  216.       if (runState == JobStatus.SUCCEEDED) {
  217.         out.print("<b>Status:</b> Succeeded<br>n");
  218.         out.print("<b>Started at:</b> " + new Date(job.getStartTime()) + "<br>n");
  219.         out.print("<b>Finished at:</b> " + new Date(job.getFinishTime()) +
  220.                   "<br>n");
  221.         out.print("<b>Finished in:</b> " + StringUtils.formatTimeDiff(
  222.             job.getFinishTime(), job.getStartTime()) + "<br>n");
  223.       } else if (runState == JobStatus.FAILED) {
  224.         out.print("<b>Status:</b> Failed<br>n");
  225.         out.print("<b>Started at:</b> " + new Date(job.getStartTime()) + "<br>n");
  226.         out.print("<b>Failed at:</b> " + new Date(job.getFinishTime()) +
  227.                   "<br>n");
  228.         out.print("<b>Failed in:</b> " + StringUtils.formatTimeDiff(
  229.             job.getFinishTime(), job.getStartTime()) + "<br>n");
  230.       } else if (runState == JobStatus.KILLED) {
  231.         out.print("<b>Status:</b> Killed<br>n");
  232.         out.print("<b>Started at:</b> " + new Date(job.getStartTime()) + "<br>n");
  233.         out.print("<b>Killed at:</b> " + new Date(job.getFinishTime()) +
  234.                   "<br>n");
  235.         out.print("<b>Killed in:</b> " + StringUtils.formatTimeDiff(
  236.             job.getFinishTime(), job.getStartTime()) + "<br>n");
  237.       }
  238.     }
  239.     out.print("<b>Job Cleanup:</b>");
  240.     printJobLevelTaskSummary(out, jobId, "cleanup", job.getCleanupTasks());
  241.     out.print("<br>n");
  242.     if (flakyTaskTrackers > 0) {
  243.       out.print("<b>Black-listed TaskTrackers:</b> " + 
  244.           "<a href="jobblacklistedtrackers.jsp?jobid=" + jobId + "">" +
  245.           flakyTaskTrackers + "</a><br>n");
  246.     }
  247.     out.print("<hr>n");
  248.     out.print("<table border=2 cellpadding="5" cellspacing="2">");
  249.     out.print("<tr><th>Kind</th><th>% Complete</th><th>Num Tasks</th>" +
  250.               "<th>Pending</th><th>Running</th><th>Complete</th>" +
  251.               "<th>Killed</th>" +
  252.               "<th><a href="jobfailures.jsp?jobid=" + jobId + 
  253.               "">Failed/Killed<br>Task Attempts</a></th></tr>n");
  254.     printTaskSummary(out, jobId, "map", status.mapProgress(), 
  255.                      job.getMapTasks());
  256.     printTaskSummary(out, jobId, "reduce", status.reduceProgress(),
  257.                      job.getReduceTasks());
  258.     out.print("</table>n");
  259.     
  260.     %>
  261.     <p/>
  262.     <table border=2 cellpadding="5" cellspacing="2">
  263.     <tr>
  264.       <th><br/></th>
  265.       <th>Counter</th>
  266.       <th>Map</th>
  267.       <th>Reduce</th>
  268.       <th>Total</th>
  269.     </tr>
  270.     <%
  271.     Counters mapCounters = job.getMapCounters();
  272.     Counters reduceCounters = job.getReduceCounters();
  273.     Counters totalCounters = job.getCounters();
  274.     
  275.     for (String groupName : totalCounters.getGroupNames()) {
  276.       Counters.Group totalGroup = totalCounters.getGroup(groupName);
  277.       Counters.Group mapGroup = mapCounters.getGroup(groupName);
  278.       Counters.Group reduceGroup = reduceCounters.getGroup(groupName);
  279.       
  280.       Format decimal = new DecimalFormat();
  281.       
  282.       boolean isFirst = true;
  283.       for (Counters.Counter counter : totalGroup) {
  284.         String name = counter.getDisplayName();
  285.         String mapValue = decimal.format(mapGroup.getCounter(name));
  286.         String reduceValue = decimal.format(reduceGroup.getCounter(name));
  287.         String totalValue = decimal.format(counter.getCounter());
  288.         %>
  289.         <tr>
  290.           <%
  291.           if (isFirst) {
  292.             isFirst = false;
  293.             %>
  294.             <td rowspan="<%=totalGroup.size()%>"><%=totalGroup.getDisplayName()%></td>
  295.             <%
  296.           }
  297.           %>
  298.           <td><%=name%></td>
  299.           <td align="right"><%=mapValue%></td>
  300.           <td align="right"><%=reduceValue%></td>
  301.           <td align="right"><%=totalValue%></td>
  302.         </tr>
  303.         <%
  304.       }
  305.     }
  306.     %>
  307.     </table>
  308. <hr>Map Completion Graph - 
  309. <%
  310. if("off".equals(request.getParameter("map.graph"))) {
  311.   session.setAttribute("map.graph", "off");
  312. } else if("on".equals(request.getParameter("map.graph"))){
  313.   session.setAttribute("map.graph", "on");
  314. }
  315. if("off".equals(request.getParameter("reduce.graph"))) {
  316.   session.setAttribute("reduce.graph", "off");
  317. } else if("on".equals(request.getParameter("reduce.graph"))){
  318.   session.setAttribute("reduce.graph", "on");
  319. }
  320. if("off".equals(session.getAttribute("map.graph"))) { %>
  321. <a href="/jobdetails.jsp?jobid=<%=jobId%>&refresh=<%=refresh%>&map.graph=on" > open </a>
  322. <%} else { %> 
  323. <a href="/jobdetails.jsp?jobid=<%=jobId%>&refresh=<%=refresh%>&map.graph=off" > close </a>
  324. <br><embed src="/taskgraph?type=map&jobid=<%=jobId%>" 
  325.        width="<%=TaskGraphServlet.width + 2 * TaskGraphServlet.xmargin%>" 
  326.        height="<%=TaskGraphServlet.height + 3 * TaskGraphServlet.ymargin%>"
  327.        style="width:100%" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" />
  328. <%}%>
  329. <%if(job.getReduceTasks().length > 0) { %>
  330. <hr>Reduce Completion Graph -
  331. <%if("off".equals(session.getAttribute("reduce.graph"))) { %>
  332. <a href="/jobdetails.jsp?jobid=<%=jobId%>&refresh=<%=refresh%>&reduce.graph=on" > open </a>
  333. <%} else { %> 
  334. <a href="/jobdetails.jsp?jobid=<%=jobId%>&refresh=<%=refresh%>&reduce.graph=off" > close </a>
  335.  
  336.  <br><embed src="/taskgraph?type=reduce&jobid=<%=jobId%>" 
  337.        width="<%=TaskGraphServlet.width + 2 * TaskGraphServlet.xmargin%>" 
  338.        height="<%=TaskGraphServlet.height + 3 * TaskGraphServlet.ymargin%>" 
  339.        style="width:100%" type="image/svg+xml" pluginspage="http://www.adobe.com/svg/viewer/install/" />
  340. <%} }%>
  341. <hr>
  342. <% if(JSPUtil.conf.getBoolean(PRIVATE_ACTIONS_KEY, false)) { %>
  343.   <table border="0"> <tr> <td>
  344.   Change priority from <%=job.getPriority()%> to:
  345.   <form action="jobdetails.jsp" method="post">
  346.   <input type="hidden" name="action" value="changeprio"/>
  347.   <input type="hidden" name="jobid" value="<%=jobId%>"/>
  348.   </td><td> <select name="prio"> 
  349.   <%
  350.     JobPriority jobPrio = job.getPriority();
  351.     for (JobPriority prio : JobPriority.values()) {
  352.       if(jobPrio != prio) {
  353.         %> <option value=<%=prio%>><%=prio%></option> <%
  354.       }
  355.     }
  356.   %>
  357.   </select> </td><td><input type="submit" value="Submit"> </form></td></tr> </table>
  358. <% } %>
  359. <table border="0"> <tr>
  360.     
  361. <% if(JSPUtil.conf.getBoolean(PRIVATE_ACTIONS_KEY, false) 
  362.      && runState == JobStatus.RUNNING) { %>
  363. <br/><a href="jobdetails.jsp?action=confirm&jobid=<%=jobId%>"> Kill this job </a>
  364. <% } %>
  365. <hr>
  366. <hr>
  367. <a href="jobtracker.jsp">Go back to JobTracker</a><br>
  368. <%
  369. out.println(ServletUtil.htmlFooter());
  370. %>