YARN-5728. TestMiniYarnClusterNodeUtilization.testUpdateNodeUtilization timeout.

(cherry picked from commit f8bed5e9a7)
This commit is contained in:
Akira Ajisaka 2017-07-31 11:09:13 +09:00
parent 8bfb9971ca
commit 98c3544e94
No known key found for this signature in database
GPG Key ID: C1EDBB9CA400FD50
1 changed files with 12 additions and 1 deletions

View File

@ -21,6 +21,7 @@ package org.apache.hadoop.yarn.server;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Collection;
import java.util.Map;
@ -36,6 +37,7 @@ import org.apache.hadoop.fs.FileContext;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.ha.HAServiceProtocol;
import org.apache.hadoop.metrics2.lib.DefaultMetricsSystem;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.token.Token;
import org.apache.hadoop.service.AbstractService;
import org.apache.hadoop.service.CompositeService;
@ -445,7 +447,16 @@ public class MiniYARNCluster extends CompositeService {
public static String getHostname() {
try {
return InetAddress.getLocalHost().getHostName();
String hostname = InetAddress.getLocalHost().getHostName();
// Create InetSocketAddress to see whether it is resolved or not.
// If not, just return "localhost".
InetSocketAddress addr =
NetUtils.createSocketAddrForHost(hostname, 1);
if (addr.isUnresolved()) {
return "localhost";
} else {
return hostname;
}
}
catch (UnknownHostException ex) {
throw new RuntimeException(ex);