示例#1
0
        /// <summary>
        /// Using
        /// <see cref="GetConf"/>
        /// methods get the list of given
        /// <paramref name="type"/>
        /// of
        /// addresses
        /// </summary>
        /// <?/>
        /// <?/>
        /// <?/>
        /// <?/>
        /// <exception cref="System.Exception"/>
        private void GetAddressListFromTool(TestGetConf.TestType type, HdfsConfiguration
                                            conf, bool checkPort, IList <DFSUtil.ConfiguredNNAddress> expected)
        {
            string         @out   = GetAddressListFromTool(type, conf, expected.Count != 0);
            IList <string> values = new AList <string>();
            // Convert list of addresses returned to an array of string
            StringTokenizer tokenizer = new StringTokenizer(@out);

            while (tokenizer.HasMoreTokens())
            {
                string s = tokenizer.NextToken().Trim();
                values.AddItem(s);
            }
            string[] actual = Sharpen.Collections.ToArray(values, new string[values.Count]);
            // Convert expected list to String[] of hosts
            int i = 0;

            string[] expectedHosts = new string[expected.Count];
            foreach (DFSUtil.ConfiguredNNAddress cnn in expected)
            {
                IPEndPoint addr = cnn.GetAddress();
                if (!checkPort)
                {
                    expectedHosts[i++] = addr.GetHostName();
                }
                else
                {
                    expectedHosts[i++] = addr.GetHostName() + ":" + addr.Port;
                }
            }
            // Compare two arrays
            NUnit.Framework.Assert.IsTrue(Arrays.Equals(expectedHosts, actual));
        }
示例#2
0
        private static string GetResolvedAddress(IPEndPoint address)
        {
            address = NetUtils.GetConnectAddress(address);
            StringBuilder sb       = new StringBuilder();
            IPAddress     resolved = address.Address;

            if (resolved == null || resolved.IsAnyLocalAddress() || resolved.IsLoopbackAddress
                    ())
            {
                string lh = address.GetHostName();
                try
                {
                    lh = Sharpen.Runtime.GetLocalHost().ToString();
                }
                catch (UnknownHostException)
                {
                }
                //Ignore and fallback.
                sb.Append(lh);
            }
            else
            {
                sb.Append(address.GetHostName());
            }
            sb.Append(":").Append(address.Port);
            return(sb.ToString());
        }
示例#3
0
        public virtual void TestGetConnectAddress()
        {
            NetUtils.AddStaticResolution("host", "127.0.0.1");
            IPEndPoint addr        = NetUtils.CreateSocketAddrForHost("host", 1);
            IPEndPoint connectAddr = NetUtils.GetConnectAddress(addr);

            Assert.Equal(addr.GetHostName(), connectAddr.GetHostName());
            addr        = new IPEndPoint(1);
            connectAddr = NetUtils.GetConnectAddress(addr);
            Assert.Equal(Runtime.GetLocalHost().GetHostName(), connectAddr
                         .GetHostName());
        }
示例#4
0
					 GetCMProxy(string containerMgrBindAddr, ContainerId containerId)
				{
					IPEndPoint addr = NetUtils.GetConnectAddress(this._enclosing._enclosing.server);
					string containerManagerBindAddr = addr.GetHostName() + ":" + addr.Port;
					Token token = this._enclosing.tokenSecretManager.CreateNMToken(containerId.GetApplicationAttemptId
						(), NodeId.NewInstance(addr.GetHostName(), addr.Port), "user");
					ContainerManagementProtocolProxy cmProxy = new ContainerManagementProtocolProxy(this
						._enclosing._enclosing.conf);
					ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData proxy = new 
						ContainerManagementProtocolProxy.ContainerManagementProtocolProxyData(this, YarnRPC
						.Create(this._enclosing._enclosing.conf), containerManagerBindAddr, containerId, 
						token);
					return proxy;
				}
