Search in sources :

Example 61 with FileDoesNotExistException

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

the class FileSystemMasterTest method renameToNonExistentParent.

@Test
public void renameToNonExistentParent() throws Exception {
    CreateFileContext context = CreateFileContext.mergeFrom(CreateFilePOptions.newBuilder().setBlockSizeBytes(Constants.KB).setRecursive(true));
    mFileSystemMaster.createFile(NESTED_URI, context);
    try {
        mFileSystemMaster.rename(NESTED_URI, new AlluxioURI("/testDNE/b"), RenameContext.defaults());
        fail("Rename to a non-existent parent path should not succeed.");
    } catch (FileDoesNotExistException e) {
    // Expected case.
    }
}
Also used : CreateFileContext(alluxio.master.file.contexts.CreateFileContext) FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 62 with FileDoesNotExistException

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

the class CpCommand method copy.

/**
 * Copies a file or a directory in the Alluxio filesystem.
 *
 * @param srcPath the source {@link AlluxioURI} (could be a file or a directory)
 * @param dstPath the {@link AlluxioURI} of the destination path in the Alluxio filesystem
 * @param recursive indicates whether directories should be copied recursively
 */
private void copy(AlluxioURI srcPath, AlluxioURI dstPath, boolean recursive) throws AlluxioException, IOException {
    URIStatus srcStatus = mFileSystem.getStatus(srcPath);
    URIStatus dstStatus = null;
    try {
        dstStatus = mFileSystem.getStatus(dstPath);
    } catch (FileDoesNotExistException e) {
    // if the destination does not exist, it will be created
    }
    if (!srcStatus.isFolder()) {
        if (dstStatus != null && dstStatus.isFolder()) {
            dstPath = new AlluxioURI(PathUtils.concatPath(dstPath.getPath(), srcPath.getName()));
        }
        copyFile(srcPath, dstPath);
    } else {
        if (!recursive) {
            throw new IOException(srcPath.getPath() + " is a directory," + " to copy it please use \"cp -R/-r/--recursive <src> <dst>\"");
        }
        List<URIStatus> statuses;
        statuses = mFileSystem.listStatus(srcPath);
        if (dstStatus != null) {
            if (!dstStatus.isFolder()) {
                throw new InvalidPathException(ExceptionMessage.DESTINATION_CANNOT_BE_FILE.getMessage());
            }
            // subdirectory of the destination
            if (srcStatus.isFolder()) {
                dstPath = new AlluxioURI(PathUtils.concatPath(dstPath.getPath(), srcPath.getName()));
                mFileSystem.createDirectory(dstPath);
                System.out.println("Created directory: " + dstPath);
            }
        }
        if (dstStatus == null) {
            mFileSystem.createDirectory(dstPath);
            System.out.println("Created directory: " + dstPath);
        }
        preserveAttributes(srcPath, dstPath);
        List<String> errorMessages = new ArrayList<>();
        for (URIStatus status : statuses) {
            try {
                copy(new AlluxioURI(srcPath.getScheme(), srcPath.getAuthority(), status.getPath()), new AlluxioURI(dstPath.getScheme(), dstPath.getAuthority(), PathUtils.concatPath(dstPath.getPath(), status.getName())), recursive);
            } catch (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)

Example 63 with FileDoesNotExistException

use of alluxio.exception.FileDoesNotExistException 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 64 with FileDoesNotExistException

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

the class CatCommand method runPlainPath.

@Override
protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
    URIStatus status = mFileSystem.getStatus(path);
    if (status.isFolder()) {
        throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path));
    }
    byte[] buf = new byte[Constants.MB];
    try (FileInStream is = mFileSystem.openFile(path)) {
        int read = is.read(buf);
        while (read != -1) {
            System.out.write(buf, 0, read);
            read = is.read(buf);
        }
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInStream(alluxio.client.file.FileInStream) URIStatus(alluxio.client.file.URIStatus)

Example 65 with FileDoesNotExistException

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

the class ChecksumCommand method runPlainPath.

@Override
protected void runPlainPath(AlluxioURI plainPath, CommandLine cl) throws AlluxioException, IOException {
    URIStatus status = mFileSystem.getStatus(plainPath);
    if (status.isFolder()) {
        throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(plainPath.getPath()));
    }
    String str = calculateChecksum(plainPath);
    System.out.println("md5sum: " + str + "\n");
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) URIStatus(alluxio.client.file.URIStatus)

Aggregations

FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)126 AlluxioURI (alluxio.AlluxioURI)90 InvalidPathException (alluxio.exception.InvalidPathException)42 IOException (java.io.IOException)39 URIStatus (alluxio.client.file.URIStatus)34 Test (org.junit.Test)31 AlluxioException (alluxio.exception.AlluxioException)26 ArrayList (java.util.ArrayList)26 LockedInodePath (alluxio.master.file.meta.LockedInodePath)22 AccessControlException (alluxio.exception.AccessControlException)19 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)14 Inode (alluxio.master.file.meta.Inode)14 FileInfo (alluxio.wire.FileInfo)14 BlockInfoException (alluxio.exception.BlockInfoException)13 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)10 UnavailableException (alluxio.exception.status.UnavailableException)9 BlockInfo (alluxio.wire.BlockInfo)9 FileBlockInfo (alluxio.wire.FileBlockInfo)9 DirectoryNotEmptyException (alluxio.exception.DirectoryNotEmptyException)8 InodeFile (alluxio.master.file.meta.InodeFile)7