@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 |
UNKNOWN_HOSTNAME |
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 boolean |
containsLocalIp(List<InetSocketAddress> clusterAddresses,
AlluxioConfiguration conf) |
static InetSocketAddress |
getBindAddress(NetworkAddressUtils.ServiceType service,
AlluxioConfiguration conf)
Helper method to get the bind hostname for a given service.
|
static String |
getBindHost(NetworkAddressUtils.ServiceType service,
AlluxioConfiguration conf)
Helper method to get the
InetSocketAddress bind address on a given service. |
static String |
getClientHostName(AlluxioConfiguration conf)
Gets the local hostname to be used by the client.
|
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,
AlluxioConfiguration conf)
Provides an externally resolvable hostname for client to communicate with the service.
|
static SocketAddress |
getDataPortSocketAddress(WorkerNetAddress netAddress,
AlluxioConfiguration conf)
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(int timeoutMs)
Gets a local hostname for the host this JVM is running on with '.' replaced with '_' for
metrics usage.
|
static String |
getLocalHostName(int timeoutMs)
Gets a local host name 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(AlluxioConfiguration conf)
Gets a local node name from configuration if it is available, falling back on localhost lookup.
|
static int |
getPort(NetworkAddressUtils.ServiceType service,
AlluxioConfiguration conf)
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,
ServiceType serviceType,
AlluxioConfiguration conf,
UserState userState)
Test if the input address is serving an Alluxio service.
|
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 String UNKNOWN_HOSTNAME
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, 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, AlluxioConfiguration conf)
Specified Hostname | Specified Bind Host | Enable Network IP Address Used | Returned Connect Host |
---|---|---|---|
hostname | hostname | true/false | hostname |
not defined | hostname | true/false | hostname |
hostname | 0.0.0.0 or not defined | true/false | hostname |
not defined | 0.0.0.0 or not defined | false | local hostname |
not defined | 0.0.0.0 or not defined | true | local IP address |
service
- Service type used to connectconf
- configurationpublic static int getPort(NetworkAddressUtils.ServiceType service, AlluxioConfiguration conf)
service
- Service type used to connectconf
- Alluxio configurationpublic static InetSocketAddress getBindAddress(NetworkAddressUtils.ServiceType service, AlluxioConfiguration conf)
service
- the service nameconf
- Alluxio configurationpublic static String getBindHost(NetworkAddressUtils.ServiceType service, AlluxioConfiguration conf)
InetSocketAddress
bind address on a given service.
Host bind information searching order:
service
- the service nameconf
- Alluxio configurationpublic static String getClientHostName(AlluxioConfiguration conf)
conf
- Alluxio configurationpublic static String getLocalNodeName(AlluxioConfiguration conf)
conf
- Alluxio configurationpublic static String getLocalHostName(int timeoutMs)
timeoutMs
- Timeout in milliseconds to use for checking that a possible local host is
reachablepublic static String getLocalHostMetricName(int timeoutMs)
timeoutMs
- Timeout in milliseconds to use for checking that a possible local host is
reachablepublic 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 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, AlluxioConfiguration conf)
netAddress
- the input network address representationconf
- Alluxio configurationpublic static void pingService(InetSocketAddress address, ServiceType serviceType, AlluxioConfiguration conf, UserState userState) throws AlluxioStatusException
address
- the network address to pingserviceType
- the Alluxio service typeconf
- Alluxio configurationuserState
- the UserStateAlluxioStatusException
public static boolean containsLocalIp(List<InetSocketAddress> clusterAddresses, AlluxioConfiguration conf)
clusterAddresses
- addresses of all nodes in the Raft clusterconf
- Alluxio configurationCopyright © 2023. All Rights Reserved.