Refine search
myNode = new NodeBase(localHostName, getRack(rackIter.next())); topology = NetworkTopology.getInstance(conf); topology.sortByDistance(myNode, nodes, nodes.length);
int newDepth = NodeBase.locationToDepth(node.getNetworkLocation()) + 1; netlock.writeLock().lock(); try { if( node instanceof InnerNode ) { throw new IllegalArgumentException( "Not allow to add an inner node: "+NodeBase.getPath(node)); NodeBase.getPath(node), newDepth, this); throw new InvalidTopologyException("Failed to add " + NodeBase.getPath(node) + ": You cannot have a rack and a non-rack node at the same " + "level of the network topology."); Node rack = getNodeForNetworkLocation(node); if (rack != null && !(rack instanceof InnerNode)) { throw new IllegalArgumentException("Unexpected data node " LOG.info("Adding a new node: "+NodeBase.getPath(node)); if (rack == null) { incrementRacks();
scope=scope.substring(1); scope = NodeBase.normalize(scope); int excludedCountInScope = 0; // the number of nodes in both scope & excludedNodes int excludedCountOffScope = 0; // the number of nodes outside scope & excludedNodes if (excludedNodes != null) { for (Node node : excludedNodes) { node = getNode(NodeBase.getPath(node)); if (node == null) { continue; if ((NodeBase.getPath(node) + NodeBase.PATH_SEPARATOR_STR) .startsWith(scope + NodeBase.PATH_SEPARATOR_STR)) { excludedCountInScope++; Node n = getNode(scope); int scopeNodeCount = 0; if (n != null) {
OneBlockInfo(Path path, long offset, long len, String[] hosts, String[] topologyPaths) { this.onepath = path; this.offset = offset; this.hosts = hosts; this.length = len; assert (hosts.length == topologyPaths.length || topologyPaths.length == 0); // if the file system does not have any rack information, then // use dummy rack location. if (topologyPaths.length == 0) { topologyPaths = new String[hosts.length]; for (int i = 0; i < topologyPaths.length; i++) { topologyPaths[i] = (new NodeBase(hosts[i], NetworkTopology.DEFAULT_RACK)).toString(); } } // The topology paths have the host name included as the last // component. Strip it. this.racks = new String[topologyPaths.length]; for (int i = 0; i < topologyPaths.length; i++) { this.racks[i] = (new NodeBase(topologyPaths[i])).getNetworkLocation(); } } }
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; }
/** Remove a node * Update node counter & rack counter if neccessary * @param node * node to be removed */ public void remove(Node node) { if (node==null) return; if( node instanceof InnerNode ) { throw new IllegalArgumentException( "Not allow to remove an inner node: "+NodeBase.getPath(node)); } LOG.info("Removing a node: "+NodeBase.getPath(node)); netlock.writeLock().lock(); try { if (clusterMap.remove(node)) { InnerNode rack = (InnerNode)getNode(node.getNetworkLocation()); if (rack == null) { numOfRacks--; } } LOG.debug("NetworkTopology became:\n" + this.toString()); } finally { netlock.writeLock().unlock(); } }
/** convert a network tree to a string. */ @Override public String toString() { // print the number of racks StringBuilder tree = new StringBuilder(); tree.append("Number of racks: "); tree.append(numOfRacks); tree.append("\n"); // print the number of leaves int numOfLeaves = getNumOfLeaves(); tree.append("Expected number of leaves:"); tree.append(numOfLeaves); tree.append("\n"); // print nodes for(int i=0; i<numOfLeaves; i++) { tree.append(NodeBase.getPath(clusterMap.getLeaf(i, null))); tree.append("\n"); } return tree.toString(); }
/** @return this node's path as its string representation */ @Override public String toString() { return getPath(this); }
/** * Resolve clientmachine address to get a network location path */ static Node getClientNode(BlockManager bm, String clientMachine) { List<String> hosts = new ArrayList<>(1); hosts.add(clientMachine); List<String> rName = bm.getDatanodeManager() .resolveNetworkLocation(hosts); Node clientNode = null; if (rName != null) { // Able to resolve clientMachine mapping. // Create a temp node to findout the rack local nodes clientNode = new NodeBase(rName.get(0) + NodeBase.PATH_SEPARATOR_STR + clientMachine); } return clientNode; }
String rName = dnsToSwitchMapping.resolve(hosts).get(0); if (rName != null) client = new NodeBase(rName + NodeBase.PATH_SEPARATOR_STR + targethost); networktopology.sortByDistance(client, b.getLocations(), activeLen);
/** Remove a node * Update node counter and rack counter if necessary * @param node node to be removed; can be null */ public void remove(Node node) { if (node==null) return; if( node instanceof InnerNode ) { throw new IllegalArgumentException( "Not allow to remove an inner node: "+NodeBase.getPath(node)); } LOG.info("Removing a node: "+NodeBase.getPath(node)); netlock.writeLock().lock(); try { if (clusterMap.remove(node)) { InnerNode rack = (InnerNode)getNode(node.getNetworkLocation()); if (rack == null) { numOfRacks--; } } LOG.debug("NetworkTopology became:\n{}", this); } finally { netlock.writeLock().unlock(); } }
public static int locationToDepth(String location) { String normalizedLocation = normalize(location); int length = normalizedLocation.length(); int depth = 0; for (int i = 0; i < length; i++) { if (normalizedLocation.charAt(i) == PATH_SEPARATOR) { depth++; } } return depth; } }
String rName = resolvedHosts.get(0); if (rName != null) { client = new NodeBase(rName + NodeBase.PATH_SEPARATOR_STR + targetHost); networktopology.sortByDistanceUsingNetworkLocation(client, lb.getLocations(), activeLen); } else { networktopology.sortByDistance(client, lb.getLocations(), activeLen);
public int getNetworkDistance(DatanodeInfo datanodeInfo) throws IOException { // If applications disable the feature or the client machine can't // resolve its network location, clientNode will be set to null. if (clientNode == null) { return DFSUtilClient.isLocalAddress(NetUtils. createSocketAddr(datanodeInfo.getXferAddr())) ? 0 : Integer.MAX_VALUE; } NodeBase node = new NodeBase(datanodeInfo.getHostName(), datanodeInfo.getNetworkLocation()); return NetworkTopology.getDistanceByPath(clientNode, node); } }
public class SearchVisitor implements IVisitor { private Integer searchId; public SearchVisitor(Integer searchId) { this.searchId= searchId; } @Override public void visit(NodeBase node) { if (node instanceof Employee) { if (((Employee)node).getId().equals(searchId)) { System.out.println("Found the node " + node.toString() + "!"); } } } }
OneBlockInfo(Path path, long offset, long len, String[] hosts, String[] pTopologyPaths) { String[] topologyPaths = pTopologyPaths; this.onepath = path; this.offset = offset; this.hosts = hosts; this.length = len; assert (hosts.length == topologyPaths.length || topologyPaths.length == 0); // if the file ystem does not have any rack information, then // use dummy rack location. if (topologyPaths.length == 0) { topologyPaths = new String[hosts.length]; for (int i = 0; i < topologyPaths.length; i++) { topologyPaths[i] = (new NodeBase(hosts[i], NetworkTopology.DEFAULT_RACK)).toString(); } } // The topology paths have the host name included as the last // component. Strip it. this.racks = new String[topologyPaths.length]; for (int i = 0; i < topologyPaths.length; i++) { this.racks[i] = (new NodeBase(topologyPaths[i])).getNetworkLocation(); } } }
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; }
/** Remove a node * Update node counter & rack counter if neccessary * @param node * node to be removed */ public void remove(Node node) { if (node==null) return; if( node instanceof InnerNode ) { throw new IllegalArgumentException( "Not allow to remove an inner node: "+NodeBase.getPath(node)); } LOG.info("Removing a node: "+NodeBase.getPath(node)); netlock.writeLock().lock(); try { if (clusterMap.remove(node)) { InnerNode rack = (InnerNode)getNode(node.getNetworkLocation()); if (rack == null) { numOfRacks--; } } LOG.debug("NetworkTopology became:\n" + this.toString()); } finally { netlock.writeLock().unlock(); } }