@Override public boolean add(Node n) { if (!isAncestor(n)) { throw new IllegalArgumentException(n.getName() + ", which is located at " + n.getNetworkLocation() + ", is not a descendant of " + getPath(this)); n.setParent(this); n.setLevel(this.level+1); Node prev = childrenMap.put(n.getName(), n); if (prev != null) { for(int i=0; i<children.size(); i++) { if (children.get(i).getName().equals(n.getName())) { children.set(i, n); return false;
return 0; int maxReaderLevel = reader.getLevel(); int maxNodeLevel = node.getLevel(); int currentLevelToCompare = maxReaderLevel > maxNodeLevel ? maxNodeLevel : maxReaderLevel; Node n = node; weight = 0; while(r != null && r.getLevel() > currentLevelToCompare) { r = r.getParent(); weight++; while(n != null && n.getLevel() > currentLevelToCompare) { n = n.getParent(); weight++; r = r.getParent(); n = n.getParent(); weight+=2;
/** * Get the path of a node * @param node a non-null node * @return the path of a node */ public static String getPath(Node node) { return node.getNetworkLocation() + PATH_SEPARATOR_STR + node.getName(); }
@Override protected Node getNodeForNetworkLocation(Node node) { // if node only with default rack info, here we need to add default // nodegroup info if (NetworkTopology.DEFAULT_RACK.equals(node.getNetworkLocation())) { node.setNetworkLocation(node.getNetworkLocation() + DEFAULT_NODEGROUP); } Node nodeGroup = getNode(node.getNetworkLocation()); if (nodeGroup == null) { nodeGroup = new InnerNodeWithNodeGroup(node.getNetworkLocation()); } return getNode(nodeGroup.getNetworkLocation()); }
@Override public boolean remove(Node n) { if (!isAncestor(n)) { throw new IllegalArgumentException(n.getName() + ", which is located at " + n.getNetworkLocation() + ", is not a descendant of " + getPath(this)); if (childrenMap.containsKey(n.getName())) { for (int i=0; i<children.size(); i++) { if (children.get(i).getName().equals(n.getName())) { children.remove(i); childrenMap.remove(n.getName()); numOfLeaves--; n.setParent(null); return true; if (parentNode.getNumOfChildren() == 0) { for(int i=0; i < children.size(); i++) { if (children.get(i).getName().equals(parentName)) { children.remove(i); childrenMap.remove(parentName);
/** Judge if this node is the parent of node <i>n</i> * * @param n a node * @return true if this node is the parent of <i>n</i> */ public boolean isParent(Node n) { return n.getNetworkLocation().equals(getPath(this)); }
int newDepth = NodeBase.locationToDepth(node.getNetworkLocation()) + 1; netlock.writeLock().lock(); try { depthOfAllLeaves = node.getLevel();
if (isLeaf) { // excluded node is a leaf node if (excludedNode != null && childrenMap.containsKey(excludedNode.getName())) { int excludedIndex = children.indexOf(excludedNode); if (excludedIndex != -1 && leafIndex >= 0) {
if (NetworkTopology.DEFAULT_RACK.equals(node.getNetworkLocation())) { node.setNetworkLocation(node.getNetworkLocation() + NetworkTopologyWithNodeGroup.DEFAULT_NODEGROUP); Node nodeGroup = getNode(node.getNetworkLocation()); if (nodeGroup == null) { nodeGroup = new InnerNodeWithNodeGroup(node.getNetworkLocation()); rack = getNode(nodeGroup.getNetworkLocation()); (!(rack instanceof InnerNode) || rack.getParent() == null)) { throw new IllegalArgumentException("Unexpected data node " + node.toString()
/** * Compare the parents of each node for equality * * <p>To be overridden in subclasses for specific NetworkTopology * implementations, as alternative to overriding the full * {@link #isOnSameRack(Node, Node)} method. * * @param node1 the first node to compare * @param node2 the second node to compare * @return true if their parents are equal, false otherwise * * @see #isOnSameRack(Node, Node) */ protected boolean isSameParents(Node node1, Node node2) { return node1.getParent()==node2.getParent(); }
private Node addHostToNodeMapping(String host, String networkLoc) { Node node; if ((node = clusterMap.getNode(networkLoc+"/"+host)) == null) { node = new NodeBase(host, networkLoc); clusterMap.add(node); if (node.getLevel() < getNumTaskCacheLevels()) { LOG.fatal("Got a host whose level is: " + node.getLevel() + "." + " Should get at least a level of value: " + getNumTaskCacheLevels()); try { stopTracker(); } catch (IOException ie) { LOG.warn("Exception encountered during shutdown: " + StringUtils.stringifyException(ie)); System.exit(-1); } } hostnameToNodeMap.put(host, node); // Make an entry for the node at the max level in the cache nodesAtMaxLevel.add(getParentNode(node, getNumTaskCacheLevels() - 1)); } return node; }
@Override public boolean remove(Node n) { LOG.debug("removing node {}", n.getName()); if (!isAncestor(n)) { throw new IllegalArgumentException(n.getName() + ", which is located at " + n.getNetworkLocation() + ", is not a descendant of " + getPath(this)); if (isParent(n)) { if (childrenMap.containsKey(n.getName())) { for (int i=0; i<children.size(); i++) { if (children.get(i).getName().equals(n.getName())) { children.remove(i); childrenMap.remove(n.getName()); childrenStorageInfo.remove(dnDescriptor.getName()); for (StorageType st : dnDescriptor.getStorageTypes()) { n.setParent(null); return true; if (children.get(i).getName().equals(parentName)) { children.remove(i); childrenMap.remove(parentName);
if(reader != null && node != null) { String readerPath = normalizeNetworkLocationPath( reader.getNetworkLocation()); String nodePath = normalizeNetworkLocationPath( node.getNetworkLocation()); if(reader.getName().equals(node.getName())) { weight = 0; } else {
/** Judge if this node is an ancestor of node <i>n</i> * * @param n a node * @return true if this node is an ancestor of <i>n</i> */ public boolean isAncestor(Node n) { return getPath(this).equals(NodeBase.PATH_SEPARATOR_STR) || (n.getNetworkLocation()+NodeBase.PATH_SEPARATOR_STR). startsWith(getPath(this)+NodeBase.PATH_SEPARATOR_STR); }
"Not allow to add an inner node: "+NodeBase.getPath(node)); int newDepth = NodeBase.locationToDepth(node.getNetworkLocation()) + 1; netlock.writeLock().lock(); try { depthOfAllLeaves = node.getLevel();
@Override public void addNode(List<NMContainerStatus> containerStatuses, RMNode rmNode) { if (LOG.isDebugEnabled()) { LOG.debug("Node added event from: " + rmNode.getNode().getName()); } // Ignoring this currently : at least one NODE_UPDATE heartbeat is // required to ensure node eligibility. }
@Override public boolean isOnSameRack( Node node1, Node node2) { if (node1 == null || node2 == null || node1.getParent() == null || node2.getParent() == null) { return false; } netlock.readLock().lock(); try { return isSameParents(node1.getParent(), node2.getParent()); } finally { netlock.readLock().unlock(); } }
private Node addHostToNodeMapping(String host, String networkLoc) { Node node = null; synchronized (nodesAtMaxLevel) { if ((node = clusterMap.getNode(networkLoc+"/"+host)) == null) { node = new NodeBase(host, networkLoc); clusterMap.add(node); if (node.getLevel() < getNumTaskCacheLevels()) { LOG.fatal("Got a host whose level is: " + node.getLevel() + "." + " Should get at least a level of value: " + getNumTaskCacheLevels()); try { stopTracker(); } catch (IOException ie) { LOG.warn("Exception encountered during shutdown: " + StringUtils.stringifyException(ie)); System.exit(-1); } } hostnameToNodeMap.put(host, node); // Make an entry for the node at the max level in the cache nodesAtMaxLevel.add(getParentNode(node, getNumTaskCacheLevels() - 1)); } } return node; }
@Override public boolean add(Node n) { LOG.debug("adding node {}", n.getName()); if (!isAncestor(n)) { throw new IllegalArgumentException(n.getName() + ", which is located at " + n.getNetworkLocation() + ", is not a descendant of " + getPath(this)); if (isParent(n)) { n.setParent(this); n.setLevel(this.level + 1); Node prev = childrenMap.put(n.getName(), n); if (prev != null) { for(int i=0; i<children.size(); i++) { if (children.get(i).getName().equals(n.getName())) { children.set(i, n); updateExistingDatanode(dnDescriptor);
String parent = n.getNetworkLocation(); String currentPath = getPath(this); if (!isAncestor(n)) throw new IllegalArgumentException(n.getName() +", which is located at " +parent+", is not a descendent of "+currentPath); if (children.get(i).getName().equals(n.getName())) { children.remove(i); numOfLeaves--; n.setParent(null); return true; int i; for(i=0; i<children.size(); i++) { if (children.get(i).getName().equals(parentName)) { parentNode = (InnerNode)children.get(i); break;