Skip to content

Commit f48a7b0

Browse files
committed
docs
1 parent 52bbae8 commit f48a7b0

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

core/src/main/java/org/apache/spark/status/api/v1/TaskSorting.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import java.util.HashSet;
2424
import java.util.Set;
2525

26+
// exposed for jersey
2627
@DeveloperApi
2728
public enum TaskSorting {
2829
ID,

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ import javax.ws.rs.ext.{MessageBodyWriter, Provider}
2828
import com.fasterxml.jackson.annotation.JsonInclude
2929
import com.fasterxml.jackson.databind.{ObjectMapper, SerializationFeature}
3030

31+
/**
32+
* This class converts the POJO metric responses into json, using jackson.
33+
*
34+
* This doesn't follow the standard jersey-jackson plugin options, because we want to stick
35+
* with an old version of jersey (since we have it from yarn anyway) and don't want to pull in lots
36+
* of dependencies from a new plugin.
37+
*
38+
* Note that jersey automatically discovers this class based on its package and its annotations.
39+
*/
3140
@Provider
3241
@Produces(Array(MediaType.APPLICATION_JSON))
3342
private[v1] class JacksonMessageWriter extends MessageBodyWriter[Object]{

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,16 @@ import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
2828
import org.apache.spark.SecurityManager
2929
import org.apache.spark.ui.SparkUI
3030

31+
/**
32+
* Main entry point for serving spark application metrics as json, using JAX-RS.
33+
*
34+
* Each resource should have endpoints that return **public** classes defined in api.scala. Mima
35+
* binary compatibility checks ensure that we don't inadvertently make changes that break the api.
36+
* The returned objects are automatically converted to json by jackson with JacksonMessageWriter.
37+
* In addition, there are a number of tests in HistoryServerSuite that compare the json to "golden
38+
* files". Any changes and additions should be reflected there as well -- see the notes in
39+
* HistoryServerSuite.
40+
*/
3141
@Path("/v1")
3242
private[v1] class JsonRootResource extends UIRootFromServletContext {
3343

@@ -156,4 +166,8 @@ private[v1] class BadParameterException(msg: String) extends WebApplicationExcep
156166
}
157167
}
158168

169+
/**
170+
* Signal to JacksonMessageWriter to not convert the message into json (which would result in an
171+
* extra set of quotes).
172+
*/
159173
private[v1] case class ErrorWrapper(s: String)

core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@ import org.scalatest.mock.MockitoSugar
2828
import org.apache.spark.{JsonTestUtils, SecurityManager, SparkConf}
2929
import org.apache.spark.ui.SparkUI
3030

31+
/**
32+
* A collection of tests against the historyserver, including comparing responses from the json
33+
* metrics api to a set of known "golden files". If new endpoints / parameters are added,
34+
* cases should be added to this test suite. The expected outcomes can be genered by running
35+
* the HistoryServerSuite.main. Note that this will blindly generate new expectation files matching
36+
* the current behavior -- the developer must verify that behavior is correct.
37+
*
38+
* Similarly, if the behavior is changed, HistoryServerSuite.main can be run to update the
39+
* expectations. However, in general this should be done with extreme caution, as the metrics
40+
* are considered part of Spark's public api.
41+
*/
3142
class HistoryServerSuite extends FunSuite with BeforeAndAfter with Matchers with MockitoSugar
3243
with JsonTestUtils {
3344

0 commit comments

Comments
 (0)