示例#5
0
        public virtual void TestGetMasterAddress()
        {
            YarnConfiguration conf = new YarnConfiguration();
            // Default is yarn framework
            string masterHostname = Master.GetMasterAddress(conf).GetHostName();
            // no address set so should default to default rm address
            IPEndPoint rmAddr = NetUtils.CreateSocketAddr(YarnConfiguration.DefaultRmAddress);

            NUnit.Framework.Assert.AreEqual(masterHostname, rmAddr.GetHostName());
            // Trying invalid master address for classic
            conf.Set(MRConfig.FrameworkName, MRConfig.ClassicFrameworkName);
            conf.Set(MRConfig.MasterAddress, "local:invalid");
            // should throw an exception for invalid value
            try
            {
                Master.GetMasterAddress(conf);
                NUnit.Framework.Assert.Fail("Should not reach here as there is a bad master address"
                                            );
            }
            catch (Exception)
            {
            }
            // Expected
            // Change master address to a valid value
            conf.Set(MRConfig.MasterAddress, "bar.com:8042");
            masterHostname = Master.GetMasterAddress(conf).GetHostName();
            NUnit.Framework.Assert.AreEqual(masterHostname, "bar.com");
            // change framework to yarn
            conf.Set(MRConfig.FrameworkName, MRConfig.YarnFrameworkName);
            conf.Set(YarnConfiguration.RmAddress, "foo1.com:8192");
            masterHostname = Master.GetMasterAddress(conf).GetHostName();
            NUnit.Framework.Assert.AreEqual(masterHostname, "foo1.com");
        }
示例#6
0
        /// <summary>Log in as the Kerberose principal designated for the proxy</summary>
        /// <param name="conf">the configuration holding this information in it.</param>
        /// <exception cref="System.IO.IOException">on any error.</exception>
        protected internal virtual void DoSecureLogin(Configuration conf)
        {
            IPEndPoint socAddr = GetBindAddress(conf);

            SecurityUtil.Login(conf, YarnConfiguration.ProxyKeytab, YarnConfiguration.ProxyPrincipal
                               , socAddr.GetHostName());
        }
示例#7
0
        /// <exception cref="Sharpen.UnknownHostException"/>
        public static string GetApplicationWebURLOnJHSWithoutScheme(Configuration conf, ApplicationId
                                                                    appId)
        {
            //construct the history url for job
            string addr             = GetJHSWebappURLWithoutScheme(conf);
            IEnumerator <string> it = AddrSplitter.Split(addr).GetEnumerator();

            it.Next();
            // ignore the bind host
            string port = it.Next();

            // Use hs address to figure out the host for webapp
            addr = conf.Get(JHAdminConfig.MrHistoryAddress, JHAdminConfig.DefaultMrHistoryAddress
                            );
            string     host      = AddrSplitter.Split(addr).GetEnumerator().Next();
            string     hsAddress = Joiner.Join(host, ":", port);
            IPEndPoint address   = NetUtils.CreateSocketAddr(hsAddress, GetDefaultJHSWebappPort
                                                                 (), GetDefaultJHSWebappURLWithoutScheme());
            StringBuilder sb = new StringBuilder();

            if (address.Address.IsAnyLocalAddress() || address.Address.IsLoopbackAddress())
            {
                sb.Append(Sharpen.Runtime.GetLocalHost().ToString());
            }
            else
            {
                sb.Append(address.GetHostName());
            }
            sb.Append(":").Append(address.Port);
            sb.Append("/jobhistory/job/");
            JobID jobId = TypeConverter.FromYarn(appId);

            sb.Append(jobId.ToString());
            return(sb.ToString());
        }
 private string GetHost(IPEndPoint isa)
 {
     //@@@ Will this work with literal IPv6 addresses, or do we
     //@@@ need to wrap these in [] for the string representation?
     //@@@ Having it in this method at least allows for easy workarounds.
     return(isa.IsUnresolved() ? isa.GetHostName() : isa.Address.GetHostAddress());
 }
        /// <exception cref="System.IO.IOException"/>
        protected override void LoginAsFCUser()
        {
            IPEndPoint socAddr = NameNode.GetAddress(conf);

            SecurityUtil.Login(conf, DFSConfigKeys.DfsNamenodeKeytabFileKey, DFSConfigKeys.DfsNamenodeKerberosPrincipalKey
                               , socAddr.GetHostName());
        }
