Java Code Examples for org.apache.hadoop.fs.FileSystem#getCanonicalServiceName()

The following examples show how to use org.apache.hadoop.fs.FileSystem#getCanonicalServiceName() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: hadoop   File: TestDFSClientFailover.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test that the client doesn't ever try to DNS-resolve the logical URI.
 * Regression test for HADOOP-9150.
 */
@Test
public void testDoesntDnsResolveLogicalURI() throws Exception {
  FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
  NameService spyNS = spyOnNameService();
  String logicalHost = fs.getUri().getHost();
  Path qualifiedRoot = fs.makeQualified(new Path("/"));
  
  // Make a few calls against the filesystem.
  fs.getCanonicalServiceName();
  fs.listStatus(qualifiedRoot);
  
  // Ensure that the logical hostname was never resolved.
  Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost));
}
 
Example 2
/**
 * Regression test for HADOOP-8408.
 */
@Test
public void testGetCanonicalServiceNameWithNonDefaultMountTable()
    throws URISyntaxException, IOException {
  
  Configuration conf = new Configuration();
  ConfigUtil.addLink(conf, MOUNT_TABLE_NAME, "/user", new URI("file:///"));
  
  FileSystem viewFs = FileSystem.get(new URI(FsConstants.VIEWFS_SCHEME +
      "://" + MOUNT_TABLE_NAME), conf);
  
  String serviceName = viewFs.getCanonicalServiceName();
  assertNull(serviceName);
}
 
Example 3
@Test
public void testGetCanonicalServiceNameWithDefaultMountTable()
    throws URISyntaxException, IOException {
  
  Configuration conf = new Configuration();
  ConfigUtil.addLink(conf, "/user", new URI("file:///"));
  
  FileSystem viewFs = FileSystem.get(FsConstants.VIEWFS_URI, conf);
  
  String serviceName = viewFs.getCanonicalServiceName();
  assertNull(serviceName);
}
 
Example 4
Source Project: big-c   File: TestDFSClientFailover.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Test that the client doesn't ever try to DNS-resolve the logical URI.
 * Regression test for HADOOP-9150.
 */
@Test
public void testDoesntDnsResolveLogicalURI() throws Exception {
  FileSystem fs = HATestUtil.configureFailoverFs(cluster, conf);
  NameService spyNS = spyOnNameService();
  String logicalHost = fs.getUri().getHost();
  Path qualifiedRoot = fs.makeQualified(new Path("/"));
  
  // Make a few calls against the filesystem.
  fs.getCanonicalServiceName();
  fs.listStatus(qualifiedRoot);
  
  // Ensure that the logical hostname was never resolved.
  Mockito.verify(spyNS, Mockito.never()).lookupAllHostAddr(Mockito.eq(logicalHost));
}
 
Example 5
/**
 * Regression test for HADOOP-8408.
 */
@Test
public void testGetCanonicalServiceNameWithNonDefaultMountTable()
    throws URISyntaxException, IOException {
  
  Configuration conf = new Configuration();
  ConfigUtil.addLink(conf, MOUNT_TABLE_NAME, "/user", new URI("file:///"));
  
  FileSystem viewFs = FileSystem.get(new URI(FsConstants.VIEWFS_SCHEME +
      "://" + MOUNT_TABLE_NAME), conf);
  
  String serviceName = viewFs.getCanonicalServiceName();
  assertNull(serviceName);
}
 
Example 6
@Test
public void testGetCanonicalServiceNameWithDefaultMountTable()
    throws URISyntaxException, IOException {
  
  Configuration conf = new Configuration();
  ConfigUtil.addLink(conf, "/user", new URI("file:///"));
  
  FileSystem viewFs = FileSystem.get(FsConstants.VIEWFS_URI, conf);
  
  String serviceName = viewFs.getCanonicalServiceName();
  assertNull(serviceName);
}
 
Example 7
Source Project: hbase   File: FSUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param conf the Configuration of HBase
 * @return Whether srcFs and desFs are on same hdfs or not
 */
public static boolean isSameHdfs(Configuration conf, FileSystem srcFs, FileSystem desFs) {
  // By getCanonicalServiceName, we could make sure both srcFs and desFs
  // show a unified format which contains scheme, host and port.
  String srcServiceName = srcFs.getCanonicalServiceName();
  String desServiceName = desFs.getCanonicalServiceName();

  if (srcServiceName == null || desServiceName == null) {
    return false;
  }
  if (srcServiceName.equals(desServiceName)) {
    return true;
  }
  if (srcServiceName.startsWith("ha-hdfs") && desServiceName.startsWith("ha-hdfs")) {
    Collection<String> internalNameServices =
      conf.getTrimmedStringCollection("dfs.internal.nameservices");
    if (!internalNameServices.isEmpty()) {
      if (internalNameServices.contains(srcServiceName.split(":")[1])) {
        return true;
      } else {
        return false;
      }
    }
  }
  if (srcFs instanceof DistributedFileSystem && desFs instanceof DistributedFileSystem) {
    // If one serviceName is an HA format while the other is a non-HA format,
    // maybe they refer to the same FileSystem.
    // For example, srcFs is "ha-hdfs://nameservices" and desFs is "hdfs://activeNamenode:port"
    Set<InetSocketAddress> srcAddrs = getNNAddresses((DistributedFileSystem) srcFs, conf);
    Set<InetSocketAddress> desAddrs = getNNAddresses((DistributedFileSystem) desFs, conf);
    if (Sets.intersection(srcAddrs, desAddrs).size() > 0) {
      return true;
    }
  }

  return false;
}