MAPREDUCE-7260. Cross origin request support for Job history server web UI. Contributed by Adam Antal

This commit is contained in:
Szilard Nemeth 2020-01-29 14:42:52 +01:00
parent 825db8fe2a
commit 7f3e1e0c07
2 changed files with 22 additions and 0 deletions

View File

@ -255,6 +255,13 @@ public class JHAdminConfig {
public static final String MR_HISTORY_XFS_OPTIONS = MR_HISTORY_XFS_PREFIX + public static final String MR_HISTORY_XFS_OPTIONS = MR_HISTORY_XFS_PREFIX +
"xframe-options"; "xframe-options";
/**
* CORS settings.
*/
public static final String MR_HISTORY_ENABLE_CORS_FILTER = MR_HISTORY_PREFIX +
"webapp.cross-origin.enabled";
public static final boolean DEFAULT_MR_HISTORY_ENABLE_CORS_FILTER = false;
/** /**
* Settings for .jhist file format. * Settings for .jhist file format.
*/ */

View File

@ -75,6 +75,7 @@ import org.apache.hadoop.mapreduce.v2.hs.webapp.HsWebApp;
import org.apache.hadoop.mapreduce.v2.jobhistory.JHAdminConfig; import org.apache.hadoop.mapreduce.v2.jobhistory.JHAdminConfig;
import org.apache.hadoop.mapreduce.v2.util.MRWebAppUtil; import org.apache.hadoop.mapreduce.v2.util.MRWebAppUtil;
import org.apache.hadoop.net.NetUtils; import org.apache.hadoop.net.NetUtils;
import org.apache.hadoop.security.HttpCrossOriginFilterInitializer;
import org.apache.hadoop.security.UserGroupInformation; import org.apache.hadoop.security.UserGroupInformation;
import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod; import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
import org.apache.hadoop.security.token.Token; import org.apache.hadoop.security.token.Token;
@ -154,6 +155,9 @@ public class HistoryClientService extends AbstractService {
@VisibleForTesting @VisibleForTesting
protected void initializeWebApp(Configuration conf) throws IOException { protected void initializeWebApp(Configuration conf) throws IOException {
webApp = new HsWebApp(history); webApp = new HsWebApp(history);
setupFilters(conf);
InetSocketAddress bindAddress = MRWebAppUtil.getJHSWebBindAddress(conf); InetSocketAddress bindAddress = MRWebAppUtil.getJHSWebBindAddress(conf);
ApplicationClientProtocol appClientProtocol = ApplicationClientProtocol appClientProtocol =
ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class); ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class);
@ -196,6 +200,17 @@ public class HistoryClientService extends AbstractService {
return this.bindAddress; return this.bindAddress;
} }
private void setupFilters(Configuration conf) {
boolean enableCorsFilter =
conf.getBoolean(JHAdminConfig.MR_HISTORY_ENABLE_CORS_FILTER,
JHAdminConfig.DEFAULT_MR_HISTORY_ENABLE_CORS_FILTER);
if (enableCorsFilter) {
conf.setBoolean(HttpCrossOriginFilterInitializer.PREFIX
+ HttpCrossOriginFilterInitializer.ENABLED_SUFFIX, true);
}
}
private class HSClientProtocolHandler implements HSClientProtocol { private class HSClientProtocolHandler implements HSClientProtocol {
private RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null); private RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(null);