示例#10
0
        /// <exception cref="System.IO.IOException"/>
        internal JournalNodeRpcServer(Configuration conf, JournalNode jn)
        {
            this.jn = jn;
            Configuration confCopy = new Configuration(conf);

            // Ensure that nagling doesn't kick in, which could cause latency issues.
            confCopy.SetBoolean(CommonConfigurationKeysPublic.IpcServerTcpnodelayKey, true);
            IPEndPoint addr = GetAddress(confCopy);

            RPC.SetProtocolEngine(confCopy, typeof(QJournalProtocolPB), typeof(ProtobufRpcEngine
                                                                               ));
            QJournalProtocolServerSideTranslatorPB translator = new QJournalProtocolServerSideTranslatorPB
                                                                    (this);
            BlockingService service = QJournalProtocolProtos.QJournalProtocolService.NewReflectiveBlockingService
                                          (translator);

            this.server = new RPC.Builder(confCopy).SetProtocol(typeof(QJournalProtocolPB)).SetInstance
                              (service).SetBindAddress(addr.GetHostName()).SetPort(addr.Port).SetNumHandlers(HandlerCount
                                                                                                             ).SetVerbose(false).Build();
            // set service-level authorization security policy
            if (confCopy.GetBoolean(CommonConfigurationKeys.HadoopSecurityAuthorization, false
                                    ))
            {
                server.RefreshServiceAcl(confCopy, new HDFSPolicyProvider());
            }
        }
        /// <exception cref="System.IO.IOException"/>
        private void DoSecureLogin(Configuration conf)
        {
            IPEndPoint socAddr = GetBindAddress(conf);

            SecurityUtil.Login(conf, YarnConfiguration.TimelineServiceKeytab, YarnConfiguration
                               .TimelineServicePrincipal, socAddr.GetHostName());
        }
示例#12
0
        /// <exception cref="System.IO.IOException"/>
        private void ParseConfAndFindOtherNN()
        {
            Configuration conf = GetConf();

            nsId = DFSUtil.GetNamenodeNameServiceId(conf);
            if (!HAUtil.IsHAEnabled(conf, nsId))
            {
                throw new HadoopIllegalArgumentException("HA is not enabled for this namenode.");
            }
            nnId = HAUtil.GetNameNodeId(conf, nsId);
            NameNode.InitializeGenericKeys(conf, nsId, nnId);
            if (!HAUtil.UsesSharedEditsDir(conf))
            {
                throw new HadoopIllegalArgumentException("Shared edits storage is not enabled for this namenode."
                                                         );
            }
            Configuration otherNode = HAUtil.GetConfForOtherNode(conf);

            otherNNId    = HAUtil.GetNameNodeId(otherNode, nsId);
            otherIpcAddr = NameNode.GetServiceAddress(otherNode, true);
            Preconditions.CheckArgument(otherIpcAddr.Port != 0 && !otherIpcAddr.Address.IsAnyLocalAddress
                                            (), "Could not determine valid IPC address for other NameNode (%s)" + ", got: %s"
                                        , otherNNId, otherIpcAddr);
            string scheme = DFSUtil.GetHttpClientScheme(conf);

            otherHttpAddr = DFSUtil.GetInfoServerWithDefaultHost(otherIpcAddr.GetHostName(),
                                                                 otherNode, scheme).ToURL();
            dirsToFormat     = FSNamesystem.GetNamespaceDirs(conf);
            editUrisToFormat = FSNamesystem.GetNamespaceEditsDirs(conf, false);
            sharedEditsUris  = FSNamesystem.GetSharedEditsDirs(conf);
        }
示例#13
0
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual void DoSecureLogin(Configuration conf)
        {
            IPEndPoint socAddr = GetBindAddress(conf);

            SecurityUtil.Login(conf, JHAdminConfig.MrHistoryKeytab, JHAdminConfig.MrHistoryPrincipal
                               , socAddr.GetHostName());
        }
        /// <summary>Get the connection string.</summary>
        /// <returns>the string</returns>
        /// <exception cref="System.InvalidOperationException">if the connection is not yet valid
        ///     </exception>
        public virtual string GetConnectionString()
        {
            Preconditions.CheckState(factory != null, "service not started");
            IPEndPoint addr = factory.GetLocalAddress();

            return(string.Format("%s:%d", addr.GetHostName(), addr.Port));
        }
