Spark Utils find localIpAddress
来源:互联网 发布:软件定义 编辑:程序博客网 时间:2024/06/07 23:10
/** * Get the local host's IP address in dotted-quad format (e.g. 1.2.3.4). * Note, this is typically not used from within core spark. */ private lazy val localIpAddress: InetAddress = findLocalInetAddress() private def findLocalInetAddress(): InetAddress = { val defaultIpOverride = System.getenv("SPARK_LOCAL_IP") if (defaultIpOverride != null) { InetAddress.getByName(defaultIpOverride) } else { val address = InetAddress.getLocalHost if (address.isLoopbackAddress) { // Address resolves to something like 127.0.1.1, which happens on Debian; try to find // a better address using the local network interfaces // getNetworkInterfaces returns ifs in reverse order compared to ifconfig output order // on unix-like system. On windows, it returns in index order. // It's more proper to pick ip address following system output order. val activeNetworkIFs = NetworkInterface.getNetworkInterfaces.asScala.toSeq val reOrderedNetworkIFs = if (isWindows) activeNetworkIFs else activeNetworkIFs.reverse for (ni <- reOrderedNetworkIFs) { val addresses = ni.getInetAddresses.asScala .filterNot(addr => addr.isLinkLocalAddress || addr.isLoopbackAddress).toSeq if (addresses.nonEmpty) { val addr = addresses.find(_.isInstanceOf[Inet4Address]).getOrElse(addresses.head) // because of Inet6Address.toHostName may add interface at the end if it knows about it val strippedAddress = InetAddress.getByAddress(addr.getAddress) // We've found an address that looks reasonable! logWarning("Your hostname, " + InetAddress.getLocalHost.getHostName + " resolves to" + " a loopback address: " + address.getHostAddress + "; using " + strippedAddress.getHostAddress + " instead (on interface " + ni.getName + ")") logWarning("Set SPARK_LOCAL_IP if you need to bind to another address") return strippedAddress } } logWarning("Your hostname, " + InetAddress.getLocalHost.getHostName + " resolves to" + " a loopback address: " + address.getHostAddress + ", but we couldn't find any" + " external IP address!") logWarning("Set SPARK_LOCAL_IP if you need to bind to another address") } address } }
0 0
- Spark Utils find localIpAddress
- Spark-utils 类
- Spark中Utils.getCallSite()的作用
- Spark中Utils.getCallSite()的作用
- UTILS
- Utils
- utils
- utils
- Utils
- Utils
- Utils
- utils
- Utils
- Utils
- Utils
- UTILS
- Utils
- Utils
- mysql赋予外部访问权限
- opencv将灰度图转化为RGB三通道图像
- linux 内核配置文件/etc/grub.conf
- RN部署热更新学习
- springboot 使用Servlet,Filter,Listener的方法
- Spark Utils find localIpAddress
- java 数据结构
- C#中文本文件与二进制文件
- 51nod_1046 A^B Mod C
- 数据库同步
- 实现足够大List<int>剔除重复的数字
- can’t refactor code used in this language
- MySQL存储过程decimal得到值为0.00问题
- What exactly is copy-on-modify semantics in R, and where is the canonical source?