Skip to content

Commit cd37845

Browse files
committed
switch to using java.util.Dates for times
1 parent a4ab5aa commit cd37845

File tree

18 files changed

+101
-47
lines changed

18 files changed

+101
-47
lines changed

core/src/main/scala/org/apache/spark/status/api/v1/AllJobsResource.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.spark.status.api.v1
1818

19+
import java.util.Date
1920
import javax.ws.rs._
2021
import javax.ws.rs.core.MediaType
2122

@@ -75,8 +76,8 @@ object AllJobsResource {
7576
jobId = job.jobId,
7677
name = lastStageName,
7778
description = lastStageDescription,
78-
submissionTime = job.submissionTime,
79-
completionTime = job.completionTime,
79+
submissionTime = job.submissionTime.map{new Date(_)},
80+
completionTime = job.completionTime.map{new Date(_)},
8081
stageIds = job.stageIds,
8182
jobGroup = job.jobGroup,
8283
status = job.status,

core/src/main/scala/org/apache/spark/status/api/v1/AllStagesResource.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.spark.status.api.v1
1818

19+
import java.util.Date
1920
import javax.ws.rs.{QueryParam, PathParam, GET, Produces}
2021
import javax.ws.rs.core.MediaType
2122

@@ -135,7 +136,7 @@ object AllStagesResource {
135136
taskId = uiData.taskInfo.taskId,
136137
index = uiData.taskInfo.index,
137138
attempt = uiData.taskInfo.attempt,
138-
launchTime = uiData.taskInfo.launchTime,
139+
launchTime = new Date(uiData.taskInfo.launchTime),
139140
executorId = uiData.taskInfo.executorId,
140141
host = uiData.taskInfo.host,
141142
taskLocality = uiData.taskInfo.taskLocality.toString(),

core/src/main/scala/org/apache/spark/status/api/v1/ApplicationInfo.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
package org.apache.spark.status.api.v1
1919

20+
import java.util.Date
21+
2022
case class ApplicationInfo(
2123
id: String,
2224
name: String,
23-
startTime: Long,
24-
endTime: Long,
25+
startTime: Date,
26+
endTime: Date,
2527
sparkUser: String,
2628
completed: Boolean = false)

core/src/main/scala/org/apache/spark/status/api/v1/ApplicationListResource.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.spark.status.api.v1
1818

19+
import java.util.Date
1920
import javax.ws.rs.core.MediaType
2021
import javax.ws.rs.{DefaultValue, QueryParam, Produces, GET}
2122

@@ -45,7 +46,7 @@ class ApplicationListResource(uiRoot: UIRoot) {
4546
allApps.filter{app =>
4647
val statusOk = (app.completed && includeCompleted) ||
4748
(!app.completed && includeRunning)
48-
val dateOk = app.startTime >= minDate.timestamp && app.startTime <= maxDate.timestamp
49+
val dateOk = app.startTime.getTime >= minDate.timestamp && app.startTime.getTime <= maxDate.timestamp
4950
statusOk && dateOk
5051
}
5152
}
@@ -56,8 +57,8 @@ object ApplicationsListResource {
5657
ApplicationInfo(
5758
id = app.id,
5859
name = app.name,
59-
startTime = app.startTime,
60-
endTime = app.endTime,
60+
startTime = new Date(app.startTime),
61+
endTime = new Date(app.endTime),
6162
sparkUser = app.sparkUser,
6263
completed = app.completed
6364
)
@@ -67,8 +68,8 @@ object ApplicationsListResource {
6768
ApplicationInfo(
6869
id = internal.id,
6970
name = internal.desc.name,
70-
startTime = internal.startTime,
71-
endTime = internal.endTime,
71+
startTime = new Date(internal.startTime),
72+
endTime = new Date(internal.endTime),
7273
sparkUser = internal.desc.user,
7374
completed = completed
7475
)

core/src/main/scala/org/apache/spark/status/api/v1/CustomObjectMapper.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
*/
1717
package org.apache.spark.status.api.v1
1818

19+
import java.text.SimpleDateFormat
20+
import java.util.{SimpleTimeZone, Calendar}
1921
import javax.ws.rs.Produces
2022
import javax.ws.rs.core.MediaType
2123
import javax.ws.rs.ext.{ContextResolver, Provider}
@@ -34,9 +36,20 @@ class CustomObjectMapper extends ContextResolver[ObjectMapper]{
3436
mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule)
3537
mapper.enable(SerializationFeature.INDENT_OUTPUT)
3638
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
39+
mapper.setDateFormat(CustomObjectMapper.makeISODateFormat)
3740

3841
override def getContext(tpe: Class[_]): ObjectMapper = {
3942
mapper
4043
}
4144

4245
}
46+
47+
object CustomObjectMapper {
48+
def makeISODateFormat: SimpleDateFormat = {
49+
val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'");
50+
val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"));
51+
iso8601.setCalendar(cal);
52+
iso8601;
53+
}
54+
55+
}

core/src/main/scala/org/apache/spark/status/api/v1/JobData.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@
1616
*/
1717
package org.apache.spark.status.api.v1
1818

19+
import java.util.Date
20+
1921
import org.apache.spark.JobExecutionStatus
2022

2123
case class JobData(
2224
jobId: Int,
2325
name: String,
2426
description: Option[String],
25-
submissionTime: Option[Long],
26-
completionTime: Option[Long],
27+
submissionTime: Option[Date],
28+
completionTime: Option[Date],
2729
stageIds: Seq[Int],
2830
jobGroup: Option[String],
2931
status: JobExecutionStatus,

core/src/main/scala/org/apache/spark/status/api/v1/SimpleDateParam.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ private[api] class SimpleDateParam(val originalValue: String) {
4141

4242
private[api] object SimpleDateParam {
4343
val formats = Seq(
44-
"yyyy-MM-dd'T'HH:mm:ssz",
44+
"yyyy-MM-dd'T'HH:mm:ss.SSSz",
4545
"yyyy-MM-dd"
4646
).map{new SimpleDateFormat(_)}
4747
}

core/src/main/scala/org/apache/spark/status/api/v1/TaskData.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
package org.apache.spark.status.api.v1
1919

20+
import java.util.Date
21+
2022
case class TaskData(
2123
taskId: Long,
2224
index: Int,
2325
attempt: Int,
24-
launchTime: Long,
26+
launchTime: Date,
2527
executorId: String,
2628
host: String,
2729
taskLocality: String,

core/src/main/scala/org/apache/spark/ui/SparkUI.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
package org.apache.spark.ui
1919

20+
import java.util.Date
21+
2022
import org.apache.spark.status.api.v1.{ApplicationInfo, JsonRootResource}
2123
import org.apache.spark.status.api.v1.UIRoot
2224
import org.apache.spark.{Logging, SecurityManager, SparkConf, SparkContext}
@@ -96,8 +98,8 @@ private[spark] class SparkUI private (
9698
id = appName,
9799
name = appName,
98100
//TODO
99-
startTime = -1,
100-
endTime = -1,
101+
startTime = new Date(-1),
102+
endTime = new Date(-1),
101103
sparkUser = "",
102104
completed = false
103105
))
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
[ {
22
"id" : "local-1425081759269",
33
"name" : "Spark shell",
4-
"startTime" : 1425081758277,
5-
"endTime" : 1425081766912,
4+
"startTime" : "2015-02-28T00:02:38.277GMT",
5+
"endTime" : "2015-02-28T00:02:46.912GMT",
66
"sparkUser" : "irashid",
77
"completed" : true
88
}, {
99
"id" : "local-1422981780767",
1010
"name" : "Spark shell",
11-
"startTime" : 1422981779720,
12-
"endTime" : 1422981788731,
11+
"startTime" : "2015-02-03T16:42:59.720GMT",
12+
"endTime" : "2015-02-03T16:43:08.731GMT",
1313
"sparkUser" : "irashid",
1414
"completed" : true
1515
}, {
1616
"id" : "local-1422981759269",
1717
"name" : "Spark shell",
18-
"startTime" : 1422981758277,
19-
"endTime" : 1422981766912,
18+
"startTime" : "2015-02-03T16:42:38.277GMT",
19+
"endTime" : "2015-02-03T16:42:46.912GMT",
2020
"sparkUser" : "irashid",
2121
"completed" : true
2222
} ]

0 commit comments

Comments
 (0)