use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class LineageMasterTest method createLineageWithNonExistingFile.
/**
* Tests that an exception is thrown when trying to create a lineage for a non-existing file via
* the {@link LineageMaster#createLineage(List, List, Job)} method.
*/
@Test
public void createLineageWithNonExistingFile() throws Exception {
AlluxioURI missingInput = new AlluxioURI("/test1");
Mockito.when(mFileSystemMaster.getFileId(missingInput)).thenReturn(IdUtils.INVALID_FILE_ID);
mLineageMaster.start(true);
// try catch block used because ExpectedExceptionRule conflicts with Powermock
try {
mLineageMaster.createLineage(Lists.newArrayList(missingInput), Lists.newArrayList(new AlluxioURI("/test2")), mJob);
Assert.fail();
} catch (FileDoesNotExistException e) {
Assert.assertEquals(ExceptionMessage.LINEAGE_INPUT_FILE_NOT_EXIST.getMessage("/test1"), e.getMessage());
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method getattr.
/**
* Retrieves file attributes.
*
* @param path The path on the FS of the file
* @param stat FUSE data structure to fill with file attrs
* @return 0 on success, negative value on error
*/
@Override
public int getattr(String path, FileStat stat) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
LOG.trace("getattr({}) [Alluxio: {}]", path, turi);
try {
if (!mFileSystem.exists(turi)) {
return -ErrorCodes.ENOENT();
}
final URIStatus status = mFileSystem.getStatus(turi);
stat.st_size.set(status.getLength());
final long ctime_sec = status.getLastModificationTimeMs() / 1000;
//keeps only the "residual" nanoseconds not caputred in
// citme_sec
final long ctime_nsec = (status.getLastModificationTimeMs() % 1000) * 1000;
stat.st_ctim.tv_sec.set(ctime_sec);
stat.st_ctim.tv_nsec.set(ctime_nsec);
stat.st_mtim.tv_sec.set(ctime_sec);
stat.st_mtim.tv_nsec.set(ctime_nsec);
// TODO(andreareale): understand how to map FileInfo#getOwner()
// and FileInfo#getGroup() to UIDs and GIDs of the node
// where alluxio-fuse is mounted.
// While this is not done, just use uid and gid of the user
// running alluxio-fuse.
stat.st_uid.set(UID_AND_GID[0]);
stat.st_gid.set(UID_AND_GID[1]);
final int mode;
if (status.isFolder()) {
mode = FileStat.S_IFDIR;
} else {
mode = FileStat.S_IFREG;
}
stat.st_mode.set(mode);
} catch (InvalidPathException e) {
LOG.debug("Invalid path {}", path, e);
return -ErrorCodes.ENOENT();
} catch (FileDoesNotExistException e) {
LOG.debug("File does not exist {}", path, e);
return -ErrorCodes.ENOENT();
} catch (IOException e) {
LOG.error("IOException on {}", path, e);
return -ErrorCodes.EIO();
} catch (AlluxioException e) {
LOG.error("AlluxioException on {}", path, e);
return -ErrorCodes.EFAULT();
} catch (Throwable e) {
LOG.error("Unexpected exception on {}", path, e);
return -ErrorCodes.EFAULT();
}
return 0;
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method rmInternal.
/**
* Convenience internal method to remove files or directories.
*
* @param path The path to remove
* @param mustBeFile When true, returns an error when trying to
* remove a directory
* @return 0 on success, a negative value on error
*/
private int rmInternal(String path, boolean mustBeFile) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
try {
if (!mFileSystem.exists(turi)) {
LOG.error("File {} does not exist", turi);
return -ErrorCodes.ENOENT();
}
final URIStatus status = mFileSystem.getStatus(turi);
if (mustBeFile && status.isFolder()) {
LOG.error("File {} is a directory", turi);
return -ErrorCodes.EISDIR();
}
mFileSystem.delete(turi);
} catch (FileDoesNotExistException e) {
LOG.debug("File does not exist {}", path, e);
return -ErrorCodes.ENOENT();
} catch (IOException e) {
LOG.error("IOException on {}", path, e);
return -ErrorCodes.EIO();
} catch (AlluxioException e) {
LOG.error("AlluxioException on {}", path, e);
return -ErrorCodes.EFAULT();
} catch (Throwable e) {
LOG.error("Unexpected exception on {}", path, e);
return -ErrorCodes.EFAULT();
}
return 0;
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method readdir.
/**
* Reads the contents of a directory.
*
* @param path The FS path of the directory
* @param buff The FUSE buffer to fill
* @param filter FUSE filter
* @param offset Ignored in alluxio-fuse
* @param fi FileInfo data structure kept by FUSE
* @return 0 on success, a negative value on error
*/
@Override
public int readdir(String path, Pointer buff, FuseFillDir filter, @off_t long offset, FuseFileInfo fi) {
final AlluxioURI turi = mPathResolverCache.getUnchecked(path);
LOG.trace("readdir({}) [Alluxio: {}]", path, turi);
try {
if (!mFileSystem.exists(turi)) {
return -ErrorCodes.ENOENT();
}
final URIStatus status = mFileSystem.getStatus(turi);
if (!status.isFolder()) {
return -ErrorCodes.ENOTDIR();
}
final List<URIStatus> ls = mFileSystem.listStatus(turi);
// standard . and .. entries
filter.apply(buff, ".", null, 0);
filter.apply(buff, "..", null, 0);
for (final URIStatus file : ls) {
filter.apply(buff, file.getName(), null, 0);
}
} catch (FileDoesNotExistException e) {
LOG.debug("File does not exist {}", path, e);
return -ErrorCodes.ENOENT();
} catch (InvalidPathException e) {
LOG.debug("Invalid path {}", path, e);
return -ErrorCodes.ENOENT();
} catch (IOException e) {
LOG.error("IOException on {}", path, e);
return -ErrorCodes.EIO();
} catch (AlluxioException e) {
LOG.error("AlluxioException on {}", path, e);
return -ErrorCodes.EFAULT();
} catch (Throwable e) {
LOG.error("Unexpected exception on {}", path, e);
return -ErrorCodes.EFAULT();
}
return 0;
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class AlluxioFuseFileSystem method rename.
/**
* Renames a path.
*
* @param oldPath the source path in the FS
* @param newPath the destination path in the FS
* @return 0 on success, a negative value on error
*/
@Override
public int rename(String oldPath, String newPath) {
final AlluxioURI oldUri = mPathResolverCache.getUnchecked(oldPath);
final AlluxioURI newUri = mPathResolverCache.getUnchecked(newPath);
LOG.trace("rename({}, {}) [Alluxio: {}, {}]", oldPath, newPath, oldUri, newUri);
try {
if (!mFileSystem.exists(oldUri)) {
LOG.error("File {} does not exist", oldPath);
return -ErrorCodes.ENOENT();
} else {
mFileSystem.rename(oldUri, newUri);
}
} catch (FileDoesNotExistException e) {
LOG.debug("File {} does not exist", oldPath);
return -ErrorCodes.ENOENT();
} catch (IOException e) {
LOG.error("IOException while moving {} to {}", oldPath, newPath, e);
return -ErrorCodes.EIO();
} catch (AlluxioException e) {
LOG.error("Exception while moving {} to {}", oldPath, newPath, e);
return -ErrorCodes.EFAULT();
} catch (Throwable e) {
LOG.error("Unexpected exception on mv {} {}", oldPath, newPath, e);
return -ErrorCodes.EFAULT();
}
return 0;
}
Aggregations