|
@@ -45,6 +45,13 @@ public class NetworkTopology {
|
|
|
public static final Log LOG =
|
|
|
LogFactory.getLog(NetworkTopology.class);
|
|
|
|
|
|
+ public static class InvalidTopologyException extends RuntimeException {
|
|
|
+ private static final long serialVersionUID = 1L;
|
|
|
+ public InvalidTopologyException(String msg) {
|
|
|
+ super(msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/** InnerNode represents a switch/router of a data center or rack.
|
|
|
* Different from a leaf node, it has non-null children.
|
|
|
*/
|
|
@@ -311,6 +318,8 @@ public class NetworkTopology {
|
|
|
* the root cluster map
|
|
|
*/
|
|
|
InnerNode clusterMap = new InnerNode(InnerNode.ROOT);
|
|
|
+ /** Depth of all leaf nodes */
|
|
|
+ private int depthOfAllLeaves = -1;
|
|
|
/** rack counter */
|
|
|
private int numOfRacks = 0;
|
|
|
/** the lock used to manage access */
|
|
@@ -328,6 +337,7 @@ public class NetworkTopology {
|
|
|
*/
|
|
|
public void add(Node node) {
|
|
|
if (node==null) return;
|
|
|
+ String oldTopoStr = this.toString();
|
|
|
if( node instanceof InnerNode ) {
|
|
|
throw new IllegalArgumentException(
|
|
|
"Not allow to add an inner node: "+NodeBase.getPath(node));
|
|
@@ -345,6 +355,19 @@ public class NetworkTopology {
|
|
|
if (rack == null) {
|
|
|
numOfRacks++;
|
|
|
}
|
|
|
+ if (!(node instanceof InnerNode)) {
|
|
|
+ if (depthOfAllLeaves == -1) {
|
|
|
+ depthOfAllLeaves = node.getLevel();
|
|
|
+ } else {
|
|
|
+ if (depthOfAllLeaves != node.getLevel()) {
|
|
|
+ LOG.error("Error: can't add leaf node at depth " +
|
|
|
+ node.getLevel() + " to topology:\n" + oldTopoStr);
|
|
|
+ throw new InvalidTopologyException("Invalid network topology. " +
|
|
|
+ "You cannot have a rack and a non-rack node at the same " +
|
|
|
+ "level of the network topology.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
if(LOG.isDebugEnabled()) {
|
|
|
LOG.debug("NetworkTopology became:\n" + this.toString());
|