MAPREDUCE-6951. Improve exception message when mapreduce.jobhistory.webapp.address is in wrong format. Contributed by Prabhu Joseph.

This commit is contained in:
Rohith Sharma K S 2017-10-11 14:27:38 +05:30
parent d8d37b63c7
commit 639f98cc9d
2 changed files with 19 additions and 3 deletions

View File

@ -33,6 +33,7 @@
import java.net.InetAddress; import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.NoSuchElementException;
import java.util.Iterator; import java.util.Iterator;
import static org.apache.hadoop.http.HttpConfig.Policy; import static org.apache.hadoop.http.HttpConfig.Policy;
@ -126,9 +127,15 @@ public static String getApplicationWebURLOnJHSWithoutScheme(Configuration conf,
throws UnknownHostException { throws UnknownHostException {
//construct the history url for job //construct the history url for job
String addr = getJHSWebappURLWithoutScheme(conf); String addr = getJHSWebappURLWithoutScheme(conf);
Iterator<String> it = ADDR_SPLITTER.split(addr).iterator(); String port;
it.next(); // ignore the bind host try{
String port = it.next(); Iterator<String> it = ADDR_SPLITTER.split(addr).iterator();
it.next(); // ignore the bind host
port = it.next();
} catch(NoSuchElementException e) {
throw new IllegalArgumentException("MapReduce JobHistory WebApp Address"
+ " does not contain a valid host:port authority: " + addr);
}
// Use hs address to figure out the host for webapp // Use hs address to figure out the host for webapp
addr = conf.get(JHAdminConfig.MR_HISTORY_ADDRESS, addr = conf.get(JHAdminConfig.MR_HISTORY_ADDRESS,
JHAdminConfig.DEFAULT_MR_HISTORY_ADDRESS); JHAdminConfig.DEFAULT_MR_HISTORY_ADDRESS);

View File

@ -51,6 +51,7 @@
import org.apache.hadoop.mapreduce.v2.api.records.TaskId; import org.apache.hadoop.mapreduce.v2.api.records.TaskId;
import org.apache.hadoop.mapreduce.v2.api.records.TaskState; import org.apache.hadoop.mapreduce.v2.api.records.TaskState;
import org.apache.hadoop.mapreduce.v2.api.records.TaskType; import org.apache.hadoop.mapreduce.v2.api.records.TaskType;
import org.apache.hadoop.mapreduce.v2.jobhistory.JHAdminConfig;
import org.apache.hadoop.util.ApplicationClassLoader; import org.apache.hadoop.util.ApplicationClassLoader;
import org.apache.hadoop.util.StringUtils; import org.apache.hadoop.util.StringUtils;
import org.apache.hadoop.yarn.api.ApplicationConstants; import org.apache.hadoop.yarn.api.ApplicationConstants;
@ -527,4 +528,12 @@ public void testSystemClasses() {
assertFalse("/fake/Klass must not be a system class", assertFalse("/fake/Klass must not be a system class",
ApplicationClassLoader.isSystemClass("/fake/Klass", systemClasses)); ApplicationClassLoader.isSystemClass("/fake/Klass", systemClasses));
} }
@Test(expected = IllegalArgumentException.class)
public void testInvalidWebappAddress() throws Exception {
Configuration conf = new Configuration();
conf.set(JHAdminConfig.MR_HISTORY_WEBAPP_ADDRESS, "19888");
MRWebAppUtil.getApplicationWebURLOnJHSWithScheme(
conf, ApplicationId.newInstance(0, 1));
}
} }