Exemple #1
0
        /// <summary>Convert a DatanodeInfo to a Json map.</summary>
        internal static IDictionary <string, object> ToJsonMap(DatanodeInfo datanodeinfo)
        {
            if (datanodeinfo == null)
            {
                return(null);
            }
            // TODO: Fix storageID
            IDictionary <string, object> m = new SortedDictionary <string, object>();

            m["ipAddr"] = datanodeinfo.GetIpAddr();
            // 'name' is equivalent to ipAddr:xferPort. Older clients (1.x, 0.23.x)
            // expects this instead of the two fields.
            m["name"]                = datanodeinfo.GetXferAddr();
            m["hostName"]            = datanodeinfo.GetHostName();
            m["storageID"]           = datanodeinfo.GetDatanodeUuid();
            m["xferPort"]            = datanodeinfo.GetXferPort();
            m["infoPort"]            = datanodeinfo.GetInfoPort();
            m["infoSecurePort"]      = datanodeinfo.GetInfoSecurePort();
            m["ipcPort"]             = datanodeinfo.GetIpcPort();
            m["capacity"]            = datanodeinfo.GetCapacity();
            m["dfsUsed"]             = datanodeinfo.GetDfsUsed();
            m["remaining"]           = datanodeinfo.GetRemaining();
            m["blockPoolUsed"]       = datanodeinfo.GetBlockPoolUsed();
            m["cacheCapacity"]       = datanodeinfo.GetCacheCapacity();
            m["cacheUsed"]           = datanodeinfo.GetCacheUsed();
            m["lastUpdate"]          = datanodeinfo.GetLastUpdate();
            m["lastUpdateMonotonic"] = datanodeinfo.GetLastUpdateMonotonic();
            m["xceiverCount"]        = datanodeinfo.GetXceiverCount();
            m["networkLocation"]     = datanodeinfo.GetNetworkLocation();
            m["adminState"]          = datanodeinfo.GetAdminState().ToString();
            return(m);
        }
Exemple #2
0
 private void Compare(DatanodeInfo dn1, DatanodeInfo dn2)
 {
     NUnit.Framework.Assert.AreEqual(dn1.GetAdminState(), dn2.GetAdminState());
     NUnit.Framework.Assert.AreEqual(dn1.GetBlockPoolUsed(), dn2.GetBlockPoolUsed());
     NUnit.Framework.Assert.AreEqual(dn1.GetBlockPoolUsedPercent(), dn2.GetBlockPoolUsedPercent
                                         (), Delta);
     NUnit.Framework.Assert.AreEqual(dn1.GetCapacity(), dn2.GetCapacity());
     NUnit.Framework.Assert.AreEqual(dn1.GetDatanodeReport(), dn2.GetDatanodeReport());
     NUnit.Framework.Assert.AreEqual(dn1.GetDfsUsed(), dn1.GetDfsUsed());
     NUnit.Framework.Assert.AreEqual(dn1.GetDfsUsedPercent(), dn1.GetDfsUsedPercent(),
                                     Delta);
     NUnit.Framework.Assert.AreEqual(dn1.GetIpAddr(), dn2.GetIpAddr());
     NUnit.Framework.Assert.AreEqual(dn1.GetHostName(), dn2.GetHostName());
     NUnit.Framework.Assert.AreEqual(dn1.GetInfoPort(), dn2.GetInfoPort());
     NUnit.Framework.Assert.AreEqual(dn1.GetIpcPort(), dn2.GetIpcPort());
     NUnit.Framework.Assert.AreEqual(dn1.GetLastUpdate(), dn2.GetLastUpdate());
     NUnit.Framework.Assert.AreEqual(dn1.GetLevel(), dn2.GetLevel());
     NUnit.Framework.Assert.AreEqual(dn1.GetNetworkLocation(), dn2.GetNetworkLocation(
                                         ));
 }
        public virtual void TestDataLocality()
        {
            Configuration conf = WebHdfsTestUtil.CreateConf();

            string[] racks      = new string[] { Rack0, Rack0, Rack1, Rack1, Rack2, Rack2 };
            int      nDataNodes = racks.Length;

            Log.Info("nDataNodes=" + nDataNodes + ", racks=" + Arrays.AsList(racks));
            MiniDFSCluster cluster = new MiniDFSCluster.Builder(conf).NumDataNodes(nDataNodes
                                                                                   ).Racks(racks).Build();

            try
            {
                cluster.WaitActive();
                DistributedFileSystem dfs = cluster.GetFileSystem();
                NameNode        namenode  = cluster.GetNameNode();
                DatanodeManager dm        = namenode.GetNamesystem().GetBlockManager().GetDatanodeManager
                                                ();
                Log.Info("dm=" + dm);
                long   blocksize = DFSConfigKeys.DfsBlockSizeDefault;
                string f         = "/foo";
                {
                    //test CREATE
                    for (int i = 0; i < nDataNodes; i++)
                    {
                        //set client address to a particular datanode
                        DataNode dn     = cluster.GetDataNodes()[i];
                        string   ipAddr = dm.GetDatanode(dn.GetDatanodeId()).GetIpAddr();
                        //The chosen datanode must be the same as the client address
                        DatanodeInfo chosen = NamenodeWebHdfsMethods.ChooseDatanode(namenode, f, PutOpParam.OP
                                                                                    .Create, -1L, blocksize, null);
                        NUnit.Framework.Assert.AreEqual(ipAddr, chosen.GetIpAddr());
                    }
                }
                //create a file with one replica.
                Path p = new Path(f);
                FSDataOutputStream @out = dfs.Create(p, (short)1);
                @out.Write(1);
                @out.Close();
                //get replica location.
                LocatedBlocks locatedblocks = NameNodeAdapter.GetBlockLocations(namenode, f, 0, 1
                                                                                );
                IList <LocatedBlock> lb = locatedblocks.GetLocatedBlocks();
                NUnit.Framework.Assert.AreEqual(1, lb.Count);
                DatanodeInfo[] locations = lb[0].GetLocations();
                NUnit.Framework.Assert.AreEqual(1, locations.Length);
                DatanodeInfo expected = locations[0];
                {
                    //For GETFILECHECKSUM, OPEN and APPEND,
                    //the chosen datanode must be the same as the replica location.
                    //test GETFILECHECKSUM
                    DatanodeInfo chosen = NamenodeWebHdfsMethods.ChooseDatanode(namenode, f, GetOpParam.OP
                                                                                .Getfilechecksum, -1L, blocksize, null);
                    NUnit.Framework.Assert.AreEqual(expected, chosen);
                }
                {
                    //test OPEN
                    DatanodeInfo chosen = NamenodeWebHdfsMethods.ChooseDatanode(namenode, f, GetOpParam.OP
                                                                                .Open, 0, blocksize, null);
                    NUnit.Framework.Assert.AreEqual(expected, chosen);
                }
                {
                    //test APPEND
                    DatanodeInfo chosen = NamenodeWebHdfsMethods.ChooseDatanode(namenode, f, PostOpParam.OP
                                                                                .Append, -1L, blocksize, null);
                    NUnit.Framework.Assert.AreEqual(expected, chosen);
                }
            }
            finally
            {
                cluster.Shutdown();
            }
        }