[120] | 1 | package org.apache.hadoop.mapred; |
---|
| 2 | |
---|
| 3 | import javax.servlet.*; |
---|
| 4 | import javax.servlet.http.*; |
---|
| 5 | import javax.servlet.jsp.*; |
---|
| 6 | import java.io.*; |
---|
| 7 | import java.util.*; |
---|
| 8 | import org.apache.hadoop.mapred.*; |
---|
| 9 | import org.apache.hadoop.util.*; |
---|
| 10 | import org.apache.hadoop.fs.*; |
---|
| 11 | import javax.servlet.jsp.*; |
---|
| 12 | import java.text.SimpleDateFormat; |
---|
| 13 | import org.apache.hadoop.mapred.*; |
---|
| 14 | import org.apache.hadoop.mapred.JobHistory.*; |
---|
| 15 | |
---|
| 16 | public final class jobhistory_jsp extends org.apache.jasper.runtime.HttpJspBase |
---|
| 17 | implements org.apache.jasper.runtime.JspSourceDependent { |
---|
| 18 | |
---|
| 19 | |
---|
| 20 | private static SimpleDateFormat dateFormat = |
---|
| 21 | new SimpleDateFormat("d/MM HH:mm:ss"); |
---|
| 22 | |
---|
| 23 | |
---|
| 24 | private void printJob(String trackerHostName, String trackerid, |
---|
| 25 | String jobId, String jobName, |
---|
| 26 | String user, Path logFile, JspWriter out) |
---|
| 27 | throws IOException { |
---|
| 28 | out.print("<tr>"); |
---|
| 29 | out.print("<td>" + trackerHostName + "</td>"); |
---|
| 30 | out.print("<td>" + new Date(Long.parseLong(trackerid)) + "</td>"); |
---|
| 31 | out.print("<td>" + "<a href=\"jobdetailshistory.jsp?jobid=" + jobId + |
---|
| 32 | "&logFile=" + logFile.toString() + "\">" + jobId + "</a></td>"); |
---|
| 33 | out.print("<td>" + jobName + "</td>"); |
---|
| 34 | out.print("<td>" + user + "</td>"); |
---|
| 35 | out.print("</tr>"); |
---|
| 36 | } |
---|
| 37 | |
---|
| 38 | private static java.util.List _jspx_dependants; |
---|
| 39 | |
---|
| 40 | public Object getDependants() { |
---|
| 41 | return _jspx_dependants; |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | public void _jspService(HttpServletRequest request, HttpServletResponse response) |
---|
| 45 | throws java.io.IOException, ServletException { |
---|
| 46 | |
---|
| 47 | JspFactory _jspxFactory = null; |
---|
| 48 | PageContext pageContext = null; |
---|
| 49 | HttpSession session = null; |
---|
| 50 | ServletContext application = null; |
---|
| 51 | ServletConfig config = null; |
---|
| 52 | JspWriter out = null; |
---|
| 53 | Object page = this; |
---|
| 54 | JspWriter _jspx_out = null; |
---|
| 55 | PageContext _jspx_page_context = null; |
---|
| 56 | |
---|
| 57 | |
---|
| 58 | try { |
---|
| 59 | _jspxFactory = JspFactory.getDefaultFactory(); |
---|
| 60 | response.setContentType("text/html; charset=UTF-8"); |
---|
| 61 | pageContext = _jspxFactory.getPageContext(this, request, response, |
---|
| 62 | null, true, 8192, true); |
---|
| 63 | _jspx_page_context = pageContext; |
---|
| 64 | application = pageContext.getServletContext(); |
---|
| 65 | config = pageContext.getServletConfig(); |
---|
| 66 | session = pageContext.getSession(); |
---|
| 67 | out = pageContext.getOut(); |
---|
| 68 | _jspx_out = out; |
---|
| 69 | |
---|
| 70 | out.write('\n'); |
---|
| 71 | out.write("\n<html>\n<head>\n<title>Hadoop Map/Reduce Administration</title>\n<link rel=\"stylesheet\" type=\"text/css\" href=\"/static/hadoop.css\">\n</head>\n<body>\n<h1>Hadoop Map/Reduce History Viewer</h1>\n<hr>\n<h2>Available History </h2>\n"); |
---|
| 72 | |
---|
| 73 | PathFilter jobLogFileFilter = new PathFilter() { |
---|
| 74 | public boolean accept(Path path) { |
---|
| 75 | return !(path.getName().endsWith(".xml")); |
---|
| 76 | } |
---|
| 77 | }; |
---|
| 78 | |
---|
| 79 | FileSystem fs = (FileSystem) application.getAttribute("fileSys"); |
---|
| 80 | String historyLogDir = (String) application.getAttribute("historyLogDir"); |
---|
| 81 | if (fs == null) { |
---|
| 82 | out.println("Null file system. May be namenode is in safemode!"); |
---|
| 83 | return; |
---|
| 84 | } |
---|
| 85 | Path[] jobFiles = FileUtil.stat2Paths(fs.listStatus(new Path(historyLogDir), |
---|
| 86 | jobLogFileFilter)); |
---|
| 87 | if (null == jobFiles ) { |
---|
| 88 | out.println("NULL files !!!"); |
---|
| 89 | return ; |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | // sort the files on creation time. |
---|
| 93 | Arrays.sort(jobFiles, new Comparator<Path>() { |
---|
| 94 | public int compare(Path p1, Path p2) { |
---|
| 95 | String dp1 = null; |
---|
| 96 | String dp2 = null; |
---|
| 97 | |
---|
| 98 | try { |
---|
| 99 | dp1 = JobHistory.JobInfo.decodeJobHistoryFileName(p1.getName()); |
---|
| 100 | dp2 = JobHistory.JobInfo.decodeJobHistoryFileName(p2.getName()); |
---|
| 101 | } catch (IOException ioe) { |
---|
| 102 | throw new RuntimeException(ioe); |
---|
| 103 | } |
---|
| 104 | |
---|
| 105 | String[] split1 = dp1.split("_"); |
---|
| 106 | String[] split2 = dp2.split("_"); |
---|
| 107 | |
---|
| 108 | // compare job tracker start time |
---|
| 109 | int res = new Date(Long.parseLong(split1[1])).compareTo( |
---|
| 110 | new Date(Long.parseLong(split2[1]))); |
---|
| 111 | if (res == 0) { |
---|
| 112 | res = new Date(Long.parseLong(split1[3])).compareTo( |
---|
| 113 | new Date(Long.parseLong(split2[3]))); |
---|
| 114 | } |
---|
| 115 | if (res == 0) { |
---|
| 116 | Long l1 = Long.parseLong(split1[4]); |
---|
| 117 | res = l1.compareTo(Long.parseLong(split2[4])); |
---|
| 118 | } |
---|
| 119 | return res; |
---|
| 120 | } |
---|
| 121 | }); |
---|
| 122 | |
---|
| 123 | out.print("<table align=center border=2 cellpadding=\"5\" cellspacing=\"2\">"); |
---|
| 124 | out.print("<tr><td align=\"center\" colspan=\"9\"><b>Available Jobs </b></td></tr>\n"); |
---|
| 125 | out.print("<tr>"); |
---|
| 126 | out.print("<td>Job tracker Host Name</td>" + |
---|
| 127 | "<td>Job tracker Start time</td>" + |
---|
| 128 | "<td>Job Id</td><td>Name</td><td>User</td>") ; |
---|
| 129 | out.print("</tr>"); |
---|
| 130 | |
---|
| 131 | Set<String> displayedJobs = new HashSet<String>(); |
---|
| 132 | for (Path jobFile: jobFiles) { |
---|
| 133 | String decodedJobFileName = |
---|
| 134 | JobHistory.JobInfo.decodeJobHistoryFileName(jobFile.getName()); |
---|
| 135 | |
---|
| 136 | String[] jobDetails = decodedJobFileName.split("_"); |
---|
| 137 | String trackerHostName = jobDetails[0]; |
---|
| 138 | String trackerStartTime = jobDetails[1]; |
---|
| 139 | String jobId = jobDetails[2] + "_" +jobDetails[3] + "_" + jobDetails[4] ; |
---|
| 140 | String user = jobDetails[5]; |
---|
| 141 | String jobName = jobDetails[6]; |
---|
| 142 | |
---|
| 143 | // Check if the job is already displayed. There can be multiple job |
---|
| 144 | // history files for jobs that have restarted |
---|
| 145 | if (displayedJobs.contains(jobId)) { |
---|
| 146 | continue; |
---|
| 147 | } else { |
---|
| 148 | displayedJobs.add(jobId); |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | // Encode the logfile name again to cancel the decoding done by the browser |
---|
| 152 | String encodedJobFileName = |
---|
| 153 | JobHistory.JobInfo.encodeJobHistoryFileName(jobFile.getName()); |
---|
| 154 | |
---|
| 155 | out.write("\n<center>\n"); |
---|
| 156 | |
---|
| 157 | printJob(trackerHostName, trackerStartTime, jobId, |
---|
| 158 | jobName, user, new Path(jobFile.getParent(), encodedJobFileName), |
---|
| 159 | out) ; |
---|
| 160 | |
---|
| 161 | out.write("\n</center> \n"); |
---|
| 162 | |
---|
| 163 | } // end while trackers |
---|
| 164 | |
---|
| 165 | out.write('\n'); |
---|
| 166 | out.write(" \n</body></html>\n"); |
---|
| 167 | } catch (Throwable t) { |
---|
| 168 | if (!(t instanceof SkipPageException)){ |
---|
| 169 | out = _jspx_out; |
---|
| 170 | if (out != null && out.getBufferSize() != 0) |
---|
| 171 | out.clearBuffer(); |
---|
| 172 | if (_jspx_page_context != null) _jspx_page_context.handlePageException(t); |
---|
| 173 | } |
---|
| 174 | } finally { |
---|
| 175 | if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context); |
---|
| 176 | } |
---|
| 177 | } |
---|
| 178 | } |
---|