<%@ page
  contentType="text/html; charset=UTF-8"
  import="javax.servlet.http.*"
  import="java.io.*"
  import="java.util.*"
  import="org.apache.hadoop.mapred.*"
  import="org.apache.hadoop.util.*"
  import="java.text.SimpleDateFormat"
  import="org.apache.hadoop.mapred.JobHistory.*"
%>
<jsp:include page="loadhistory.jsp">
	<jsp:param name="jobid" value="<%=request.getParameter("jobid") %>"/>
	<jsp:param name="jobTrackerId" value="<%=request.getParameter("jobTrackerId") %>"/>
</jsp:include>
<%!	private static SimpleDateFormat dateFormat = new SimpleDateFormat("d/MM HH:mm:ss") ; %>

<%	
	String jobid = request.getParameter("jobid");
	String jobTrackerId = request.getParameter("jobTrackerId");
	String taskStatus = request.getParameter("status"); 
	String taskType = request.getParameter("taskType"); 
	
	JobHistory.JobInfo job = (JobHistory.JobInfo)request.getSession().getAttribute("job");
	
	Map<String, JobHistory.Task> tasks = job.getAllTasks(); 
%>
<html>
<body>
<h2><%=taskStatus%> <%=taskType %> task list for <a href="jobdetailshistory.jsp?jobid=<%=jobid%>&&jobTrackerId=<%=jobTrackerId %>"><%=jobid %> </a></h2>
<center>
<table border="2" cellpadding="5" cellspacing="2">
<tr><td>Task Id</td><td>Start Time</td><td>Finish Time<br/></td><td>Error</td></tr>
<%
	for( JobHistory.Task task : tasks.values() ) {
	  if( taskType.equals(task.get(Keys.TASK_TYPE) ) ){
	    if( taskStatus.equals(task.get(Keys.TASK_STATUS)) || taskStatus.equals("all")){
	       printTask(jobid, jobTrackerId, task, out); 
	    }
	  }
	}
%>
</table>
<%!
	private void printTask(String jobid, String trackerId, JobHistory.Task task, JspWriter out) throws IOException{
  		out.print("<tr>"); 
  		out.print("<td>" + "<a href=\"taskdetailshistory.jsp?jobid=" + jobid + 
  		    "&jobTrackerId="+ trackerId +"&taskid="+task.get(Keys.TASKID)+"\">" + 
  		    task.get(Keys.TASKID) + "</a></td>");
  		out.print("<td>" + StringUtils.getFormattedTimeWithDiff(dateFormat, 
  		    task.getLong(Keys.START_TIME), 0 ) + "</td>");
		out.print("<td>" + StringUtils.getFormattedTimeWithDiff(dateFormat, 
		    task.getLong(Keys.FINISH_TIME), task.getLong(Keys.START_TIME) ) + "</td>");
  		out.print("<td>" + task.get(Keys.ERROR) + "</td>");
  		out.print("</tr>"); 
	}
%>
</center>
</body>
</html>
