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

The following are Jave code examples for showing how to use createSocketAddrForHost() 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-oss   File: TestSecurityUtil.java   Source Code and License Vote up 7 votes
private void verifyServiceAddr(String host, String ip) {
  InetSocketAddress addr;
  int port = 123;

  // test host, port tuple
  //LOG.info("test tuple ("+host+","+port+")");
  addr = NetUtils.createSocketAddrForHost(host, port);
  verifyAddress(addr, host, ip, port);

  // test authority with no default port
  //LOG.info("test authority '"+host+":"+port+"'");
  addr = NetUtils.createSocketAddr(host+":"+port);
  verifyAddress(addr, host, ip, port);

  // test authority with a default port, make sure default isn't used
  //LOG.info("test authority '"+host+":"+port+"' with ignored default port");
  addr = NetUtils.createSocketAddr(host+":"+port, port+1);
  verifyAddress(addr, host, ip, port);

  // test host-only authority, using port as default port
  //LOG.info("test host:"+host+" port:"+port);
  addr = NetUtils.createSocketAddr(host, port);
  verifyAddress(addr, host, ip, port);
}
 
Example 2
Project: hadoop   File: TestSecurityUtil.java   Source Code and License Vote up 6 votes
private void verifyServiceAddr(String host, String ip) {
  InetSocketAddress addr;
  int port = 123;

  // test host, port tuple
  //LOG.info("test tuple ("+host+","+port+")");
  addr = NetUtils.createSocketAddrForHost(host, port);
  verifyAddress(addr, host, ip, port);

  // test authority with no default port
  //LOG.info("test authority '"+host+":"+port+"'");
  addr = NetUtils.createSocketAddr(host+":"+port);
  verifyAddress(addr, host, ip, port);

  // test authority with a default port, make sure default isn't used
  //LOG.info("test authority '"+host+":"+port+"' with ignored default port");
  addr = NetUtils.createSocketAddr(host+":"+port, port+1);
  verifyAddress(addr, host, ip, port);

  // test host-only authority, using port as default port
  //LOG.info("test host:"+host+" port:"+port);
  addr = NetUtils.createSocketAddr(host, port);
  verifyAddress(addr, host, ip, port);
}
 
Example 3
Project: hadoop-oss   File: Client.java   Source Code and License Vote up 5 votes
/**
 * Update the server address if the address corresponding to the host
 * name has changed.
 *
 * @return true if an addr change was detected.
 * @throws IOException when the hostname cannot be resolved.
 */
private synchronized boolean updateAddress() throws IOException {
  // Do a fresh lookup with the old host name.
  InetSocketAddress currentAddr = NetUtils.createSocketAddrForHost(
                           server.getHostName(), server.getPort());

  if (!server.equals(currentAddr)) {
    LOG.warn("Address change detected. Old: " + server.toString() +
                             " New: " + currentAddr.toString());
    server = currentAddr;
    return true;
  }
  return false;
}
 
Example 4
Project: hadoop-oss   File: TestSecurityUtil.java   Source Code and License Vote up 5 votes
@Test
public void testGoodHostsAndPorts() {
  InetSocketAddress compare = NetUtils.createSocketAddrForHost("localhost", 123);
  runGoodCases(compare, "localhost", 123);
  runGoodCases(compare, "localhost:", 123);
  runGoodCases(compare, "localhost:123", 456);
}
 
Example 5
Project: hadoop   File: TestRPC.java   Source Code and License Vote up 5 votes
public static Token newContainerToken(NodeId nodeId, byte[] password,
    ContainerTokenIdentifier tokenIdentifier) {
  // RPC layer client expects ip:port as service for tokens
  InetSocketAddress addr =
      NetUtils.createSocketAddrForHost(nodeId.getHost(), nodeId.getPort());
  // NOTE: use SecurityUtil.setTokenService if this becomes a "real" token
  Token containerToken =
      Token.newInstance(tokenIdentifier.getBytes(),
        ContainerTokenIdentifier.KIND.toString(), password, SecurityUtil
          .buildTokenService(addr).toString());
  return containerToken;
}
 
Example 6
Project: hadoop   File: BaseNMTokenSecretManager.java   Source Code and License Vote up 5 votes
public static Token newInstance(byte[] password,
    NMTokenIdentifier identifier) {
  NodeId nodeId = identifier.getNodeId();
  // RPC layer client expects ip:port as service for tokens
  InetSocketAddress addr =
      NetUtils.createSocketAddrForHost(nodeId.getHost(), nodeId.getPort());
  Token nmToken =
      Token.newInstance(identifier.getBytes(),
        NMTokenIdentifier.KIND.toString(), password, SecurityUtil
          .buildTokenService(addr).toString());
  return nmToken;
}
 
Example 7
Project: hadoop   File: BuilderUtils.java   Source Code and License Vote up 5 votes
@VisibleForTesting
public static Token newContainerToken(NodeId nodeId,
    byte[] password, ContainerTokenIdentifier tokenIdentifier) {
  // RPC layer client expects ip:port as service for tokens
  InetSocketAddress addr =
      NetUtils.createSocketAddrForHost(nodeId.getHost(), nodeId.getPort());
  // NOTE: use SecurityUtil.setTokenService if this becomes a "real" token
  Token containerToken =
      newToken(Token.class, tokenIdentifier.getBytes(),
        ContainerTokenIdentifier.KIND.toString(), password, SecurityUtil
          .buildTokenService(addr).toString());
  return containerToken;
}
 
