예제 #1
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);
        }
예제 #2
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();
        }
예제 #3
0
        /// <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();
                }
            }
        }
예제 #4
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();
 }
예제 #5
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;
        }
예제 #6
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);
        }
예제 #7
0
        /// <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();
            }
        }
예제 #8
0
            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);
            }