Java Code Examples for org.apache.hadoop.net.NetworkTopology

Following code examples demonstrate how to use org.apache.hadoop.net.NetworkTopologyfrom hadoop. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.apache.hadoop.net.NetworkTopologyand various code implementation of this class.

  
  public BlockPlacementPolicyFakeData(Configuration conf,  FSClusterStats stats,
                           NetworkTopology clusterMap) {
    initialize(conf, stats, clusterMap, null, null, null);
    
    FSNamesystem.LOG.info("new BlockPlacementPolicyFakeData: " + this);
    lastInstance = this;
  } 


    public void testNetworkTopology() {
        DatanodeDescriptor rack1_data1 = new DatanodeDescriptor(new DatanodeID("rack1_data1"), "/rack1/data1", "localhost");
        DatanodeDescriptor rack1_data2 = new DatanodeDescriptor(new DatanodeID("rack1_data2"), "/rack1/data2", "localhost");
        DatanodeDescriptor rack1_data3 = new DatanodeDescriptor(new DatanodeID("rack1_data3"), "/rack1/data3", "localhost");
        DatanodeDescriptor rack2_data1 = new DatanodeDescriptor(new DatanodeID("rack2_data1"), "/rack2/data1", "localhost");
        DatanodeDescriptor rack2_data2 = new DatanodeDescriptor(new DatanodeID("rack2_data2"), "/rack2/data2", "localhost");

        NetworkTopology networkTopology = new NetworkTopology();

        networkTopology.add(rack1_data1);
        networkTopology.add(rack1_data2);
        networkTopology.add(rack1_data3);
        networkTopology.add(rack2_data1);
        networkTopology.add(rack2_data2);

        Assert.assertEquals(4, networkTopology.getDistance(rack2_data1, rack2_data2));
        Assert.assertEquals(6, networkTopology.getDistance(rack1_data1, rack2_data2));

        Assert.assertEquals("/rack2/data2", networkTopology.getNode("/rack2/data2").getNetworkLocation());

    } 

    @Override
    public void initialize(Configuration conf, FSClusterStats stats,
                           NetworkTopology clusterMap,
                           Host2NodesMap host2datanodeMap) {
        super.initialize(conf, stats, clusterMap, host2datanodeMap);

        this.chooseNodeByCapacity = conf.getBoolean(
                DFS_BLOCK_PLACEMENT_POLICY_CAPACITY_EANBLED, true);

        this.capacityWeightFactor = conf.getFloat(
                DFS_BLOCK_PLACEMENT_POLICY_CAPACITY_FACTOR, this.capacityWeightFactor);

        CapacityBlockPlacementPolicy.totalRandomPrintInterval = conf.getLong(
                DFS_BLOCK_PLACEMENT_POLICY_CAPACITY_PRINTINTERVAL, CapacityBlockPlacementPolicy.totalRandomPrintInterval);

        if (this.capacityWeightFactor < 0)
            this.capacityWeightFactor = 0;

        LOG.info(DFS_BLOCK_PLACEMENT_POLICY_CAPACITY_EANBLED + " : " + this.chooseNodeByCapacity);
        LOG.info(DFS_BLOCK_PLACEMENT_POLICY_CAPACITY_FACTOR + " : " + this.capacityWeightFactor);
        LOG.info(DFS_BLOCK_PLACEMENT_POLICY_CAPACITY_PRINTINTERVAL + " : " + totalRandomPrintInterval + " second(s)");
    } 

    public static void main(String[] args) {

        Configuration conf = new Configuration();
        conf.addResource(new Path("/data/gitrep/springcloud2/RepairHdfs/src/main/java/core-site.xml"));
        conf.addResource(new Path("/data/gitrep/springcloud2/RepairHdfs/src/main/java/hdfs-site.xml"));
        NetworkTopology clusterMap = NetworkTopology.getInstance(conf);
        Node node = clusterMap.chooseRandom(NodeBase.ROOT);
        System.out.println(node);

    } 

Advertisement
Javadoc
The class represents a cluster of computer with a tree hierarchical network topology. For example, a

cluster may be consists of many data centers filled with racks of computers. In a network topology, leaves represent data nodes (computers) and inner nodes represent switches/routers that manage traffic in/out of data centers or racks.

Read More
Advertisement