[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.
This commit is contained in:
Parag Chaudhari 2017-01-24 08:41:46 -06:00 committed by Imran Rashid
parent 752502be05
commit 0ff67a1cf9
7 changed files with 311 additions and 5 deletions

View file

@ -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 {

View file

@ -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
} ]
} ]

View file

@ -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
} ]
} ]

View file

@ -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
} ]
} ]

View file

@ -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
} ]
} ]

View file

@ -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",

View file

@ -267,12 +267,23 @@ can be identified by their `[attempt-id]`. In the API listed below, when running
<br>
<code>?status=[completed|running]</code> list only applications in the chosen state.
<br>
<code>?minDate=[date]</code> earliest date/time to list.
<code>?minDate=[date]</code> earliest start date/time to list.
<br>
<code>?maxDate=[date]</code> latest start date/time to list.
<br>
<code>?minEndDate=[date]</code> earliest end date/time to list.
<br>
<code>?maxEndDate=[date]</code> latest end date/time to list.
<br>
<code>?limit=[limit]</code> limits the number of applications listed.
<br>Examples:
<br><code>?minDate=2015-02-10</code>
<br><code>?minDate=2015-02-03T16:42:40.000GMT</code>
<br><code>?maxDate=[date]</code> latest date/time to list; uses same format as <code>minDate</code>.
<br><code>?limit=[limit]</code> limits the number of applications listed.</td>
<br><code>?maxDate=2015-02-11T20:41:30.000GMT</code>
<br><code>?minEndDate=2015-02-12</code>
<br><code>?minEndDate=2015-02-12T09:15:10.000GMT</code>
<br><code>?maxEndDate=2015-02-14T16:30:45.000GMT</code>
<br><code>?limit=10</code></td>
</tr>
<tr>
<td><code>/applications/[app-id]/jobs</code></td>