Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ class SparkHadoopUtil extends Logging {
ugi.getAuthenticationMethod() == UserGroupInformation.AuthenticationMethod.PROXY
}

def getHistoryServerTimeZone: String = sparkConf.get("spark.history.timeZone", "GMT")

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.

Please add this config to internal/config.


}

object SparkHadoopUtil {
Expand Down
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.getHistoryServerTimeZone.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.getHistoryServerTimeZone
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.getHistoryServerTimeZone)
try {
gmtDay.parse(originalValue).getTime()
} catch {
Expand Down
5 changes: 4 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,9 @@ private[spark] object Utils extends Logging {
}
}

def getHistoryServerTimeZone: TimeZone =
TimeZone.getTimeZone(SparkHadoopUtil.get.getHistoryServerTimeZone)

}

private[util] object CallerContext extends Logging {
Expand Down