Search in sources :

Example 46 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class CpCommand method copyWildcardToLocal.

/**
 * Copies a list of files or directories specified by srcPaths from the Alluxio filesystem to
 * dstPath in the local filesystem. This method is used when the input path contains wildcards.
 *
 * @param srcPaths the list of files in the Alluxio filesystem
 * @param dstPath the {@link AlluxioURI} of the destination directory in the local filesystem
 */
private void copyWildcardToLocal(List<AlluxioURI> srcPaths, AlluxioURI dstPath) throws AlluxioException, IOException {
    File dstFile = new File(dstPath.getPath());
    if (dstFile.exists() && !dstFile.isDirectory()) {
        throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
    }
    if (!dstFile.exists()) {
        if (!dstFile.mkdirs()) {
            throw new IOException("Fail to create directory: " + dstPath);
        } else {
            System.out.println("Create directory: " + dstPath);
        }
    }
    List<String> errorMessages = new ArrayList<>();
    for (AlluxioURI srcPath : srcPaths) {
        try {
            File dstSubFile = new File(dstFile.getAbsoluteFile(), srcPath.getName());
            copyToLocal(srcPath, new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), dstSubFile.getPath()));
        } catch (IOException e) {
            errorMessages.add(e.getMessage());
        }
    }
    if (errorMessages.size() != 0) {
        throw new IOException(Joiner.on('\n').join(errorMessages));
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 47 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class CpCommand method copyWildcard.

/**
 * Copies a list of files or directories specified by srcPaths to the destination specified by
 * dstPath. This method is used when the original source path contains wildcards.
 *
 * @param srcPaths a list of files or directories in the Alluxio filesystem
 * @param dstPath the destination in the Alluxio filesystem
 * @param recursive indicates whether directories should be copied recursively
 */
private void copyWildcard(List<AlluxioURI> srcPaths, AlluxioURI dstPath, boolean recursive) throws AlluxioException, IOException {
    URIStatus dstStatus = null;
    try {
        dstStatus = mFileSystem.getStatus(dstPath);
    } catch (FileDoesNotExistException e) {
    // if the destination does not exist, it will be created
    }
    if (dstStatus != null && !dstStatus.isFolder()) {
        throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
    }
    if (dstStatus == null) {
        mFileSystem.createDirectory(dstPath);
        System.out.println("Created directory: " + dstPath);
    }
    List<String> errorMessages = new ArrayList<>();
    for (AlluxioURI srcPath : srcPaths) {
        try {
            copy(srcPath, new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), srcPath.getName())), recursive);
        } catch (AlluxioException | IOException e) {
            errorMessages.add(e.getMessage());
        }
    }
    if (errorMessages.size() != 0) {
        throw new IOException(Joiner.on('\n').join(errorMessages));
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) URIStatus(alluxio.client.file.URIStatus) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 48 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class PathTranslator method toAlluxioPath.

/**
 * Returns the corresponding alluxio path, for the specified ufs path.
 *
 * @param ufsPath the ufs path to translate
 * @return the corresponding alluxio path
 * @throws IOException if the ufs path is not mounted
 */
public String toAlluxioPath(String ufsPath) throws IOException {
    String suffix = ufsPath.endsWith("/") ? "/" : "";
    AlluxioURI ufsUri = new AlluxioURI(ufsPath);
    // first look for an exact match
    if (mPathMap.inverse().containsKey(ufsUri)) {
        AlluxioURI match = mPathMap.inverse().get(ufsUri);
        if (match.equals(ufsUri)) {
            // bypassed UFS path, return as is
            return ufsPath;
        }
        return checkAndAddSchemeAuthority(mPathMap.inverse().get(ufsUri)) + suffix;
    }
    // otherwise match by longest prefix
    BiMap.Entry<AlluxioURI, AlluxioURI> longestPrefix = null;
    int longestPrefixDepth = -1;
    for (BiMap.Entry<AlluxioURI, AlluxioURI> entry : mPathMap.entrySet()) {
        try {
            AlluxioURI valueUri = entry.getValue();
            if (valueUri.isAncestorOf(ufsUri) && valueUri.getDepth() > longestPrefixDepth) {
                longestPrefix = entry;
                longestPrefixDepth = valueUri.getDepth();
            }
        } catch (InvalidPathException e) {
            throw new IOException(e);
        }
    }
    if (longestPrefix == null) {
        // TODO(yuzhu): instead of throwing an exception, mount the path?
        throw new IOException(String.format("Failed to translate ufs path (%s). Mapping missing from translator", ufsPath));
    }
    if (longestPrefix.getKey().equals(longestPrefix.getValue())) {
        // return ufsPath if set the key and value to be same when bypass path.
        return ufsPath;
    }
    try {
        String difference = PathUtils.subtractPaths(ufsUri.getPath(), longestPrefix.getValue().getPath());
        AlluxioURI mappedUri = longestPrefix.getKey().join(difference);
        return checkAndAddSchemeAuthority(mappedUri) + suffix;
    } catch (InvalidPathException e) {
        throw new IOException(e);
    }
}
Also used : BiMap(com.google.common.collect.BiMap) HashBiMap(com.google.common.collect.HashBiMap) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Example 49 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class CephFSUnderFileSystem method createDirect.

