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

网格计算

开发平台:

Java

  1. <%@ page
  2.   contentType="text/html; charset=UTF-8"
  3.   import="java.io.*"
  4.   import="java.util.*"
  5.   import="org.apache.hadoop.mapred.*"
  6.   import="org.apache.hadoop.util.*"
  7.   import="org.apache.hadoop.fs.*"
  8.   import="javax.servlet.jsp.*"
  9.   import="java.text.SimpleDateFormat"
  10.   import="org.apache.hadoop.mapred.*"
  11.   import="org.apache.hadoop.mapred.JobHistory.*"
  12. %>
  13. <%!
  14.   private static SimpleDateFormat dateFormat = 
  15.                                     new SimpleDateFormat("d/MM HH:mm:ss");
  16. %>
  17. <html>
  18. <head>
  19. <title>Hadoop Map/Reduce Administration</title>
  20. <link rel="stylesheet" type="text/css" href="/static/hadoop.css">
  21. </head>
  22. <body>
  23. <h1>Hadoop Map/Reduce History Viewer</h1>
  24. <hr>
  25. <h2>Available History </h2>
  26. <%
  27.     PathFilter jobLogFileFilter = new PathFilter() {
  28.       public boolean accept(Path path) {
  29.         return !(path.getName().endsWith(".xml"));
  30.       }
  31.     };
  32.     
  33.     FileSystem fs = (FileSystem) application.getAttribute("fileSys");
  34.     String historyLogDir = (String) application.getAttribute("historyLogDir");
  35.     if (fs == null) {
  36.       out.println("Null file system. May be namenode is in safemode!");
  37.       return;
  38.     }
  39.     Path[] jobFiles = FileUtil.stat2Paths(fs.listStatus(new Path(historyLogDir),
  40.                                           jobLogFileFilter));
  41.     if (null == jobFiles )  {
  42.       out.println("NULL files !!!"); 
  43.       return ; 
  44.     }
  45.     // sort the files on creation time.
  46.     Arrays.sort(jobFiles, new Comparator<Path>() {
  47.       public int compare(Path p1, Path p2) {
  48.         String dp1 = null;
  49.         String dp2 = null;
  50.         
  51.         try {
  52.           dp1 = JobHistory.JobInfo.decodeJobHistoryFileName(p1.getName());
  53.           dp2 = JobHistory.JobInfo.decodeJobHistoryFileName(p2.getName());
  54.         } catch (IOException ioe) {
  55.             throw new RuntimeException(ioe);
  56.         }
  57.                 
  58.         String[] split1 = dp1.split("_");
  59.         String[] split2 = dp2.split("_");
  60.         
  61.         // compare job tracker start time
  62.         int res = new Date(Long.parseLong(split1[1])).compareTo(
  63.                              new Date(Long.parseLong(split2[1])));
  64.         if (res == 0) {
  65.           res = new Date(Long.parseLong(split1[3])).compareTo(
  66.                            new Date(Long.parseLong(split2[3])));
  67.         }
  68.         if (res == 0) {
  69.           Long l1 = Long.parseLong(split1[4]);
  70.           res = l1.compareTo(Long.parseLong(split2[4]));
  71.         }
  72.         return res;
  73.       }
  74.     });
  75.     out.print("<table align=center border=2 cellpadding="5" cellspacing="2">");
  76.     out.print("<tr><td align="center" colspan="9"><b>Available Jobs </b></td></tr>n");
  77.     out.print("<tr>");
  78.     out.print("<td>Job tracker Host Name</td>" +
  79.               "<td>Job tracker Start time</td>" +
  80.               "<td>Job Id</td><td>Name</td><td>User</td>") ; 
  81.     out.print("</tr>"); 
  82.     
  83.     Set<String> displayedJobs = new HashSet<String>();
  84.     for (Path jobFile: jobFiles) {
  85.       String decodedJobFileName = 
  86.           JobHistory.JobInfo.decodeJobHistoryFileName(jobFile.getName());
  87.       String[] jobDetails = decodedJobFileName.split("_");
  88.       String trackerHostName = jobDetails[0];
  89.       String trackerStartTime = jobDetails[1];
  90.       String jobId = jobDetails[2] + "_" +jobDetails[3] + "_" + jobDetails[4] ;
  91.       String user = jobDetails[5];
  92.       String jobName = jobDetails[6];
  93.       
  94.       // Check if the job is already displayed. There can be multiple job 
  95.       // history files for jobs that have restarted
  96.       if (displayedJobs.contains(jobId)) {
  97.         continue;
  98.       } else {
  99.         displayedJobs.add(jobId);
  100.       }
  101.       
  102.       // Encode the logfile name again to cancel the decoding done by the browser
  103.       String encodedJobFileName = 
  104.           JobHistory.JobInfo.encodeJobHistoryFileName(jobFile.getName());
  105. %>
  106. <center>
  107. <%
  108.       printJob(trackerHostName, trackerStartTime, jobId,
  109.                jobName, user, new Path(jobFile.getParent(), encodedJobFileName), 
  110.                out) ; 
  111. %>
  112. </center> 
  113. <%
  114.     } // end while trackers 
  115. %>
  116. <%!
  117.     private void printJob(String trackerHostName, String trackerid,
  118.                           String jobId, String jobName,
  119.                           String user, Path logFile, JspWriter out)
  120.     throws IOException {
  121.       out.print("<tr>"); 
  122.       out.print("<td>" + trackerHostName + "</td>"); 
  123.       out.print("<td>" + new Date(Long.parseLong(trackerid)) + "</td>"); 
  124.       out.print("<td>" + "<a href="jobdetailshistory.jsp?jobid=" + jobId + 
  125.                 "&logFile=" + logFile.toString() + "">" + jobId + "</a></td>"); 
  126.       out.print("<td>" + jobName + "</td>"); 
  127.       out.print("<td>" + user + "</td>"); 
  128.       out.print("</tr>");
  129.     }
  130. %> 
  131. </body></html>