MAPREDUCE-6817. The format of job start time in JHS is different from those of submit and finish time. (Haibo Chen via kasha)
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/a793cec2 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/a793cec2 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/a793cec2 Branch: refs/heads/YARN-5972 Commit: a793cec2c9a7ad80aaf67be9dec2245e8ecce63c Parents: 9f5d2c4 Author: Karthik Kambatla <ka...@cloudera.com> Authored: Wed Dec 7 13:36:49 2016 -0800 Committer: Karthik Kambatla <ka...@cloudera.com> Committed: Wed Dec 7 13:36:49 2016 -0800 ---------------------------------------------------------------------- .../mapreduce/v2/hs/webapp/HsJobsBlock.java | 2 +- .../mapreduce/v2/hs/webapp/dao/JobInfo.java | 15 +++++++++- .../mapreduce/v2/hs/webapp/dao/TestJobInfo.java | 29 +++++++++++++++++++- 3 files changed, 43 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/a793cec2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsJobsBlock.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsJobsBlock.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsJobsBlock.java index 92c5e2b..b234ca3 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsJobsBlock.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/HsJobsBlock.java @@ -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>\",\"") http://git-wip-us.apache.org/repos/asf/hadoop/blob/a793cec2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/JobInfo.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/JobInfo.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/JobInfo.java index eddbccf..d12a729 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/JobInfo.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/main/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/JobInfo.java @@ -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; http://git-wip-us.apache.org/repos/asf/hadoop/blob/a793cec2/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/TestJobInfo.java ---------------------------------------------------------------------- diff --git a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/TestJobInfo.java b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/TestJobInfo.java index 51f87e0..c8b749f 100644 --- a/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/TestJobInfo.java +++ b/hadoop-mapreduce-project/hadoop-mapreduce-client/hadoop-mapreduce-client-hs/src/test/java/org/apache/hadoop/mapreduce/v2/hs/webapp/dao/TestJobInfo.java @@ -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)); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org