当前位置: 首页>>代码示例>>Java>>正文


Java NetUtils.getHostPortString方法代码示例

本文整理汇总了Java中org.apache.hadoop.net.NetUtils.getHostPortString方法的典型用法代码示例。如果您正苦于以下问题:Java NetUtils.getHostPortString方法的具体用法?Java NetUtils.getHostPortString怎么用?Java NetUtils.getHostPortString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.net.NetUtils的用法示例。


在下文中一共展示了NetUtils.getHostPortString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSessionCookie

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
@Test
public void testSessionCookie() throws IOException {
  try {
      startServer(true);
  } catch (Exception e) {
      // Auto-generated catch block
      e.printStackTrace();
  }

  URL base = new URL("http://" + NetUtils.getHostPortString(server
          .getConnectorAddress(0)));
  HttpURLConnection conn = (HttpURLConnection) new URL(base,
          "/echo").openConnection();

  String header = conn.getHeaderField("Set-Cookie");
  List<HttpCookie> cookies = HttpCookie.parse(header);
  Assert.assertTrue(!cookies.isEmpty());
  Log.info(header);
  Assert.assertFalse(header.contains("; Expires="));
  Assert.assertTrue("token".equals(cookies.get(0).getValue()));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:22,代码来源:TestAuthenticationSessionCookie.java

示例2: testHttpsCookie

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
@Test
public void testHttpsCookie() throws IOException, GeneralSecurityException {
  URL base = new URL("https://" + NetUtils.getHostPortString(server
          .getConnectorAddress(1)));
  HttpsURLConnection conn = (HttpsURLConnection) new URL(base,
          "/echo").openConnection();
  conn.setSSLSocketFactory(clientSslFactory.createSSLSocketFactory());

  String header = conn.getHeaderField("Set-Cookie");
  List<HttpCookie> cookies = HttpCookie.parse(header);
  Assert.assertTrue(!cookies.isEmpty());
  Assert.assertTrue(header.contains("; HttpOnly"));
  Assert.assertTrue(cookies.get(0).getSecure());
  Assert.assertTrue("token".equals(cookies.get(0).getValue()));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:16,代码来源:TestHttpCookieFlag.java

示例3: getNNServiceRpcAddresses

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
/**
 * Returns list of InetSocketAddresses corresponding to namenodes from the
 * configuration.
 * 
 * Returns namenode address specifically configured for datanodes (using
 * service ports), if found. If not, regular RPC address configured for other
 * clients is returned.
 * 
 * @param conf configuration
 * @return list of InetSocketAddress
 * @throws IOException on error
 */
public static Map<String, Map<String, InetSocketAddress>> getNNServiceRpcAddresses(
    Configuration conf) throws IOException {
  // Use default address as fall back
  String defaultAddress;
  try {
    defaultAddress = NetUtils.getHostPortString(NameNode.getAddress(conf));
  } catch (IllegalArgumentException e) {
    defaultAddress = null;
  }
  
  Map<String, Map<String, InetSocketAddress>> addressList =
    getAddresses(conf, defaultAddress,
      DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY, DFS_NAMENODE_RPC_ADDRESS_KEY);
  if (addressList.isEmpty()) {
    throw new IOException("Incorrect configuration: namenode address "
        + DFS_NAMENODE_SERVICE_RPC_ADDRESS_KEY + " or "  
        + DFS_NAMENODE_RPC_ADDRESS_KEY
        + " is not configured.");
  }
  return addressList;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:34,代码来源:DFSUtil.java

示例4: testLogsEnabled

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
@Test
public void testLogsEnabled() throws Exception {
  Configuration conf = new Configuration();
  conf.setBoolean(
      CommonConfigurationKeysPublic.HADOOP_HTTP_LOGS_ENABLED, true);
  startServer(conf);
  URL url = new URL("http://"
      + NetUtils.getHostPortString(server.getConnectorAddress(0)) + "/logs");
  HttpURLConnection conn = (HttpURLConnection)url.openConnection();
  assertEquals(HttpStatus.SC_OK, conn.getResponseCode());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:12,代码来源:TestHttpServerLogs.java

示例5: testDisabledAuthorizationOfDefaultServlets

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
/**
 * Verify the access for /logs, /stacks, /conf, /logLevel and /metrics
 * servlets, when authentication filters are set, but authorization is not
 * enabled.
 * @throws Exception 
 */
@Test
@Ignore
public void testDisabledAuthorizationOfDefaultServlets() throws Exception {

  Configuration conf = new Configuration();

  // Authorization is disabled by default
  conf.set(HttpServer.FILTER_INITIALIZERS_PROPERTY,
      DummyFilterInitializer.class.getName());
  conf.set(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
      MyGroupsProvider.class.getName());
  Groups.getUserToGroupsMappingService(conf);
  MyGroupsProvider.clearMapping();
  MyGroupsProvider.mapping.put("userA", Arrays.asList("groupA"));
  MyGroupsProvider.mapping.put("userB", Arrays.asList("groupB"));

  HttpServer myServer = new HttpServer.Builder().setName("test")
      .addEndpoint(new URI("http://localhost:0")).setFindPort(true).build();
  myServer.setAttribute(HttpServer.CONF_CONTEXT_ATTRIBUTE, conf);
  myServer.start();
  String serverURL = "http://" + NetUtils.getHostPortString(myServer.getConnectorAddress(0)) + "/";
  for (String servlet : new String[] { "conf", "logs", "stacks",
      "logLevel", "metrics" }) {
    for (String user : new String[] { "userA", "userB" }) {
      assertEquals(HttpURLConnection.HTTP_OK, getHttpStatusCode(serverURL
          + servlet, user));
    }
  }
  myServer.stop();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:37,代码来源:TestHttpServer.java

示例6: setup

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
@BeforeClass
public static void setup() throws Exception {
  conf = new Configuration();
  conf.setInt(HttpServer2.HTTP_MAX_THREADS, 10);

  File base = new File(BASEDIR);
  FileUtil.fullyDelete(base);
  base.mkdirs();
  keystoresDir = new File(BASEDIR).getAbsolutePath();
  sslConfDir = KeyStoreTestUtil.getClasspathDir(TestSSLHttpServer.class);

  KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, conf, false, true,
      excludeCiphers);

  Configuration sslConf = KeyStoreTestUtil.getSslConfig();

  clientSslFactory = new SSLFactory(SSLFactory.Mode.CLIENT, sslConf);
  clientSslFactory.init();

  server = new HttpServer2.Builder()
      .setName("test")
      .addEndpoint(new URI("https://localhost"))
      .setConf(conf)
      .keyPassword(sslConf.get("ssl.server.keystore.keypassword"))
      .keyStore(sslConf.get("ssl.server.keystore.location"),
          sslConf.get("ssl.server.keystore.password"),
          sslConf.get("ssl.server.keystore.type", "jks"))
      .trustStore(sslConf.get("ssl.server.truststore.location"),
          sslConf.get("ssl.server.truststore.password"),
          sslConf.get("ssl.server.truststore.type", "jks"))
      .excludeCiphers(
          sslConf.get("ssl.server.exclude.cipher.list")).build();
  server.addServlet("echo", "/echo", TestHttpServer.EchoServlet.class);
  server.addServlet("longheader", "/longheader", LongHeaderServlet.class);
  server.start();
  baseUrl = new URL("https://"
      + NetUtils.getHostPortString(server.getConnectorAddress(0)));
  LOG.info("HTTP server started: " + baseUrl);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:40,代码来源:TestSSLHttpServer.java

示例7: testHttpCookie

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
@Test
public void testHttpCookie() throws IOException {
  URL base = new URL("http://" + NetUtils.getHostPortString(server
          .getConnectorAddress(0)));
  HttpURLConnection conn = (HttpURLConnection) new URL(base,
          "/echo").openConnection();

  String header = conn.getHeaderField("Set-Cookie");
  List<HttpCookie> cookies = HttpCookie.parse(header);
  Assert.assertTrue(!cookies.isEmpty());
  Assert.assertTrue(header.contains("; HttpOnly"));
  Assert.assertTrue("token".equals(cookies.get(0).getValue()));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:14,代码来源:TestHttpCookieFlag.java

示例8: testDisabledAuthorizationOfDefaultServlets

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
/**
 * Verify the access for /logs, /stacks, /conf, /logLevel and /metrics
 * servlets, when authentication filters are set, but authorization is not
 * enabled.
 * @throws Exception 
 */
@Test
public void testDisabledAuthorizationOfDefaultServlets() throws Exception {

  Configuration conf = new Configuration();

  // Authorization is disabled by default
  conf.set(HttpServer2.FILTER_INITIALIZER_PROPERTY,
      DummyFilterInitializer.class.getName());
  conf.set(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
      MyGroupsProvider.class.getName());
  Groups.getUserToGroupsMappingService(conf);
  MyGroupsProvider.clearMapping();
  MyGroupsProvider.mapping.put("userA", Arrays.asList("groupA"));
  MyGroupsProvider.mapping.put("userB", Arrays.asList("groupB"));

  HttpServer2 myServer = new HttpServer2.Builder().setName("test")
      .addEndpoint(new URI("http://localhost:0")).setFindPort(true).build();
  myServer.setAttribute(HttpServer2.CONF_CONTEXT_ATTRIBUTE, conf);
  myServer.start();
  String serverURL = "http://" + NetUtils.getHostPortString(myServer.getConnectorAddress(0)) + "/";
  for (String servlet : new String[] { "conf", "logs", "stacks",
      "logLevel", "metrics" }) {
    for (String user : new String[] { "userA", "userB" }) {
      assertEquals(HttpURLConnection.HTTP_OK, getHttpStatusCode(serverURL
          + servlet, user));
    }
  }
  myServer.stop();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:36,代码来源:TestHttpServer.java

示例9: getServerURL

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
/**
 * Pass in a server, return a URL bound to localhost and its port
 * @param server server
 * @return a URL bonded to the base of the server
 * @throws MalformedURLException if the URL cannot be created.
 */
public static URL getServerURL(HttpServer2 server)
    throws MalformedURLException {
  assertNotNull("No server", server);
  return new URL("http://"
      + NetUtils.getHostPortString(server.getConnectorAddress(0)));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:13,代码来源:HttpServerFunctionalTest.java

示例10: testMRWebAppSSLDisabled

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
@Test
public void testMRWebAppSSLDisabled() throws Exception {
  MRApp app = new MRApp(2, 2, true, this.getClass().getName(), true) {
    @Override
    protected ClientService createClientService(AppContext context) {
      return new MRClientService(context);
    }
  };
  Configuration conf = new Configuration();
  // MR is explicitly disabling SSL, even though setting as HTTPS_ONLY
  conf.set(YarnConfiguration.YARN_HTTP_POLICY_KEY, Policy.HTTPS_ONLY.name());
  Job job = app.submit(conf);

  String hostPort =
      NetUtils.getHostPortString(((MRClientService) app.getClientService())
        .getWebApp().getListenerAddress());
  // http:// should be accessible
  URL httpUrl = new URL("http://" + hostPort);
  HttpURLConnection conn = (HttpURLConnection) httpUrl.openConnection();
  InputStream in = conn.getInputStream();
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  IOUtils.copyBytes(in, out, 1024);
  Assert.assertTrue(out.toString().contains("MapReduce Application"));

  // https:// is not accessible.
  URL httpsUrl = new URL("https://" + hostPort);
  try {
    HttpURLConnection httpsConn =
        (HttpURLConnection) httpsUrl.openConnection();
    httpsConn.getInputStream();
    Assert.fail("https:// is not accessible, expected to fail");
  } catch (Exception e) {
    Assert.assertTrue(e instanceof SSLException);
  }

  app.waitForState(job, JobState.SUCCEEDED);
  app.verifyCompleted();
}
 
开发者ID:naver,项目名称:hadoop,代码行数:39,代码来源:TestAMWebApp.java

示例11: setRegistration

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
NamenodeRegistration setRegistration() {
  nodeRegistration = new NamenodeRegistration(
      NetUtils.getHostPortString(rpcServer.getRpcAddress()),
      NetUtils.getHostPortString(getHttpAddress()),
      getFSImage().getStorage(), getRole());
  return nodeRegistration;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:NameNode.java

示例12: testDynamicLogLevel

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
public void testDynamicLogLevel() throws Exception {
  String logName = TestLogLevel.class.getName();
  Log testlog = LogFactory.getLog(logName);

  //only test Log4JLogger
  if (testlog instanceof Log4JLogger) {
    Logger log = ((Log4JLogger)testlog).getLogger();
    log.debug("log.debug1");
    log.info("log.info1");
    log.error("log.error1");
    assertTrue(!Level.ERROR.equals(log.getEffectiveLevel()));

    HttpServer2 server = new HttpServer2.Builder().setName("..")
        .addEndpoint(new URI("http://localhost:0")).setFindPort(true)
        .build();
    
    server.start();
    String authority = NetUtils.getHostPortString(server
        .getConnectorAddress(0));

    //servlet
    URL url = new URL("http://" + authority + "/logLevel?log=" + logName
        + "&level=" + Level.ERROR);
    out.println("*** Connecting to " + url);
    URLConnection connection = url.openConnection();
    connection.connect();

    BufferedReader in = new BufferedReader(new InputStreamReader(
        connection.getInputStream()));
    for(String line; (line = in.readLine()) != null; out.println(line));
    in.close();

    log.debug("log.debug2");
    log.info("log.info2");
    log.error("log.error2");
    assertTrue(Level.ERROR.equals(log.getEffectiveLevel()));

    //command line
    String[] args = {"-setlevel", authority, logName, Level.DEBUG.toString()};
    LogLevel.main(args);
    log.debug("log.debug3");
    log.info("log.info3");
    log.error("log.error3");
    assertTrue(Level.DEBUG.equals(log.getEffectiveLevel()));
  }
  else {
    out.println(testlog.getClass() + " not tested.");
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:50,代码来源:TestLogLevel.java

示例13: any

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
@SuppressWarnings("unchecked") // for any(Token.class)
@Test
public void testLazyTokenFetchForSWebhdfs() throws Exception {
  MiniDFSCluster cluster = null;
  SWebHdfsFileSystem fs = null;
  try {
    final Configuration clusterConf = new HdfsConfiguration(conf);
    SecurityUtil.setAuthenticationMethod(SIMPLE, clusterConf);
    clusterConf.setBoolean(DFSConfigKeys
   .DFS_NAMENODE_DELEGATION_TOKEN_ALWAYS_USE_KEY, true);
    String BASEDIR = System.getProperty("test.build.dir",
     	  "target/test-dir") + "/" + TestWebHdfsTokens.class.getSimpleName();
    String keystoresDir;
    String sslConfDir;
   
    clusterConf.setBoolean(DFSConfigKeys.DFS_WEBHDFS_ENABLED_KEY, true);
    clusterConf.set(DFSConfigKeys.DFS_HTTP_POLICY_KEY, HttpConfig.Policy.HTTPS_ONLY.name());
    clusterConf.set(DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY, "localhost:0");
    clusterConf.set(DFSConfigKeys.DFS_DATANODE_HTTPS_ADDRESS_KEY, "localhost:0");
 
    File base = new File(BASEDIR);
    FileUtil.fullyDelete(base);
    base.mkdirs();
    keystoresDir = new File(BASEDIR).getAbsolutePath();
    sslConfDir = KeyStoreTestUtil.getClasspathDir(TestWebHdfsTokens.class);
    KeyStoreTestUtil.setupSSLConfig(keystoresDir, sslConfDir, clusterConf, false);
 
    // trick the NN into thinking security is enabled w/o it trying
    // to login from a keytab
    UserGroupInformation.setConfiguration(clusterConf);
    cluster = new MiniDFSCluster.Builder(clusterConf).numDataNodes(1).build();
    cluster.waitActive();
    InetSocketAddress addr = cluster.getNameNode().getHttpsAddress();
    String nnAddr = NetUtils.getHostPortString(addr);
    clusterConf.set(DFSConfigKeys.DFS_NAMENODE_HTTPS_ADDRESS_KEY, nnAddr);
    SecurityUtil.setAuthenticationMethod(KERBEROS, clusterConf);
    UserGroupInformation.setConfiguration(clusterConf);
    
    uri = DFSUtil.createUri(
      "swebhdfs", cluster.getNameNode().getHttpsAddress());
    validateLazyTokenFetch(clusterConf);
    } finally {
      IOUtils.cleanup(null, fs);
      if (cluster != null) {
        cluster.shutdown();
      }
   }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:49,代码来源:TestWebHdfsTokens.java

示例14: testAuthorizationOfDefaultServlets

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
/**
 * Verify the administrator access for /logs, /stacks, /conf, /logLevel and
 * /metrics servlets.
 * 
 * @throws Exception
 */
@Test
@Ignore
public void testAuthorizationOfDefaultServlets() throws Exception {
  Configuration conf = new Configuration();
  conf.setBoolean(CommonConfigurationKeys.HADOOP_SECURITY_AUTHORIZATION,
      true);
  conf.setBoolean(CommonConfigurationKeys.HADOOP_SECURITY_INSTRUMENTATION_REQUIRES_ADMIN,
      true);
  conf.set(HttpServer.FILTER_INITIALIZERS_PROPERTY,
      DummyFilterInitializer.class.getName());

  conf.set(CommonConfigurationKeys.HADOOP_SECURITY_GROUP_MAPPING,
      MyGroupsProvider.class.getName());
  Groups.getUserToGroupsMappingService(conf);
  MyGroupsProvider.clearMapping();
  MyGroupsProvider.mapping.put("userA", Arrays.asList("groupA"));
  MyGroupsProvider.mapping.put("userB", Arrays.asList("groupB"));
  MyGroupsProvider.mapping.put("userC", Arrays.asList("groupC"));
  MyGroupsProvider.mapping.put("userD", Arrays.asList("groupD"));
  MyGroupsProvider.mapping.put("userE", Arrays.asList("groupE"));

  HttpServer myServer = new HttpServer.Builder().setName("test")
      .addEndpoint(new URI("http://localhost:0")).setFindPort(true).setConf(conf)
      .setACL(new AccessControlList("userA,userB groupC,groupD")).build();
  myServer.setAttribute(HttpServer.CONF_CONTEXT_ATTRIBUTE, conf);
  myServer.start();

  String serverURL = "http://"
      + NetUtils.getHostPortString(myServer.getConnectorAddress(0)) + "/";
  for (String servlet : new String[] { "conf", "logs", "stacks",
      "logLevel", "metrics" }) {
    for (String user : new String[] { "userA", "userB", "userC", "userD" }) {
      assertEquals(HttpURLConnection.HTTP_OK, getHttpStatusCode(serverURL
          + servlet, user));
    }
    assertEquals(HttpURLConnection.HTTP_UNAUTHORIZED, getHttpStatusCode(
        serverURL + servlet, "userE"));
  }
  myServer.stop();
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:47,代码来源:TestHttpServer.java

示例15: testPathSpecFilters

import org.apache.hadoop.net.NetUtils; //导入方法依赖的package包/类
@Test
public void testPathSpecFilters() throws Exception {
  Configuration conf = new Configuration();
  
  //start a http server with CountingFilter
  conf.set(HttpServer2.FILTER_INITIALIZER_PROPERTY,
      RecordingFilter.Initializer.class.getName());
  String[] pathSpecs = { "/path", "/path/*" };
  HttpServer2 http = createTestServer(conf, pathSpecs);
  http.start();

  final String baseURL = "/path";
  final String baseSlashURL = "/path/";
  final String addedURL = "/path/nodes";
  final String addedSlashURL = "/path/nodes/";
  final String longURL = "/path/nodes/foo/job";
  final String rootURL = "/";
  final String allURL = "/*";

  final String[] filteredUrls = {baseURL, baseSlashURL, addedURL, 
      addedSlashURL, longURL};
  final String[] notFilteredUrls = {rootURL, allURL};

  // access the urls and verify our paths specs got added to the 
  // filters
  final String prefix = "http://"
      + NetUtils.getHostPortString(http.getConnectorAddress(0));
  try {
    for(int i = 0; i < filteredUrls.length; i++) {
      access(prefix + filteredUrls[i]);
    }
    for(int i = 0; i < notFilteredUrls.length; i++) {
      access(prefix + notFilteredUrls[i]);
    }
  } finally {
    http.stop();
  }

  LOG.info("RECORDS = " + RECORDS);
  
  //verify records
  for(int i = 0; i < filteredUrls.length; i++) {
    assertTrue(RECORDS.remove(filteredUrls[i]));
  }
  assertTrue(RECORDS.isEmpty());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:47,代码来源:TestPathFilter.java


注:本文中的org.apache.hadoop.net.NetUtils.getHostPortString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。