當前位置: 首頁>>代碼示例>>Java>>正文


Java NetUtils.createSocketAddr方法代碼示例

本文整理匯總了Java中org.apache.hadoop.net.NetUtils.createSocketAddr方法的典型用法代碼示例。如果您正苦於以下問題:Java NetUtils.createSocketAddr方法的具體用法?Java NetUtils.createSocketAddr怎麽用?Java NetUtils.createSocketAddr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.hadoop.net.NetUtils的用法示例。


在下文中一共展示了NetUtils.createSocketAddr方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: start

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
public void start(Configuration conf) {
  YarnRPC rpc = YarnRPC.create(conf);
  //TODO : use fixed port ??
  InetSocketAddress address = NetUtils.createSocketAddr(hostAddress);
  InetAddress hostNameResolved = null;
  try {
    address.getAddress();
    hostNameResolved = InetAddress.getLocalHost();
  } catch (UnknownHostException e) {
    throw new YarnRuntimeException(e);
  }

  server =
      rpc.getServer(protocol, this, address,
          conf, null, 1);
  server.start();
  this.bindAddress = NetUtils.getConnectAddress(server);
   super.start();
   amRunning = true;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:21,代碼來源:TestClientRedirect.java

示例2: start

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
void start() throws IOException {
  final InetSocketAddress httpAddr = getAddress(conf);

  final String httpsAddrString = conf.get(
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_HTTPS_ADDRESS_DEFAULT);
  InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);

  HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
      httpAddr, httpsAddr, "journal",
      DFSConfigKeys.DFS_JOURNALNODE_KERBEROS_INTERNAL_SPNEGO_PRINCIPAL_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_KEYTAB_FILE_KEY);

  httpServer = builder.build();
  httpServer.setAttribute(JN_ATTRIBUTE_KEY, localJournalNode);
  httpServer.setAttribute(JspHelper.CURRENT_CONF, conf);
  httpServer.addInternalServlet("getJournal", "/getJournal",
      GetJournalEditServlet.class, true);
  httpServer.start();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:21,代碼來源:JournalNodeHttpServer.java

示例3: getAddressesForNameserviceId

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
static Map<String, InetSocketAddress> getAddressesForNameserviceId(
    Configuration conf, String nsId, String defaultValue, String... keys) {
  Collection<String> nnIds = getNameNodeIds(conf, nsId);
  Map<String, InetSocketAddress> ret = Maps.newHashMap();
  for (String nnId : emptyAsSingletonNull(nnIds)) {
    String suffix = concatSuffixes(nsId, nnId);
    String address = getConfValue(defaultValue, suffix, conf, keys);
    if (address != null) {
      InetSocketAddress isa = NetUtils.createSocketAddr(address);
      if (isa.isUnresolved()) {
        LOG.warn("Namenode for {} remains unresolved for ID {}. Check your "
            + "hdfs-site.xml file to ensure namenodes are configured "
            + "properly.", nsId, nnId);
      }
      ret.put(nnId, isa);
    }
  }
  return ret;
}
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:20,代碼來源:NuCypherExtUtilClient.java

