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

The following are Jave code examples for showing how to use getCanonicalServiceName() of the org.apache.hadoop.fs.FileSystem class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: hadoop-oss   File: TestViewFileSystemDelegationTokenSupport.java   Source Code and License Vote up 5 votes
/**
 * 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 2
Project: hadoop-oss   File: TestViewFileSystemDelegationTokenSupport.java   Source Code and License Vote up 5 votes
@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 3
Project: hadoop   File: TestDFSClientFailover.java   Source Code and License Vote up 5 votes
/**
 * 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 4
Project: hadoop   File: TestViewFileSystemDelegationTokenSupport.java   Source Code and License Vote up 5 votes
/**
 * 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 5
Project: hadoop   File: TestViewFileSystemDelegationTokenSupport.java   Source Code and License Vote up 5 votes
@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 6
Project: ditb   File: FSHDFSUtils.java   Source Code and License Vote up 5 votes
/**
 * @param conf the Configuration of HBase
 * @param srcFs
 * @param desFs
 * @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;
}