Example #1
0
 /// <exception cref="System.Exception"/>
 protected override void ServiceStart()
 {
     try
     {
         Configuration       conf = GetConfig();
         HttpServer2.Builder b    = new HttpServer2.Builder().SetName("proxy").AddEndpoint(URI
                                                                                           .Create(WebAppUtils.GetHttpSchemePrefix(conf) + bindAddress + ":" + port)).SetFindPort
                                        (port == 0).SetConf(GetConfig()).SetACL(acl);
         if (YarnConfiguration.UseHttps(conf))
         {
             WebAppUtils.LoadSslConfiguration(b);
         }
         proxyServer = b.Build();
         proxyServer.AddServlet(ProxyUriUtils.ProxyServletName, ProxyUriUtils.ProxyPathSpec
                                , typeof(WebAppProxyServlet));
         proxyServer.SetAttribute(FetcherAttribute, fetcher);
         proxyServer.SetAttribute(IsSecurityEnabledAttribute, isSecurityEnabled);
         proxyServer.SetAttribute(ProxyHostAttribute, proxyHost);
         proxyServer.Start();
     }
     catch (IOException e)
     {
         Log.Error("Could not start proxy web server", e);
         throw;
     }
     base.ServiceStart();
 }
Example #2
0
        public static void Setup()
        {
            conf = new Configuration();
            conf.SetInt(HttpServer2.HttpMaxThreads, 10);
            FilePath @base = new FilePath(Basedir);

            FileUtil.FullyDelete(@base);
            @base.Mkdirs();
            keystoresDir = new FilePath(Basedir).GetAbsolutePath();
            sslConfDir   = KeyStoreTestUtil.GetClasspathDir(typeof(TestSSLHttpServer));
            KeyStoreTestUtil.SetupSSLConfig(keystoresDir, sslConfDir, conf, false);
            Configuration sslConf = new Configuration(false);

            sslConf.AddResource("ssl-server.xml");
            sslConf.AddResource("ssl-client.xml");
            clientSslFactory = new SSLFactory(SSLFactory.Mode.Client, sslConf);
            clientSslFactory.Init();
            server = new HttpServer2.Builder().SetName("test").AddEndpoint(new URI("https://localhost"
                                                                                   )).SetConf(conf).KeyPassword(sslConf.Get("ssl.server.keystore.keypassword")).KeyStore
                         (sslConf.Get("ssl.server.keystore.location"), sslConf.Get("ssl.server.keystore.password"
                                                                                   ), sslConf.Get("ssl.server.keystore.type", "jks")).TrustStore(sslConf.Get("ssl.server.truststore.location"
                                                                                                                                                             ), sslConf.Get("ssl.server.truststore.password"), sslConf.Get("ssl.server.truststore.type"
                                                                                                                                                                                                                           , "jks")).Build();
            server.AddServlet("echo", "/echo", typeof(TestHttpServer.EchoServlet));
            server.AddServlet("longheader", "/longheader", typeof(HttpServerFunctionalTest.LongHeaderServlet
                                                                  ));
            server.Start();
            baseUrl = new Uri("https://" + NetUtils.GetHostPortString(server.GetConnectorAddress
                                                                          (0)));
            Log.Info("HTTP server started: " + baseUrl);
        }
        /// <summary>Test to verify the read timeout</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestGetImageTimeout()
        {
            HttpServer2 testServer = HttpServerFunctionalTest.CreateServer("hdfs");

            try
            {
                testServer.AddServlet("ImageTransfer", ImageServlet.PathSpec, typeof(TestTransferFsImage.TestImageTransferServlet
                                                                                     ));
                testServer.Start();
                Uri serverURL = HttpServerFunctionalTest.GetServerURL(testServer);
                TransferFsImage.timeout = 2000;
                try
                {
                    TransferFsImage.GetFileClient(serverURL, "txid=1", null, null, false);
                    NUnit.Framework.Assert.Fail("TransferImage Should fail with timeout");
                }
                catch (SocketTimeoutException e)
                {
                    NUnit.Framework.Assert.AreEqual("Read should timeout", "Read timed out", e.Message
                                                    );
                }
            }
            finally
            {
                if (testServer != null)
                {
                    testServer.Stop();
                }
            }
        }
        /// <summary>Create and start a server with the test webapp</summary>
        /// <returns>the newly started server</returns>
        /// <exception cref="System.IO.IOException">on any failure</exception>
        /// <exception cref="System.Exception">if a condition was not met</exception>
        public static HttpServer2 CreateAndStartTestServer()
        {
            HttpServer2 server = CreateTestServer();

            server.Start();
            return(server);
        }
