diff options
author | Parag Chaudhari <paragpc@amazon.com> | 2017-01-24 08:41:46 -0600 |
---|---|---|
committer | Imran Rashid <irashid@cloudera.com> | 2017-01-24 08:41:46 -0600 |
commit | 0ff67a1cf91ce4a36657c789c0fe676f4f89282f (patch) | |
tree | 52b3c6e83733a8b38cddc8ced32ba535e399da50 /core | |
parent | 752502be053c66a95b04204b4ae0e9574394bc58 (diff) | |
download | spark-0ff67a1cf91ce4a36657c789c0fe676f4f89282f.tar.gz spark-0ff67a1cf91ce4a36657c789c0fe676f4f89282f.tar.bz2 spark-0ff67a1cf91ce4a36657c789c0fe676f4f89282f.zip |
[SPARK-14049][CORE] Add functionality in spark history sever API to query applications by end time
## What changes were proposed in this pull request?
Currently, spark history server REST API provides functionality to query applications by application start time range based on minDate and maxDate query parameters, but it lacks support to query applications by their end time. In this pull request we are proposing optional minEndDate and maxEndDate query parameters and filtering capability based on these parameters to spark history server REST API. This functionality can be used for following queries,
1. Applications finished in last 'x' minutes
2. Applications finished before 'y' time
3. Applications finished between 'x' time to 'y' time
4. Applications started from 'x' time and finished before 'y' time.
For backward compatibility, we can keep existing minDate and maxDate query parameters as they are and they can continue support filtering based on start time range.
## How was this patch tested?
Existing unit tests and 4 new unit tests.
Author: Parag Chaudhari <paragpc@amazon.com>
Closes #11867 from paragpc/master-SHS-query-by-endtime_2.
Diffstat (limited to 'core')
6 files changed, 297 insertions, 2 deletions
diff --git a/core/src/main/scala/org/apache/spark/status/api/v1/ApplicationListResource.scala b/core/src/main/scala/org/apache/spark/status/api/v1/ApplicationListResource.scala index 76779290d4..a0239266d8 100644 --- a/core/src/main/scala/org/apache/spark/status/api/v1/ApplicationListResource.scala +++ b/core/src/main/scala/org/apache/spark/status/api/v1/ApplicationListResource.scala @@ -30,6 +30,8 @@ private[v1] class ApplicationListResource(uiRoot: UIRoot) { @QueryParam("status") status: JList[ApplicationStatus], @DefaultValue("2010-01-01") @QueryParam("minDate") minDate: SimpleDateParam, @DefaultValue("3000-01-01") @QueryParam("maxDate") maxDate: SimpleDateParam, + @DefaultValue("2010-01-01") @QueryParam("minEndDate") minEndDate: SimpleDateParam, + @DefaultValue("3000-01-01") @QueryParam("maxEndDate") maxEndDate: SimpleDateParam, @QueryParam("limit") limit: Integer) : Iterator[ApplicationInfo] = { @@ -43,11 +45,27 @@ private[v1] class ApplicationListResource(uiRoot: UIRoot) { // keep the app if *any* attempts fall in the right time window ((!anyRunning && includeCompleted) || (anyRunning && includeRunning)) && app.attempts.exists { attempt => - val start = attempt.startTime.getTime - start >= minDate.timestamp && start <= maxDate.timestamp + isAttemptInRange(attempt, minDate, maxDate, minEndDate, maxEndDate, anyRunning) } }.take(numApps) } + + private def isAttemptInRange( + attempt: ApplicationAttemptInfo, + minStartDate: SimpleDateParam, + maxStartDate: SimpleDateParam, + minEndDate: SimpleDateParam, + maxEndDate: SimpleDateParam, + anyRunning: Boolean): Boolean = { + val startTimeOk = attempt.startTime.getTime >= minStartDate.timestamp && + attempt.startTime.getTime <= maxStartDate.timestamp + // If the maxEndDate is in the past, exclude all running apps. + val endTimeOkForRunning = anyRunning && (maxEndDate.timestamp > System.currentTimeMillis()) + val endTimeOkForCompleted = !anyRunning && (attempt.endTime.getTime >= minEndDate.timestamp && + attempt.endTime.getTime <= maxEndDate.timestamp) + val endTimeOk = endTimeOkForRunning || endTimeOkForCompleted + startTimeOk && endTimeOk + } } private[spark] object ApplicationsListResource { diff --git a/core/src/test/resources/HistoryServerExpectations/maxEndDate_app_list_json_expectation.json b/core/src/test/resources/HistoryServerExpectations/maxEndDate_app_list_json_expectation.json new file mode 100644 index 0000000000..1842f1888b --- /dev/null +++ b/core/src/test/resources/HistoryServerExpectations/maxEndDate_app_list_json_expectation.json @@ -0,0 +1,95 @@ +[ { + "id" : "local-1430917381535", + "name" : "Spark shell", + "attempts" : [ { + "attemptId" : "2", + "startTime" : "2015-05-06T13:03:00.893GMT", + "endTime" : "2015-05-06T13:03:00.950GMT", + "lastUpdated" : "", + "duration" : 57, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1430917380893, + "endTimeEpoch" : 1430917380950 + }, { + "attemptId" : "1", + "startTime" : "2015-05-06T13:03:00.880GMT", + "endTime" : "2015-05-06T13:03:00.890GMT", + "lastUpdated" : "", + "duration" : 10, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1430917380880, + "endTimeEpoch" : 1430917380890 + } ] +}, { + "id" : "local-1426533911241", + "name" : "Spark shell", + "attempts" : [ { + "attemptId" : "2", + "startTime" : "2015-03-17T23:11:50.242GMT", + "endTime" : "2015-03-17T23:12:25.177GMT", + "lastUpdated" : "", + "duration" : 34935, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1426633910242, + "endTimeEpoch" : 1426633945177 + }, { + "attemptId" : "1", + "startTime" : "2015-03-16T19:25:10.242GMT", + "endTime" : "2015-03-16T19:25:45.177GMT", + "lastUpdated" : "", + "duration" : 34935, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1426533910242, + "endTimeEpoch" : 1426533945177 + } ] +}, { + "id" : "local-1425081759269", + "name" : "Spark shell", + "attempts" : [ { + "startTime" : "2015-02-28T00:02:38.277GMT", + "endTime" : "2015-02-28T00:02:46.912GMT", + "lastUpdated" : "", + "duration" : 8635, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1425081758277, + "endTimeEpoch" : 1425081766912 + } ] +}, { + "id" : "local-1422981780767", + "name" : "Spark shell", + "attempts" : [ { + "startTime" : "2015-02-03T16:42:59.720GMT", + "endTime" : "2015-02-03T16:43:08.731GMT", + "lastUpdated" : "", + "duration" : 9011, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1422981779720, + "endTimeEpoch" : 1422981788731 + } ] +}, { + "id" : "local-1422981759269", + "name" : "Spark shell", + "attempts" : [ { + "startTime" : "2015-02-03T16:42:38.277GMT", + "endTime" : "2015-02-03T16:42:46.912GMT", + "lastUpdated" : "", + "duration" : 8635, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1422981758277, + "endTimeEpoch" : 1422981766912 + } ] +} ] diff --git a/core/src/test/resources/HistoryServerExpectations/minDate_and_maxEndDate_app_list_json_expectation.json b/core/src/test/resources/HistoryServerExpectations/minDate_and_maxEndDate_app_list_json_expectation.json new file mode 100644 index 0000000000..24f9f21ec6 --- /dev/null +++ b/core/src/test/resources/HistoryServerExpectations/minDate_and_maxEndDate_app_list_json_expectation.json @@ -0,0 +1,53 @@ +[ { + "id" : "local-1430917381535", + "name" : "Spark shell", + "attempts" : [ { + "attemptId" : "2", + "startTime" : "2015-05-06T13:03:00.893GMT", + "endTime" : "2015-05-06T13:03:00.950GMT", + "lastUpdated" : "", + "duration" : 57, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1430917380893, + "endTimeEpoch" : 1430917380950 + }, { + "attemptId" : "1", + "startTime" : "2015-05-06T13:03:00.880GMT", + "endTime" : "2015-05-06T13:03:00.890GMT", + "lastUpdated" : "", + "duration" : 10, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1430917380880, + "endTimeEpoch" : 1430917380890 + } ] +}, { + "id" : "local-1426533911241", + "name" : "Spark shell", + "attempts" : [ { + "attemptId" : "2", + "startTime" : "2015-03-17T23:11:50.242GMT", + "endTime" : "2015-03-17T23:12:25.177GMT", + "lastUpdated" : "", + "duration" : 34935, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1426633910242, + "endTimeEpoch" : 1426633945177 + }, { + "attemptId" : "1", + "startTime" : "2015-03-16T19:25:10.242GMT", + "endTime" : "2015-03-16T19:25:45.177GMT", + "lastUpdated" : "", + "duration" : 34935, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1426533910242, + "endTimeEpoch" : 1426533945177 + } ] +} ] diff --git a/core/src/test/resources/HistoryServerExpectations/minEndDate_and_maxEndDate_app_list_json_expectation.json b/core/src/test/resources/HistoryServerExpectations/minEndDate_and_maxEndDate_app_list_json_expectation.json new file mode 100644 index 0000000000..3745e8a09a --- /dev/null +++ b/core/src/test/resources/HistoryServerExpectations/minEndDate_and_maxEndDate_app_list_json_expectation.json @@ -0,0 +1,53 @@ +[ { + "id" : "local-1430917381535", + "name" : "Spark shell", + "attempts" : [ { + "attemptId" : "2", + "startTime" : "2015-05-06T13:03:00.893GMT", + "endTime" : "2015-05-06T13:03:00.950GMT", + "lastUpdated" : "", + "duration" : 57, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1430917380893, + "endTimeEpoch" : 1430917380950 + }, { + "attemptId" : "1", + "startTime" : "2015-05-06T13:03:00.880GMT", + "endTime" : "2015-05-06T13:03:00.890GMT", + "lastUpdated" : "", + "duration" : 10, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1430917380880, + "endTimeEpoch" : 1430917380890 + } ] +}, { + "id" : "local-1426533911241", + "name" : "Spark shell", + "attempts" : [ { + "attemptId" : "2", + "startTime" : "2015-03-17T23:11:50.242GMT", + "endTime" : "2015-03-17T23:12:25.177GMT", + "lastUpdated" : "", + "duration" : 34935, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1426633910242, + "endTimeEpoch" : 1426633945177 + }, { + "attemptId" : "1", + "startTime" : "2015-03-16T19:25:10.242GMT", + "endTime" : "2015-03-16T19:25:45.177GMT", + "lastUpdated" : "", + "duration" : 34935, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1426533910242, + "endTimeEpoch" : 1426533945177 + } ] +} ]
\ No newline at end of file diff --git a/core/src/test/resources/HistoryServerExpectations/minEndDate_app_list_json_expectation.json b/core/src/test/resources/HistoryServerExpectations/minEndDate_app_list_json_expectation.json new file mode 100644 index 0000000000..05233db441 --- /dev/null +++ b/core/src/test/resources/HistoryServerExpectations/minEndDate_app_list_json_expectation.json @@ -0,0 +1,70 @@ +[ { + "id" : "app-20161116163331-0000", + "name" : "Spark shell", + "attempts" : [ { + "startTime" : "2016-11-16T22:33:29.916GMT", + "endTime" : "2016-11-16T22:33:40.587GMT", + "lastUpdated" : "", + "duration" : 10671, + "sparkUser" : "jose", + "completed" : true, + "startTimeEpoch" : 1479335609916, + "lastUpdatedEpoch" : 0, + "endTimeEpoch" : 1479335620587 + } ] +}, { + "id" : "app-20161115172038-0000", + "name" : "Spark shell", + "attempts" : [ { + "startTime" : "2016-11-15T23:20:37.079GMT", + "endTime" : "2016-11-15T23:22:18.874GMT", + "lastUpdated" : "", + "duration" : 101795, + "sparkUser" : "jose", + "completed" : true, + "startTimeEpoch" : 1479252037079, + "lastUpdatedEpoch" : 0, + "endTimeEpoch" : 1479252138874 + } ] +}, { + "id" : "local-1430917381534", + "name" : "Spark shell", + "attempts" : [ { + "startTime" : "2015-05-06T13:03:00.893GMT", + "endTime" : "2015-05-06T13:03:11.398GMT", + "lastUpdated" : "", + "duration" : 10505, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1430917380893, + "endTimeEpoch" : 1430917391398 + } ] +}, { + "id" : "local-1430917381535", + "name" : "Spark shell", + "attempts" : [ { + "attemptId" : "2", + "startTime" : "2015-05-06T13:03:00.893GMT", + "endTime" : "2015-05-06T13:03:00.950GMT", + "lastUpdated" : "", + "duration" : 57, + "sparkUser" : "irashid", + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1430917380893, + "endTimeEpoch" : 1430917380950 + }, { + "attemptId" : "1", + "startTime" : "2015-05-06T13:03:00.880GMT", + "endTime" : "2015-05-06T13:03:00.890GMT", + "lastUpdated" : "", + "duration" : 10, + "sparkUser" : "irashid", + "completed" : true, + "completed" : true, + "lastUpdatedEpoch" : 0, + "startTimeEpoch" : 1430917380880, + "endTimeEpoch" : 1430917380890 + } ] +} ]
\ No newline at end of file diff --git a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala index cd3959a2b1..b2eded43ba 100644 --- a/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala +++ b/core/src/test/scala/org/apache/spark/deploy/history/HistoryServerSuite.scala @@ -102,6 +102,12 @@ class HistoryServerSuite extends SparkFunSuite with BeforeAndAfter with Matchers "minDate app list json" -> "applications?minDate=2015-02-10", "maxDate app list json" -> "applications?maxDate=2015-02-10", "maxDate2 app list json" -> "applications?maxDate=2015-02-03T16:42:40.000GMT", + "minEndDate app list json" -> "applications?minEndDate=2015-05-06T13:03:00.950GMT", + "maxEndDate app list json" -> "applications?maxEndDate=2015-05-06T13:03:00.950GMT", + "minEndDate and maxEndDate app list json" -> + "applications?minEndDate=2015-03-16&maxEndDate=2015-05-06T13:03:00.950GMT", + "minDate and maxEndDate app list json" -> + "applications?minDate=2015-03-16&maxEndDate=2015-05-06T13:03:00.950GMT", "limit app list json" -> "applications?limit=3", "one app json" -> "applications/local-1422981780767", "one app multi-attempt json" -> "applications/local-1426533911241", |