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

网格计算

开发平台:

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="java.text.DecimalFormat"
  8.   import="org.apache.hadoop.mapred.*"
  9.   import="org.apache.hadoop.util.*"
  10. %>
  11. <%
  12.   JobTracker tracker = (JobTracker) application.getAttribute("job.tracker");
  13.   String trackerName = 
  14.            StringUtils.simpleHostname(tracker.getJobTrackerMachine());
  15.   String type = request.getParameter("type");
  16. %>
  17. <%!
  18.   public void generateTaskTrackerTable(JspWriter out,
  19.                                        String type,
  20.                                        JobTracker tracker) throws IOException {
  21.     Collection c;
  22.     if (("blacklisted").equals(type)) {
  23.       c = tracker.blacklistedTaskTrackers();
  24.     } else if (("active").equals(type)) {
  25.       c = tracker.activeTaskTrackers();
  26.     } else {
  27.       c = tracker.taskTrackers();
  28.     }
  29.     if (c.size() == 0) {
  30.       out.print("There are currently no known " + type + " Task Trackers.");
  31.     } else {
  32.       out.print("<center>n");
  33.       out.print("<table border="2" cellpadding="5" cellspacing="2">n");
  34.       out.print("<tr><td align="center" colspan="6"><b>Task Trackers</b></td></tr>n");
  35.       out.print("<tr><td><b>Name</b></td><td><b>Host</b></td>" +
  36.                 "<td><b># running tasks</b></td>" +
  37.                 "<td><b>Max Map Tasks</b></td>" +
  38.                 "<td><b>Max Reduce Tasks</b></td>" +
  39.                 "<td><b>Failures</b></td>" +
  40.                 "<td><b>Seconds since heartbeat</b></td></tr>n");
  41.       int maxFailures = 0;
  42.       String failureKing = null;
  43.       for (Iterator it = c.iterator(); it.hasNext(); ) {
  44.         TaskTrackerStatus tt = (TaskTrackerStatus) it.next();
  45.         long sinceHeartbeat = System.currentTimeMillis() - tt.getLastSeen();
  46.         if (sinceHeartbeat > 0) {
  47.           sinceHeartbeat = sinceHeartbeat / 1000;
  48.         }
  49.         int numCurTasks = 0;
  50.         for (Iterator it2 = tt.getTaskReports().iterator(); it2.hasNext(); ) {
  51.           it2.next();
  52.           numCurTasks++;
  53.         }
  54.         int numFailures = tt.getFailures();
  55.         if (numFailures > maxFailures) {
  56.           maxFailures = numFailures;
  57.           failureKing = tt.getTrackerName();
  58.         }
  59.         out.print("<tr><td><a href="http://");
  60.         out.print(tt.getHost() + ":" + tt.getHttpPort() + "/">");
  61.         out.print(tt.getTrackerName() + "</a></td><td>");
  62.         out.print(tt.getHost() + "</td><td>" + numCurTasks +
  63.                   "</td><td>" + tt.getMaxMapTasks() +
  64.                   "</td><td>" + tt.getMaxReduceTasks() + 
  65.                   "</td><td>" + numFailures + 
  66.                   "</td><td>" + sinceHeartbeat + "</td></tr>n");
  67.       }
  68.       out.print("</table>n");
  69.       out.print("</center>n");
  70.       if (maxFailures > 0) {
  71.         out.print("Highest Failures: " + failureKing + " with " + maxFailures + 
  72.                   " failures<br>n");
  73.       }
  74.     }
  75.   }
  76. %>
  77. <html>
  78. <title><%=trackerName%> Hadoop Machine List</title>
  79. <body>
  80. <h1><a href="jobtracker.jsp"><%=trackerName%></a> Hadoop Machine List</h1>
  81. <h2>Task Trackers</h2>
  82. <%
  83.   generateTaskTrackerTable(out, type, tracker);
  84. %>
  85. <%
  86. out.println(ServletUtil.htmlFooter());
  87. %>