Example #5
0
        public static void SetUp()
        {
            Configuration conf = new Configuration();

            conf.Set(HttpServer2.FilterInitializerProperty, typeof(TestHttpCookieFlag.DummyFilterInitializer
                                                                   ).FullName);
            FilePath @base = new FilePath(Basedir);

            FileUtil.FullyDelete(@base);
            @base.Mkdirs();
            keystoresDir = new FilePath(Basedir).GetAbsolutePath();
            sslConfDir   = KeyStoreTestUtil.GetClasspathDir(typeof(TestSSLHttpServer));
            KeyStoreTestUtil.SetupSSLConfig(keystoresDir, sslConfDir, conf, false);
            Configuration sslConf = new Configuration(false);

            sslConf.AddResource("ssl-server.xml");
            sslConf.AddResource("ssl-client.xml");
            clientSslFactory = new SSLFactory(SSLFactory.Mode.Client, sslConf);
            clientSslFactory.Init();
            server = new HttpServer2.Builder().SetName("test").AddEndpoint(new URI("http://localhost"
                                                                                   )).AddEndpoint(new URI("https://localhost")).SetConf(conf).KeyPassword(sslConf.Get
                                                                                                                                                              ("ssl.server.keystore.keypassword")).KeyStore(sslConf.Get("ssl.server.keystore.location"
                                                                                                                                                                                                                        ), sslConf.Get("ssl.server.keystore.password"), sslConf.Get("ssl.server.keystore.type"
                                                                                                                                                                                                                                                                                    , "jks")).TrustStore(sslConf.Get("ssl.server.truststore.location"), sslConf.Get(
                                                                                                                                                                                                                                                                                                             "ssl.server.truststore.password"), sslConf.Get("ssl.server.truststore.type", "jks"
                                                                                                                                                                                                                                                                                                                                                            )).Build();
            server.AddServlet("echo", "/echo", typeof(TestHttpServer.EchoServlet));
            server.Start();
        }
