Skip to content

Commit f0264a7

Browse files
committed
switch to using jersey for metrics json
1 parent bceb3a9 commit f0264a7

File tree

55 files changed

+776
-562
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+776
-562
lines changed

core/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,11 @@
219219
<artifactId>jackson-module-scala_2.10</artifactId>
220220
<version>2.3.1</version>
221221
</dependency>
222+
<dependency>
223+
<groupId>org.glassfish.jersey.media</groupId>
224+
<artifactId>jersey-media-json-jackson</artifactId>
225+
<version>2.15</version>
226+
</dependency>
222227
<dependency>
223228
<groupId>org.apache.mesos</groupId>
224229
<artifactId>mesos</artifactId>

core/src/main/java/org/apache/spark/JobExecutionStatus.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,31 @@
1717

1818
package org.apache.spark;
1919

20+
import com.google.common.base.Joiner;
21+
22+
import java.util.Arrays;
23+
2024
public enum JobExecutionStatus {
2125
RUNNING,
2226
SUCCEEDED,
2327
FAILED,
24-
UNKNOWN
28+
UNKNOWN;
29+
30+
31+
private static String VALID_VALUES = Joiner.on(", ").join(
32+
Arrays.asList(JobExecutionStatus.values()));
33+
34+
public static JobExecutionStatus fromString(String str) {
35+
if (str == null) {
36+
return null;
37+
}
38+
try {
39+
JobExecutionStatus res = valueOf(str.toUpperCase());
40+
return res;
41+
} catch (IllegalArgumentException iae) {
42+
throw new IllegalArgumentException(
43+
String.format("Illegal type='%s'. Supported type values: %s",
44+
str, VALID_VALUES));
45+
}
46+
}
2547
}
Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,31 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17-
package org.apache.spark.deploy.history
1817

19-
import javax.servlet.http.HttpServletRequest
18+
package org.apache.spark.status.api;
2019

21-
import org.apache.spark.status.{UIRoot, JsonRequestHandler, StatusJsonRoute}
22-
import org.apache.spark.status.api.ApplicationInfo
20+
import com.google.common.base.Joiner;
2321

