コード例 #1
0
        /// <exception cref="System.Exception"/>
        protected override void ServiceStart()
        {
            string bindAddress = WebAppUtils.GetWebAppBindURL(GetConfig(), YarnConfiguration.
                                                              NmBindHost, WebAppUtils.GetNMWebAppURLWithoutScheme(GetConfig()));
            bool enableCors = GetConfig().GetBoolean(YarnConfiguration.NmWebappEnableCorsFilter
                                                     , YarnConfiguration.DefaultNmWebappEnableCorsFilter);

            if (enableCors)
            {
                GetConfig().SetBoolean(HttpCrossOriginFilterInitializer.Prefix + HttpCrossOriginFilterInitializer
                                       .EnabledSuffix, true);
            }
            Log.Info("Instantiating NMWebApp at " + bindAddress);
            try
            {
                this.webApp = WebApps.$for <Context>("node", this.nmContext, "ws").At(bindAddress)
                              .With(GetConfig()).WithHttpSpnegoPrincipalKey(YarnConfiguration.NmWebappSpnegoUserNameKey
                                                                            ).WithHttpSpnegoKeytabKey(YarnConfiguration.NmWebappSpnegoKeytabFileKey).Start(this
                                                                                                                                                           .nmWebApp);
                this.port = this.webApp.HttpServer().GetConnectorAddress(0).Port;
            }
            catch (Exception e)
            {
                string msg = "NMWebapps failed to start.";
                Log.Error(msg, e);
                throw new YarnRuntimeException(msg, e);
            }
            base.ServiceStart();
        }
コード例 #2
0
        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);
            }
        }