示例#15
0
        /// <exception cref="System.IO.IOException"/>
        internal static void CheckPath(MiniDFSCluster cluster, FileSystem fileSys)
        {
            IPEndPoint add = cluster.GetNameNode().GetNameNodeAddress();

            // Test upper/lower case
            fileSys.CheckPath(new Path("hdfs://" + StringUtils.ToUpperCase(add.GetHostName())
                                       + ":" + add.Port));
        }
        protected override byte[] TargetToData(HAServiceTarget target)
        {
            IPEndPoint addr = target.GetAddress();

            return(((HAZKInfoProtos.ActiveNodeInfo)HAZKInfoProtos.ActiveNodeInfo.NewBuilder()
                    .SetHostname(addr.GetHostName()).SetPort(addr.Port).SetZkfcPort(target.GetZKFCAddress
                                                                                        ().Port).SetNameserviceId(localNNTarget.GetNameServiceId()).SetNamenodeId(localNNTarget
                                                                                                                                                                  .GetNameNodeId()).Build()).ToByteArray());
        }
示例#17
0
        /// <summary>Helper function that generates the decommissioning report.</summary>
        /// <remarks>
        /// Helper function that generates the decommissioning report.  Connect to each
        /// Namenode over http via JmxJsonServlet to collect the data nodes status.
        /// </remarks>
        internal virtual ClusterJspHelper.DecommissionStatus GenerateDecommissioningReport
            ()
        {
            string        clusterid = string.Empty;
            Configuration conf      = new Configuration();
            IList <DFSUtil.ConfiguredNNAddress> cnns = null;

            try
            {
                cnns = DFSUtil.FlattenAddressMap(DFSUtil.GetNNServiceRpcAddresses(conf));
            }
            catch (Exception e)
            {
                // catch any exception encountered other than connecting to namenodes
                ClusterJspHelper.DecommissionStatus dInfo = new ClusterJspHelper.DecommissionStatus
                                                                (clusterid, e);
                return(dInfo);
            }
            // Outer map key is datanode. Inner map key is namenode and the value is
            // decom status of the datanode for the corresponding namenode
            IDictionary <string, IDictionary <string, string> > statusMap = new Dictionary <string
                                                                                            , IDictionary <string, string> >();
            // Map of exceptions encountered when connecting to namenode
            // key is namenode and value is exception
            IDictionary <string, Exception> decommissionExceptions = new Dictionary <string, Exception
                                                                                     >();
            IList <string> unreportedNamenode = new AList <string>();

            foreach (DFSUtil.ConfiguredNNAddress cnn in cnns)
            {
                IPEndPoint isa = cnn.GetAddress();
                ClusterJspHelper.NamenodeMXBeanHelper nnHelper = null;
                try
                {
                    nnHelper = new ClusterJspHelper.NamenodeMXBeanHelper(isa, conf);
                    string mbeanProps = QueryMbean(nnHelper.httpAddress, conf);
                    if (clusterid.Equals(string.Empty))
                    {
                        clusterid = nnHelper.GetClusterId(mbeanProps);
                    }
                    nnHelper.GetDecomNodeInfoForReport(statusMap, mbeanProps);
                }
                catch (Exception e)
                {
                    // catch exceptions encountered while connecting to namenodes
                    string nnHost = isa.GetHostName();
                    decommissionExceptions[nnHost] = e;
                    unreportedNamenode.AddItem(nnHost);
                    continue;
                }
            }
            UpdateUnknownStatus(statusMap, unreportedNamenode);
            GetDecommissionNodeClusterState(statusMap);
            return(new ClusterJspHelper.DecommissionStatus(statusMap, clusterid, GetDatanodeHttpPort
                                                               (conf), decommissionExceptions));
        }
示例#18
0
        /// <summary>Construct the service key for a token</summary>
        /// <param name="addr">InetSocketAddress of remote connection with a token</param>
        /// <returns>
        /// "ip:port" or "host:port" depending on the value of
        /// hadoop.security.token.service.use_ip
        /// </returns>
        public static Text BuildTokenService(IPEndPoint addr)
        {
            string host = null;

            if (useIpForTokenService)
            {
                if (addr.IsUnresolved())
                {
                    // host has no ip address
                    throw new ArgumentException(new UnknownHostException(addr.GetHostName()));
                }
                host = addr.Address.GetHostAddress();
            }
            else
            {
                host = StringUtils.ToLowerCase(addr.GetHostName());
            }
            return(new Text(host + ":" + addr.Port));
        }
