Пример #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();
 }
Пример #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
        public virtual void TestRequiresAuthorizationAccess()
        {
            Configuration  conf    = new Configuration();
            ServletContext context = Org.Mockito.Mockito.Mock <ServletContext>();

            Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.ConfContextAttribute)).
            ThenReturn(conf);
            HttpServletRequest  request  = Org.Mockito.Mockito.Mock <HttpServletRequest>();
            HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>();

            //requires admin access to instrumentation, FALSE by default
            Assert.True(HttpServer2.IsInstrumentationAccessAllowed(context,
                                                                   request, response));
            //requires admin access to instrumentation, TRUE
            conf.SetBoolean(CommonConfigurationKeys.HadoopSecurityInstrumentationRequiresAdmin
                            , true);
            conf.SetBoolean(CommonConfigurationKeys.HadoopSecurityAuthorization, true);
            AccessControlList acls = Org.Mockito.Mockito.Mock <AccessControlList>();

            Org.Mockito.Mockito.When(acls.IsUserAllowed(Org.Mockito.Mockito.Any <UserGroupInformation
                                                                                 >())).ThenReturn(false);
            Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.AdminsAcl)).ThenReturn(
                acls);
            NUnit.Framework.Assert.IsFalse(HttpServer2.IsInstrumentationAccessAllowed(context
                                                                                      , request, response));
        }
Пример #4
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();
                }
            }
        }
Пример #5
0
        public virtual void TestNotificationOnLastRetryUnregistrationFailure()
        {
            HttpServer2 server = StartHttpServer();
            MRApp       app    = Org.Mockito.Mockito.Spy(new TestJobEndNotifier.MRAppWithCustomContainerAllocator
                                                             (this, 2, 2, false, this.GetType().FullName, true, 2, false));

            // Currently, we will have isLastRetry always equals to false at beginning
            // of MRAppMaster, except staging area exists or commit already started at
            // the beginning.
            // Now manually set isLastRetry to true and this should reset to false when
            // unregister failed.
            app.isLastAMRetry = true;
            Org.Mockito.Mockito.DoNothing().When(app).Sysexit();
            JobConf conf = new JobConf();

            conf.Set(JobContext.MrJobEndNotificationUrl, TestJobEndNotifier.JobEndServlet.baseUrl
                     + "jobend?jobid=$jobId&status=$jobStatus");
            JobImpl job = (JobImpl)app.Submit(conf);

            app.WaitForState(job, JobState.Running);
            app.GetContext().GetEventHandler().Handle(new JobEvent(app.GetJobId(), JobEventType
                                                                   .JobAmReboot));
            app.WaitForInternalState(job, JobStateInternal.Reboot);
            // Now shutdown. User should see FAILED state.
            // Unregistration fails: isLastAMRetry is recalculated, this is
            ///reboot will stop service internally, we don't need to shutdown twice
            app.WaitForServiceToStop(10000);
            NUnit.Framework.Assert.IsFalse(app.IsLastAMRetry());
            // Since it's not last retry, JobEndServlet didn't called
            NUnit.Framework.Assert.AreEqual(0, TestJobEndNotifier.JobEndServlet.calledTimes);
            NUnit.Framework.Assert.IsNull(TestJobEndNotifier.JobEndServlet.requestUri);
            NUnit.Framework.Assert.IsNull(TestJobEndNotifier.JobEndServlet.foundJobState);
            server.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);
        }
