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

    https://github.com/apache/spark/pull/2469#discussion_r18122033
  
    --- Diff: 
yarn/stable/src/main/scala/org/apache/spark/deploy/yarn/YarnRMClientImpl.scala 
---
    @@ -69,7 +74,32 @@ private class YarnRMClientImpl(args: 
ApplicationMasterArguments) extends YarnRMC
         appAttemptId
       }
     
    -  override def getProxyHostAndPort(conf: YarnConfiguration) = 
WebAppUtils.getProxyHostAndPort(conf)
    +  override def getAmIpFilterParams(conf: YarnConfiguration, proxyBase: 
String) = {
    +    // Figure out which scheme Yarn is using. Note the method seems to 
have been added after 2.2,
    +    // so not all stable releases have it.
    +    val prefix = Try(classOf[WebAppUtils].getMethod("getHttpSchemePrefix", 
classOf[Configuration])
    +        .invoke(null, conf).asInstanceOf[String]).getOrElse("http://";)
    +
    +    // If running a new enough Yarn, use the HA-aware API for retrieving 
the RM addresses.
    +    val method = 
Try(classOf[WebAppUtils].getMethod("getProxyHostsAndPortsForAmFilter",
    +      classOf[Configuration]))
    +    method match {
    +      case Success(proxiesMethod) =>
    +        val proxies = proxiesMethod.invoke(null, 
conf).asInstanceOf[JList[String]]
    +        val hosts = proxies.map { proxy => proxy.split(":")(0) }
    +        val uriBases = proxies.map { proxy => prefix + proxy + proxyBase }
    +        Map("PROXY_HOSTS" -> hosts.mkString(","), "PROXY_URI_BASES" -> 
uriBases.mkString(","))
    +
    +      case Failure(e: NoSuchMethodException) =>
    +        val proxy = WebAppUtils.getProxyHostAndPort(conf)
    +        val parts = proxy.split(":")
    +        val uriBase = prefix + proxy + proxyBase
    +        Map("PROXY_HOST" -> parts(0), "PROXY_URI_BASE" -> uriBase)
    +
    +      case Failure(e) =>
    +        throw e
    +    }
    +  }
    --- End diff --
    
    I actually think this whole block is clearer with Java's plain old try 
catch, particular because the things you are `Try`ing are pretty long.


---
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 [email protected] or file a JIRA ticket
with INFRA.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to