示例#19
0
        // Exit/return codes.
        // Skip 4 - was used in previous versions, but no longer returned.
        /// <exception cref="System.Exception"/>
        public virtual int Run(string[] args)
        {
            ParseArgs(args);
            ParseConfAndFindOtherNN();
            NameNode.CheckAllowFormat(conf);
            IPEndPoint myAddr = NameNode.GetAddress(conf);

            SecurityUtil.Login(conf, DFSConfigKeys.DfsNamenodeKeytabFileKey, DFSConfigKeys.DfsNamenodeKerberosPrincipalKey
                               , myAddr.GetHostName());
            return(SecurityUtil.DoAsLoginUserOrFatal(new _PrivilegedAction_110(this)));
        }
示例#20
0
        /// <exception cref="Com.Jcraft.Jsch.JSchException"/>
        private bool DoFence(Session session, IPEndPoint serviceAddr)
        {
            int port = serviceAddr.Port;

            try
            {
                Log.Info("Looking for process running on port " + port);
                int rc = ExecCommand(session, "PATH=$PATH:/sbin:/usr/sbin fuser -v -k -n tcp " +
                                     port);
                if (rc == 0)
                {
                    Log.Info("Successfully killed process that was " + "listening on port " + port);
                    // exit code 0 indicates the process was successfully killed.
                    return(true);
                }
                else
                {
                    if (rc == 1)
                    {
                        // exit code 1 indicates either that the process was not running
                        // or that fuser didn't have root privileges in order to find it
                        // (eg running as a different user)
                        Log.Info("Indeterminate response from trying to kill service. " + "Verifying whether it is running using nc..."
                                 );
                        rc = ExecCommand(session, "nc -z " + serviceAddr.GetHostName() + " " + serviceAddr
                                         .Port);
                        if (rc == 0)
                        {
                            // the service is still listening - we are unable to fence
                            Log.Warn("Unable to fence - it is running but we cannot kill it");
                            return(false);
                        }
                        else
                        {
                            Log.Info("Verified that the service is down.");
                            return(true);
                        }
                    }
                }
                // other
                Log.Info("rc: " + rc);
                return(rc == 0);
            }
            catch (Exception e)
            {
                Log.Warn("Interrupted while trying to fence via ssh", e);
                return(false);
            }
            catch (IOException e)
            {
                Log.Warn("Unknown failure while trying to fence via ssh", e);
                return(false);
            }
        }
示例#21
0
        public static string GetResolvedMRHistoryWebAppURLWithoutScheme(Configuration conf
                                                                        , bool isSSLEnabled)
        {
            IPEndPoint address = null;

            if (isSSLEnabled)
            {
                address = conf.GetSocketAddr(JHAdminConfig.MrHistoryWebappHttpsAddress, JHAdminConfig
                                             .DefaultMrHistoryWebappHttpsAddress, JHAdminConfig.DefaultMrHistoryWebappHttpsPort
                                             );
            }
            else
            {
                address = conf.GetSocketAddr(JHAdminConfig.MrHistoryWebappAddress, JHAdminConfig.
                                             DefaultMrHistoryWebappAddress, JHAdminConfig.DefaultMrHistoryWebappPort);
            }
            address = NetUtils.GetConnectAddress(address);
            StringBuilder sb       = new StringBuilder();
            IPAddress     resolved = address.Address;

            if (resolved == null || resolved.IsAnyLocalAddress() || resolved.IsLoopbackAddress
                    ())
            {
                string lh = address.GetHostName();
                try
                {
                    lh = Sharpen.Runtime.GetLocalHost().ToString();
                }
                catch (UnknownHostException)
                {
                }
                //Ignore and fallback.
                sb.Append(lh);
            }
            else
            {
                sb.Append(address.GetHostName());
            }
            sb.Append(":").Append(address.Port);
            return(sb.ToString());
        }
示例#22
0
        /// <exception cref="Org.Apache.Hadoop.HA.BadFencingConfigurationException"/>
        public virtual bool TryFence(HAServiceTarget target, string argsStr)
        {
            SshFenceByTcpPort.Args args        = new SshFenceByTcpPort.Args(argsStr);
            IPEndPoint             serviceAddr = target.GetAddress();
            string  host = serviceAddr.GetHostName();
            Session session;

            try
            {
                session = CreateSession(serviceAddr.GetHostName(), args);
            }
            catch (JSchException e)
            {
                Log.Warn("Unable to create SSH session", e);
                return(false);
            }
            Log.Info("Connecting to " + host + "...");
            try
            {
                session.Connect(GetSshConnectTimeout());
            }
            catch (JSchException e)
            {
                Log.Warn("Unable to connect to " + host + " as user " + args.user, e);
                return(false);
            }
            Log.Info("Connected to " + host);
            try
            {
                return(DoFence(session, serviceAddr));
            }
            catch (JSchException e)
            {
                Log.Warn("Unable to achieve fencing on remote host", e);
                return(false);
            }
            finally
            {
                session.Disconnect();
            }
        }
