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

The following are Jave code examples for showing how to use getUri() 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: alluxio   File: HdfsAndAlluxioUtils_update.java   Source Code and License Vote up 5 votes
/**
 * 此方法用于获取文件的 Uri
 *
 * @param fileSystemInfo
 *            文件系统信息
 * @return Uri
 */
public static URI getUri(FileSystemInfo fileSystemInfo) {
	FileSystem fs = getFileSystem(fileSystemInfo);
	try {
		return fs.getUri();
	} finally {
		closeFileSystem(fs);
	}
}
 
Example 2
Project: hadoop   File: JobResourceUploader.java   Source Code and License Vote up 5 votes
private boolean compareFs(FileSystem srcFs, FileSystem destFs) {
  URI srcUri = srcFs.getUri();
  URI dstUri = destFs.getUri();
  if (srcUri.getScheme() == null) {
    return false;
  }
  if (!srcUri.getScheme().equals(dstUri.getScheme())) {
    return false;
  }
  String srcHost = srcUri.getHost();
  String dstHost = dstUri.getHost();
  if ((srcHost != null) && (dstHost != null)) {
    try {
      srcHost = InetAddress.getByName(srcHost).getCanonicalHostName();
      dstHost = InetAddress.getByName(dstHost).getCanonicalHostName();
    } catch (UnknownHostException ue) {
      return false;
    }
    if (!srcHost.equals(dstHost)) {
      return false;
    }
  } else if (srcHost == null && dstHost != null) {
    return false;
  } else if (srcHost != null && dstHost == null) {
    return false;
  }
  // check for ports
  if (srcUri.getPort() != dstUri.getPort()) {
    return false;
  }
  return true;
}
 
Example 3
Project: hadoop   File: AdminHelper.java   Source Code and License Vote up 5 votes
static DistributedFileSystem getDFS(Configuration conf)
    throws IOException {
  FileSystem fs = FileSystem.get(conf);
  if (!(fs instanceof DistributedFileSystem)) {
    throw new IllegalArgumentException("FileSystem " + fs.getUri() +
        " is not an HDFS file system");
  }
  return (DistributedFileSystem)fs;
}
 
Example 4
Project: hadoop   File: DFSAdmin.java   Source Code and License Vote up 5 votes
/** Constructor */
public DFSAdminCommand(FileSystem fs) {
  super(fs.getConf());
  if (!(fs instanceof DistributedFileSystem)) {
    throw new IllegalArgumentException("FileSystem " + fs.getUri() + 
        " is not an HDFS file system");
  }
  this.dfs = (DistributedFileSystem)fs;
}
 
Example 5
Project: hadoop   File: DFSAdmin.java   Source Code and License Vote up 5 votes
protected DistributedFileSystem getDFS() throws IOException {
  FileSystem fs = getFS();
  if (!(fs instanceof DistributedFileSystem)) {
    throw new IllegalArgumentException("FileSystem " + fs.getUri() + 
    " is not an HDFS file system");
  }
  return (DistributedFileSystem)fs;
}
 
Example 6
Project: hadoop   File: DistCpUtils.java   Source Code and License Vote up 5 votes
/**
 * Determines if a file system supports ACLs by running a canary getAclStatus
 * request on the file system root.  This method is used before distcp job
 * submission to fail fast if the user requested preserving ACLs, but the file
 * system cannot support ACLs.
 *
 * @param fs FileSystem to check
 * @throws AclsNotSupportedException if fs does not support ACLs
 */
public static void checkFileSystemAclSupport(FileSystem fs)
    throws AclsNotSupportedException {
  try {
    fs.getAclStatus(new Path(Path.SEPARATOR));
  } catch (Exception e) {
    throw new AclsNotSupportedException("ACLs not supported for file system: "
      + fs.getUri());
  }
}
 
Example 7
Project: hadoop   File: DistCpUtils.java   Source Code and License Vote up 5 votes
/**
 * Determines if a file system supports XAttrs by running a getXAttrs request
 * on the file system root. This method is used before distcp job submission
 * to fail fast if the user requested preserving XAttrs, but the file system
 * cannot support XAttrs.
 * 
 * @param fs FileSystem to check
 * @throws XAttrsNotSupportedException if fs does not support XAttrs
 */
public static void checkFileSystemXAttrSupport(FileSystem fs)
    throws XAttrsNotSupportedException {
  try {
    fs.getXAttrs(new Path(Path.SEPARATOR));
  } catch (Exception e) {
    throw new XAttrsNotSupportedException("XAttrs not supported for file system: "
      + fs.getUri());
  }
}
 
Example 8
Project: hadoop   File: DistCpUtils.java   Source Code and License Vote up 5 votes
public static boolean compareFs(FileSystem srcFs, FileSystem destFs) {
  URI srcUri = srcFs.getUri();
  URI dstUri = destFs.getUri();
  if (srcUri.getScheme() == null) {
    return false;
  }
  if (!srcUri.getScheme().equals(dstUri.getScheme())) {
    return false;
  }
  String srcHost = srcUri.getHost();
  String dstHost = dstUri.getHost();
  if ((srcHost != null) && (dstHost != null)) {
    try {
      srcHost = InetAddress.getByName(srcHost).getCanonicalHostName();
      dstHost = InetAddress.getByName(dstHost).getCanonicalHostName();
    } catch(UnknownHostException ue) {
      if (LOG.isDebugEnabled())
        LOG.debug("Could not compare file-systems. Unknown host: ", ue);
      return false;
    }
    if (!srcHost.equals(dstHost)) {
      return false;
    }
  }
  else if (srcHost == null && dstHost != null) {
    return false;
  }
  else if (srcHost != null) {
    return false;
  }

  //check for ports

  return srcUri.getPort() == dstUri.getPort();
}
 
Example 9
Project: ditb   File: TestHBaseOnOtherDfsCluster.java   Source Code and License Vote up 4 votes
private void assertFsSameUri(FileSystem sourceFs, FileSystem targetFs) {
  Path source = new Path(sourceFs.getUri());
  Path target = new Path(targetFs.getUri());
  assertEquals(source, target);
}