Skip to content

Commit

Permalink
avoid jersey-media-json-jackson b/c of potential version conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
squito committed Apr 27, 2015
1 parent a157a2f commit 4a234d3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
5 changes: 0 additions & 5 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,6 @@
<version>1.9</version>
<scope>${hadoop.deps.scope}</scope>
</dependency>
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
<artifactId>jersey-media-json-jackson</artifactId>
<version>2.15</version>
</dependency>
<dependency>
<groupId>org.apache.mesos</groupId>
<artifactId>mesos</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@
*/
package org.apache.spark.status.api.v1

import java.io.OutputStream
import java.lang.annotation.Annotation
import java.lang.reflect.Type
import java.text.SimpleDateFormat
import java.util.{Calendar, SimpleTimeZone}
import java.util.{SimpleTimeZone, Calendar}
import javax.ws.rs.Produces
import javax.ws.rs.core.MediaType
import javax.ws.rs.ext.{ContextResolver, Provider}
import javax.ws.rs.core.{MultivaluedMap, MediaType}
import javax.ws.rs.ext.{Provider, MessageBodyWriter}

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

@Provider
@Produces(Array(MediaType.APPLICATION_JSON))
private[v1] class CustomObjectMapper extends ContextResolver[ObjectMapper]{
class JacksonMessageWriter extends MessageBodyWriter[Object]{

val mapper = new ObjectMapper() {
override def writeValueAsString(t: Any): String = {
super.writeValueAsString(t)
Expand All @@ -36,14 +40,38 @@ private[v1] class CustomObjectMapper extends ContextResolver[ObjectMapper]{
mapper.registerModule(com.fasterxml.jackson.module.scala.DefaultScalaModule)
mapper.enable(SerializationFeature.INDENT_OUTPUT)
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
mapper.setDateFormat(CustomObjectMapper.makeISODateFormat)
mapper.setDateFormat(JacksonMessageWriter.makeISODateFormat)

override def isWriteable(
aClass: Class[_],
`type`: Type,
annotations: Array[Annotation],
mediaType: MediaType): Boolean = {
true
}

override def writeTo(
t: Object,
aClass: Class[_],
`type`: Type,
annotations: Array[Annotation],
mediaType: MediaType,
multivaluedMap: MultivaluedMap[String, AnyRef],
outputStream: OutputStream): Unit = {
mapper.writeValue(outputStream, t)
}

override def getContext(tpe: Class[_]): ObjectMapper = {
mapper
override def getSize(
t: Object,
aClass: Class[_],
`type`: Type,
annotations: Array[Annotation],
mediaType: MediaType): Long = {
-1L
}
}

private[spark] object CustomObjectMapper {
private[spark] object JacksonMessageWriter {
def makeISODateFormat: SimpleDateFormat = {
val iso8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'GMT'")
val cal = Calendar.getInstance(new SimpleTimeZone(0, "GMT"))
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/org/apache/spark/ui/UISeleniumSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.apache.spark._
import org.apache.spark.api.java.StorageLevels
import org.apache.spark.deploy.history.HistoryServerSuite
import org.apache.spark.shuffle.FetchFailedException
import org.apache.spark.status.api.v1.{StageStatus, CustomObjectMapper}
import org.apache.spark.status.api.v1.{JacksonMessageWriter, StageStatus}

/**
* Selenium tests for the Spark Web UI.
Expand Down Expand Up @@ -580,7 +580,7 @@ class UISeleniumSuite extends FunSuite with WebBrowser with Matchers with Before
}

def parseDate(json: JValue): Long = {
CustomObjectMapper.makeISODateFormat.parse(json.extract[String]).getTime
JacksonMessageWriter.makeISODateFormat.parse(json.extract[String]).getTime
}

def getJson(ui: SparkUI, path: String): JValue = {
Expand Down

0 comments on commit 4a234d3

Please sign in to comment.