@ThreadSafe public final class NetworkAddressUtils extends Object
Modifier and Type | Class and Description |
---|---|
static class |
NetworkAddressUtils.ServiceType
Different types of services that client uses to connect.
|
Modifier and Type | Field and Description |
---|---|
static String |
WILDCARD_ADDRESS |
static boolean |
WINDOWS
Checks if the underlying OS is Windows.
|
Modifier and Type | Method and Description |
---|---|
static void |
assertValidPort(InetSocketAddress address)
Checks if the given port in the address is valid.
|
static void |
assertValidPort(int port)
Checks if the given port is valid.
|
static InetSocketAddress |
getBindAddress(NetworkAddressUtils.ServiceType service)
Helper method to get the bind hostname for a given service.
|
static String |
getBindHost(NetworkAddressUtils.ServiceType service)
Helper method to get the
InetSocketAddress bind address on a given service. |
static String |
getClientHostName()
Gets the local hostname to be used by the client.
|
static InetSocketAddress |
getConnectAddress(NetworkAddressUtils.ServiceType service)
Helper method to get the
InetSocketAddress address for client to communicate with the
service. |
static InetSocketAddress |
getConnectAddress(NetworkAddressUtils.ServiceType service,
AlluxioConfiguration conf)
Helper method to get the
InetSocketAddress address for client to communicate with the
service. |
static String |
getConnectHost(NetworkAddressUtils.ServiceType service)
Provides an externally resolvable hostname for client to communicate with the service.
|
static String |
getConnectHost(NetworkAddressUtils.ServiceType service,
AlluxioConfiguration conf)
Provides an externally resolvable hostname for client to communicate with the service.
|
static SocketAddress |
getDataPortSocketAddress(WorkerNetAddress netAddress)
Extracts dataPort socket address from Alluxio representation of network address.
|
static String |
getFqdnHost(InetSocketAddress addr)
Gets FQDN(Full Qualified Domain Name) from Java representations of network address, except
String representation which should be handled by
resolveHostName(String) which will
handle the situation where hostname is null. |
static String |
getFqdnHost(WorkerNetAddress addr)
Gets FQDN(Full Qualified Domain Name) from Alluxio representation of network address.
|
static String |
getLocalHostMetricName()
Gets a local hostname for the host this JVM is running on with '.' replaced with '_' for
metrics usage.
|
static String |
getLocalHostName()
Gets a local hostname for the host this JVM is running on.
|
static String |
getLocalHostName(int timeoutMs)
Gets a local host name for the host this JVM is running on.
|
static String |
getLocalIpAddress()
Gets a local IP address for the host this JVM is running on.
|
static String |
getLocalIpAddress(int timeoutMs)
Gets a local IP address for the host this JVM is running on.
|
static String |
getLocalNodeName()
Gets a local node name from configuration if it is available, falling back on localhost lookup.
|
static int |
getPort(NetworkAddressUtils.ServiceType service)
Gets the port number on a given service type.
|
static int |
getPort(NetworkAddressUtils.ServiceType service,
AlluxioConfiguration config)
Gets the port number on a given service type.
|
static InetSocketAddress |
getRpcPortSocketAddress(WorkerNetAddress netAddress)
Extracts rpcPort InetSocketAddress from Alluxio representation of network address.
|
static boolean |
isServing(String host,
int port) |
static InetSocketAddress |
parseInetSocketAddress(String address)
Parses
InetSocketAddress from a String. |
static void |
pingService(InetSocketAddress address,
String serviceName)
Test if the input address is serving an Alluxio service.
|
static AlluxioURI |
replaceHostName(AlluxioURI path)
Replaces and resolves the hostname in a given address or path string.
|
static String |
resolveHostName(String hostname)
Resolves a given hostname by a canonical hostname.
|
static String |
resolveIpAddress(String hostname)
Resolves a given hostname IP address.
|
public static final String WILDCARD_ADDRESS
public static final boolean WINDOWS
public static void assertValidPort(int port)
port
- the port to checkpublic static void assertValidPort(InetSocketAddress address)
address
- the InetSocketAddress
with the port to checkpublic static InetSocketAddress getConnectAddress(NetworkAddressUtils.ServiceType service)
InetSocketAddress
address for client to communicate with the
service.service
- the service name used to connectpublic static InetSocketAddress getConnectAddress(NetworkAddressUtils.ServiceType service, AlluxioConfiguration conf)
InetSocketAddress
address for client to communicate with the
service.service
- the service name used to connectconf
- the configuration to use for looking up the connect addresspublic static String getConnectHost(NetworkAddressUtils.ServiceType service)
Specified Hostname | Specified Bind Host | Returned Connect Host |
---|---|---|
hostname | hostname | hostname |
not defined | hostname | hostname |
hostname | 0.0.0.0 or not defined | hostname |
not defined | 0.0.0.0 or not defined | localhost |
service
- Service type used to connectpublic static String getConnectHost(NetworkAddressUtils.ServiceType service, AlluxioConfiguration conf)
Specified Hostname | Specified Bind Host | Returned Connect Host |
---|---|---|
hostname | hostname | hostname |
not defined | hostname | hostname |
hostname | 0.0.0.0 or not defined | hostname |
not defined | 0.0.0.0 or not defined | localhost |
service
- Service type used to connectconf
- configurationpublic static int getPort(NetworkAddressUtils.ServiceType service)
service
- Service type used to connectpublic static int getPort(NetworkAddressUtils.ServiceType service, AlluxioConfiguration config)
service
- Service type used to connectconfig
- configurationpublic static InetSocketAddress getBindAddress(NetworkAddressUtils.ServiceType service)
service
- the service namepublic static String getBindHost(NetworkAddressUtils.ServiceType service)
InetSocketAddress
bind address on a given service.
Host bind information searching order:
service
- the service namepublic static String getClientHostName()
public static String getLocalNodeName()
public static String getLocalHostName()
public static String getLocalHostName(int timeoutMs)
timeoutMs
- Timeout in milliseconds to use for checking that a possible local host is
reachablepublic static String getLocalHostMetricName()
public static String getLocalIpAddress()
public static String getLocalIpAddress(int timeoutMs)
timeoutMs
- Timeout in milliseconds to use for checking that a possible local IP is
reachablepublic static boolean isServing(String host, int port)
host
- the host to try to connect toport
- the port to try to connect on@Nullable public static AlluxioURI replaceHostName(AlluxioURI path) throws UnknownHostException
path
- an address or path string, e.g., "hdfs://host:port/dir", "file:///dir", "/dir"UnknownHostException
- if the hostname cannot be resolved@Nullable public static String resolveHostName(String hostname) throws UnknownHostException
hostname
- the input hostname, which could be an aliasUnknownHostException
- if the given hostname cannot be resolvedpublic static String resolveIpAddress(String hostname) throws UnknownHostException
hostname
- the input hostname, which could be an aliasUnknownHostException
- if the given hostname cannot be resolvedpublic static String getFqdnHost(InetSocketAddress addr)
resolveHostName(String)
which will
handle the situation where hostname is null.addr
- the input network address representation, can not be nullpublic static String getFqdnHost(WorkerNetAddress addr) throws UnknownHostException
addr
- the input network address representationUnknownHostException
- if the host is not known@Nullable public static InetSocketAddress parseInetSocketAddress(String address) throws IOException
InetSocketAddress
from a String.address
- socket address to parseIOException
public static InetSocketAddress getRpcPortSocketAddress(WorkerNetAddress netAddress)
netAddress
- the input network address representationpublic static SocketAddress getDataPortSocketAddress(WorkerNetAddress netAddress)
netAddress
- the input network address representationpublic static void pingService(InetSocketAddress address, String serviceName) throws UnauthenticatedException, ConnectionFailedException
address
- the network address to pingserviceName
- the Alluxio service nameUnauthenticatedException
- If the user is not authenticatedConnectionFailedException
- If there is a protocol transport errorCopyright © 2023. All Rights Reserved.