@@ -66,57 +66,49 @@ private[spark] class YarnClusterSchedulerBackend(
66
66
override def getDriverLogUrls : Option [Map [String , String ]] = {
67
67
var yarnClientOpt : Option [YarnClient ] = None
68
68
var driverLogs : Option [Map [String , String ]] = None
69
- val appId : String = applicationId()
70
- if (appId == null ) {
71
- logError(" Application Id not set. Cannot get Driver Log URLs" )
72
- None
73
- } else {
74
- try {
75
- val yarnConf = new YarnConfiguration (sc.hadoopConfiguration)
76
- val containerId = YarnSparkHadoopUtil .get.getContainerId
69
+ try {
70
+ val yarnConf = new YarnConfiguration (sc.hadoopConfiguration)
71
+ val containerId = YarnSparkHadoopUtil .get.getContainerId
72
+ yarnClientOpt = Some (YarnClient .createYarnClient())
73
+ yarnClientOpt.foreach { yarnClient =>
74
+ yarnClient.init(yarnConf)
75
+ yarnClient.start()
76
+ val addresses =
77
+ NetworkInterface .getNetworkInterfaces.asScala
78
+ .flatMap(_.getInetAddresses.asScala)
79
+ .toSeq
77
80
78
- yarnClientOpt = Some (YarnClient .createYarnClient())
79
-
80
- yarnClientOpt.foreach { yarnClient =>
81
- yarnClient.init(yarnConf)
82
- yarnClient.start()
83
- val addresses =
84
- NetworkInterface .getNetworkInterfaces.asScala
85
- .flatMap(_.getInetAddresses.asScala)
86
- .toSeq
87
-
88
- val nodeReport =
89
- yarnClient.getNodeReports(NodeState .RUNNING ).asScala.find { x =>
90
- val host = x.getNodeId.getHost
91
- addresses.exists { address =>
92
- address.getHostAddress == host ||
93
- address.getHostName == host ||
94
- address.getCanonicalHostName == host
95
- }
81
+ val nodeReport =
82
+ yarnClient.getNodeReports(NodeState .RUNNING ).asScala.find { x =>
83
+ val host = x.getNodeId.getHost
84
+ addresses.exists { address =>
85
+ address.getHostAddress == host ||
86
+ address.getHostName == host ||
87
+ address.getCanonicalHostName == host
96
88
}
97
- nodeReport.foreach { report =>
98
- val httpAddress = report.getHttpAddress
99
- // lookup appropriate http scheme for container log urls
100
- val yarnHttpPolicy = yarnConf.get(
101
- YarnConfiguration .YARN_HTTP_POLICY_KEY ,
102
- YarnConfiguration .YARN_HTTP_POLICY_DEFAULT
103
- )
104
- val user = Utils .getCurrentUserName()
105
- val httpScheme = if (yarnHttpPolicy == " HTTPS_ONLY" ) " https://" else " http://"
106
- val baseUrl = s " $httpScheme$httpAddress/node/containerlogs/ $containerId/ $user"
107
- logInfo(s " Base URL for logs: $baseUrl" )
108
- driverLogs = Some (
109
- Map (" stderr" -> s " $baseUrl/stderr?start=0 " , " stdout" -> s " $baseUrl/stdout?start=0 " ))
110
89
}
90
+ nodeReport.foreach { report =>
91
+ val httpAddress = report.getHttpAddress
92
+ // lookup appropriate http scheme for container log urls
93
+ val yarnHttpPolicy = yarnConf.get(
94
+ YarnConfiguration .YARN_HTTP_POLICY_KEY ,
95
+ YarnConfiguration .YARN_HTTP_POLICY_DEFAULT
96
+ )
97
+ val user = Utils .getCurrentUserName()
98
+ val httpScheme = if (yarnHttpPolicy == " HTTPS_ONLY" ) " https://" else " http://"
99
+ val baseUrl = s " $httpScheme$httpAddress/node/containerlogs/ $containerId/ $user"
100
+ logInfo(s " Base URL for logs: $baseUrl" )
101
+ driverLogs = Some (
102
+ Map (" stderr" -> s " $baseUrl/stderr?start=0 " , " stdout" -> s " $baseUrl/stdout?start=0 " ))
111
103
}
112
- } catch {
113
- case e : Exception =>
114
- logInfo(" Node Report API is not available in the version of YARN being used, so AM" +
115
- " logs link will not appear in application UI" , e)
116
- } finally {
117
- yarnClientOpt.foreach(_.close())
118
104
}
119
- driverLogs
105
+ } catch {
106
+ case e : Exception =>
107
+ logInfo(" Node Report API is not available in the version of YARN being used, so AM" +
108
+ " logs link will not appear in application UI" , e)
109
+ } finally {
110
+ yarnClientOpt.foreach(_.close())
120
111
}
112
+ driverLogs
121
113
}
122
114
}
0 commit comments