Skip to content

Commit 9c817a8

Browse files
gaborgsomogyiMarcelo Vanzin
authored andcommitted
[SPARK-29637][CORE] Add description to Job SHS web API
### Why are the changes needed? Starting from Spark 2.3, the SHS REST API endpoint `/applications/<app_id>/jobs/` is not including `description` in the JobData returned. This is not the case until Spark 2.2. In this PR I've added the mentioned field. ### Does this PR introduce any user-facing change? Yes. Old API response: ``` [ { "jobId" : 0, "name" : "foreach at <console>:26", "submissionTime" : "2019-10-28T12:41:54.301GMT", "completionTime" : "2019-10-28T12:41:54.731GMT", "stageIds" : [ 0 ], "jobGroup" : "test", "status" : "SUCCEEDED", "numTasks" : 1, "numActiveTasks" : 0, "numCompletedTasks" : 1, "numSkippedTasks" : 0, "numFailedTasks" : 0, "numKilledTasks" : 0, "numCompletedIndices" : 1, "numActiveStages" : 0, "numCompletedStages" : 1, "numSkippedStages" : 0, "numFailedStages" : 0, "killedTasksSummary" : { } } ] ``` New API response: ``` [ { "jobId" : 0, "name" : "foreach at <console>:26", "description" : "job", <= This is the addition here "submissionTime" : "2019-10-28T13:37:24.107GMT", "completionTime" : "2019-10-28T13:37:24.613GMT", "stageIds" : [ 0 ], "jobGroup" : "test", "status" : "SUCCEEDED", "numTasks" : 1, "numActiveTasks" : 0, "numCompletedTasks" : 1, "numSkippedTasks" : 0, "numFailedTasks" : 0, "numKilledTasks" : 0, "numCompletedIndices" : 1, "numActiveStages" : 0, "numCompletedStages" : 1, "numSkippedStages" : 0, "numFailedStages" : 0, "killedTasksSummary" : { } } ] ``` ### How was this patch tested? Extended + existing unit tests. Manually: * Open spark-shell ``` scala> sc.setJobGroup("test", "job", false); scala> val foo = sc.textFile("/user/foo.txt"); foo: org.apache.spark.rdd.RDD[String] = /user/foo.txt MapPartitionsRDD[1] at textFile at <console>:24 scala> foo.foreach(println); ``` * Access REST API `http://SHS-host:port/api/v1/applications/<app-id>/jobs/` Closes #26295 from gaborgsomogyi/SPARK-29637. Authored-by: Gabor Somogyi <gabor.g.somogyi@gmail.com> Signed-off-by: Marcelo Vanzin <vanzin@cloudera.com>
1 parent 44c1c03 commit 9c817a8

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

core/src/main/scala/org/apache/spark/status/AppStatusListener.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,8 @@ private[spark] class AppStatusListener(
355355

356356
val lastStageInfo = event.stageInfos.sortBy(_.stageId).lastOption
357357
val jobName = lastStageInfo.map(_.name).getOrElse("")
358+
val description = Option(event.properties)
359+
.flatMap { p => Option(p.getProperty(SparkContext.SPARK_JOB_DESCRIPTION)) }
358360
val jobGroup = Option(event.properties)
359361
.flatMap { p => Option(p.getProperty(SparkContext.SPARK_JOB_GROUP_ID)) }
360362
val sqlExecutionId = Option(event.properties)
@@ -363,6 +365,7 @@ private[spark] class AppStatusListener(
363365
val job = new LiveJob(
364366
event.jobId,
365367
jobName,
368+
description,
366369
if (event.time > 0) Some(new Date(event.time)) else None,
367370
event.stageIds,
368371
jobGroup,

core/src/main/scala/org/apache/spark/status/LiveEntity.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ private[spark] abstract class LiveEntity {
6262
private class LiveJob(
6363
val jobId: Int,
6464
name: String,
65+
description: Option[String],
6566
val submissionTime: Option[Date],
6667
val stageIds: Seq[Int],
6768
jobGroup: Option[String],
@@ -92,7 +93,7 @@ private class LiveJob(
9293
val info = new v1.JobData(
9394
jobId,
9495
name,
95-
None, // description is always None?
96+
description,
9697
submissionTime,
9798
completionTime,
9899
stageIds,

core/src/test/scala/org/apache/spark/status/AppStatusListenerSuite.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class AppStatusListenerSuite extends SparkFunSuite with BeforeAndAfter {
155155
new StageInfo(2, 0, "stage2", 4, Nil, Seq(1), "details2"))
156156

157157
val jobProps = new Properties()
158+
jobProps.setProperty(SparkContext.SPARK_JOB_DESCRIPTION, "jobDescription")
158159
jobProps.setProperty(SparkContext.SPARK_JOB_GROUP_ID, "jobGroup")
159160
jobProps.setProperty(SparkContext.SPARK_SCHEDULER_POOL, "schedPool")
160161

@@ -163,7 +164,7 @@ class AppStatusListenerSuite extends SparkFunSuite with BeforeAndAfter {
163164
check[JobDataWrapper](1) { job =>
164165
assert(job.info.jobId === 1)
165166
assert(job.info.name === stages.last.name)
166-
assert(job.info.description === None)
167+
assert(job.info.description === Some("jobDescription"))
167168
assert(job.info.status === JobExecutionStatus.RUNNING)
168169
assert(job.info.submissionTime === Some(new Date(time)))
169170
assert(job.info.jobGroup === Some("jobGroup"))

0 commit comments

Comments
 (0)