Пример #7
0
        public virtual void TestNotificationOnLastRetryNormalShutdown()
        {
            HttpServer2 server = StartHttpServer();
            // Act like it is the second attempt. Default max attempts is 2
            MRApp app = Org.Mockito.Mockito.Spy(new TestJobEndNotifier.MRAppWithCustomContainerAllocator
                                                    (this, 2, 2, true, this.GetType().FullName, true, 2, true));

            Org.Mockito.Mockito.DoNothing().When(app).Sysexit();
            JobConf conf = new JobConf();

            conf.Set(JobContext.MrJobEndNotificationUrl, TestJobEndNotifier.JobEndServlet.baseUrl
                     + "jobend?jobid=$jobId&status=$jobStatus");
            JobImpl job = (JobImpl)app.Submit(conf);

            app.WaitForInternalState(job, JobStateInternal.Succeeded);
            // Unregistration succeeds: successfullyUnregistered is set
            app.ShutDownJob();
            NUnit.Framework.Assert.IsTrue(app.IsLastAMRetry());
            NUnit.Framework.Assert.AreEqual(1, TestJobEndNotifier.JobEndServlet.calledTimes);
            NUnit.Framework.Assert.AreEqual("jobid=" + job.GetID() + "&status=SUCCEEDED", TestJobEndNotifier.JobEndServlet
                                            .requestUri.GetQuery());
            NUnit.Framework.Assert.AreEqual(JobState.Succeeded.ToString(), TestJobEndNotifier.JobEndServlet
                                            .foundJobState);
            server.Stop();
        }
Пример #8
0
        public virtual void TestAbsentNotificationOnNotLastRetryUnregistrationFailure()
        {
            HttpServer2 server = StartHttpServer();
            MRApp       app    = Org.Mockito.Mockito.Spy(new TestJobEndNotifier.MRAppWithCustomContainerAllocator
                                                             (this, 2, 2, false, this.GetType().FullName, true, 1, false));

            Org.Mockito.Mockito.DoNothing().When(app).Sysexit();
            JobConf conf = new JobConf();

            conf.Set(JobContext.MrJobEndNotificationUrl, TestJobEndNotifier.JobEndServlet.baseUrl
                     + "jobend?jobid=$jobId&status=$jobStatus");
            JobImpl job = (JobImpl)app.Submit(conf);

            app.WaitForState(job, JobState.Running);
            app.GetContext().GetEventHandler().Handle(new JobEvent(app.GetJobId(), JobEventType
                                                                   .JobAmReboot));
            app.WaitForInternalState(job, JobStateInternal.Reboot);
            // Now shutdown.
            // Unregistration fails: isLastAMRetry is recalculated, this is not
            app.ShutDownJob();
            // Not the last AM attempt. So user should that the job is still running.
            app.WaitForState(job, JobState.Running);
            NUnit.Framework.Assert.IsFalse(app.IsLastAMRetry());
            NUnit.Framework.Assert.AreEqual(0, TestJobEndNotifier.JobEndServlet.calledTimes);
            NUnit.Framework.Assert.IsNull(TestJobEndNotifier.JobEndServlet.requestUri);
            NUnit.Framework.Assert.IsNull(TestJobEndNotifier.JobEndServlet.foundJobState);
            server.Stop();
        }
Пример #9
0
            /// <exception cref="System.Exception"/>
            protected override void ServiceStart()
            {
                Configuration conf        = this.GetConfig();
                string        bindAddress = conf.Get(YarnConfiguration.ProxyAddress);

                bindAddress = StringUtils.Split(bindAddress, ':')[0];
                AccessControlList acl = new AccessControlList(conf.Get(YarnConfiguration.YarnAdminAcl
                                                                       , YarnConfiguration.DefaultYarnAdminAcl));

                this.proxyServer = new HttpServer2.Builder().SetName("proxy").AddEndpoint(URI.Create
                                                                                              (WebAppUtils.GetHttpSchemePrefix(conf) + bindAddress + ":0")).SetFindPort(true).
                                   SetConf(conf).SetACL(acl).Build();
                this.proxyServer.AddServlet(ProxyUriUtils.ProxyServletName, ProxyUriUtils.ProxyPathSpec
                                            , typeof(WebAppProxyServlet));
                this.appReportFetcher = new TestWebAppProxyServlet.AppReportFetcherForTest(this,
                                                                                           conf);
                this.proxyServer.SetAttribute(WebAppProxy.FetcherAttribute, this.appReportFetcher
                                              );
                this.proxyServer.SetAttribute(WebAppProxy.IsSecurityEnabledAttribute, true);
                string proxy = WebAppUtils.GetProxyHostAndPort(conf);

                string[] proxyParts = proxy.Split(":");
                string   proxyHost  = proxyParts[0];

                this.proxyServer.SetAttribute(WebAppProxy.ProxyHostAttribute, proxyHost);
                this.proxyServer.Start();
                TestWebAppProxyServlet.Log.Info("Proxy server is started at port {}", this.proxyServer
                                                .GetConnectorAddress(0).Port);
            }