Example 8
Project: hadoop   File: AMLauncher.java   Source Code and License Vote up 5 votes
protected ContainerManagementProtocol getContainerMgrProxy(
    final ContainerId containerId) {

  final NodeId node = masterContainer.getNodeId();
  final InetSocketAddress containerManagerBindAddress =
      NetUtils.createSocketAddrForHost(node.getHost(), node.getPort());

  final YarnRPC rpc = YarnRPC.create(conf); // TODO: Don't create again and again.

  UserGroupInformation currentUser =
      UserGroupInformation.createRemoteUser(containerId
          .getApplicationAttemptId().toString());

  String user =
      rmContext.getRMApps()
          .get(containerId.getApplicationAttemptId().getApplicationId())
          .getUser();
  org.apache.hadoop.yarn.api.records.Token token =
      rmContext.getNMTokenSecretManager().createNMToken(
          containerId.getApplicationAttemptId(), node, user);
  currentUser.addToken(ConverterUtils.convertFromYarn(token,
      containerManagerBindAddress));

  return currentUser
      .doAs(new PrivilegedAction<ContainerManagementProtocol>() {

        @Override
        public ContainerManagementProtocol run() {
          return (ContainerManagementProtocol) rpc.getProxy(
              ContainerManagementProtocol.class,
              containerManagerBindAddress, conf);
        }
      });
}
 
Example 9
Project: hadoop   File: TaskAttemptListenerImpl.java   Source Code and License Vote up 5 votes
protected void startRpcServer() {
  Configuration conf = getConfig();
  try {
    server = 
        new RPC.Builder(conf).setProtocol(TaskUmbilicalProtocol.class)
          .setInstance(this).setBindAddress("0.0.0.0")
          .setPort(0).setNumHandlers(
              conf.getInt(MRJobConfig.MR_AM_TASK_LISTENER_THREAD_COUNT, 
                  MRJobConfig.DEFAULT_MR_AM_TASK_LISTENER_THREAD_COUNT))
                  .setVerbose(false).setSecretManager(jobTokenSecretManager)
                  .build();
    
    // Enable service authorization?
    if (conf.getBoolean(
        CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, 
        false)) {
      refreshServiceAcls(conf, new MRAMPolicyProvider());
    }

    server.start();
    this.address = NetUtils.createSocketAddrForHost(
        context.getNMHostname(),
        server.getListenerAddress().getPort());
  } catch (IOException e) {
    throw new YarnRuntimeException(e);
  }
}
 
Example 10
Project: hadoop   File: MRClientService.java   Source Code and License Vote up 5 votes
protected void serviceStart() throws Exception {
  Configuration conf = getConfig();
  YarnRPC rpc = YarnRPC.create(conf);
  InetSocketAddress address = new InetSocketAddress(0);

  server =
      rpc.getServer(MRClientProtocol.class, protocolHandler, address,
          conf, appContext.getClientToAMTokenSecretManager(),
          conf.getInt(MRJobConfig.MR_AM_JOB_CLIENT_THREAD_COUNT, 
              MRJobConfig.DEFAULT_MR_AM_JOB_CLIENT_THREAD_COUNT),
              MRJobConfig.MR_AM_JOB_CLIENT_PORT_RANGE);
  
  // Enable service authorization?
  if (conf.getBoolean(
      CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHORIZATION, 
      false)) {
    refreshServiceAcls(conf, new MRAMPolicyProvider());
  }

  server.start();
  this.bindAddress = NetUtils.createSocketAddrForHost(appContext.getNMHostname(),
      server.getListenerAddress().getPort());
  LOG.info("Instantiated MRClientService at " + this.bindAddress);
  try {
    // Explicitly disabling SSL for map reduce task as we can't allow MR users
    // to gain access to keystore file for opening SSL listener. We can trust
    // RM/NM to issue SSL certificates but definitely not MR-AM as it is
    // running in user-land.
    webApp =
        WebApps.$for("mapreduce", AppContext.class, appContext, "ws")
          .withHttpPolicy(conf, Policy.HTTP_ONLY).start(new AMWebApp());
  } catch (Exception e) {
    LOG.error("Webapps failed to start. Ignoring for now:", e);
  }
  super.serviceStart();
}
 
Example 11
Project: hadoop   File: MRApp.java   Source Code and License Vote up 5 votes
public static Token newContainerToken(NodeId nodeId,
    byte[] password, ContainerTokenIdentifier tokenIdentifier) {
  // RPC layer client expects ip:port as service for tokens
  InetSocketAddress addr =
      NetUtils.createSocketAddrForHost(nodeId.getHost(), nodeId.getPort());
  // NOTE: use SecurityUtil.setTokenService if this becomes a "real" token
  Token containerToken =
      Token.newInstance(tokenIdentifier.getBytes(),
        ContainerTokenIdentifier.KIND.toString(), password, SecurityUtil
          .buildTokenService(addr).toString());
  return containerToken;
}
 
Example 12
Project: hadoop   File: Client.java   Source Code and License Vote up 5 votes
/**
 * Update the server address if the address corresponding to the host
 * name has changed.
 *
 * @return true if an addr change was detected.
 * @throws IOException when the hostname cannot be resolved.
 */
private synchronized boolean updateAddress() throws IOException {
  // Do a fresh lookup with the old host name.
  InetSocketAddress currentAddr = NetUtils.createSocketAddrForHost(
                           server.getHostName(), server.getPort());

  if (!server.equals(currentAddr)) {
    LOG.warn("Address change detected. Old: " + server.toString() +
                             " New: " + currentAddr.toString());
    server = currentAddr;
    return true;
  }
  return false;
}
 
Example 13
Project: hadoop   File: TestSecurityUtil.java   Source Code and License Vote up 5 votes
@Test
public void testGoodHostsAndPorts() {
  InetSocketAddress compare = NetUtils.createSocketAddrForHost("localhost", 123);
  runGoodCases(compare, "localhost", 123);
  runGoodCases(compare, "localhost:", 123);
  runGoodCases(compare, "localhost:123", 456);
}