public virtual void TestContextSpecificServletFilterWhenInitThrowsException() { Configuration conf = new Configuration(); HttpServer2 http = CreateTestServer(conf); HttpServer2.DefineFilter(http.webAppContext, "ErrorFilter", typeof(TestServletFilter.ErrorFilter ).FullName, null, null); try { http.Start(); NUnit.Framework.Assert.Fail("expecting exception"); } catch (IOException e) { GenericTestUtils.AssertExceptionContains("Unable to initialize WebAppContext", e); } }
/// <exception cref="System.IO.IOException"/> private void InitWebHdfs(Configuration conf) { if (WebHdfsFileSystem.IsEnabled(conf, HttpServer2.Log)) { // set user pattern based on configuration file UserParam.SetUserPattern(conf.Get(DFSConfigKeys.DfsWebhdfsUserPatternKey, DFSConfigKeys .DfsWebhdfsUserPatternDefault)); // add authentication filter for webhdfs string className = conf.Get(DFSConfigKeys.DfsWebhdfsAuthenticationFilterKey, DFSConfigKeys .DfsWebhdfsAuthenticationFilterDefault); string name = className; string pathSpec = WebHdfsFileSystem.PathPrefix + "/*"; IDictionary <string, string> @params = GetAuthFilterParams(conf); HttpServer2.DefineFilter(httpServer.GetWebAppContext(), name, className, @params, new string[] { pathSpec }); HttpServer2.Log.Info("Added filter '" + name + "' (class=" + className + ")"); // add webhdfs packages httpServer.AddJerseyResourcePackage(typeof(NamenodeWebHdfsMethods).Assembly.GetName () + ";" + typeof(Param).Assembly.GetName(), pathSpec); } }
private void StartWebApp() { Configuration conf = GetConfig(); TimelineAuthenticationFilter.SetTimelineDelegationTokenSecretManager(secretManagerService .GetTimelineDelegationTokenSecretManager()); // Always load pseudo authentication filter to parse "user.name" in an URL // to identify a HTTP request's user in insecure mode. // When Kerberos authentication type is set (i.e., secure mode is turned on), // the customized filter will be loaded by the timeline server to do Kerberos // + DT authentication. string initializers = conf.Get("hadoop.http.filter.initializers"); bool modifiedInitializers = false; initializers = initializers == null || initializers.Length == 0 ? string.Empty : initializers; if (!initializers.Contains(typeof(CrossOriginFilterInitializer).FullName)) { if (conf.GetBoolean(YarnConfiguration.TimelineServiceHttpCrossOriginEnabled, YarnConfiguration .TimelineServiceHttpCrossOriginEnabledDefault)) { if (initializers.Contains(typeof(HttpCrossOriginFilterInitializer).FullName)) { initializers = initializers.ReplaceAll(typeof(HttpCrossOriginFilterInitializer).FullName , typeof(CrossOriginFilterInitializer).FullName); } else { if (initializers.Length != 0) { initializers += ","; } initializers += typeof(CrossOriginFilterInitializer).FullName; } modifiedInitializers = true; } } if (!initializers.Contains(typeof(TimelineAuthenticationFilterInitializer).FullName )) { if (initializers.Length != 0) { initializers += ","; } initializers += typeof(TimelineAuthenticationFilterInitializer).FullName; modifiedInitializers = true; } string[] parts = initializers.Split(","); AList <string> target = new AList <string>(); foreach (string filterInitializer in parts) { filterInitializer = filterInitializer.Trim(); if (filterInitializer.Equals(typeof(AuthenticationFilterInitializer).FullName)) { modifiedInitializers = true; continue; } target.AddItem(filterInitializer); } string actualInitializers = StringUtils.Join(target, ","); if (modifiedInitializers) { conf.Set("hadoop.http.filter.initializers", actualInitializers); } string bindAddress = WebAppUtils.GetWebAppBindURL(conf, YarnConfiguration.TimelineServiceBindHost , WebAppUtils.GetAHSWebAppURLWithoutScheme(conf)); try { AHSWebApp ahsWebApp = new AHSWebApp(timelineDataManager, ahsClientService); webApp = WebApps.$for <ApplicationHistoryClientService>("applicationhistory", ahsClientService , "ws").With(conf).WithAttribute(YarnConfiguration.TimelineServiceWebappAddress, conf.Get(YarnConfiguration.TimelineServiceWebappAddress)).At(bindAddress).Build( ahsWebApp); HttpServer2 httpServer = webApp.HttpServer(); string[] names = conf.GetTrimmedStrings(YarnConfiguration.TimelineServiceUiNames); WebAppContext webAppContext = httpServer.GetWebAppContext(); foreach (string name in names) { string webPath = conf.Get(YarnConfiguration.TimelineServiceUiWebPathPrefix + name ); string onDiskPath = conf.Get(YarnConfiguration.TimelineServiceUiOnDiskPathPrefix + name); WebAppContext uiWebAppContext = new WebAppContext(); uiWebAppContext.SetContextPath(webPath); uiWebAppContext.SetWar(onDiskPath); string[] AllUrls = new string[] { "/*" }; FilterHolder[] filterHolders = webAppContext.GetServletHandler().GetFilters(); foreach (FilterHolder filterHolder in filterHolders) { if (!"guice".Equals(filterHolder.GetName())) { HttpServer2.DefineFilter(uiWebAppContext, filterHolder.GetName(), filterHolder.GetClassName (), filterHolder.GetInitParameters(), AllUrls); } } Log.Info("Hosting " + name + " from " + onDiskPath + " at " + webPath); httpServer.AddContext(uiWebAppContext, true); } httpServer.Start(); conf.UpdateConnectAddr(YarnConfiguration.TimelineServiceBindHost, YarnConfiguration .TimelineServiceWebappAddress, YarnConfiguration.DefaultTimelineServiceWebappAddress , this.GetListenerAddress()); Log.Info("Instantiating AHSWebApp at " + GetPort()); } catch (Exception e) { string msg = "AHSWebApp failed to start."; Log.Error(msg, e); throw new YarnRuntimeException(msg, e); } }
public virtual WebApp Build(WebApp webapp) { if (webapp == null) { webapp = new _WebApp_171(); } // Defaults should be fine in usual cases webapp.SetName(name); webapp.SetWebServices(wsName); string basePath = "/" + name; webapp.SetRedirectPath(basePath); IList <string> pathList = new AList <string>(); if (basePath.Equals("/")) { webapp.AddServePathSpec("/*"); pathList.AddItem("/*"); } else { webapp.AddServePathSpec(basePath); webapp.AddServePathSpec(basePath + "/*"); pathList.AddItem(basePath + "/*"); } if (wsName != null && !wsName.Equals(basePath)) { if (wsName.Equals("/")) { webapp.AddServePathSpec("/*"); pathList.AddItem("/*"); } else { webapp.AddServePathSpec("/" + wsName); webapp.AddServePathSpec("/" + wsName + "/*"); pathList.AddItem("/" + wsName + "/*"); } } if (conf == null) { conf = new Configuration(); } try { if (application != null) { webapp.SetHostClass(application.GetType()); } else { string cls = InferHostClass(); Log.Debug("setting webapp host class to {}", cls); webapp.SetHostClass(Sharpen.Runtime.GetType(cls)); } if (devMode) { if (port > 0) { try { new Uri("http://localhost:" + port + "/__stop").GetContent(); Log.Info("stopping existing webapp instance"); Sharpen.Thread.Sleep(100); } catch (ConnectException e) { Log.Info("no existing webapp instance found: {}", e.ToString()); } catch (Exception e) { // should not be fatal Log.Warn("error stopping existing instance: {}", e.ToString()); } } else { Log.Error("dev mode does NOT work with ephemeral port!"); System.Environment.Exit(1); } } string httpScheme; if (this.httpPolicy == null) { httpScheme = WebAppUtils.GetHttpSchemePrefix(conf); } else { httpScheme = (httpPolicy == HttpConfig.Policy.HttpsOnly) ? WebAppUtils.HttpsPrefix : WebAppUtils.HttpPrefix; } HttpServer2.Builder builder = new HttpServer2.Builder().SetName(name).AddEndpoint (URI.Create(httpScheme + bindAddress + ":" + port)).SetConf(conf).SetFindPort(findPort ).SetACL(new AccessControlList(conf.Get(YarnConfiguration.YarnAdminAcl, YarnConfiguration .DefaultYarnAdminAcl))).SetPathSpec(Sharpen.Collections.ToArray(pathList, new string [0])); bool hasSpnegoConf = spnegoPrincipalKey != null && conf.Get(spnegoPrincipalKey) != null && spnegoKeytabKey != null && conf.Get(spnegoKeytabKey) != null; if (hasSpnegoConf) { builder.SetUsernameConfKey(spnegoPrincipalKey).SetKeytabConfKey(spnegoKeytabKey). SetSecurityEnabled(UserGroupInformation.IsSecurityEnabled()); } if (httpScheme.Equals(WebAppUtils.HttpsPrefix)) { WebAppUtils.LoadSslConfiguration(builder); } HttpServer2 server = builder.Build(); foreach (WebApps.Builder.ServletStruct @struct in servlets) { server.AddServlet(@struct.name, @struct.spec, @struct.clazz); } foreach (KeyValuePair <string, object> entry in attributes) { server.SetAttribute(entry.Key, entry.Value); } HttpServer2.DefineFilter(server.GetWebAppContext(), "guice", typeof(GuiceFilter). FullName, null, new string[] { "/*" }); webapp.SetConf(conf); webapp.SetHttpServer(server); } catch (TypeLoadException e) { throw new WebAppException("Error starting http server", e); } catch (IOException e) { throw new WebAppException("Error starting http server", e); } Injector injector = Guice.CreateInjector(webapp, new _AbstractModule_280(this)); Log.Info("Registered webapp guice modules"); // save a guice filter instance for webapp stop (mostly for unit tests) webapp.SetGuiceFilter(injector.GetInstance <GuiceFilter>()); if (devMode) { injector.GetInstance <Dispatcher>().SetDevMode(devMode); Log.Info("in dev mode!"); } return(webapp); }