@Override
public OutputStream createDirect(String path, CreateOptions options) throws IOException {
    path = stripPath(path);
    String parentPath;
    try {
        parentPath = PathUtils.getParent(path);
    } catch (InvalidPathException e) {
        throw new IOException("Invalid path " + path, e);
    }
    IOException te = null;
    RetryPolicy retryPolicy = new CountingRetry(MAX_TRY);
    while (retryPolicy.attempt()) {
        try {
            // support creating CephFS files with specified block size and replication.
            if (options.getCreateParent()) {
                if (mkdirs(parentPath, MkdirsOptions.defaults(mUfsConf)) && !isDirectory(parentPath)) {
                    throw new IOException(ExceptionMessage.PARENT_CREATION_FAILED.getMessage(path));
                }
            }
            int flags = CephMount.O_WRONLY | CephMount.O_CREAT | CephMount.O_TRUNC;
            short mode = options.getMode().toShort();
            int fd = openInternal(path, flags, mode);
            return new CephOutputStream(mMount, fd);
        } catch (IOException e) {
            LOG.warn("Retry count {} : {}", retryPolicy.getAttemptCount(), e.toString());
            te = e;
        }
    }
    throw te;
}
Also used : CountingRetry(alluxio.retry.CountingRetry) IOException(java.io.IOException) RetryPolicy(alluxio.retry.RetryPolicy) InvalidPathException(alluxio.exception.InvalidPathException)

Example 50 with InvalidPathException

use of alluxio.exception.InvalidPathException in project alluxio by Alluxio.

the class CpCommand method copyWildcardToLocal.

/**
   * Copies a list of files or directories specified by srcPaths from the Alluxio filesystem to
   * dstPath in the local filesystem. This method is used when the input path contains wildcards.
   *
   * @param srcPaths the list of files in the Alluxio filesystem
   * @param dstPath the {@link AlluxioURI} of the destination directory in the local filesystem
   * @throws AlluxioException when Alluxio exception occurs
   * @throws IOException when non-Alluxio exception occurs
   */
private void copyWildcardToLocal(List<AlluxioURI> srcPaths, AlluxioURI dstPath) throws AlluxioException, IOException {
    File dstFile = new File(dstPath.getPath());
    if (dstFile.exists() && !dstFile.isDirectory()) {
        throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
    }
    if (!dstFile.exists()) {
        if (!dstFile.mkdirs()) {
            throw new IOException("Fail to create directory: " + dstPath);
        } else {
            System.out.println("Create directory: " + dstPath);
        }
    }
    List<String> errorMessages = new ArrayList<>();
    for (AlluxioURI srcPath : srcPaths) {
        try {
            File dstSubFile = new File(dstFile.getAbsoluteFile(), srcPath.getName());
            copyToLocal(srcPath, new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), dstSubFile.getPath()));
        } catch (IOException e) {
            errorMessages.add(e.getMessage());
        }
    }
    if (errorMessages.size() != 0) {
        throw new IOException(Joiner.on('\n').join(errorMessages));
    }
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) File(java.io.File) InvalidPathException(alluxio.exception.InvalidPathException) AlluxioURI(alluxio.AlluxioURI)

Aggregations

InvalidPathException (alluxio.exception.InvalidPathException)82 AlluxioURI (alluxio.AlluxioURI)51 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)44 IOException (java.io.IOException)40 ArrayList (java.util.ArrayList)25 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)19 AccessControlException (alluxio.exception.AccessControlException)17 AlluxioException (alluxio.exception.AlluxioException)17 LockedInodePath (alluxio.master.file.meta.LockedInodePath)17 MountTable (alluxio.master.file.meta.MountTable)14 UnderFileSystem (alluxio.underfs.UnderFileSystem)14 Inode (alluxio.master.file.meta.Inode)12 MountInfo (alluxio.master.file.meta.options.MountInfo)11 BlockInfoException (alluxio.exception.BlockInfoException)10 UnavailableException (alluxio.exception.status.UnavailableException)9 LockResource (alluxio.resource.LockResource)9 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)8 InodeDirectory (alluxio.master.file.meta.InodeDirectory)8 Test (org.junit.Test)8 URIStatus (alluxio.client.file.URIStatus)7