Example #6
0
        public virtual void TestStartedServerIsAlive()
        {
            HttpServer2 server = null;

            server = CreateTestServer();
            AssertNotLive(server);
            server.Start();
            AssertAlive(server);
            Stop(server);
        }
        /// <seealso cref="Org.Apache.Hadoop.Hdfs.DFSUtil.GetHttpPolicy(Org.Apache.Hadoop.Conf.Configuration)
        ///     ">
        /// for information related to the different configuration options and
        /// Http Policy is decided.
        /// </seealso>
        /// <exception cref="System.IO.IOException"/>
        internal virtual void Start()
        {
            HttpConfig.Policy policy          = DFSUtil.GetHttpPolicy(conf);
            string            infoHost        = bindAddress.GetHostName();
            IPEndPoint        httpAddr        = bindAddress;
            string            httpsAddrString = conf.GetTrimmed(DFSConfigKeys.DfsNamenodeHttpsAddressKey
                                                                , DFSConfigKeys.DfsNamenodeHttpsAddressDefault);
            IPEndPoint httpsAddr = NetUtils.CreateSocketAddr(httpsAddrString);

            if (httpsAddr != null)
            {
                // If DFS_NAMENODE_HTTPS_BIND_HOST_KEY exists then it overrides the
                // host name portion of DFS_NAMENODE_HTTPS_ADDRESS_KEY.
                string bindHost = conf.GetTrimmed(DFSConfigKeys.DfsNamenodeHttpsBindHostKey);
                if (bindHost != null && !bindHost.IsEmpty())
                {
                    httpsAddr = new IPEndPoint(bindHost, httpsAddr.Port);
                }
            }
            HttpServer2.Builder builder = DFSUtil.HttpServerTemplateForNNAndJN(conf, httpAddr
                                                                               , httpsAddr, "hdfs", DFSConfigKeys.DfsNamenodeKerberosInternalSpnegoPrincipalKey
                                                                               , DFSConfigKeys.DfsNamenodeKeytabFileKey);
            httpServer = builder.Build();
            if (policy.IsHttpsEnabled())
            {
                // assume same ssl port for all datanodes
                IPEndPoint datanodeSslPort = NetUtils.CreateSocketAddr(conf.GetTrimmed(DFSConfigKeys
                                                                                       .DfsDatanodeHttpsAddressKey, infoHost + ":" + DFSConfigKeys.DfsDatanodeHttpsDefaultPort
                                                                                       ));
                httpServer.SetAttribute(DFSConfigKeys.DfsDatanodeHttpsPortKey, datanodeSslPort.Port
                                        );
            }
            InitWebHdfs(conf);
            httpServer.SetAttribute(NamenodeAttributeKey, nn);
            httpServer.SetAttribute(JspHelper.CurrentConf, conf);
            SetupServlets(httpServer, conf);
            httpServer.Start();
            int connIdx = 0;

            if (policy.IsHttpEnabled())
            {
                httpAddress = httpServer.GetConnectorAddress(connIdx++);
                conf.Set(DFSConfigKeys.DfsNamenodeHttpAddressKey, NetUtils.GetHostPortString(httpAddress
                                                                                             ));
            }
            if (policy.IsHttpsEnabled())
            {
                httpsAddress = httpServer.GetConnectorAddress(connIdx);
                conf.Set(DFSConfigKeys.DfsNamenodeHttpsAddressKey, NetUtils.GetHostPortString(httpsAddress
                                                                                              ));
            }
        }
Example #8
0
        public virtual void TestServletFilter()
        {
            Configuration conf = new Configuration();

            //start a http server with CountingFilter
            conf.Set(HttpServer2.FilterInitializerProperty, typeof(TestServletFilter.SimpleFilter.Initializer
                                                                   ).FullName);
            HttpServer2 http = CreateTestServer(conf);

            http.Start();
            string fsckURL       = "/fsck";
            string stacksURL     = "/stacks";
            string ajspURL       = "/a.jsp";
            string logURL        = "/logs/a.log";
            string hadooplogoURL = "/static/hadoop-logo.jpg";

            string[] urls = new string[] { fsckURL, stacksURL, ajspURL, logURL, hadooplogoURL };
            Random   ran  = new Random();

            int[] sequence = new int[50];
            //generate a random sequence and update counts
            for (int i = 0; i < sequence.Length; i++)
            {
                sequence[i] = ran.Next(urls.Length);
            }
            //access the urls as the sequence
            string prefix = "http://" + NetUtils.GetHostPortString(http.GetConnectorAddress(0
                                                                                            ));

            try
            {
                for (int i_1 = 0; i_1 < sequence.Length; i_1++)
                {
                    Access(prefix + urls[sequence[i_1]]);
                    //make sure everything except fsck get filtered
                    if (sequence[i_1] == 0)
                    {
                        Assert.Equal(null, uri);
                    }
                    else
                    {
                        Assert.Equal(urls[sequence[i_1]], uri);
                        uri = null;
                    }
                }
            }
            finally
            {
                http.Stop();
            }
        }
