Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,8 @@ private[history] class FsHistoryProvider(conf: SparkConf, clock: Clock)
} else {
Map()
}
Map("Event log directory" -> logDir.toString) ++ safeMode
Map("Event log directory" -> logDir.toString,
"Time zone" -> Utils.getTimeZone.getID) ++ safeMode
}

override def stop(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ import java.lang.annotation.Annotation
import java.lang.reflect.Type
import java.nio.charset.StandardCharsets
import java.text.SimpleDateFormat
import java.util.{Calendar, Locale, SimpleTimeZone}
import java.util.{Calendar, Locale}
import javax.ws.rs.Produces
import javax.ws.rs.core.{MediaType, MultivaluedMap}
import javax.ws.rs.ext.{MessageBodyWriter, Provider}

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature}

import org.apache.spark.util.Utils

/**
* This class converts the POJO metric responses into json, using jackson.
*
Expand Down Expand Up @@ -86,8 +88,9 @@ private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{

private[spark] object JacksonMessageWriter {
def makeISODateFormat: SimpleDateFormat = {
val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'", Locale.US)
val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"))
val timeZone = Utils.getTimeZone
val iso8601 = new SimpleDateFormat(s"yyyy-MM-dd'T'HH:mm:ss.SSS'${timeZone.getID}'", Locale.US)
val cal = Calendar.getInstance(timeZone)
iso8601.setCalendar(cal)
iso8601
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
package org.apache.spark.status.api.v1

import java.text.{ParseException, SimpleDateFormat}
import java.util.{Locale, TimeZone}
import java.util.Locale
import javax.ws.rs.WebApplicationException
import javax.ws.rs.core.Response
import javax.ws.rs.core.Response.Status

import org.apache.spark.util.Utils

private[v1] class SimpleDateParam(val originalValue: String) {

val timestamp: Long = {
Expand All @@ -31,7 +33,7 @@ private[v1] class SimpleDateParam(val originalValue: String) {
} catch {
case _: ParseException =>
val gmtDay = new SimpleDateFormat("yyyy-MM-dd", Locale.US)
gmtDay.setTimeZone(TimeZone.getTimeZone("GMT"))
gmtDay.setTimeZone(Utils.getTimeZone)
try {
gmtDay.parse(originalValue).getTime()
} catch {
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import java.nio.ByteBuffer
import java.nio.channels.{Channels, FileChannel}
import java.nio.charset.StandardCharsets
import java.nio.file.{Files, Paths}
import java.util.{Locale, Properties, Random, UUID}
import java.util.{Locale, Properties, Random, TimeZone, UUID}
import java.util.concurrent._
import java.util.concurrent.atomic.AtomicBoolean
import java.util.zip.GZIPInputStream
Expand Down Expand Up @@ -2742,6 +2742,11 @@ private[spark] object Utils extends Logging {
}
}

def getTimeZone: TimeZone = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please image that this method will be used outside scope of the current issue?
What's about users who does not have spark history at all?

The name of method, the class and the package does not tell us that this method somehow related ONLY to history server, such API makes me easy to do wrong assumptions.

val sparkConf = new SparkConf(false).loadFromSystemProperties(true)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make SparkConf as a input param instead of create a new instance for every function call?

TimeZone.getTimeZone(sparkConf.get("spark.history.timeZone", "GMT"))
}

}

private[util] object CallerContext extends Logging {
Expand Down