示例#23
0
 /// <summary>Construct the http server based on the response.</summary>
 /// <remarks>
 /// Construct the http server based on the response.
 /// The fromURL field in the response specifies the endpoint of the http
 /// server. However, the address might not be accurate since the server can
 /// bind to multiple interfaces. Here the client plugs in the address specified
 /// in the configuration and generates the URI.
 /// </remarks>
 private Uri GetHttpServerURI(string scheme, int port)
 {
     try
     {
         return(new Uri(scheme, addr.GetHostName(), port, string.Empty));
     }
     catch (UriFormatException e)
     {
         // Unreachable
         throw new RuntimeException(e);
     }
 }
示例#24
0
        public virtual void TestIsInSafemode()
        {
            // Check for the standby nn without client failover.
            NameNode nn2 = cluster.GetNameNode(1);

            NUnit.Framework.Assert.IsTrue("nn2 should be in standby state", nn2.IsStandbyState
                                              ());
            IPEndPoint            nameNodeAddress = nn2.GetNameNodeAddress();
            Configuration         conf            = new Configuration();
            DistributedFileSystem dfs             = new DistributedFileSystem();

            try
            {
                dfs.Initialize(URI.Create("hdfs://" + nameNodeAddress.GetHostName() + ":" + nameNodeAddress
                                          .Port), conf);
                dfs.IsInSafeMode();
                NUnit.Framework.Assert.Fail("StandBy should throw exception for isInSafeMode");
            }
            catch (IOException e)
            {
                if (e is RemoteException)
                {
                    IOException sbExcpetion = ((RemoteException)e).UnwrapRemoteException();
                    NUnit.Framework.Assert.IsTrue("StandBy nn should not support isInSafeMode", sbExcpetion
                                                  is StandbyException);
                }
                else
                {
                    throw;
                }
            }
            finally
            {
                if (null != dfs)
                {
                    dfs.Close();
                }
            }
            // Check with Client FailOver
            cluster.TransitionToStandby(0);
            cluster.TransitionToActive(1);
            cluster.GetNameNodeRpc(1).SetSafeMode(HdfsConstants.SafeModeAction.SafemodeEnter,
                                                  false);
            DistributedFileSystem dfsWithFailOver = (DistributedFileSystem)fs;

            NUnit.Framework.Assert.IsTrue("ANN should be in SafeMode", dfsWithFailOver.IsInSafeMode
                                              ());
            cluster.GetNameNodeRpc(1).SetSafeMode(HdfsConstants.SafeModeAction.SafemodeLeave,
                                                  false);
            NUnit.Framework.Assert.IsFalse("ANN should be out of SafeMode", dfsWithFailOver.IsInSafeMode
                                               ());
        }
示例#25
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
                                                                                              ));
            }
        }
示例#26
0
 // check that the socket addr has:
 // 1) the InetSocketAddress has the correct hostname, ie. exact host/ip given
 // 2) the address is resolved, ie. has an ip
 // 3,4) the socket's InetAddress has the same hostname, and the correct ip
 // 5) the port is correct
 private void VerifyValues(IPEndPoint addr, string host, string ip, int port)
 {
     Assert.True(!addr.IsUnresolved());
     // don't know what the standard resolver will return for hostname.
     // should be host for host; host or ip for ip is ambiguous
     if (!SecurityUtil.useIpForTokenService)
     {
         Assert.Equal(host, addr.GetHostName());
         Assert.Equal(host, addr.Address.GetHostName());
     }
     Assert.Equal(ip, addr.Address.GetHostAddress());
     Assert.Equal(port, addr.Port);
 }