示例4: newProxy

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
@Private
@VisibleForTesting
protected ContainerManagementProtocol newProxy(final YarnRPC rpc,
    String containerManagerBindAddr, ContainerId containerId, Token token)
    throws InvalidToken {

  if (token == null) {
    throw new InvalidToken("No NMToken sent for "
        + containerManagerBindAddr);
  }
  
  final InetSocketAddress cmAddr =
      NetUtils.createSocketAddr(containerManagerBindAddr);
  LOG.info("Opening proxy : " + containerManagerBindAddr);
  // the user in createRemoteUser in this context has to be ContainerID
  UserGroupInformation user =
      UserGroupInformation.createRemoteUser(containerId
          .getApplicationAttemptId().toString());

  org.apache.hadoop.security.token.Token<NMTokenIdentifier> nmToken =
      ConverterUtils.convertFromYarn(token, cmAddr);
  user.addToken(nmToken);

  return NMProxy.createNMProxy(conf, ContainerManagementProtocol.class,
    user, rpc, cmAddr);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:ContainerManagementProtocolProxy.java

示例5: start

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
void start() throws IOException {
  final InetSocketAddress httpAddr = getHttpAddress(conf);

  final String httpsAddrString = conf.get(
      NfsConfigKeys.NFS_HTTPS_ADDRESS_KEY,
      NfsConfigKeys.NFS_HTTPS_ADDRESS_DEFAULT);
  InetSocketAddress httpsAddr = NetUtils.createSocketAddr(httpsAddrString);

  HttpServer2.Builder builder = DFSUtil.httpServerTemplateForNNAndJN(conf,
      httpAddr, httpsAddr, "nfs3",
      NfsConfigKeys.DFS_NFS_KERBEROS_PRINCIPAL_KEY,
      NfsConfigKeys.DFS_NFS_KEYTAB_FILE_KEY);

  this.httpServer = builder.build();
  this.httpServer.start();
  
  HttpConfig.Policy policy = DFSUtil.getHttpPolicy(conf);
  int connIdx = 0;
  if (policy.isHttpEnabled()) {
    infoPort = httpServer.getConnectorAddress(connIdx++).getPort();
  }

  if (policy.isHttpsEnabled()) {
    infoSecurePort = httpServer.getConnectorAddress(connIdx).getPort();
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:27,代碼來源:Nfs3HttpServer.java

示例6: createSocketForPipeline

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
/**
 * Create a socket for a write pipeline
 * @param first the first datanode 
 * @param length the pipeline length
 * @param client client
 * @return the socket connected to the first datanode
 */
static Socket createSocketForPipeline(final DatanodeInfo first,
    final int length, final DFSClient client) throws IOException {
  final String dnAddr = first.getXferAddr(
      client.getConf().connectToDnViaHostname);
  if (DFSClient.LOG.isDebugEnabled()) {
    DFSClient.LOG.debug("Connecting to datanode " + dnAddr);
  }
  final InetSocketAddress isa = NetUtils.createSocketAddr(dnAddr);
  final Socket sock = client.socketFactory.createSocket();
  final int timeout = client.getDatanodeReadTimeout(length);
  NetUtils.connect(sock, isa, client.getRandomLocalInterfaceAddr(), client.getConf().socketTimeout);
  sock.setSoTimeout(timeout);
  sock.setSendBufferSize(HdfsConstants.DEFAULT_DATA_SOCKET_SIZE);
  if(DFSClient.LOG.isDebugEnabled()) {
    DFSClient.LOG.debug("Send buf size " + sock.getSendBufferSize());
  }
  return sock;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:26,代碼來源:DFSOutputStream.java

示例7: substituteForWildcardAddress

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
/**
 * Substitute a default host in the case that an address has been configured
 * with a wildcard. This is used, for example, when determining the HTTP
 * address of the NN -- if it's configured to bind to 0.0.0.0, we want to
 * substitute the hostname from the filesystem URI rather than trying to
 * connect to 0.0.0.0.
 * @param configuredAddress the address found in the configuration
 * @param defaultHost the host to substitute with, if configuredAddress
 * is a local/wildcard address.
 * @return the substituted address
 * @throws IOException if it is a wildcard address and security is enabled
 */
@VisibleForTesting
static String substituteForWildcardAddress(String configuredAddress,
  String defaultHost) throws IOException {
  InetSocketAddress sockAddr = NetUtils.createSocketAddr(configuredAddress);
  InetSocketAddress defaultSockAddr = NetUtils.createSocketAddr(defaultHost
      + ":0");
  final InetAddress addr = sockAddr.getAddress();
  if (addr != null && addr.isAnyLocalAddress()) {
    if (UserGroupInformation.isSecurityEnabled() &&
        defaultSockAddr.getAddress().isAnyLocalAddress()) {
      throw new IOException("Cannot use a wildcard address with security. " +
          "Must explicitly set bind address for Kerberos");
    }
    return defaultHost + ":" + sockAddr.getPort();
  } else {
    return configuredAddress;
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:31,代碼來源:DFSUtil.java

示例8: buildDTServiceName

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
/**
 * create the service name for a Delegation token
 * @param uri of the service
 * @param defPort is used if the uri lacks a port
 * @return the token service, or null if no authority
 * @see #buildTokenService(InetSocketAddress)
 */
public static String buildDTServiceName(URI uri, int defPort) {
  String authority = uri.getAuthority();
  if (authority == null) {
    return null;
  }
  InetSocketAddress addr = NetUtils.createSocketAddr(authority, defPort);
  return buildTokenService(addr).toString();
 }
 
開發者ID:nucypher,項目名稱:hadoop-oss,代碼行數:16,代碼來源:SecurityUtil.java

示例9: getLifelineRpcServerAddress

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
/**
 * Given a configuration get the address of the lifeline RPC server.
 * If the lifeline RPC is not configured returns null.
 *
 * @param conf configuration
 * @return address or null
 */
InetSocketAddress getLifelineRpcServerAddress(Configuration conf) {
  String addr = getTrimmedOrNull(conf, DFS_NAMENODE_LIFELINE_RPC_ADDRESS_KEY);
  if (addr == null) {
    return null;
  }
  return NetUtils.createSocketAddr(addr);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:15,代碼來源:NameNode.java

示例10: getApplicationWebURLOnJHSWithoutScheme

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
public static String getApplicationWebURLOnJHSWithoutScheme(Configuration conf,
    ApplicationId appId)
    throws UnknownHostException {
  //construct the history url for job
  String addr = getJHSWebappURLWithoutScheme(conf);
  Iterator<String> it = ADDR_SPLITTER.split(addr).iterator();
  it.next(); // ignore the bind host
  String port = it.next();
  // Use hs address to figure out the host for webapp
  addr = conf.get(JHAdminConfig.MR_HISTORY_ADDRESS,
      JHAdminConfig.DEFAULT_MR_HISTORY_ADDRESS);
  String host = ADDR_SPLITTER.split(addr).iterator().next();
  String hsAddress = JOINER.join(host, ":", port);
  InetSocketAddress address = NetUtils.createSocketAddr(
    hsAddress, getDefaultJHSWebappPort(),
    getDefaultJHSWebappURLWithoutScheme());
  StringBuffer sb = new StringBuffer();
  if (address.getAddress().isAnyLocalAddress() || 
      address.getAddress().isLoopbackAddress()) {
    sb.append(InetAddress.getLocalHost().getCanonicalHostName());
  } else {
    sb.append(address.getHostName());
  }
  sb.append(":").append(address.getPort());
  sb.append("/jobhistory/job/");
  JobID jobId = TypeConverter.fromYarn(appId);
  sb.append(jobId.toString());
  return sb.toString();
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:30,代碼來源:MRWebAppUtil.java

示例11: getSocketAddr

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
/**
 * Get the socket address for <code>name</code> property as a
 * <code>InetSocketAddress</code>. On a HA cluster,
 * this fetches the address corresponding to the RM identified by
 * {@link #RM_HA_ID}.
 * @param name property name.
 * @param defaultAddress the default value
 * @param defaultPort the default port
 * @return InetSocketAddress
 */
@Override
public InetSocketAddress getSocketAddr(
    String name, String defaultAddress, int defaultPort) {
  String address;
  if (HAUtil.isHAEnabled(this) && getServiceAddressConfKeys(this).contains(name)) {
    address = HAUtil.getConfValueForRMInstance(name, defaultAddress, this);
  } else {
    address = get(name, defaultAddress);
  }
  return NetUtils.createSocketAddr(address, defaultPort, name);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:22,代碼來源:YarnConfiguration.java

示例12: getBestNodeDNAddrPair

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
/**
 * Get the best node from which to stream the data.
 * @param block LocatedBlock, containing nodes in priority order.
 * @param ignoredNodes Do not choose nodes in this array (may be null)
 * @return The DNAddrPair of the best node.
 * @throws IOException
 */
private DNAddrPair getBestNodeDNAddrPair(LocatedBlock block,
    Collection<DatanodeInfo> ignoredNodes) throws IOException {
  DatanodeInfo[] nodes = block.getLocations();
  StorageType[] storageTypes = block.getStorageTypes();
  DatanodeInfo chosenNode = null;
  StorageType storageType = null;
  if (nodes != null) {
    for (int i = 0; i < nodes.length; i++) {
      if (!deadNodes.containsKey(nodes[i])
          && (ignoredNodes == null || !ignoredNodes.contains(nodes[i]))) {
        chosenNode = nodes[i];
        // Storage types are ordered to correspond with nodes, so use the same
        // index to get storage type.
        if (storageTypes != null && i < storageTypes.length) {
          storageType = storageTypes[i];
        }
        break;
      }
    }
  }
  if (chosenNode == null) {
    throw new IOException("No live nodes contain block " + block.getBlock() +
        " after checking nodes = " + Arrays.toString(nodes) +
        ", ignoredNodes = " + ignoredNodes);
  }
  final String dnAddr =
      chosenNode.getXferAddr(dfsClient.getConf().connectToDnViaHostname);
  if (DFSClient.LOG.isDebugEnabled()) {
    DFSClient.LOG.debug("Connecting to datanode " + dnAddr);
  }
  InetSocketAddress targetAddr = NetUtils.createSocketAddr(dnAddr);
  return new DNAddrPair(chosenNode, targetAddr, storageType);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:41,代碼來源:DFSInputStream.java

示例13: getContainerManagementProtocolProxy

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
protected ContainerManagementProtocol getContainerManagementProtocolProxy(
    final YarnRPC rpc, org.apache.hadoop.yarn.api.records.Token nmToken,
    NodeId nodeId, String user) {
  ContainerManagementProtocol proxy;
  UserGroupInformation ugi = UserGroupInformation.createRemoteUser(user);
  final InetSocketAddress addr =
      NetUtils.createSocketAddr(nodeId.getHost(), nodeId.getPort());
  if (nmToken != null) {
    ugi.addToken(ConverterUtils.convertFromYarn(nmToken, addr));      
  }
  proxy =
      NMProxy.createNMProxy(conf, ContainerManagementProtocol.class, ugi,
        rpc, addr);
  return proxy;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:16,代碼來源:TestContainerManagerSecurity.java

示例14: testShortCircuitRenewCancel

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
@Test
public void testShortCircuitRenewCancel()
    throws IOException, InterruptedException {
  InetSocketAddress addr = NetUtils.createSocketAddr(
      InetAddress.getLocalHost().getHostName(), 123, null);
  checkShortCircuitRenewCancel(addr, addr, true);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:8,代碼來源:TestClientRMTokens.java

示例15: getAddress

import org.apache.hadoop.net.NetUtils; //導入方法依賴的package包/類
private static InetSocketAddress getAddress(Configuration conf) {
  String addr = conf.get(DFSConfigKeys.DFS_JOURNALNODE_HTTP_ADDRESS_KEY,
      DFSConfigKeys.DFS_JOURNALNODE_HTTP_ADDRESS_DEFAULT);
  return NetUtils.createSocketAddr(addr,
      DFSConfigKeys.DFS_JOURNALNODE_HTTP_PORT_DEFAULT,
      DFSConfigKeys.DFS_JOURNALNODE_HTTP_ADDRESS_KEY);
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:8,代碼來源:JournalNodeHttpServer.java


注:本文中的org.apache.hadoop.net.NetUtils.createSocketAddr方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。