Beispiel #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();
 }
        /// <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
                                                                                              ));
            }
        }
Beispiel #3
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();
        }
Beispiel #4
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));
        }
 /// <summary>Sets fsimage for use by servlets.</summary>
 /// <param name="fsImage">FSImage to set</param>
 internal virtual void SetFSImage(FSImage fsImage)
 {
     httpServer.SetAttribute(FsimageAttributeKey, fsImage);
 }
Beispiel #6
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");
        }
Beispiel #7
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);
            }