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);
|
JobInfo job = new JobInfo(j);
|
||||||
jobsTableData.append("[\"")
|
jobsTableData.append("[\"")
|
||||||
.append(dateFormat.format(new Date(job.getSubmitTime()))).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(dateFormat.format(new Date(job.getFinishTime()))).append("\",\"")
|
||||||
.append("<a href='").append(url("job", job.getId())).append("'>")
|
.append("<a href='").append(url("job", job.getId())).append("'>")
|
||||||
.append(job.getId()).append("</a>\",\"")
|
.append(job.getId()).append("</a>\",\"")
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.hadoop.mapreduce.v2.hs.webapp.dao;
|
package org.apache.hadoop.mapreduce.v2.hs.webapp.dao;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
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.XmlRootElement;
|
||||||
import javax.xml.bind.annotation.XmlTransient;
|
import javax.xml.bind.annotation.XmlTransient;
|
||||||
|
|
||||||
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import org.apache.hadoop.mapreduce.JobACL;
|
import org.apache.hadoop.mapreduce.JobACL;
|
||||||
import org.apache.hadoop.mapreduce.v2.api.records.JobReport;
|
import org.apache.hadoop.mapreduce.v2.api.records.JobReport;
|
||||||
import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId;
|
import org.apache.hadoop.mapreduce.v2.api.records.TaskAttemptId;
|
||||||
|
@ -44,7 +46,8 @@ import org.apache.hadoop.security.authorize.AccessControlList;
|
||||||
@XmlRootElement(name = "job")
|
@XmlRootElement(name = "job")
|
||||||
@XmlAccessorType(XmlAccessType.FIELD)
|
@XmlAccessorType(XmlAccessType.FIELD)
|
||||||
public class JobInfo {
|
public class JobInfo {
|
||||||
private static final String NA = "N/A";
|
@VisibleForTesting
|
||||||
|
static final String NA = "N/A";
|
||||||
|
|
||||||
protected long submitTime;
|
protected long submitTime;
|
||||||
protected long startTime;
|
protected long startTime;
|
||||||
|
@ -228,6 +231,16 @@ public class JobInfo {
|
||||||
return this.startTime;
|
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() {
|
public String getStartTimeStr() {
|
||||||
String str = NA;
|
String str = NA;
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,8 @@ import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
@ -153,7 +155,7 @@ public class TestJobInfo {
|
||||||
when(job.getID()).thenReturn(jobId);
|
when(job.getID()).thenReturn(jobId);
|
||||||
|
|
||||||
JobInfo jobInfo = new JobInfo(job);
|
JobInfo jobInfo = new JobInfo(job);
|
||||||
Assert.assertEquals("N/A", jobInfo.getStartTimeStr());
|
Assert.assertEquals(JobInfo.NA, jobInfo.getStartTimeStr());
|
||||||
|
|
||||||
Date date = new Date();
|
Date date = new Date();
|
||||||
when(jobReport.getStartTime()).thenReturn(date.getTime());
|
when(jobReport.getStartTime()).thenReturn(date.getTime());
|
||||||
|
@ -161,4 +163,29 @@ public class TestJobInfo {
|
||||||
jobInfo = new JobInfo(job);
|
jobInfo = new JobInfo(job);
|
||||||
Assert.assertEquals(date.toString(), jobInfo.getStartTimeStr());
|
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