Example #9
0
        public virtual void TestPathSpecFilters()
        {
            Configuration conf = new Configuration();

            //start a http server with CountingFilter
            conf.Set(HttpServer2.FilterInitializerProperty, typeof(TestPathFilter.RecordingFilter.Initializer
                                                                   ).FullName);
            string[]    pathSpecs = new string[] { "/path", "/path/*" };
            HttpServer2 http      = CreateTestServer(conf, pathSpecs);

            http.Start();
            string baseURL       = "/path";
            string baseSlashURL  = "/path/";
            string addedURL      = "/path/nodes";
            string addedSlashURL = "/path/nodes/";
            string longURL       = "/path/nodes/foo/job";
            string rootURL       = "/";
            string allURL        = "/*";

            string[] filteredUrls = new string[] { baseURL, baseSlashURL, addedURL, addedSlashURL
                                                   , longURL };
            string[] notFilteredUrls = new string[] { rootURL, allURL };
            // access the urls and verify our paths specs got added to the
            // filters
            string prefix = "http://" + NetUtils.GetHostPortString(http.GetConnectorAddress(0
                                                                                            ));

            try
            {
                for (int i = 0; i < filteredUrls.Length; i++)
                {
                    Access(prefix + filteredUrls[i]);
                }
                for (int i_1 = 0; i_1 < notFilteredUrls.Length; i_1++)
                {
                    Access(prefix + notFilteredUrls[i_1]);
                }
            }
            finally
            {
                http.Stop();
            }
            Log.Info("RECORDS = " + Records);
            //verify records
            for (int i_2 = 0; i_2 < filteredUrls.Length; i_2++)
            {
                Assert.True(Records.Remove(filteredUrls[i_2]));
            }
            Assert.True(Records.IsEmpty());
        }
Example #10
0
        public virtual void TestWepAppContextAfterServerStop()
        {
            HttpServer2 server = null;
            string      key    = "test.attribute.key";
            string      value  = "test.attribute.value";

            server = CreateTestServer();
            AssertNotLive(server);
            server.Start();
            server.SetAttribute(key, value);
            AssertAlive(server);
            Assert.Equal(value, server.GetAttribute(key));
            Stop(server);
            NUnit.Framework.Assert.IsNull("Server context should have cleared", server.GetAttribute
                                              (key));
        }
Example #11
0
        /// <exception cref="System.IO.IOException"/>
        internal virtual void Start()
        {
            IPEndPoint httpAddr        = GetAddress(conf);
            string     httpsAddrString = conf.Get(DFSConfigKeys.DfsJournalnodeHttpsAddressKey, DFSConfigKeys
                                                  .DfsJournalnodeHttpsAddressDefault);
            IPEndPoint httpsAddr = NetUtils.CreateSocketAddr(httpsAddrString);

            HttpServer2.Builder builder = DFSUtil.HttpServerTemplateForNNAndJN(conf, httpAddr
                                                                               , httpsAddr, "journal", DFSConfigKeys.DfsJournalnodeKerberosInternalSpnegoPrincipalKey
                                                                               , DFSConfigKeys.DfsJournalnodeKeytabFileKey);
            httpServer = builder.Build();
            httpServer.SetAttribute(JnAttributeKey, localJournalNode);
            httpServer.SetAttribute(JspHelper.CurrentConf, conf);
            httpServer.AddInternalServlet("getJournal", "/getJournal", typeof(GetJournalEditServlet
                                                                              ), true);
            httpServer.Start();
        }
