org.apache.hadoop.hbase.HConstants#LOCALHOST源码实例Demo

下面列出了org.apache.hadoop.hbase.HConstants#LOCALHOST 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: hbase   文件: TestThriftConnection.java
private static Connection createConnection(int port, boolean useHttp) throws IOException {
  Configuration conf = HBaseConfiguration.create(TEST_UTIL.getConfiguration());
  conf.set(ConnectionUtils.HBASE_CLIENT_CONNECTION_IMPL,
      ThriftConnection.class.getName());
  if (useHttp) {
    conf.set(Constants.HBASE_THRIFT_CLIENT_BUIDLER_CLASS,
        ThriftConnection.HTTPThriftClientBuilder.class.getName());
  }
  String host = HConstants.LOCALHOST;
  if (useHttp) {
    host = "http://" + host;
  }
  conf.set(Constants.HBASE_THRIFT_SERVER_NAME, host);
  conf.setInt(Constants.HBASE_THRIFT_SERVER_PORT, port);
  return ConnectionFactory.createConnection(conf);
}
 
@BeforeClass
public static void setUpBeforeClass() throws Exception {
  kdc = SimpleKdcServerUtil.
    getRunningSimpleKdcServer(new File(TEST_UTIL.getDataTestDir().toString()),
      HBaseTestingUtility::randomFreePort);

  File keytabDir = Paths.get(TEST_UTIL.getRandomDir().toString()).toAbsolutePath().toFile();
  assertTrue(keytabDir.mkdirs());

  clientPrincipal = "[email protected]" + kdc.getKdcConfig().getKdcRealm();
  clientKeytab = new File(keytabDir, clientPrincipal + ".keytab");
  kdc.createAndExportPrincipals(clientKeytab, clientPrincipal);

  serverPrincipal = "hbase/" + HConstants.LOCALHOST + "@" + kdc.getKdcConfig().getKdcRealm();
  serverKeytab = new File(keytabDir, serverPrincipal.replace('/', '_') + ".keytab");

  spnegoServerPrincipal = "HTTP/" + HConstants.LOCALHOST + "@" + kdc.getKdcConfig().getKdcRealm();
  // Add SPNEGO principal to server keytab
  kdc.createAndExportPrincipals(serverKeytab, serverPrincipal, spnegoServerPrincipal);

  TEST_UTIL.getConfiguration().setBoolean(Constants.USE_HTTP_CONF_KEY, true);
  addSecurityConfigurations(TEST_UTIL.getConfiguration());

  TestThriftHttpServer.setUpBeforeClass();
}
 
源代码3 项目: hbase   文件: TestThriftHttpServer.java
void runThriftServer(int customHeaderSize) throws Exception {
  // Add retries in case we see stuff like connection reset
  Exception clientSideException =  null;
  for (int i = 0; i < 10; i++) {
    clientSideException =  null;
    ThriftServerRunner tsr = createBoundServer(getThriftServerSupplier());
    String url = "http://" + HConstants.LOCALHOST + ":" + tsr.getThriftServer().listenPort;
    try {
      checkHttpMethods(url);
      talkToThriftServer(url, customHeaderSize);
      break;
    } catch (Exception ex) {
      clientSideException = ex;
      LOG.info("Client-side Exception", ex);
    } finally {
      tsr.close();
      tsr.join();
      if (tsr.getRunException() != null) {
        LOG.error("Invocation of HBase Thrift server threw exception", tsr.getRunException());
        throw tsr.getRunException();
      }
    }
  }

  if (clientSideException != null) {
    LOG.error("Thrift Client", clientSideException);
    throw clientSideException;
  }
}
 
源代码4 项目: hbase   文件: ProcessBasedLocalHBaseCluster.java
private final String generateConfig(ServerType serverType, int rpcPort,
    String daemonDir) {
  StringBuilder sb = new StringBuilder();
  Map<String, Object> confMap = new TreeMap<>();
  confMap.put(HConstants.CLUSTER_DISTRIBUTED, true);

  if (serverType == ServerType.MASTER) {
    confMap.put(HConstants.MASTER_PORT, rpcPort);

    int masterInfoPort = HBaseTestingUtility.randomFreePort();
    reportWebUIPort("master", masterInfoPort);
    confMap.put(HConstants.MASTER_INFO_PORT, masterInfoPort);
  } else if (serverType == ServerType.RS) {
    confMap.put(HConstants.REGIONSERVER_PORT, rpcPort);

    int rsInfoPort = HBaseTestingUtility.randomFreePort();
    reportWebUIPort("region server", rsInfoPort);
    confMap.put(HConstants.REGIONSERVER_INFO_PORT, rsInfoPort);
  } else {
    confMap.put(HConstants.ZOOKEEPER_DATA_DIR, daemonDir);
  }

  confMap.put(HConstants.ZOOKEEPER_CLIENT_PORT, zkClientPort);
  confMap.put(HConstants.HREGION_MAX_FILESIZE, MAX_FILE_SIZE_OVERRIDE);

  if (dfsCluster != null) {
    String fsURL = "hdfs://" + HConstants.LOCALHOST + ":" + dfsCluster.getNameNodePort();
    confMap.put("fs.defaultFS", fsURL);
    confMap.put("hbase.rootdir", fsURL + "/hbase_test");
  }

  sb.append("<configuration>\n");
  for (Map.Entry<String, Object> entry : confMap.entrySet()) {
    sb.append("  <property>\n");
    sb.append("    <name>" + entry.getKey() + "</name>\n");
    sb.append("    <value>" + entry.getValue() + "</value>\n");
    sb.append("  </property>\n");
  }
  sb.append("</configuration>\n");
  return sb.toString();
}