public virtual void SetUp() { FileSystem.SetDefaultUri(Conf, "hdfs://localhost:0"); Conf.Set(DFSConfigKeys.DfsNamenodeHttpAddressKey, "0.0.0.0:0"); // Set properties to make HDFS aware of NodeGroup. Conf.Set(DFSConfigKeys.DfsBlockReplicatorClassnameKey, typeof(BlockPlacementPolicyWithNodeGroup ).FullName); Conf.Set(CommonConfigurationKeysPublic.NetTopologyImplKey, typeof(NetworkTopologyWithNodeGroup ).FullName); Conf.SetBoolean(DFSConfigKeys.DfsNamenodeAvoidStaleDatanodeForWriteKey, true); FilePath baseDir = PathUtils.GetTestDir(typeof(TestReplicationPolicyWithNodeGroup )); Conf.Set(DFSConfigKeys.DfsNamenodeNameDirKey, new FilePath(baseDir, "name").GetPath ()); DFSTestUtil.FormatNameNode(Conf); namenode = new NameNode(Conf); BlockManager bm = namenode.GetNamesystem().GetBlockManager(); replicator = bm.GetBlockPlacementPolicy(); cluster = bm.GetDatanodeManager().GetNetworkTopology(); // construct network topology for (int i = 0; i < NumOfDatanodes; i++) { cluster.Add(dataNodes[i]); } SetupDataNodeCapacity(); }
/// <summary> /// Change whether the block placement policy will prefer the writer's /// local Datanode or not. /// </summary> /// <param name="prefer">if true, prefer local node</param> public static void SetWritingPrefersLocalNode(BlockManager bm, bool prefer) { BlockPlacementPolicy bpp = bm.GetBlockPlacementPolicy(); Preconditions.CheckState(bpp is BlockPlacementPolicyDefault, "Must use default policy, got %s" , bpp.GetType()); ((BlockPlacementPolicyDefault)bpp).SetPreferLocalNode(prefer); }
/// <summary> /// Get an instance of the configured Block Placement Policy based on the /// the configuration property /// <see cref="Org.Apache.Hadoop.Hdfs.DFSConfigKeys.DfsBlockReplicatorClassnameKey"/> /// . /// </summary> /// <param name="conf">the configuration to be used</param> /// <param name="stats">an object that is used to retrieve the load on the cluster</param> /// <param name="clusterMap">the network topology of the cluster</param> /// <returns>an instance of BlockPlacementPolicy</returns> public static BlockPlacementPolicy GetInstance(Configuration conf, FSClusterStats stats, NetworkTopology clusterMap, Host2NodesMap host2datanodeMap) { Type replicatorClass = conf.GetClass <BlockPlacementPolicy>(DFSConfigKeys.DfsBlockReplicatorClassnameKey , DFSConfigKeys.DfsBlockReplicatorClassnameDefault); BlockPlacementPolicy replicator = ReflectionUtils.NewInstance(replicatorClass, conf ); replicator.Initialize(conf, stats, clusterMap, host2datanodeMap); return(replicator); }