Github user squito commented on a diff in the pull request:

    https://github.com/apache/spark/pull/4435#discussion_r27981125
  
    --- Diff: 
core/src/main/scala/org/apache/spark/status/api/v1/JsonRootResource.scala ---
    @@ -0,0 +1,160 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *    http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.spark.status.api.v1
    +
    +import javax.servlet.ServletContext
    +import javax.ws.rs._
    +import javax.ws.rs.core.{Context, Response}
    +
    +import com.sun.jersey.api.core.ResourceConfig
    +import com.sun.jersey.spi.container.servlet.ServletContainer
    +import org.eclipse.jetty.server.handler.ContextHandler
    +import org.eclipse.jetty.servlet.{ServletContextHandler, ServletHolder}
    +
    +import org.apache.spark.SecurityManager
    +import org.apache.spark.ui.SparkUI
    +
    +@Path("/v1")
    +private[v1] class JsonRootResource extends UIRootFromServletContext {
    +
    +  @Path("applications")
    +  def getApplicationList(): ApplicationListResource = {
    +    new ApplicationListResource(uiRoot)
    +  }
    +
    +  @Path("applications/{appId}")
    +  def getApplication(): OneApplicationResource = {
    +    new OneApplicationResource(uiRoot)
    +  }
    +
    +  @Path("applications/{appId}/jobs")
    +  def getJobs(): AllJobsResource = {
    +    new AllJobsResource(uiRoot)
    +  }
    +
    +  @Path("applications/{appId}/jobs/{jobId: \\d+}")
    +  def getJob(): OneJobResource = {
    +    new OneJobResource(uiRoot)
    +  }
    +
    +
    +  @Path("applications/{appId}/executors")
    +  def getExecutors(): ExecutorListResource = {
    +    new ExecutorListResource(uiRoot)
    +  }
    +
    +  @Path("applications/{appId}/stages")
    +  def getStages(): AllStagesResource= {
    +    new AllStagesResource(uiRoot)
    +  }
    +
    +  @Path("applications/{appId}/stages/{stageId: \\d+}")
    +  def getStage(): OneStageResource= {
    +    new OneStageResource(uiRoot)
    +  }
    +
    +  @Path("applications/{appId}/storage/rdd")
    +  def getRdds(): AllRDDResource = {
    +    new AllRDDResource(uiRoot)
    +  }
    +
    +  @Path("applications/{appId}/storage/rdd/{rddId: \\d+}")
    +  def getRdd(): OneRDDResource = {
    +    new OneRDDResource(uiRoot)
    +  }
    +
    +}
    +
    +private[spark] object JsonRootResource {
    +
    +  def getJsonServlet(uiRoot: UIRoot): ServletContextHandler = {
    +    val jerseyContext = new 
ServletContextHandler(ServletContextHandler.NO_SESSIONS)
    +    jerseyContext.setContextPath("/json")
    +    val holder:ServletHolder = new ServletHolder(classOf[ServletContainer])
    +    
holder.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
    +      "com.sun.jersey.api.core.PackagesResourceConfig")
    +    holder.setInitParameter("com.sun.jersey.config.property.packages",
    +      "org.apache.spark.status.api.v1")
    +    
holder.setInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS,
    +      classOf[SecurityFilter].getCanonicalName)
    +    UIRootFromServletContext.setUiRoot(jerseyContext, uiRoot)
    +    jerseyContext.addServlet(holder, "/*")
    +    jerseyContext
    +  }
    +}
    +
    +
    +/**
    + * This trait is shared by the all the root containers for application UI 
information --
    + * the HistoryServer, the Master UI, and the application UI.  This 
provides the common
    + * interface needed for them all to expose application info as json.
    + */
    +private[spark] trait UIRoot {
    +  def getSparkUI(appKey: String): Option[SparkUI]
    +  def getApplicationInfoList: Seq[ApplicationInfo]
    +
    +  /**
    +   * Get the spark UI with the given appID, and apply a function
    +   * to it.  If there is no such app, throw an appropriate exception
    +   */
    +  def withSparkUI[T](appId: String)(f: SparkUI => T): T = {
    +    getSparkUI(appId) match {
    +      case Some(ui) =>
    +        f(ui)
    +      case None => throw new NotFoundException("no such app: " + appId)
    +    }
    +  }
    +  def securityManager: SecurityManager
    +}
    +
    +private[v1] object UIRootFromServletContext {
    +  private val attribute = getClass.getCanonicalName
    +  def setUiRoot(contextHandler: ContextHandler, uiRoot: UIRoot): Unit = {
    +    contextHandler.setAttribute(attribute, uiRoot)
    +  }
    +  def getUiRoot(context: ServletContext): UIRoot = {
    +    context.getAttribute(attribute).asInstanceOf[UIRoot]
    +  }
    +}
    +
    +private[v1] trait UIRootFromServletContext {
    +  @Context
    +  var servletContext: ServletContext = _
    +
    +  def uiRoot: UIRoot = UIRootFromServletContext.getUiRoot(servletContext)
    +}
    +
    +private[v1] class NotFoundException(msg: String) extends 
WebApplicationException(
    +  new IllegalArgumentException(msg),
    +    Response
    +      .status(Response.Status.NOT_FOUND)
    +      .entity(msg)
    +      .build()
    +)
    +
    +private[v1] class BadParameterException(msg: String) extends 
WebApplicationException(
    +  new IllegalArgumentException(msg),
    +  Response
    +    .status(Response.Status.BAD_REQUEST)
    +    .entity(msg)
    +    .build()
    +) {
    +  def this(param: String, exp: String, actual: String) = {
    +    this("Bad value for parameter \"" + param + "\".  Expected a " + exp + 
", got \"" +
    --- End diff --
    
    string interpolation behaves strangely with quotes.  A simple `s"..."` 
doesn't like escaped quotes inside.  You can use the triple quote version 
`s"""..."""` but I had some vague recollection that it had some surprises vs. 
regular triple-quoted strings.  Just did a bit of research -- I guess what I 
want is `raw"""..."""` http://stackoverflow.com/a/25633978/1442961


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to