source: proiecte/HadoopJUnit/hadoop-0.20.1/src/webapps/job/jobhistory.jsp @ 155

Last change on this file since 155 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 4.6 KB
Line 
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
46    // sort the files on creation time.
47    Arrays.sort(jobFiles, new Comparator<Path>() {
48      public int compare(Path p1, Path p2) {
49        String dp1 = null;
50        String dp2 = null;
51       
52        try {
53          dp1 = JobHistory.JobInfo.decodeJobHistoryFileName(p1.getName());
54          dp2 = JobHistory.JobInfo.decodeJobHistoryFileName(p2.getName());
55        } catch (IOException ioe) {
56            throw new RuntimeException(ioe);
57        }
58               
59        String[] split1 = dp1.split("_");
60        String[] split2 = dp2.split("_");
61       
62        // compare job tracker start time
63        int res = new Date(Long.parseLong(split1[1])).compareTo(
64                             new Date(Long.parseLong(split2[1])));
65        if (res == 0) {
66          res = new Date(Long.parseLong(split1[3])).compareTo(
67                           new Date(Long.parseLong(split2[3])));
68        }
69        if (res == 0) {
70          Long l1 = Long.parseLong(split1[4]);
71          res = l1.compareTo(Long.parseLong(split2[4]));
72        }
73        return res;
74      }
75    });
76
77    out.print("<table align=center border=2 cellpadding=\"5\" cellspacing=\"2\">");
78    out.print("<tr><td align=\"center\" colspan=\"9\"><b>Available Jobs </b></td></tr>\n");
79    out.print("<tr>");
80    out.print("<td>Job tracker Host Name</td>" +
81              "<td>Job tracker Start time</td>" +
82              "<td>Job Id</td><td>Name</td><td>User</td>") ; 
83    out.print("</tr>"); 
84   
85    Set<String> displayedJobs = new HashSet<String>();
86    for (Path jobFile: jobFiles) {
87      String decodedJobFileName = 
88          JobHistory.JobInfo.decodeJobHistoryFileName(jobFile.getName());
89
90      String[] jobDetails = decodedJobFileName.split("_");
91      String trackerHostName = jobDetails[0];
92      String trackerStartTime = jobDetails[1];
93      String jobId = jobDetails[2] + "_" +jobDetails[3] + "_" + jobDetails[4] ;
94      String user = jobDetails[5];
95      String jobName = jobDetails[6];
96     
97      // Check if the job is already displayed. There can be multiple job
98      // history files for jobs that have restarted
99      if (displayedJobs.contains(jobId)) {
100        continue;
101      } else {
102        displayedJobs.add(jobId);
103      }
104     
105      // Encode the logfile name again to cancel the decoding done by the browser
106      String encodedJobFileName = 
107          JobHistory.JobInfo.encodeJobHistoryFileName(jobFile.getName());
108%>
109<center>
110<%     
111      printJob(trackerHostName, trackerStartTime, jobId,
112               jobName, user, new Path(jobFile.getParent(), encodedJobFileName), 
113               out) ; 
114%>
115</center> 
116<%
117    } // end while trackers
118%>
119<%!
120    private void printJob(String trackerHostName, String trackerid,
121                          String jobId, String jobName,
122                          String user, Path logFile, JspWriter out)
123    throws IOException {
124      out.print("<tr>"); 
125      out.print("<td>" + trackerHostName + "</td>"); 
126      out.print("<td>" + new Date(Long.parseLong(trackerid)) + "</td>"); 
127      out.print("<td>" + "<a href=\"jobdetailshistory.jsp?jobid=" + jobId + 
128                "&logFile=" + logFile.toString() + "\">" + jobId + "</a></td>"); 
129      out.print("<td>" + jobName + "</td>"); 
130      out.print("<td>" + user + "</td>"); 
131      out.print("</tr>");
132    }
133%> 
134</body></html>
Note: See TracBrowser for help on using the repository browser.