Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -89,9 +90,7 @@ public void testInvalidRegionServerHostnameAbortsServer() throws Exception {

@Test
public void testRegionServerHostname() throws Exception {
Enumeration<NetworkInterface> netInterfaceList = NetworkInterface.getNetworkInterfaces();
while (netInterfaceList.hasMoreElements()) {
NetworkInterface ni = netInterfaceList.nextElement();
for (NetworkInterface ni : getValidNetworkInterfaces()) {
Enumeration<InetAddress> addrList = ni.getInetAddresses();
// iterate through host addresses and use each as hostname
while (addrList.hasMoreElements()) {
Expand Down Expand Up @@ -205,4 +204,22 @@ public void testRegionServerHostnameReportedToMaster() throws Exception {
assertEquals(expectedRS, servers.size());
}
}

private boolean ignoreNetworkInterface(NetworkInterface networkInterface) throws Exception {
return networkInterface == null || networkInterface.isLoopback() || networkInterface.isVirtual()
|| !networkInterface.isUp();
}

private List<NetworkInterface> getValidNetworkInterfaces() throws Exception {
List<NetworkInterface> validNetworkInterfaces = new ArrayList<>();
Enumeration<NetworkInterface> interfaces = NetworkInterface.getNetworkInterfaces();
while (interfaces.hasMoreElements()) {
NetworkInterface networkInterface = interfaces.nextElement();
if (ignoreNetworkInterface(networkInterface)) {
continue;
}
validNetworkInterfaces.add(networkInterface);
}
return validNetworkInterfaces;
}
}