Пример #10
0
        /// <summary>
        /// Assert that the result of
        /// <see cref="HttpServer2.ToString()"/>
        /// contains the specific text
        /// </summary>
        /// <param name="server">server to examine</param>
        /// <param name="text">text to search for</param>
        private void AssertToStringContains(HttpServer2 server, string text)
        {
            string description = server.ToString();

            Assert.True("Did not find \"" + text + "\" in \"" + description
                        + "\"", description.Contains(text));
        }
 /// <summary>If the server is non null, stop it</summary>
 /// <param name="server">to stop</param>
 /// <exception cref="System.Exception">on any failure</exception>
 public static void Stop(HttpServer2 server)
 {
     if (server != null)
     {
         server.Stop();
     }
 }
Пример #12
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);
        }
Пример #13
0
        public virtual void TestBindAddress()
        {
            CheckBindAddress("localhost", 0, false).Stop();
            // hang onto this one for a bit more testing
            HttpServer2 myServer  = CheckBindAddress("localhost", 0, false);
            HttpServer2 myServer2 = null;

            try
            {
                int port = myServer.GetConnectorAddress(0).Port;
                // it's already in use, true = expect a higher port
                myServer2 = CheckBindAddress("localhost", port, true);
                // try to reuse the port
                port = myServer2.GetConnectorAddress(0).Port;
                myServer2.Stop();
                NUnit.Framework.Assert.IsNull(myServer2.GetConnectorAddress(0));
                // not bound
                myServer2.OpenListeners();
                Assert.Equal(port, myServer2.GetConnectorAddress(0).Port);
            }
            finally
            {
                // expect same port
                myServer.Stop();
                if (myServer2 != null)
                {
                    myServer2.Stop();
                }
            }
        }
Пример #14
0
        public virtual void TestStoppedServerIsNotAlive()
        {
            HttpServer2 server = CreateAndStartTestServer();

            AssertAlive(server);
            Stop(server);
            AssertNotLive(server);
        }
Пример #15
0
        public virtual void TestStartedServerIsAlive()
        {
            HttpServer2 server = null;

            server = CreateTestServer();
            AssertNotLive(server);
            server.Start();
            AssertAlive(server);
            Stop(server);
        }
Пример #16
0
 /// <exception cref="Javax.Servlet.ServletException"/>
 /// <exception cref="System.IO.IOException"/>
 protected override void DoGet(HttpServletRequest request, HttpServletResponse response
                               )
 {
     // Do the authorization
     if (HttpServer2.HasAdministratorAccess(GetServletContext(), request, response))
     {
         // Authorization is done. Just call super.
         base.DoGet(request, response);
     }
 }
Пример #17
0
        public virtual void TestStoppingTwiceServerIsAllowed()
        {
            HttpServer2 server = CreateAndStartTestServer();

            AssertAlive(server);
            Stop(server);
            AssertNotLive(server);
            Stop(server);
            AssertNotLive(server);
        }
Пример #18
0
        /// <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
                                                                                              ));
            }
        }
