/// <exception cref="System.Exception"/>
 protected override void ServiceInit(Configuration conf)
 {
     serverHttpAddress = WebAppUtils.GetHttpSchemePrefix(conf) + WebAppUtils.GetAHSWebAppURLWithoutScheme
                             (conf);
     maxLoadedApplications = conf.GetLong(YarnConfiguration.ApplicationHistoryMaxApps,
                                          YarnConfiguration.DefaultApplicationHistoryMaxApps);
     base.ServiceInit(conf);
 }
 /// <exception cref="System.Exception"/>
 protected override void ServiceInit(Configuration conf)
 {
     Log.Info("ApplicationHistory Init");
     historyStore = CreateApplicationHistoryStore(conf);
     historyStore.Init(conf);
     serverHttpAddress = WebAppUtils.GetHttpSchemePrefix(conf) + WebAppUtils.GetAHSWebAppURLWithoutScheme
                             (conf);
     base.ServiceInit(conf);
 }
Exemplo n.º 3
0
 /// <summary>Default constructor</summary>
 public WebAppProxyServlet()
     : base()
 {
     conf = new YarnConfiguration();
     this.trackingUriPlugins = conf.GetInstances <TrackingUriPlugin>(YarnConfiguration.
                                                                     YarnTrackingUrlGenerator);
     this.rmAppPageUrlBase = StringHelper.Pjoin(WebAppUtils.GetResolvedRMWebAppURLWithScheme
                                                    (conf), "cluster", "app");
     this.ahsAppPageUrlBase = StringHelper.Pjoin(WebAppUtils.GetHttpSchemePrefix(conf)
                                                 + WebAppUtils.GetAHSWebAppURLWithoutScheme(conf), "applicationhistory", "apps");
 }
Exemplo n.º 4
0
        public virtual void TestSingleContainer()
        {
            ApplicationId        appId        = ApplicationId.NewInstance(0, 1);
            ApplicationAttemptId appAttemptId = ApplicationAttemptId.NewInstance(appId, 1);
            ContainerId          containerId  = ContainerId.NewContainerId(appAttemptId, 1);
            WebResource          r            = Resource();
            ClientResponse       response     = r.Path("ws").Path("v1").Path("applicationhistory").Path
                                                    ("apps").Path(appId.ToString()).Path("appattempts").Path(appAttemptId.ToString()
                                                                                                             ).Path("containers").Path(containerId.ToString()).QueryParam("user.name", Users[
                                                                                                                                                                              round]).Accept(MediaType.ApplicationJson).Get <ClientResponse>();

            if (round == 1)
            {
                NUnit.Framework.Assert.AreEqual(ClientResponse.Status.Forbidden, response.GetClientResponseStatus
                                                    ());
                return;
            }
            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, json.Length());
            JSONObject container = json.GetJSONObject("container");

            NUnit.Framework.Assert.AreEqual(containerId.ToString(), container.GetString("containerId"
                                                                                        ));
            NUnit.Framework.Assert.AreEqual("test diagnostics info", container.GetString("diagnosticsInfo"
                                                                                         ));
            NUnit.Framework.Assert.AreEqual("-1", container.GetString("allocatedMB"));
            NUnit.Framework.Assert.AreEqual("-1", container.GetString("allocatedVCores"));
            NUnit.Framework.Assert.AreEqual(NodeId.NewInstance("test host", 100).ToString(),
                                            container.GetString("assignedNodeId"));
            NUnit.Framework.Assert.AreEqual("-1", container.GetString("priority"));
            Configuration conf = new YarnConfiguration();

            NUnit.Framework.Assert.AreEqual(WebAppUtils.GetHttpSchemePrefix(conf) + WebAppUtils
                                            .GetAHSWebAppURLWithoutScheme(conf) + "/applicationhistory/logs/test host:100/container_0_0001_01_000001/"
                                            + "container_0_0001_01_000001/user1", container.GetString("logUrl"));
            NUnit.Framework.Assert.AreEqual(ContainerState.Complete.ToString(), container.GetString
                                                ("containerState"));
        }
Exemplo n.º 5
0
        /// <exception cref="System.Exception"/>
        public virtual void TestAppReportForEmptyTrackingUrl()
        {
            configuration.Set(YarnConfiguration.ProxyAddress, "localhost:9090");
            // overriding num of web server threads, see HttpServer.HTTP_MAXTHREADS
            configuration.SetInt("hadoop.http.max.threads", 5);
            TestWebAppProxyServlet.WebAppProxyServerForTest proxy = new TestWebAppProxyServlet.WebAppProxyServerForTest
                                                                        (this);
            proxy.Init(configuration);
            proxy.Start();
            int proxyPort = proxy.proxy.proxyServer.GetConnectorAddress(0).Port;

            TestWebAppProxyServlet.AppReportFetcherForTest appReportFetcher = proxy.proxy.appReportFetcher;
            try
            {
                //set AHS_ENBALED = false to simulate getting the app report from RM
                configuration.SetBoolean(YarnConfiguration.ApplicationHistoryEnabled, false);
                ApplicationId app = ApplicationId.NewInstance(0, 0);
                appReportFetcher.answer = 6;
                Uri url = new Uri("http://localhost:" + proxyPort + "/proxy/" + app.ToString());
                HttpURLConnection proxyConn = (HttpURLConnection)url.OpenConnection();
                proxyConn.Connect();
                try
                {
                    proxyConn.GetResponseCode();
                }
                catch (ConnectException)
                {
                }
                // Connection Exception is expected as we have set
                // appReportFetcher.answer = 6, which does not set anything for
                // original tracking url field in the app report.
                string appAddressInRm = WebAppUtils.GetResolvedRMWebAppURLWithScheme(configuration
                                                                                     ) + "/cluster" + "/app/" + app.ToString();
                NUnit.Framework.Assert.IsTrue("Webapp proxy servlet should have redirected to RM"
                                              , proxyConn.GetURL().ToString().Equals(appAddressInRm));
                //set AHS_ENBALED = true to simulate getting the app report from AHS
                configuration.SetBoolean(YarnConfiguration.ApplicationHistoryEnabled, true);
                proxyConn = (HttpURLConnection)url.OpenConnection();
                proxyConn.Connect();
                try
                {
                    proxyConn.GetResponseCode();
                }
                catch (ConnectException)
                {
                }
                // Connection Exception is expected as we have set
                // appReportFetcher.answer = 6, which does not set anything for
                // original tracking url field in the app report.
                string appAddressInAhs = WebAppUtils.GetHttpSchemePrefix(configuration) + WebAppUtils
                                         .GetAHSWebAppURLWithoutScheme(configuration) + "/applicationhistory" + "/apps/"
                                         + app.ToString();
                NUnit.Framework.Assert.IsTrue("Webapp proxy servlet should have redirected to AHS"
                                              , proxyConn.GetURL().ToString().Equals(appAddressInAhs));
            }
            finally
            {
                proxy.Close();
            }
        }
        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);
            }
        }