MAPREDUCE-6817. The format of job start time in JHS is different from those of submit and finish time. (Haibo Chen via kasha)
This commit is contained in:
parent
9f5d2c4fff
commit
a793cec2c9
@ -79,7 +79,7 @@ public class HsJobsBlock extends HtmlBlock {
|
||||
JobInfo job = new JobInfo(j);
|
||||
jobsTableData.append("[\"")
|
||||
.append(dateFormat.format(new Date(job.getSubmitTime()))).append("\",\"")
|
||||
.append(job.getStartTimeStr()).append("\",\"")
|
||||
.append(job.getFormattedStartTimeStr(dateFormat)).append("\",\"")
|
||||
.append(dateFormat.format(new Date(job.getFinishTime()))).append("\",\"")
|
||||
.append("<a href='").append(url("job", job.getId())).append("'>")
|
||||
.append(job.getId()).append("</a>\",\"")
|
||||
|
@ -17,6 +17,7 @@
|
||||
*/
|
||||
package org.apache.hadoop.mapreduce.v2.hs.webapp.dao;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
@ -27,6 +28,7 @@
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import javax.xml.bind.annotation.XmlTransient;
|
||||
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.apache.hadoop.mapreduce.JobACL;
|
||||
import org.apache.hadoop.mapreduce.v2.api.records.JobReport;
|
||||
import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId;
|
||||
@ -44,7 +46,8 @@
|
||||
@XmlRootElement(name = "job")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public class JobInfo {
|
||||
private static final String NA = "N/A";
|
||||
@VisibleForTesting
|
||||
static final String NA = "N/A";
|
||||
|
||||
protected long submitTime;
|
||||
protected long startTime;
|
||||
@ -228,6 +231,16 @@ public long getStartTime() {
|
||||
return this.startTime;
|
||||
}
|
||||
|
||||
public String getFormattedStartTimeStr(final DateFormat dateFormat) {
|
||||
String str = NA;
|
||||
|
||||
if (startTime >= 0) {
|
||||
str = dateFormat.format(new Date(startTime));
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
public String getStartTimeStr() {
|
||||
String str = NA;
|
||||
|
||||
|
@ -22,6 +22,8 @@
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
@ -153,7 +155,7 @@ public void testGetStartTimeStr() {
|
||||
when(job.getID()).thenReturn(jobId);
|
||||
|
||||
JobInfo jobInfo = new JobInfo(job);
|
||||
Assert.assertEquals("N/A", jobInfo.getStartTimeStr());
|
||||
Assert.assertEquals(JobInfo.NA, jobInfo.getStartTimeStr());
|
||||
|
||||
Date date = new Date();
|
||||
when(jobReport.getStartTime()).thenReturn(date.getTime());
|
||||
@ -161,4 +163,29 @@ public void testGetStartTimeStr() {
|
||||
jobInfo = new JobInfo(job);
|
||||
Assert.assertEquals(date.toString(), jobInfo.getStartTimeStr());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFormattedStartTimeStr() {
|
||||
JobReport jobReport = mock(JobReport.class);
|
||||
when(jobReport.getStartTime()).thenReturn(-1L);
|
||||
|
||||
Job job = mock(Job.class);
|
||||
when(job.getReport()).thenReturn(jobReport);
|
||||
when(job.getName()).thenReturn("TestJobInfo");
|
||||
when(job.getState()).thenReturn(JobState.SUCCEEDED);
|
||||
|
||||
JobId jobId = MRBuilderUtils.newJobId(1L, 1, 1);
|
||||
when(job.getID()).thenReturn(jobId);
|
||||
DateFormat dateFormat = new SimpleDateFormat();
|
||||
|
||||
JobInfo jobInfo = new JobInfo(job);
|
||||
Assert.assertEquals(
|
||||
JobInfo.NA, jobInfo.getFormattedStartTimeStr(dateFormat));
|
||||
|
||||
Date date = new Date();
|
||||
when(jobReport.getStartTime()).thenReturn(date.getTime());
|
||||
jobInfo = new JobInfo(job);
|
||||
Assert.assertEquals(
|
||||
dateFormat.format(date), jobInfo.getFormattedStartTimeStr(dateFormat));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user