示例#27
0
        public virtual void TestMultipleNamenodes()
        {
            HdfsConfiguration conf = new HdfsConfiguration();

            conf.Set(DFSConfigKeys.DfsNameservices, "nn1,nn2");
            // Test - configured list of namenodes are returned
            string Nn1Address = "localhost:9000";
            string Nn2Address = "localhost:9001";
            string Nn3Address = "localhost:9002";

            conf.Set(DFSUtil.AddKeySuffixes(DFSConfigKeys.DfsNamenodeRpcAddressKey, "nn1"), Nn1Address
                     );
            conf.Set(DFSUtil.AddKeySuffixes(DFSConfigKeys.DfsNamenodeRpcAddressKey, "nn2"), Nn2Address
                     );
            IDictionary <string, IDictionary <string, IPEndPoint> > nnMap = DFSUtil.GetNNServiceRpcAddresses
                                                                                (conf);

            NUnit.Framework.Assert.AreEqual(2, nnMap.Count);
            IDictionary <string, IPEndPoint> nn1Map = nnMap["nn1"];

            NUnit.Framework.Assert.AreEqual(1, nn1Map.Count);
            IPEndPoint addr = nn1Map[null];

            NUnit.Framework.Assert.AreEqual("localhost", addr.GetHostName());
            NUnit.Framework.Assert.AreEqual(9000, addr.Port);
            IDictionary <string, IPEndPoint> nn2Map = nnMap["nn2"];

            NUnit.Framework.Assert.AreEqual(1, nn2Map.Count);
            addr = nn2Map[null];
            NUnit.Framework.Assert.AreEqual("localhost", addr.GetHostName());
            NUnit.Framework.Assert.AreEqual(9001, addr.Port);
            // Test - can look up nameservice ID from service address
            CheckNameServiceId(conf, Nn1Address, "nn1");
            CheckNameServiceId(conf, Nn2Address, "nn2");
            CheckNameServiceId(conf, Nn3Address, null);
            // HA is not enabled in a purely federated config
            NUnit.Framework.Assert.IsFalse(HAUtil.IsHAEnabled(conf, "nn1"));
            NUnit.Framework.Assert.IsFalse(HAUtil.IsHAEnabled(conf, "nn2"));
        }
示例#28
0
        public RMWebAppFilter(Injector injector, Configuration conf)
            : base(injector)
        {
            // define a set of URIs which do not need to do redirection
            this.injector = injector;
            IPEndPoint sock = YarnConfiguration.UseHttps(conf) ? conf.GetSocketAddr(YarnConfiguration
                                                                                    .RmWebappHttpsAddress, YarnConfiguration.DefaultRmWebappHttpsAddress, YarnConfiguration
                                                                                    .DefaultRmWebappHttpsPort) : conf.GetSocketAddr(YarnConfiguration.RmWebappAddress
                                                                                                                                    , YarnConfiguration.DefaultRmWebappAddress, YarnConfiguration.DefaultRmWebappPort
                                                                                                                                    );

            path = sock.GetHostName() + ":" + Sharpen.Extensions.ToString(sock.Port);
            path = YarnConfiguration.UseHttps(conf) ? "https://" + path : "http://" + path;
        }
 public static void BuildMainArgs(IList <string> command, string user, string appId
                                  , string locId, IPEndPoint nmAddr, IList <string> localDirs)
 {
     command.AddItem(typeof(MockContainerLocalizer).FullName);
     command.AddItem(user);
     command.AddItem(appId);
     command.AddItem(locId);
     command.AddItem(nmAddr.GetHostName());
     command.AddItem(Sharpen.Extensions.ToString(nmAddr.Port));
     foreach (string dir in localDirs)
     {
         command.AddItem(dir);
     }
 }
示例#30
0
        /// <exception cref="System.IO.IOException"></exception>
        /// <exception cref="Sharpen.UnknownHostException"></exception>
        /// <exception cref="Apache.Http.Conn.ConnectTimeoutException"></exception>
        public virtual Socket ConnectSocket(Socket sock, IPEndPoint remoteAddress, IPEndPoint
                                            localAddress, HttpParams @params)
        {
            string    host      = remoteAddress.GetHostName();
            int       port      = remoteAddress.Port;
            IPAddress local     = null;
            int       localPort = 0;

            if (localAddress != null)
            {
                local     = localAddress.Address;
                localPort = localAddress.Port;
            }
            return(this.factory.ConnectSocket(sock, host, port, local, localPort, @params));
        }