use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class AbstractFileSystem method getFileStatus.
/**
* {@inheritDoc}
*
* If the file does not exist in Alluxio, query it from HDFS.
*/
@Override
public FileStatus getFileStatus(Path path) throws IOException {
LOG.debug("getFileStatus({})", path);
if (mStatistics != null) {
mStatistics.incrementReadOps(1);
}
AlluxioURI uri = getAlluxioPath(path);
URIStatus fileStatus;
try {
fileStatus = mFileSystem.getStatus(uri);
} catch (FileDoesNotExistException e) {
throw new FileNotFoundException(e.getMessage());
} catch (AlluxioException e) {
throw new IOException(e);
}
return new FileStatus(fileStatus.getLength(), fileStatus.isFolder(), getReplica(fileStatus), fileStatus.getBlockSizeBytes(), fileStatus.getLastModificationTimeMs(), fileStatus.getLastAccessTimeMs(), new FsPermission((short) fileStatus.getMode()), fileStatus.getOwner(), fileStatus.getGroup(), getFsPath(mAlluxioHeader, fileStatus));
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class PersistenceTest method waitUntilPersisted.
private void waitUntilPersisted(final AlluxioURI testFile) throws Exception {
// Persistence completion is asynchronous, so waiting is necessary.
CommonUtils.waitFor("async persistence is completed for file", () -> {
try {
FileInfo fileInfo = mFileSystemMaster.getFileInfo(testFile, GET_STATUS_CONTEXT);
return fileInfo.getPersistenceState().equals(PersistenceState.PERSISTED.toString());
} catch (FileDoesNotExistException | InvalidPathException | AccessControlException | IOException e) {
return false;
}
}, WaitForOptions.defaults().setTimeoutMs(30000));
FileInfo fileInfo = mFileSystemMaster.getFileInfo(testFile, GET_STATUS_CONTEXT);
Map<Long, PersistJob> persistJobs = getPersistJobs();
Assert.assertEquals(0, getPersistRequests().size());
// We update the file info before removing the persist job, so we must wait here.
CommonUtils.waitFor("persist jobs list to be empty", () -> persistJobs.isEmpty(), WaitForOptions.defaults().setTimeoutMs(5 * Constants.SECOND_MS));
Assert.assertEquals(PersistenceState.PERSISTED.toString(), fileInfo.getPersistenceState());
Assert.assertNotEquals(Constants.INVALID_UFS_FINGERPRINT, fileInfo.getUfsFingerprint());
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class DefaultAsyncPersistHandlerTest method persistenceFileAfterDeletion.
/**
* Tests persistence after deletion of files.
*/
@Test
public void persistenceFileAfterDeletion() throws Exception {
DefaultAsyncPersistHandler handler = new DefaultAsyncPersistHandler(new FileSystemMasterView(mFileSystemMaster));
AlluxioURI path = new AlluxioURI("/test");
long blockId = 0;
long workerId = 1;
long fileId = 2;
List<FileBlockInfo> blockInfoList = new ArrayList<>();
BlockLocation location = new BlockLocation().setWorkerId(workerId);
blockInfoList.add(new FileBlockInfo().setBlockInfo(new BlockInfo().setBlockId(blockId).setLocations(Lists.newArrayList(location))));
when(mFileSystemMaster.getFileBlockInfoList(path)).thenReturn(blockInfoList);
when(mFileSystemMaster.getFileId(path)).thenReturn(fileId);
when(mFileSystemMaster.getPath(fileId)).thenReturn(path);
when(mFileSystemMaster.getFileInfo(fileId)).thenReturn(new FileInfo().setLength(1).setCompleted(true));
handler.scheduleAsyncPersistence(path);
when(mFileSystemMaster.getFileInfo(fileId)).thenThrow(new FileDoesNotExistException("no file"));
List<PersistFile> persistFiles = handler.pollFilesToPersist(workerId);
assertEquals(0, persistFiles.size());
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMasterTest method listStatus.
@Test
public void listStatus() throws Exception {
final int files = 10;
List<FileInfo> infos;
List<String> filenames;
// Test files in root directory.
for (int i = 0; i < files; i++) {
createFileWithSingleBlock(ROOT_URI.join("file" + String.format("%05d", i)));
}
infos = mFileSystemMaster.listStatus(ROOT_URI, ListStatusContext.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.NEVER)));
assertEquals(files, infos.size());
// Copy out filenames to use List contains.
filenames = new ArrayList<>();
for (FileInfo info : infos) {
filenames.add(info.getPath());
}
// Compare all filenames.
for (int i = 0; i < files; i++) {
assertTrue(filenames.contains(ROOT_URI.join("file" + String.format("%05d", i)).toString()));
}
// Test single file.
createFileWithSingleBlock(ROOT_FILE_URI);
infos = mFileSystemMaster.listStatus(ROOT_FILE_URI, ListStatusContext.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.NEVER)));
assertEquals(1, infos.size());
assertEquals(ROOT_FILE_URI.getPath(), infos.get(0).getPath());
// Test files in nested directory.
for (int i = 0; i < files; i++) {
createFileWithSingleBlock(NESTED_URI.join("file" + String.format("%05d", i)));
}
infos = mFileSystemMaster.listStatus(NESTED_URI, ListStatusContext.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.NEVER)));
assertEquals(files, infos.size());
// Copy out filenames to use List contains.
filenames = new ArrayList<>();
for (FileInfo info : infos) {
filenames.add(info.getPath());
}
// Compare all filenames.
for (int i = 0; i < files; i++) {
assertTrue(filenames.contains(NESTED_URI.join("file" + String.format("%05d", i)).toString()));
}
// Test non-existent URIs.
try {
mFileSystemMaster.listStatus(NESTED_URI.join("DNE"), ListStatusContext.mergeFrom(ListStatusPOptions.newBuilder().setLoadMetadataType(LoadMetadataPType.NEVER)));
fail("listStatus() for a non-existent URI should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
}
use of alluxio.exception.FileDoesNotExistException in project alluxio by Alluxio.
the class FileSystemMasterTest method getPersistenceState.
/**
* Tests the {@link FileSystemMaster#getPersistenceState(long)} method.
*/
@Test
public void getPersistenceState() throws Exception {
AlluxioURI rootUri = new AlluxioURI("/");
long rootId = mFileSystemMaster.getFileId(rootUri);
assertEquals(PersistenceState.PERSISTED, mFileSystemMaster.getPersistenceState(rootId));
// get non-existent id
try {
mFileSystemMaster.getPersistenceState(rootId + 1234);
fail("getPath() for a non-existent id should fail.");
} catch (FileDoesNotExistException e) {
// Expected case.
}
}
Aggregations