Java Code Examples for org.apache.hadoop.net.NetUtils.isLocalAddress()

The following are Jave code examples for showing how to use isLocalAddress() of the org.apache.hadoop.net.NetUtils class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hadoop   File: RMDelegationTokenIdentifier.java   Source Code and License Vote up 6 votes
private static ApplicationClientProtocol getRmClient(Token<?> token,
    Configuration conf) throws IOException {
  String[] services = token.getService().toString().split(",");
  for (String service : services) {
    InetSocketAddress addr = NetUtils.createSocketAddr(service);
    if (localSecretManager != null) {
      // return null if it's our token
      if (localServiceAddress.getAddress().isAnyLocalAddress()) {
        if (NetUtils.isLocalAddress(addr.getAddress()) &&
            addr.getPort() == localServiceAddress.getPort()) {
          return null;
        }
      } else if (addr.equals(localServiceAddress)) {
        return null;
      }
    }
  }
  return ClientRMProxy.createRMProxy(conf, ApplicationClientProtocol.class);
}
 
Example 2
Project: hadoop   File: DFSClient.java   Source Code and License Vote up 6 votes
public static boolean isLocalAddress(InetSocketAddress targetAddr) {
  InetAddress addr = targetAddr.getAddress();
  Boolean cached = localAddrMap.get(addr.getHostAddress());
  if (cached != null) {
    if (LOG.isTraceEnabled()) {
      LOG.trace("Address " + targetAddr +
                (cached ? " is local" : " is not local"));
    }
    return cached;
  }
  
  boolean local = NetUtils.isLocalAddress(addr);

  if (LOG.isTraceEnabled()) {
    LOG.trace("Address " + targetAddr +
              (local ? " is local" : " is not local"));
  }
  localAddrMap.put(addr.getHostAddress(), local);
  return local;
}
 
Example 3
Project: hadoop-oss   File: NuCypherExtUtilClient.java   Source Code and License Vote up 5 votes
public static boolean isLocalAddress(InetSocketAddress targetAddr) {
  InetAddress addr = targetAddr.getAddress();
  Boolean cached = localAddrMap.get(addr.getHostAddress());
  if (cached != null) {
    LOG.trace("Address {} is {} local", targetAddr, (cached ? "" : "not"));
    return cached;
  }

  boolean local = NetUtils.isLocalAddress(addr);

  LOG.trace("Address {} is {} local", targetAddr, (local ? "" : "not"));
  localAddrMap.put(addr.getHostAddress(), local);
  return local;
}
 
Example 4
Project: hadoop   File: HAUtil.java   Source Code and License Vote up 5 votes
/**
 * @param conf Configuration. Please use verifyAndSetRMHAId to check.
 * @return RM Id on success
 */
public static String getRMHAId(Configuration conf) {
  int found = 0;
  String currentRMId = conf.getTrimmed(YarnConfiguration.RM_HA_ID);
  if(currentRMId == null) {
    for(String rmId : getRMHAIds(conf)) {
      String key = addSuffix(YarnConfiguration.RM_ADDRESS, rmId);
      String addr = conf.get(key);
      if (addr == null) {
        continue;
      }
      InetSocketAddress s;
      try {
        s = NetUtils.createSocketAddr(addr);
      } catch (Exception e) {
        LOG.warn("Exception in creating socket address " + addr, e);
        continue;
      }
      if (!s.isUnresolved() && NetUtils.isLocalAddress(s.getAddress())) {
        currentRMId = rmId.trim();
        found++;
      }
    }
  }
  if (found > 1) { // Only one address must match the local address
    String msg = "The HA Configuration has multiple addresses that match "
        + "local node's address.";
    throw new HadoopIllegalArgumentException(msg);
  }
  return currentRMId;
}
 
Example 5
Project: hadoop   File: DFSUtil.java   Source Code and License Vote up 4 votes
@Override
public boolean match(InetSocketAddress s) {
  return NetUtils.isLocalAddress(s.getAddress());
}