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

    https://github.com/apache/spark/pull/6166#discussion_r30432294
  
    --- Diff: 
yarn/src/main/scala/org/apache/spark/deploy/yarn/ApplicationMaster.scala ---
    @@ -262,6 +266,50 @@ private[spark] class ApplicationMaster(
     
       private def runDriver(securityMgr: SecurityManager): Unit = {
         addAmIpFilter()
    +    if (isClusterMode) {
    +      val containerId = ConverterUtils.toContainerId(
    +        
System.getenv(ApplicationConstants.Environment.CONTAINER_ID.name()))
    +      val yarnClient = YarnClient.createYarnClient()
    +      yarnClient.init(yarnConf)
    +      yarnClient.start()
    +      val addresses =
    +        NetworkInterface.getNetworkInterfaces.asScala
    +          .flatMap(_.getInetAddresses.asScala)
    +          .toSeq
    +      try {
    +        val nodeReports = 
yarnClient.getNodeReports(NodeState.RUNNING).asScala
    +        val nodeReport =
    +          nodeReports.find { x =>
    +            val host = x.getNodeId.getHost
    +            addresses.exists { address =>
    +              address.getHostAddress == host ||
    +              address.getHostName == host    ||
    +              address.getCanonicalHostName == host
    +            }
    +          }
    +
    +        nodeReport.foreach { report =>
    +          val httpAddress = report.getHttpAddress
    +          // lookup appropriate http scheme for container log urls
    +          val yarnHttpPolicy = yarnConf.get(
    +            YarnConfiguration.YARN_HTTP_POLICY_KEY,
    +            YarnConfiguration.YARN_HTTP_POLICY_DEFAULT
    +          )
    +          val user = Utils.getCurrentUserName()
    +          val httpScheme = if (yarnHttpPolicy == "HTTPS_ONLY") "https://"; 
else "http://";
    +          val baseUrl = 
s"$httpScheme$httpAddress/node/containerlogs/$containerId/$user"
    +          logInfo(s"Base URL for logs: $baseUrl")
    +          System.setProperty("spark.driver.log.stderr", 
s"$baseUrl/stderr?start=0")
    +          System.setProperty("spark.driver.log.stdout", 
s"$baseUrl/stdout?start=0")
    +        }
    +      } catch {
    +        case e: Exception =>
    +          logInfo("Container Report API is not available in the version of 
YARN being used, so AM" +
    --- End diff --
    
    Hmm, this message raises the question of "is the API available at all in 
the client interfaces in old YARN versions"? I see `getNodeReports` exists in 
the branch-2.2 branch, so when would you get into this particular situation?
    
    Also, should probably log the exception. More things can go wrong here than 
just what the message says.


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