Example #12
0
        public virtual void TestServletFilter()
        {
            Configuration conf = new Configuration();

            //start a http server with CountingFilter
            conf.Set(HttpServer2.FilterInitializerProperty, typeof(TestGlobalFilter.RecordingFilter.Initializer
                                                                   ).FullName);
            HttpServer2 http = CreateTestServer(conf);

            http.Start();
            string fsckURL      = "/fsck";
            string stacksURL    = "/stacks";
            string ajspURL      = "/a.jsp";
            string listPathsURL = "/listPaths";
            string dataURL      = "/data";
            string streamFile   = "/streamFile";
            string rootURL      = "/";
            string allURL       = "/*";
            string outURL       = "/static/a.out";
            string logURL       = "/logs/a.log";

            string[] urls = new string[] { fsckURL, stacksURL, ajspURL, listPathsURL, dataURL
                                           , streamFile, rootURL, allURL, outURL, logURL };
            //access the urls
            string prefix = "http://" + NetUtils.GetHostPortString(http.GetConnectorAddress(0
                                                                                            ));

            try
            {
                for (int i = 0; i < urls.Length; i++)
                {
                    Access(prefix + urls[i]);
                }
            }
            finally
            {
                http.Stop();
            }
            Log.Info("RECORDS = " + Records);
            //verify records
            for (int i_1 = 0; i_1 < urls.Length; i_1++)
            {
                Assert.True(Records.Remove(urls[i_1]));
            }
            Assert.True(Records.IsEmpty());
        }
Example #13
0
            public virtual WebApp Start(WebApp webapp)
            {
                WebApp      webApp     = Build(webapp);
                HttpServer2 httpServer = webApp.HttpServer();

                try
                {
                    httpServer.Start();
                    Log.Info("Web app " + name + " started at " + httpServer.GetConnectorAddress(0).Port
                             );
                }
                catch (IOException e)
                {
                    throw new WebAppException("Error starting http server", e);
                }
                return(webApp);
            }
Example #14
0
        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);
            }
        }
Example #15
0
        /// <exception cref="System.Exception"/>
        protected override void SetUp()
        {
            new FilePath(Runtime.GetProperty("build.webapps", "build/webapps") + "/test").Mkdirs
                ();
            server = new HttpServer2.Builder().SetName("test").AddEndpoint(URI.Create("http://localhost:0"
                                                                                      )).SetFindPort(true).Build();
            server.AddServlet("delay", "/delay", typeof(TestJobEndNotifier.DelayServlet));
            server.AddServlet("jobend", "/jobend", typeof(TestJobEndNotifier.JobEndServlet));
            server.AddServlet("fail", "/fail", typeof(TestJobEndNotifier.FailServlet));
            server.Start();
            int port = server.GetConnectorAddress(0).Port;

            baseUrl = new Uri("http://localhost:" + port + "/");
            TestJobEndNotifier.JobEndServlet.calledTimes = 0;
            TestJobEndNotifier.JobEndServlet.requestUri  = null;
            TestJobEndNotifier.DelayServlet.calledTimes  = 0;
            TestJobEndNotifier.FailServlet.calledTimes   = 0;
        }
Example #16
0
        public static void Setup()
        {
            Configuration conf = new Configuration();

            conf.SetInt(HttpServer2.HttpMaxThreads, 10);
            server = CreateTestServer(conf);
            server.AddServlet("echo", "/echo", typeof(TestHttpServer.EchoServlet));
            server.AddServlet("echomap", "/echomap", typeof(TestHttpServer.EchoMapServlet));
            server.AddServlet("htmlcontent", "/htmlcontent", typeof(TestHttpServer.HtmlContentServlet
                                                                    ));
            server.AddServlet("longheader", "/longheader", typeof(HttpServerFunctionalTest.LongHeaderServlet
                                                                  ));
            server.AddJerseyResourcePackage(typeof(JerseyResource).Assembly.GetName(), "/jersey/*"
                                            );
            server.Start();
            baseUrl = GetServerURL(server);
            Log.Info("HTTP server started: " + baseUrl);
        }
Example #17
0
        public virtual void TestStartedServerWithRequestLog()
        {
            HttpRequestLogAppender requestLogAppender = new HttpRequestLogAppender();

            requestLogAppender.SetName("httprequestlog");
            requestLogAppender.SetFilename(Runtime.GetProperty("test.build.data", "/tmp/") +
                                           "jetty-name-yyyy_mm_dd.log");
            Logger.GetLogger(typeof(HttpServer2).FullName + ".test").AddAppender(requestLogAppender
                                                                                 );
            HttpServer2 server = null;

            server = CreateTestServer();
            AssertNotLive(server);
            server.Start();
            AssertAlive(server);
            Stop(server);
            Logger.GetLogger(typeof(HttpServer2).FullName + ".test").RemoveAppender(requestLogAppender
                                                                                    );
        }
