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.
}
}
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));
}
}
}
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));
}
}
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);
}
}
}
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");
}
Aggregations