Java Code Examples for org.apache.hadoop.fs.Path#isAbsolute()

The following examples show how to use org.apache.hadoop.fs.Path#isAbsolute() . 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 check out the related API usage on the sidebar.
Example 1
Source Project: ignite   File: IgniteHadoopFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Convert Hadoop path into IGFS path.
 *
 * @param path Hadoop path.
 * @return IGFS path.
 */
@Nullable private IgfsPath convert(Path path) {
    if (path == null)
        return null;

    return path.isAbsolute() ? new IgfsPath(path.toUri().getPath()) :
        new IgfsPath(workingDir, path.toUri().getPath());
}
 
Example 2
Source Project: RDFS   File: RaidNode.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Make an absolute path relative by stripping the leading /
 */
static Path makeRelative(Path path) {
	if (!path.isAbsolute()) {
		return path;
	}
	String p = path.toUri().getPath();
	String relative = p.substring(1, p.length());
	return new Path(relative);
}
 
Example 3
Source Project: hadoop   File: ChRootedFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param path
 * @return  full path including the chroot 
 */
protected Path fullPath(final Path path) {
  super.checkPath(path);
  return path.isAbsolute() ? 
      new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString)
          + path.toUri().getPath()) :
      new Path(chRootPathPartString + workingDir.toUri().getPath(), path);
}
 
Example 4
Source Project: hadoop   File: ContainerLaunch.java    License: Apache License 2.0 5 votes vote down vote up
public final void symlink(Path src, Path dst) throws IOException {
  if (!src.isAbsolute()) {
    throw new IOException("Source must be absolute");
  }
  if (dst.isAbsolute()) {
    throw new IOException("Destination must be relative");
  }
  if (dst.toUri().getPath().indexOf('/') != -1) {
    mkdir(dst.getParent());
  }
  link(src, dst);
}
 
Example 5
Source Project: ignite   File: HadoopRawLocalFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Converts Hadoop path to local path.
 *
 * @param path Hadoop path.
 * @return Local path.
 */
File convert(Path path) {
    checkPath(path);

    if (path.isAbsolute())
        return new File(path.toUri().getPath());

    return new File(getWorkingDirectory().toUri().getPath(), path.toUri().getPath());
}
 
Example 6
Source Project: big-c   File: NativeAzureFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the absolute version of the path (fully qualified).
 * This is public for testing purposes.
 *
 * @param path
 * @return fully qualified path
 */
@VisibleForTesting
public Path makeAbsolute(Path path) {
  if (path.isAbsolute()) {
    return path;
  }
  return new Path(workingDir, path);
}
 
Example 7
/**
 * Makes path absolute
 *
 * @param path path to file
 * @return absolute path
 */
protected Path makeAbsolute(Path path) {
  if (path.isAbsolute()) {
    return path;
  }
  return new Path(workingDir, path);
}
 
Example 8
Source Project: hadoop   File: NativeAzureFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Get the absolute version of the path (fully qualified).
 * This is public for testing purposes.
 *
 * @param path
 * @return fully qualified path
 */
@VisibleForTesting
public Path makeAbsolute(Path path) {
  if (path.isAbsolute()) {
    return path;
  }
  return new Path(workingDir, path);
}
 
Example 9
@Override
public Path getAbsoluteTestRootPath(FileSystem fSys) {
  Path testRootPath = new Path(TEST_ROOT_DIR);
  if (testRootPath.isAbsolute()) {
    return testRootPath;
  } else {
    return new Path(fSys.getWorkingDirectory(), TEST_ROOT_DIR);
  }
}
 
Example 10
Source Project: big-c   File: NativeS3FileSystem.java    License: Apache License 2.0 5 votes vote down vote up
private static String pathToKey(Path path) {
  if (path.toUri().getScheme() != null && path.toUri().getPath().isEmpty()) {
    // allow uris without trailing slash after bucket to refer to root,
    // like s3n://mybucket
    return "";
  }
  if (!path.isAbsolute()) {
    throw new IllegalArgumentException("Path must be absolute: " + path);
  }
  String ret = path.toUri().getPath().substring(1); // remove initial slash
  if (ret.endsWith("/") && (ret.indexOf("/") != ret.length() - 1)) {
    ret = ret.substring(0, ret.length() -1);
}
  return ret;
}
 