Example #18
0
        public virtual void TestServletFilterWhenInitThrowsException()
        {
            Configuration conf = new Configuration();

            // start a http server with CountingFilter
            conf.Set(HttpServer2.FilterInitializerProperty, typeof(TestServletFilter.ErrorFilter.Initializer
                                                                   ).FullName);
            HttpServer2 http = CreateTestServer(conf);

            try
            {
                http.Start();
                NUnit.Framework.Assert.Fail("expecting exception");
            }
            catch (IOException e)
            {
                Assert.True(e.Message.Contains("Problem in starting http server. Server handlers failed"
                                               ));
            }
        }
        /// <summary>Test to verify the timeout of Image upload</summary>
        /// <exception cref="System.Exception"/>
        public virtual void TestImageUploadTimeout()
        {
            Configuration conf        = new HdfsConfiguration();
            NNStorage     mockStorage = Org.Mockito.Mockito.Mock <NNStorage>();
            HttpServer2   testServer  = HttpServerFunctionalTest.CreateServer("hdfs");

            try
            {
                testServer.AddServlet("ImageTransfer", ImageServlet.PathSpec, typeof(TestTransferFsImage.TestImageTransferServlet
                                                                                     ));
                testServer.Start();
                Uri serverURL = HttpServerFunctionalTest.GetServerURL(testServer);
                // set the timeout here, otherwise it will take default.
                TransferFsImage.timeout = 2000;
                FilePath tmpDir = new FilePath(new FileSystemTestHelper().GetTestRootDir());
                tmpDir.Mkdirs();
                FilePath         mockImageFile = FilePath.CreateTempFile("image", string.Empty, tmpDir);
                FileOutputStream imageFile     = new FileOutputStream(mockImageFile);
                imageFile.Write(Sharpen.Runtime.GetBytesForString("data"));
                imageFile.Close();
                Org.Mockito.Mockito.When(mockStorage.FindImageFile(Org.Mockito.Mockito.Any <NNStorage.NameNodeFile
                                                                                            >(), Org.Mockito.Mockito.AnyLong())).ThenReturn(mockImageFile);
                Org.Mockito.Mockito.When(mockStorage.ToColonSeparatedString()).ThenReturn("storage:info:string"
                                                                                          );
                try
                {
                    TransferFsImage.UploadImageFromStorage(serverURL, conf, mockStorage, NNStorage.NameNodeFile
                                                           .Image, 1L);
                    NUnit.Framework.Assert.Fail("TransferImage Should fail with timeout");
                }
                catch (SocketTimeoutException e)
                {
                    NUnit.Framework.Assert.AreEqual("Upload should timeout", "Read timed out", e.Message
                                                    );
                }
            }
            finally
            {
                testServer.Stop();
            }
        }
        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);
            }
        }
Example #21
0
 public static void Setup()
 {
     server = CreateTestServer();
     server.Start();
     baseUrl = GetServerURL(server);
 }
