Esempio n. 1
0
        public virtual void TestHANameNodesWithFederation()
        {
            HdfsConfiguration conf       = new HdfsConfiguration();
            string            Ns1Nn1Host = "ns1-nn1.example.com:8020";
            string            Ns1Nn2Host = "ns1-nn2.example.com:8020";
            string            Ns2Nn1Host = "ns2-nn1.example.com:8020";
            string            Ns2Nn2Host = "ns2-nn2.example.com:8020";

            conf.Set(CommonConfigurationKeys.FsDefaultNameKey, "hdfs://ns1");
            // Two nameservices, each with two NNs.
            conf.Set(DFSConfigKeys.DfsNameservices, "ns1,ns2");
            conf.Set(DFSUtil.AddKeySuffixes(DFSConfigKeys.DfsHaNamenodesKeyPrefix, "ns1"), "ns1-nn1,ns1-nn2"
                     );
            conf.Set(DFSUtil.AddKeySuffixes(DFSConfigKeys.DfsHaNamenodesKeyPrefix, "ns2"), "ns2-nn1,ns2-nn2"
                     );
            conf.Set(DFSUtil.AddKeySuffixes(DFSConfigKeys.DfsNamenodeRpcAddressKey, "ns1", "ns1-nn1"
                                            ), Ns1Nn1Host);
            conf.Set(DFSUtil.AddKeySuffixes(DFSConfigKeys.DfsNamenodeRpcAddressKey, "ns1", "ns1-nn2"
                                            ), Ns1Nn2Host);
            conf.Set(DFSUtil.AddKeySuffixes(DFSConfigKeys.DfsNamenodeRpcAddressKey, "ns2", "ns2-nn1"
                                            ), Ns2Nn1Host);
            conf.Set(DFSUtil.AddKeySuffixes(DFSConfigKeys.DfsNamenodeRpcAddressKey, "ns2", "ns2-nn2"
                                            ), Ns2Nn2Host);
            IDictionary <string, IDictionary <string, IPEndPoint> > map = DFSUtil.GetHaNnRpcAddresses
                                                                              (conf);

            NUnit.Framework.Assert.IsTrue(HAUtil.IsHAEnabled(conf, "ns1"));
            NUnit.Framework.Assert.IsTrue(HAUtil.IsHAEnabled(conf, "ns2"));
            NUnit.Framework.Assert.IsFalse(HAUtil.IsHAEnabled(conf, "ns3"));
            NUnit.Framework.Assert.AreEqual(Ns1Nn1Host, map["ns1"]["ns1-nn1"].ToString());
            NUnit.Framework.Assert.AreEqual(Ns1Nn2Host, map["ns1"]["ns1-nn2"].ToString());
            NUnit.Framework.Assert.AreEqual(Ns2Nn1Host, map["ns2"]["ns2-nn1"].ToString());
            NUnit.Framework.Assert.AreEqual(Ns2Nn2Host, map["ns2"]["ns2-nn2"].ToString());
            NUnit.Framework.Assert.AreEqual(Ns1Nn1Host, DFSUtil.GetNamenodeServiceAddr(conf,
                                                                                       "ns1", "ns1-nn1"));
            NUnit.Framework.Assert.AreEqual(Ns1Nn2Host, DFSUtil.GetNamenodeServiceAddr(conf,
                                                                                       "ns1", "ns1-nn2"));
            NUnit.Framework.Assert.AreEqual(Ns2Nn1Host, DFSUtil.GetNamenodeServiceAddr(conf,
                                                                                       "ns2", "ns2-nn1"));
            // No nameservice was given and we can't determine which service addr
            // to use as two nameservices could share a namenode ID.
            NUnit.Framework.Assert.AreEqual(null, DFSUtil.GetNamenodeServiceAddr(conf, null,
                                                                                 "ns1-nn1"));
            // Ditto for nameservice IDs, if multiple are defined
            NUnit.Framework.Assert.AreEqual(null, DFSUtil.GetNamenodeNameServiceId(conf));
            NUnit.Framework.Assert.AreEqual(null, DFSUtil.GetSecondaryNameServiceId(conf));
            ICollection <URI> uris = DFSUtil.GetNameServiceUris(conf, DFSConfigKeys.DfsNamenodeRpcAddressKey
                                                                );

            NUnit.Framework.Assert.AreEqual(2, uris.Count);
            NUnit.Framework.Assert.IsTrue(uris.Contains(new URI("hdfs://ns1")));
            NUnit.Framework.Assert.IsTrue(uris.Contains(new URI("hdfs://ns2")));
        }
Esempio n. 2
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"));
        }