Example 11
Source Project: kylin   File: KylinConfigBase.java    License: Apache License 2.0 5 votes vote down vote up
public String getMetastoreBigCellHdfsDirectory() {

        if (cachedBigCellDirectory != null)
            return cachedBigCellDirectory;

        String root = getOptional("kylin.env.hdfs-metastore-bigcell-dir");

        if (root == null) {
            return getJdbcHdfsWorkingDirectory();
        }

        Path path = new Path(root);
        if (!path.isAbsolute())
            throw new IllegalArgumentException(
                    "kylin.env.hdfs-metastore-bigcell-dir must be absolute, but got " + root);

        // make sure path is qualified
        try {
            FileSystem fs = HadoopUtil.getReadFileSystem();
            path = fs.makeQualified(path);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        root = new Path(path, StringUtils.replaceChars(getMetadataUrlPrefix(), ':', '-')).toString();

        if (!root.endsWith("/"))
            root += "/";

        cachedBigCellDirectory = root;
        if (cachedBigCellDirectory.startsWith(FILE_SCHEME)) {
            cachedBigCellDirectory = cachedBigCellDirectory.replace(FILE_SCHEME, "file://");
        } else if (cachedBigCellDirectory.startsWith(MAPRFS_SCHEME)) {
            cachedBigCellDirectory = cachedBigCellDirectory.replace(MAPRFS_SCHEME, "maprfs://");
        }

        return cachedBigCellDirectory;
    }
 
Example 12
Source Project: big-c   File: ChRootedFileSystem.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @param path
 * @return  full path including the chroot 
 */
protected Path fullPath(final Path path) {
  super.checkPath(path);
  return path.isAbsolute() ? 
      new Path((chRootPathPart.isRoot() ? "" : chRootPathPartString)
          + path.toUri().getPath()) :
      new Path(chRootPathPartString + workingDir.toUri().getPath(), path);
}
 
Example 13
Source Project: spork   File: LoadFunc.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Construct the absolute path from the file location and the current
 * directory. The current directory is either of the form 
 * {code}hdfs://<nodename>:<nodeport>/<directory>{code} in Hadoop 
 * MapReduce mode, or of the form 
 * {code}file:///<directory>{code} in Hadoop local mode.
 * 
 * @param location the location string specified in the load statement
 * @param curDir the current file system directory
 * @return the absolute path of file in the file system
 * @throws FrontendException if the scheme of the location is incompatible
 *         with the scheme of the file system
 */
public static String getAbsolutePath(String location, Path curDir) 
        throws FrontendException {
    
    if (location == null || curDir == null) {
        throw new FrontendException(
                "location: " + location + " curDir: " + curDir);
    }

    URI fsUri = curDir.toUri();
    String fsScheme = fsUri.getScheme();
    if (fsScheme == null) {
        throw new FrontendException("curDir: " + curDir);           
    }
    
    fsScheme = fsScheme.toLowerCase();
    String authority = fsUri.getAuthority();
    if(authority == null) {
        authority = "";
    }
    Path rootDir = new Path(fsScheme, authority, "/");
    
    ArrayList<String> pathStrings = new ArrayList<String>();
    
    String[] fnames = getPathStrings(location);
    for (String fname: fnames) {
        // remove leading/trailing whitespace(s)
        fname = fname.trim();
        Path p = new Path(fname);
        URI uri = p.toUri();
        // if the supplied location has a scheme (i.e. uri is absolute) or 
        // an absolute path, just use it.
        if(! (uri.isAbsolute() || p.isAbsolute())) {
            String scheme = uri.getScheme();
            if (scheme != null) {
                scheme = scheme.toLowerCase();
            }
            
            if (scheme != null && !scheme.equals(fsScheme)) {
                throw new FrontendException("Incompatible file URI scheme: "
                        + scheme + " : " + fsScheme);               
            }            
            String path = uri.getPath();
        
            fname = (p.isAbsolute()) ? 
                        new Path(rootDir, path).toString() : 
                            new Path(curDir, path).toString();
        }
        fname = fname.replaceFirst("^file:/([^/])", "file:///$1");
        // remove the trailing /
        fname = fname.replaceFirst("/$", "");
        pathStrings.add(fname);
    }

    return join(pathStrings, ",");
}
 
Example 14
Source Project: hadoop-gpu   File: NativeS3FileSystem.java    License: Apache License 2.0 4 votes vote down vote up
private static String pathToKey(Path path) {
  if (!path.isAbsolute()) {
    throw new IllegalArgumentException("Path must be absolute: " + path);
  }
  return path.toUri().getPath().substring(1); // remove initial slash
}
 
Example 15
Source Project: RDFS   File: NativeS3FileSystem.java    License: Apache License 2.0 4 votes vote down vote up
private static String pathToKey(Path path) {
  if (!path.isAbsolute()) {
    throw new IllegalArgumentException("Path must be absolute: " + path);
  }
  return path.toUri().getPath().substring(1); // remove initial slash
}
 
Example 16
Source Project: big-c   File: Jets3tFileSystemStore.java    License: Apache License 2.0 4 votes vote down vote up
private String pathToKey(Path path) {
  if (!path.isAbsolute()) {
    throw new IllegalArgumentException("Path must be absolute: " + path);
  }
  return path.toUri().getPath();
}
 
Example 17
Source Project: hadoop-gpu   File: KosmosFileSystem.java    License: Apache License 2.0 4 votes vote down vote up
private Path makeAbsolute(Path path) {
if (path.isAbsolute()) {
    return path;
}
return new Path(workingDir, path);
   }
 
Example 18
Source Project: hadoop-gpu   File: S3FileSystem.java    License: Apache License 2.0 4 votes vote down vote up
private Path makeAbsolute(Path path) {
  if (path.isAbsolute()) {
    return path;
  }
  return new Path(workingDir, path);
}
 
Example 19
Source Project: big-c   File: S3FileSystem.java    License: Apache License 2.0 4 votes vote down vote up
private Path makeAbsolute(Path path) {
  if (path.isAbsolute()) {
    return path;
  }
  return new Path(workingDir, path);
}
 
Example 20
Source Project: RDFS   File: MigrationTool.java    License: Apache License 2.0 4 votes vote down vote up
private String pathToKey(Path path) {
  if (!path.isAbsolute()) {
    throw new IllegalArgumentException("Path must be absolute: " + path);
  }
  return urlEncode(path.toUri().getPath());
}