org.apache.hadoop.net
Class NetworkTopology

java.lang.Object
  extended by org.apache.hadoop.net.NetworkTopology

public class NetworkTopology
extends Object

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.

Author:
hairong

Field Summary
static String DEFAULT_RACK
           
static org.apache.commons.logging.Log LOG
           
 
Constructor Summary
NetworkTopology()
           
 
Method Summary
 void add(DatanodeDescriptor node)
          Add a data node Update data node counter & rack counter if neccessary
 boolean contains(DatanodeDescriptor node)
          Check if the tree contains data node node
 int getDistance(DatanodeDescriptor node1, DatanodeDescriptor node2)
          Return the distance between two data nodes It is assumed that the distance from one node to its parent is 1 The distance between two nodes is calculated by summing up their distances to their closest common ancestor.
 DatanodeDescriptor[] getLeaves(Collection<String> locs)
          Return all the data nodes that belong to the subtrees of locs
 DatanodeDescriptor[] getLeaves(String loc)
          Return all the data nodes that belong to the subtree of loc
 Node getNode(String loc)
          Given a string representation of a node, return the reference to the node
 int getNumOfLeaves()
          Return the total number of data nodes
 int getNumOfRacks()
          Return the total number of racks
 boolean isOnSameRack(DatanodeDescriptor node1, DatanodeDescriptor node2)
          Check if two data nodes are on the same rack
 void remove(DatanodeDescriptor node)
          Remove a data node Update data node counter & rack counter if neccessary
 String toString()
          convert a network tree to a string
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_RACK

public static final String DEFAULT_RACK
See Also:
Constant Field Values

LOG

public static final org.apache.commons.logging.Log LOG
Constructor Detail

NetworkTopology

public NetworkTopology()
Method Detail

add

public void add(DatanodeDescriptor node)
Add a data node Update data node counter & rack counter if neccessary

Parameters:
node - data node to be added
Throws:
IllegalArgumentException - if add a data node to an existing leave

remove

public void remove(DatanodeDescriptor node)
Remove a data node Update data node counter & rack counter if neccessary

Parameters:
node - data node to be removed

contains

public boolean contains(DatanodeDescriptor node)
Check if the tree contains data node node

Parameters:
node - a data node
Returns:
true if node is already in the tree; false otherwise

getNode

public Node getNode(String loc)
Given a string representation of a node, return the reference to the node

Parameters:
loc - a path-like string representation of a node
Returns:
a reference to the node; null if the node is not in the tree

getLeaves

public DatanodeDescriptor[] getLeaves(String loc)
Return all the data nodes that belong to the subtree of loc

Parameters:
loc - a path-like string representation of a node
Returns:
an array of data nodes that belong to the subtree of loc

getLeaves

public DatanodeDescriptor[] getLeaves(Collection<String> locs)
Return all the data nodes that belong to the subtrees of locs

Parameters:
locs - a collection of strings representing nodes
Returns:
an array of data nodes that belong to subtrees of locs

getNumOfRacks

public int getNumOfRacks()
Return the total number of racks


getNumOfLeaves

public int getNumOfLeaves()
Return the total number of data nodes


getDistance

public int getDistance(DatanodeDescriptor node1,
                       DatanodeDescriptor node2)
Return the distance between two data nodes It is assumed that the distance from one node to its parent is 1 The distance between two nodes is calculated by summing up their distances to their closest common ancestor.

Parameters:
node1 - one data node
node2 - another data node
Returns:
the distance between node1 and node2
Throws:
IllegalArgumentException - when either node1 or node2 is null, or node1 or node2 do not belong to the cluster

isOnSameRack

public boolean isOnSameRack(DatanodeDescriptor node1,
                            DatanodeDescriptor node2)
Check if two data nodes are on the same rack

Parameters:
node1 - one data node
node2 - another data node
Returns:
true if node1 and node2 are pm the same rack; false otherwise
Throws:
IllegalArgumentException - when either node1 or node2 is null, or node1 or node2 do not belong to the cluster

toString

public String toString()
convert a network tree to a string

Overrides:
toString in class Object


Copyright © 2006 The Apache Software Foundation