MAPREDUCE-6910. MapReduceTrackingUriPlugin can not return the right URI of history server with HTTPS. Contributed by Lantao Jin

(cherry picked from commit 43f0503286)
This commit is contained in:
Ravi Prakash 2017-07-13 16:16:45 -07:00
parent a77fb561ef
commit 756a068143
2 changed files with 29 additions and 6 deletions

View File

@ -29,7 +29,6 @@ import org.apache.hadoop.mapreduce.v2.jobhistory.JHAdminConfig;
import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.apache.hadoop.yarn.ipc.RPCUtil;
import java.net.InetAddress;
import java.net.InetSocketAddress;
@ -76,7 +75,9 @@ public class MRWebAppUtil {
: "http://";
}
public static String getJHSWebappScheme() {
public static String getJHSWebappScheme(Configuration conf) {
setHttpPolicyInJHS(conf.get(JHAdminConfig.MR_HS_HTTP_POLICY,
JHAdminConfig.DEFAULT_MR_HS_HTTP_POLICY));
return httpPolicyInJHS == HttpConfig.Policy.HTTPS_ONLY ? "https://"
: "http://";
}
@ -101,7 +102,7 @@ public class MRWebAppUtil {
}
public static String getJHSWebappURLWithScheme(Configuration conf) {
return getJHSWebappScheme() + getJHSWebappURLWithoutScheme(conf);
return getJHSWebappScheme(conf) + getJHSWebappURLWithoutScheme(conf);
}
public static InetSocketAddress getJHSWebBindAddress(Configuration conf) {
@ -153,7 +154,7 @@ public class MRWebAppUtil {
public static String getApplicationWebURLOnJHSWithScheme(Configuration conf,
ApplicationId appId) throws UnknownHostException {
return getJHSWebappScheme()
return getJHSWebappScheme(conf)
+ getApplicationWebURLOnJHSWithoutScheme(conf, appId);
}

View File

@ -23,6 +23,7 @@ import static org.junit.Assert.assertEquals;
import java.net.URI;
import java.net.URISyntaxException;
import org.apache.hadoop.http.HttpConfig;
import org.apache.hadoop.mapreduce.v2.jobhistory.JHAdminConfig;
import org.apache.hadoop.yarn.api.records.ApplicationId;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
@ -30,17 +31,38 @@ import org.junit.Test;
public class TestMapReduceTrackingUriPlugin {
@Test
public void testProducesHistoryServerUriForAppId() throws URISyntaxException {
public void testProducesHistoryServerUriForAppId()
throws URISyntaxException {
final String historyAddress = "example.net:424242";
YarnConfiguration conf = new YarnConfiguration();
conf.set(JHAdminConfig.MR_HS_HTTP_POLICY,
HttpConfig.Policy.HTTP_ONLY.name());
conf.set(JHAdminConfig.MR_HISTORY_WEBAPP_ADDRESS, historyAddress);
MapReduceTrackingUriPlugin plugin = new MapReduceTrackingUriPlugin();
plugin.setConf(conf);
ApplicationId id = ApplicationId.newInstance(6384623l, 5);
ApplicationId id = ApplicationId.newInstance(6384623L, 5);
String jobSuffix = id.toString().replaceFirst("^application_", "job_");
URI expected =
new URI("http://" + historyAddress + "/jobhistory/job/" + jobSuffix);
URI actual = plugin.getTrackingUri(id);
assertEquals(expected, actual);
}
@Test
public void testProducesHistoryServerUriWithHTTPS()
throws URISyntaxException {
final String historyAddress = "example.net:404040";
YarnConfiguration conf = new YarnConfiguration();
conf.set(JHAdminConfig.MR_HS_HTTP_POLICY,
HttpConfig.Policy.HTTPS_ONLY.name());
conf.set(JHAdminConfig.MR_HISTORY_WEBAPP_HTTPS_ADDRESS, historyAddress);
MapReduceTrackingUriPlugin plugin = new MapReduceTrackingUriPlugin();
plugin.setConf(conf);
ApplicationId id = ApplicationId.newInstance(6384623L, 5);
String jobSuffix = id.toString().replaceFirst("^application_", "job_");
URI expected =
new URI("https://" + historyAddress + "/jobhistory/job/" + jobSuffix);
URI actual = plugin.getTrackingUri(id);
assertEquals(expected, actual);
}
}