Пример #19
0
        internal static bool IsValidRequestor(ServletContext context, string remoteUser,
                                              Configuration conf)
        {
            if (remoteUser == null)
            {
                // This really shouldn't happen...
                Log.Warn("Received null remoteUser while authorizing access to getImage servlet");
                return(false);
            }
            ICollection <string> validRequestors = new HashSet <string>();

            validRequestors.AddItem(SecurityUtil.GetServerPrincipal(conf.Get(DFSConfigKeys.DfsNamenodeKerberosPrincipalKey
                                                                             ), NameNode.GetAddress(conf).GetHostName()));
            try
            {
                validRequestors.AddItem(SecurityUtil.GetServerPrincipal(conf.Get(DFSConfigKeys.DfsSecondaryNamenodeKerberosPrincipalKey
                                                                                 ), SecondaryNameNode.GetHttpAddress(conf).GetHostName()));
            }
            catch (Exception e)
            {
                // Don't halt if SecondaryNameNode principal could not be added.
                Log.Debug("SecondaryNameNode principal could not be added", e);
                string msg = string.Format("SecondaryNameNode principal not considered, %s = %s, %s = %s"
                                           , DFSConfigKeys.DfsSecondaryNamenodeKerberosPrincipalKey, conf.Get(DFSConfigKeys
                                                                                                              .DfsSecondaryNamenodeKerberosPrincipalKey), DFSConfigKeys.DfsNamenodeSecondaryHttpAddressKey
                                           , conf.GetTrimmed(DFSConfigKeys.DfsNamenodeSecondaryHttpAddressKey, DFSConfigKeys
                                                             .DfsNamenodeSecondaryHttpAddressDefault));
                Log.Warn(msg);
            }
            if (HAUtil.IsHAEnabled(conf, DFSUtil.GetNamenodeNameServiceId(conf)))
            {
                Configuration otherNnConf = HAUtil.GetConfForOtherNode(conf);
                validRequestors.AddItem(SecurityUtil.GetServerPrincipal(otherNnConf.Get(DFSConfigKeys
                                                                                        .DfsNamenodeKerberosPrincipalKey), NameNode.GetAddress(otherNnConf).GetHostName(
                                                                            )));
            }
            foreach (string v in validRequestors)
            {
                if (v != null && v.Equals(remoteUser))
                {
                    Log.Info("ImageServlet allowing checkpointer: " + remoteUser);
                    return(true);
                }
            }
            if (HttpServer2.UserHasAdministratorAccess(context, remoteUser))
            {
                Log.Info("ImageServlet allowing administrator: " + remoteUser);
                return(true);
            }
            Log.Info("ImageServlet rejecting: " + remoteUser);
            return(false);
        }
