MAPREDUCE-6817. The format of job start time in JHS is different from those of submit and finish time. (Haibo Chen via kasha)

(cherry picked from commit a793cec2c9)
This commit is contained in:
Karthik Kambatla 2016-12-07 13:36:49 -08:00
parent a636a87270
commit 0aaaeea268
3 changed files with 43 additions and 3 deletions

View File

@ -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>\",\"")

View File

@ -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.XmlAccessorType;
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 @@ import org.apache.hadoop.security.authorize.AccessControlList;
@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 class JobInfo {
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;

View File

@ -22,6 +22,8 @@ import static org.mockito.Mockito.mock;
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 class TestJobInfo {
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 class TestJobInfo {
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));
}
}