|
@@ -18,19 +18,18 @@
|
|
|
|
|
|
package org.apache.hadoop.yarn.server.timelineservice.reader;
|
|
|
|
|
|
-import static org.apache.hadoop.fs.CommonConfigurationKeys.DEFAULT_HADOOP_HTTP_STATIC_USER;
|
|
|
-import static org.apache.hadoop.fs.CommonConfigurationKeys.HADOOP_HTTP_STATIC_USER;
|
|
|
-
|
|
|
+import java.io.IOException;
|
|
|
+import java.net.InetSocketAddress;
|
|
|
import java.net.URI;
|
|
|
-import java.util.HashMap;
|
|
|
-import java.util.Map;
|
|
|
+import java.util.LinkedHashSet;
|
|
|
+import java.util.Set;
|
|
|
|
|
|
import org.apache.hadoop.classification.InterfaceAudience.Private;
|
|
|
import org.apache.hadoop.classification.InterfaceStability.Unstable;
|
|
|
import org.apache.hadoop.conf.Configuration;
|
|
|
import org.apache.hadoop.http.HttpServer2;
|
|
|
-import org.apache.hadoop.http.lib.StaticUserWebFilter;
|
|
|
import org.apache.hadoop.security.HttpCrossOriginFilterInitializer;
|
|
|
+import org.apache.hadoop.security.SecurityUtil;
|
|
|
import org.apache.hadoop.service.CompositeService;
|
|
|
import org.apache.hadoop.util.ExitUtil;
|
|
|
import org.apache.hadoop.util.ReflectionUtils;
|
|
@@ -40,7 +39,9 @@ import org.apache.hadoop.yarn.YarnUncaughtExceptionHandler;
|
|
|
import org.apache.hadoop.yarn.conf.YarnConfiguration;
|
|
|
import org.apache.hadoop.yarn.exceptions.YarnException;
|
|
|
import org.apache.hadoop.yarn.exceptions.YarnRuntimeException;
|
|
|
+import org.apache.hadoop.yarn.server.timelineservice.reader.security.TimelineReaderAuthenticationFilterInitializer;
|
|
|
import org.apache.hadoop.yarn.server.timelineservice.storage.TimelineReader;
|
|
|
+import org.apache.hadoop.yarn.server.util.timeline.TimelineServerUtils;
|
|
|
import org.apache.hadoop.yarn.webapp.GenericExceptionHandler;
|
|
|
import org.apache.hadoop.yarn.webapp.YarnJacksonJaxbJsonProvider;
|
|
|
import org.apache.hadoop.yarn.webapp.util.WebAppUtils;
|
|
@@ -71,6 +72,17 @@ public class TimelineReaderServer extends CompositeService {
|
|
|
if (!YarnConfiguration.timelineServiceV2Enabled(conf)) {
|
|
|
throw new YarnException("timeline service v.2 is not enabled");
|
|
|
}
|
|
|
+ InetSocketAddress bindAddr = conf.getSocketAddr(
|
|
|
+ YarnConfiguration.TIMELINE_SERVICE_ADDRESS,
|
|
|
+ YarnConfiguration.DEFAULT_TIMELINE_SERVICE_ADDRESS,
|
|
|
+ YarnConfiguration.DEFAULT_TIMELINE_SERVICE_PORT);
|
|
|
+ // Login from keytab if security is enabled.
|
|
|
+ try {
|
|
|
+ SecurityUtil.login(conf, YarnConfiguration.TIMELINE_SERVICE_KEYTAB,
|
|
|
+ YarnConfiguration.TIMELINE_SERVICE_PRINCIPAL, bindAddr.getHostName());
|
|
|
+ } catch(IOException e) {
|
|
|
+ throw new YarnRuntimeException("Failed to login from keytab", e);
|
|
|
+ }
|
|
|
|
|
|
TimelineReader timelineReaderStore = createTimelineReaderStore(conf);
|
|
|
timelineReaderStore.init(conf);
|
|
@@ -130,29 +142,39 @@ public class TimelineReaderServer extends CompositeService {
|
|
|
super.serviceStop();
|
|
|
}
|
|
|
|
|
|
- private void startTimelineReaderWebApp() {
|
|
|
- Configuration conf = getConfig();
|
|
|
- String bindAddress = WebAppUtils.getWebAppBindURL(conf,
|
|
|
- YarnConfiguration.TIMELINE_SERVICE_BIND_HOST,
|
|
|
- WebAppUtils.getTimelineReaderWebAppURL(conf));
|
|
|
- LOG.info("Instantiating TimelineReaderWebApp at " + bindAddress);
|
|
|
+ protected void addFilters(Configuration conf) {
|
|
|
boolean enableCorsFilter = conf.getBoolean(
|
|
|
YarnConfiguration.TIMELINE_SERVICE_HTTP_CROSS_ORIGIN_ENABLED,
|
|
|
YarnConfiguration.TIMELINE_SERVICE_HTTP_CROSS_ORIGIN_ENABLED_DEFAULT);
|
|
|
- // setup CORS
|
|
|
+ // Setup CORS
|
|
|
if (enableCorsFilter) {
|
|
|
conf.setBoolean(HttpCrossOriginFilterInitializer.PREFIX
|
|
|
+ HttpCrossOriginFilterInitializer.ENABLED_SUFFIX, true);
|
|
|
}
|
|
|
+ String initializers = conf.get("hadoop.http.filter.initializers", "");
|
|
|
+ Set<String> defaultInitializers = new LinkedHashSet<String>();
|
|
|
+ if (!initializers.contains(
|
|
|
+ TimelineReaderAuthenticationFilterInitializer.class.getName())) {
|
|
|
+ defaultInitializers.add(
|
|
|
+ TimelineReaderAuthenticationFilterInitializer.class.getName());
|
|
|
+ }
|
|
|
+ TimelineServerUtils.setTimelineFilters(
|
|
|
+ conf, initializers, defaultInitializers);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void startTimelineReaderWebApp() {
|
|
|
+ Configuration conf = getConfig();
|
|
|
+ addFilters(conf);
|
|
|
+ String bindAddress = WebAppUtils.getWebAppBindURL(conf,
|
|
|
+ YarnConfiguration.TIMELINE_SERVICE_BIND_HOST,
|
|
|
+ WebAppUtils.getTimelineReaderWebAppURL(conf));
|
|
|
+ LOG.info("Instantiating TimelineReaderWebApp at " + bindAddress);
|
|
|
try {
|
|
|
HttpServer2.Builder builder = new HttpServer2.Builder()
|
|
|
.setName("timeline")
|
|
|
.setConf(conf)
|
|
|
.addEndpoint(URI.create("http://" + bindAddress));
|
|
|
readerWebServer = builder.build();
|
|
|
-
|
|
|
- setupOptions(conf);
|
|
|
-
|
|
|
readerWebServer.addJerseyResourcePackage(
|
|
|
TimelineReaderWebServices.class.getPackage().getName() + ";"
|
|
|
+ GenericExceptionHandler.class.getPackage().getName() + ";"
|
|
@@ -168,22 +190,6 @@ public class TimelineReaderServer extends CompositeService {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * Sets up some options and filters.
|
|
|
- *
|
|
|
- * @param conf Configuration
|
|
|
- */
|
|
|
- protected void setupOptions(Configuration conf) {
|
|
|
- Map<String, String> options = new HashMap<>();
|
|
|
- String username = conf.get(HADOOP_HTTP_STATIC_USER,
|
|
|
- DEFAULT_HADOOP_HTTP_STATIC_USER);
|
|
|
- options.put(HADOOP_HTTP_STATIC_USER, username);
|
|
|
- HttpServer2.defineFilter(readerWebServer.getWebAppContext(),
|
|
|
- "static_user_filter_timeline",
|
|
|
- StaticUserWebFilter.StaticUserFilter.class.getName(),
|
|
|
- options, new String[] {"/*"});
|
|
|
- }
|
|
|
-
|
|
|
@VisibleForTesting
|
|
|
public int getWebServerPort() {
|
|
|
return readerWebServer.getConnectorAddress(0).getPort();
|