Example #22
0
        /// <summary>Initialize SecondaryNameNode.</summary>
        /// <exception cref="System.IO.IOException"/>
        private void Initialize(Configuration conf, SecondaryNameNode.CommandLineOpts commandLineOpts
                                )
        {
            IPEndPoint infoSocAddr     = GetHttpAddress(conf);
            string     infoBindAddress = infoSocAddr.GetHostName();

            UserGroupInformation.SetConfiguration(conf);
            if (UserGroupInformation.IsSecurityEnabled())
            {
                SecurityUtil.Login(conf, DFSConfigKeys.DfsSecondaryNamenodeKeytabFileKey, DFSConfigKeys
                                   .DfsSecondaryNamenodeKerberosPrincipalKey, infoBindAddress);
            }
            // initiate Java VM metrics
            DefaultMetricsSystem.Initialize("SecondaryNameNode");
            JvmMetrics.Create("SecondaryNameNode", conf.Get(DFSConfigKeys.DfsMetricsSessionIdKey
                                                            ), DefaultMetricsSystem.Instance());
            // Create connection to the namenode.
            shouldRun     = true;
            nameNodeAddr  = NameNode.GetServiceAddress(conf, true);
            this.conf     = conf;
            this.namenode = NameNodeProxies.CreateNonHAProxy <NamenodeProtocol>(conf, nameNodeAddr
                                                                                , UserGroupInformation.GetCurrentUser(), true).GetProxy();
            // initialize checkpoint directories
            fsName              = GetInfoServer();
            checkpointDirs      = FSImage.GetCheckpointDirs(conf, "/tmp/hadoop/dfs/namesecondary");
            checkpointEditsDirs = FSImage.GetCheckpointEditsDirs(conf, "/tmp/hadoop/dfs/namesecondary"
                                                                 );
            checkpointImage = new SecondaryNameNode.CheckpointStorage(conf, checkpointDirs, checkpointEditsDirs
                                                                      );
            checkpointImage.RecoverCreate(commandLineOpts.ShouldFormat());
            checkpointImage.DeleteTempEdits();
            namesystem = new FSNamesystem(conf, checkpointImage, true);
            // Disable quota checks
            namesystem.dir.DisableQuotaChecks();
            // Initialize other scheduling parameters from the configuration
            checkpointConf = new CheckpointConf(conf);
            IPEndPoint httpAddr        = infoSocAddr;
            string     httpsAddrString = conf.GetTrimmed(DFSConfigKeys.DfsNamenodeSecondaryHttpsAddressKey
                                                         , DFSConfigKeys.DfsNamenodeSecondaryHttpsAddressDefault);
            IPEndPoint httpsAddr = NetUtils.CreateSocketAddr(httpsAddrString);

            HttpServer2.Builder builder = DFSUtil.HttpServerTemplateForNNAndJN(conf, httpAddr
                                                                               , httpsAddr, "secondary", DFSConfigKeys.DfsSecondaryNamenodeKerberosInternalSpnegoPrincipalKey
                                                                               , DFSConfigKeys.DfsSecondaryNamenodeKeytabFileKey);
            nameNodeStatusBeanName = MBeans.Register("SecondaryNameNode", "SecondaryNameNodeInfo"
                                                     , this);
            infoServer = builder.Build();
            infoServer.SetAttribute("secondary.name.node", this);
            infoServer.SetAttribute("name.system.image", checkpointImage);
            infoServer.SetAttribute(JspHelper.CurrentConf, conf);
            infoServer.AddInternalServlet("imagetransfer", ImageServlet.PathSpec, typeof(ImageServlet
                                                                                         ), true);
            infoServer.Start();
            Log.Info("Web server init done");
            HttpConfig.Policy policy = DFSUtil.GetHttpPolicy(conf);
            int connIdx = 0;

            if (policy.IsHttpEnabled())
            {
                IPEndPoint httpAddress = infoServer.GetConnectorAddress(connIdx++);
                conf.Set(DFSConfigKeys.DfsNamenodeSecondaryHttpAddressKey, NetUtils.GetHostPortString
                             (httpAddress));
            }
            if (policy.IsHttpsEnabled())
            {
                IPEndPoint httpsAddress = infoServer.GetConnectorAddress(connIdx);
                conf.Set(DFSConfigKeys.DfsNamenodeSecondaryHttpsAddressKey, NetUtils.GetHostPortString
                             (httpsAddress));
            }
            legacyOivImageDir = conf.Get(DFSConfigKeys.DfsNamenodeLegacyOivImageDirKey);
            Log.Info("Checkpoint Period   :" + checkpointConf.GetPeriod() + " secs " + "(" +
                     checkpointConf.GetPeriod() / 60 + " min)");
            Log.Info("Log Size Trigger    :" + checkpointConf.GetTxnCount() + " txns");
        }