Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions core/src/main/scala/org/apache/spark/util/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1071,21 +1071,30 @@ private[spark] object Utils extends Logging {
* Get the local machine's FQDN.
*/
def localCanonicalHostName(): String = {
customHostname.getOrElse(localIpAddress.getCanonicalHostName)
addBracketsIfNeeded(customHostname.getOrElse(localIpAddress.getCanonicalHostName))
}

/**
* Get the local machine's hostname.
* In case of IPv6, getHostAddress may return '0:0:0:0:0:0:0:1'.
*/
def localHostName(): String = {
customHostname.getOrElse(localIpAddress.getHostAddress)
addBracketsIfNeeded(customHostname.getOrElse(localIpAddress.getHostAddress))
}

/**
* Get the local machine's URI.
*/
def localHostNameForURI(): String = {
customHostname.getOrElse(InetAddresses.toUriString(localIpAddress))
addBracketsIfNeeded(customHostname.getOrElse(InetAddresses.toUriString(localIpAddress)))
}

private def addBracketsIfNeeded(addr: String): String = {
if (addr.contains(":") && !addr.contains("[")) {
"[" + addr + "]"
} else {
addr
}
}

/**
Expand Down