24-
class OneApplicationJsonRoute(val uiRoot: UIRoot) extends StatusJsonRoute[ApplicationInfo] {
25-
override def renderJson(request: HttpServletRequest): ApplicationInfo = {
26-
val appIdOpt = JsonRequestHandler.extractAppId(request.getPathInfo)
27-
appIdOpt.map{ appId =>
28-
val apps = uiRoot.getApplicationInfoList.find{_.id == appId}
29-
apps.getOrElse(throw new IllegalArgumentException("unknown app: " + appId))
30-
}.getOrElse{
31-
throw new IllegalArgumentException("no application id specified")
22+
import java.util.Arrays;
23+
24+
public enum ApplicationStatus {
25+
COMPLETED,
26+
RUNNING;
27+
28+
private static String VALID_VALUES = Joiner.on(", ").join(
29+
Arrays.asList(values()));
30+
31+
public static ApplicationStatus fromString(String str) {
32+
if (str == null) {
33+
return null;
34+
}
35+
for (ApplicationStatus status: values()) {
36+
if (status.name().equalsIgnoreCase(str))
37+
return status;
38+
}
39+
throw new IllegalArgumentException(
40+
String.format("Illegal type='%s'. Supported type values: %s",
41+
str, VALID_VALUES));
3242
}
33-
}
43+
3444
}

core/src/main/java/org/apache/spark/status/api/StageStatus.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package org.apache.spark.status.api;/*
1+
/*
22
* Licensed to the Apache Software Foundation (ASF) under one or more
33
* contributor license agreements. See the NOTICE file distributed with
44
* this work for additional information regarding copyright ownership.
@@ -15,9 +15,31 @@
1515
* limitations under the License.
1616
*/
1717

18+
package org.apache.spark.status.api;
19+
20+
import com.google.common.base.Joiner;
21+
22+
import java.util.Arrays;
23+
1824
public enum StageStatus {
1925
Active,
2026
Complete,
2127
Failed,
22-
Pending
28+
Pending;
29+
30+
private static String VALID_VALUES = Joiner.on(", ").join(
31+
Arrays.asList(values()));
32+
33+
public static StageStatus fromString(String str) {
34+
if (str == null) {
35+
return null;
36+
}
37+
for (StageStatus status: values()) {
38+
if (status.name().equalsIgnoreCase(str))
39+
return status;
40+
}
41+
throw new IllegalArgumentException(
42+
String.format("Illegal type='%s'. Supported type values: %s",
43+
str, VALID_VALUES));
44+
}
2345
}

core/src/main/scala/org/apache/spark/deploy/history/HistoryServer.scala

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,7 @@ import java.util.NoSuchElementException
2121
import javax.servlet.http.{HttpServlet, HttpServletRequest, HttpServletResponse}
2222

2323
import com.google.common.cache._
24-
import org.apache.spark.deploy.master.ui.MasterApplicationJsonRoute
25-
import org.apache.spark.status.api.ApplicationInfo
26-
import org.apache.spark.status.{UIRoot, JsonRequestHandler}
24+
import org.apache.spark.status.api.v1.{ApplicationsListResource, ApplicationInfo, JsonRootResource, UIRoot}
2725
import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
2826

2927
import org.apache.spark.{Logging, SecurityManager, SparkConf}
@@ -117,9 +115,8 @@ class HistoryServer(
117115
def initialize() {
118116
attachPage(new HistoryPage(this))
119117

120-
val jsonHandler = new JsonRequestHandler(this, securityManager)
121-
attachHandler(jsonHandler.jsonContextHandler)
122118

119+
attachHandler(JsonRootResource.getJsonServlet(this))
123120

124121
attachHandler(createStaticHandler(SparkUI.STATIC_RESOURCE_DIR, "/static"))
125122

@@ -161,7 +158,7 @@ class HistoryServer(
161158
def getApplicationList(refresh: Boolean) = provider.getListing(refresh)
162159

163160
def getApplicationInfoList: Seq[ApplicationInfo] = {
164-
getApplicationList(true).map{AllApplicationsJsonRoute.appHistoryInfoToPublicAppInfo}.toSeq
161+
getApplicationList(true).map{ApplicationsListResource.appHistoryInfoToPublicAppInfo}.toSeq
165162
}
166163

167164
/**

core/src/main/scala/org/apache/spark/deploy/master/ui/MasterApplicationJsonRoute.scala

Lines changed: 0 additions & 44 deletions
This file was deleted.

core/src/main/scala/org/apache/spark/deploy/master/ui/MasterJsonRoute.scala

Lines changed: 0 additions & 59 deletions
This file was deleted.

core/src/main/scala/org/apache/spark/deploy/master/ui/MasterWebUI.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
package org.apache.spark.deploy.master.ui
1919

2020
import org.apache.spark.Logging
21-
import org.apache.spark.deploy.history.AllApplicationsJsonRoute
2221
import org.apache.spark.deploy.master.Master
23-
import org.apache.spark.status.{JsonRequestHandler, UIRoot}
24-
import org.apache.spark.status.api.ApplicationInfo
22+
import org.apache.spark.status.api.v1.{ApplicationsListResource, ApplicationInfo, JsonRootResource, UIRoot}
2523
import org.apache.spark.ui.{SparkUI, WebUI}
2624
import org.apache.spark.ui.JettyUtils._
2725
import org.apache.spark.util.AkkaUtils
@@ -47,8 +45,7 @@ class MasterWebUI(val master: Master, requestedPort: Int)
4745
attachPage(masterPage)
4846
attachHandler(createStaticHandler(MasterWebUI.STATIC_RESOURCE_DIR, "/static"))
4947

50-
val jsonHandler = new JsonRequestHandler(this, master.securityMgr)
51-
attachHandler(jsonHandler.jsonContextHandler)
48+
attachHandler(JsonRootResource.getJsonServlet(this))
5249
}
5350

5451
/** Attach a reconstructed UI to this Master UI. Only valid after bind(). */
@@ -67,8 +64,8 @@ class MasterWebUI(val master: Master, requestedPort: Int)
6764
val state = masterPage.getMasterState
6865
val activeApps = state.activeApps.sortBy(_.startTime).reverse
6966
val completedApps = state.completedApps.sortBy(_.endTime).reverse
70-
activeApps.map{AllApplicationsJsonRoute.convertApplicationInfo(_, false)} ++
71-
completedApps.map{AllApplicationsJsonRoute.convertApplicationInfo(_, true)}
67+
activeApps.map{ApplicationsListResource.convertApplicationInfo(_, false)} ++
68+
completedApps.map{ApplicationsListResource.convertApplicationInfo(_, true)}
7269
}
7370

7471
def getSparkUI(appId: String): Option[SparkUI] = {

0 commit comments

Comments
 (0)