Пример #20
0
        public virtual void TestHasAdministratorAccess()
        {
            Configuration conf = new Configuration();

            conf.SetBoolean(CommonConfigurationKeys.HadoopSecurityAuthorization, false);
            ServletContext context = Org.Mockito.Mockito.Mock <ServletContext>();

            Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.ConfContextAttribute)).
            ThenReturn(conf);
            Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.AdminsAcl)).ThenReturn(
                null);
            HttpServletRequest request = Org.Mockito.Mockito.Mock <HttpServletRequest>();

            Org.Mockito.Mockito.When(request.GetRemoteUser()).ThenReturn(null);
            HttpServletResponse response = Org.Mockito.Mockito.Mock <HttpServletResponse>();

            //authorization OFF
            Assert.True(HttpServer2.HasAdministratorAccess(context, request
                                                           , response));
            //authorization ON & user NULL
            response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
            conf.SetBoolean(CommonConfigurationKeys.HadoopSecurityAuthorization, true);
            NUnit.Framework.Assert.IsFalse(HttpServer2.HasAdministratorAccess(context, request
                                                                              , response));
            Org.Mockito.Mockito.Verify(response).SendError(Org.Mockito.Mockito.Eq(HttpServletResponse
                                                                                  .ScForbidden), Org.Mockito.Mockito.AnyString());
            //authorization ON & user NOT NULL & ACLs NULL
            response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
            Org.Mockito.Mockito.When(request.GetRemoteUser()).ThenReturn("foo");
            Assert.True(HttpServer2.HasAdministratorAccess(context, request
                                                           , response));
            //authorization ON & user NOT NULL & ACLs NOT NULL & user not in ACLs
            response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
            AccessControlList acls = Org.Mockito.Mockito.Mock <AccessControlList>();

            Org.Mockito.Mockito.When(acls.IsUserAllowed(Org.Mockito.Mockito.Any <UserGroupInformation
                                                                                 >())).ThenReturn(false);
            Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.AdminsAcl)).ThenReturn(
                acls);
            NUnit.Framework.Assert.IsFalse(HttpServer2.HasAdministratorAccess(context, request
                                                                              , response));
            Org.Mockito.Mockito.Verify(response).SendError(Org.Mockito.Mockito.Eq(HttpServletResponse
                                                                                  .ScForbidden), Org.Mockito.Mockito.AnyString());
            //authorization ON & user NOT NULL & ACLs NOT NULL & user in in ACLs
            response = Org.Mockito.Mockito.Mock <HttpServletResponse>();
            Org.Mockito.Mockito.When(acls.IsUserAllowed(Org.Mockito.Mockito.Any <UserGroupInformation
                                                                                 >())).ThenReturn(true);
            Org.Mockito.Mockito.When(context.GetAttribute(HttpServer2.AdminsAcl)).ThenReturn(
                acls);
            Assert.True(HttpServer2.HasAdministratorAccess(context, request
                                                           , response));
        }
Пример #21
0
 /// <summary>Shut down this instance of the datanode.</summary>
 /// <remarks>
 /// Shut down this instance of the datanode.
 /// Returns only after shutdown is complete.
 /// </remarks>
 public virtual void Shutdown()
 {
     shouldRun = false;
     if (checkpointThread != null)
     {
         checkpointThread.Interrupt();
         try
         {
             checkpointThread.Join(10000);
         }
         catch (Exception)
         {
             Log.Info("Interrupted waiting to join on checkpointer thread");
             Sharpen.Thread.CurrentThread().Interrupt();
         }
     }
     // maintain status
     try
     {
         if (infoServer != null)
         {
             infoServer.Stop();
             infoServer = null;
         }
     }
     catch (Exception e)
     {
         Log.Warn("Exception shutting down SecondaryNameNode", e);
     }
     if (nameNodeStatusBeanName != null)
     {
         MBeans.Unregister(nameNodeStatusBeanName);
         nameNodeStatusBeanName = null;
     }
     try
     {
         if (checkpointImage != null)
         {
             checkpointImage.Close();
             checkpointImage = null;
         }
     }
     catch (IOException e)
     {
         Log.Warn("Exception while closing CheckpointStorage", e);
     }
     if (namesystem != null)
     {
         namesystem.Shutdown();
         namesystem = null;
     }
 }
Пример #22
0
        public virtual void TestValidServerResource()
        {
            HttpServer2 server = null;

            try
            {
                server = CreateServer("test");
            }
            finally
            {
                Stop(server);
            }
        }
Пример #23
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();
            }
        }
Пример #24
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());
        }
Пример #25
0
 public virtual void TestMissingServerResource()
 {
     try
     {
         HttpServer2 server = CreateServer("NoSuchWebapp");
         //should not have got here.
         //close the server
         string serverDescription = server.ToString();
         Stop(server);
         NUnit.Framework.Assert.Fail("Expected an exception, got " + serverDescription);
     }
     catch (FileNotFoundException expected)
     {
         log.Debug("Expected exception " + expected, expected);
     }
 }
Пример #26
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));
        }
Пример #27
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);
            }
Пример #28
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();
        }
Пример #29
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());
        }
Пример #30
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);
            }
        }