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

The following examples show how to use org.apache.hadoop.net.NetUtils#getFreeSocketPort() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestDelegationTokenRemoteFetcher.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws Exception {
  conf = new Configuration();
  fileSys = FileSystem.getLocal(conf);
  httpPort = NetUtils.getFreeSocketPort();
  serviceUrl = new URI("http://localhost:" + httpPort);
  testToken = createToken(serviceUrl);
}
 
Example 2
Source File: MiniDFSCluster.java    From hadoop with Apache License 2.0 5 votes vote down vote up
protected void setupDatanodeAddress(Configuration conf, boolean setupHostsFile,
                         boolean checkDataNodeAddrConfig) throws IOException {
  if (setupHostsFile) {
    String hostsFile = conf.get(DFS_HOSTS, "").trim();
    if (hostsFile.length() == 0) {
      throw new IOException("Parameter dfs.hosts is not setup in conf");
    }
    // Setup datanode in the include file, if it is defined in the conf
    String address = "127.0.0.1:" + NetUtils.getFreeSocketPort();
    if (checkDataNodeAddrConfig) {
      conf.setIfUnset(DFS_DATANODE_ADDRESS_KEY, address);
    } else {
      conf.set(DFS_DATANODE_ADDRESS_KEY, address);
    }
    addToFile(hostsFile, address);
    LOG.info("Adding datanode " + address + " to hosts file " + hostsFile);
  } else {
    if (checkDataNodeAddrConfig) {
      conf.setIfUnset(DFS_DATANODE_ADDRESS_KEY, "127.0.0.1:0");
    } else {
      conf.set(DFS_DATANODE_ADDRESS_KEY, "127.0.0.1:0");
    }
  }
  if (checkDataNodeAddrConfig) {
    conf.setIfUnset(DFS_DATANODE_HTTP_ADDRESS_KEY, "127.0.0.1:0");
    conf.setIfUnset(DFS_DATANODE_IPC_ADDRESS_KEY, "127.0.0.1:0");
  } else {
    conf.set(DFS_DATANODE_HTTP_ADDRESS_KEY, "127.0.0.1:0");
    conf.set(DFS_DATANODE_IPC_ADDRESS_KEY, "127.0.0.1:0");
  }
}
 
Example 3
Source File: RPCCallBenchmark.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public int getPort() {
  if (port == 0) {
    port = NetUtils.getFreeSocketPort();
    if (port == 0) {
      throw new RuntimeException("Could not find a free port");
    }
  }
  return port;
}
 
Example 4
Source File: TestDelegationTokenRemoteFetcher.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Before
public void init() throws Exception {
  conf = new Configuration();
  fileSys = FileSystem.getLocal(conf);
  httpPort = NetUtils.getFreeSocketPort();
  serviceUrl = new URI("http://localhost:" + httpPort);
  testToken = createToken(serviceUrl);
}
 
Example 5
Source File: MiniDFSCluster.java    From big-c with Apache License 2.0 5 votes vote down vote up
protected void setupDatanodeAddress(Configuration conf, boolean setupHostsFile,
                         boolean checkDataNodeAddrConfig) throws IOException {
  if (setupHostsFile) {
    String hostsFile = conf.get(DFS_HOSTS, "").trim();
    if (hostsFile.length() == 0) {
      throw new IOException("Parameter dfs.hosts is not setup in conf");
    }
    // Setup datanode in the include file, if it is defined in the conf
    String address = "127.0.0.1:" + NetUtils.getFreeSocketPort();
    if (checkDataNodeAddrConfig) {
      conf.setIfUnset(DFS_DATANODE_ADDRESS_KEY, address);
    } else {
      conf.set(DFS_DATANODE_ADDRESS_KEY, address);
    }
    addToFile(hostsFile, address);
    LOG.info("Adding datanode " + address + " to hosts file " + hostsFile);
  } else {
    if (checkDataNodeAddrConfig) {
      conf.setIfUnset(DFS_DATANODE_ADDRESS_KEY, "127.0.0.1:0");
    } else {
      conf.set(DFS_DATANODE_ADDRESS_KEY, "127.0.0.1:0");
    }
  }
  if (checkDataNodeAddrConfig) {
    conf.setIfUnset(DFS_DATANODE_HTTP_ADDRESS_KEY, "127.0.0.1:0");
    conf.setIfUnset(DFS_DATANODE_IPC_ADDRESS_KEY, "127.0.0.1:0");
  } else {
    conf.set(DFS_DATANODE_HTTP_ADDRESS_KEY, "127.0.0.1:0");
    conf.set(DFS_DATANODE_IPC_ADDRESS_KEY, "127.0.0.1:0");
  }
}
 
Example 6
Source File: RPCCallBenchmark.java    From big-c with Apache License 2.0 5 votes vote down vote up
public int getPort() {
  if (port == 0) {
    port = NetUtils.getFreeSocketPort();
    if (port == 0) {
      throw new RuntimeException("Could not find a free port");
    }
  }
  return port;
}