Search in sources :

Example 81 with FileDoesNotExistException

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));
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileStatus(org.apache.hadoop.fs.FileStatus) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FsPermission(org.apache.hadoop.fs.permission.FsPermission) URIStatus(alluxio.client.file.URIStatus) AlluxioURI(alluxio.AlluxioURI) AlluxioException(alluxio.exception.AlluxioException)

Example 82 with FileDoesNotExistException

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());
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) AccessControlException(alluxio.exception.AccessControlException) IOException(java.io.IOException) InvalidPathException(alluxio.exception.InvalidPathException)

Example 83 with FileDoesNotExistException

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());
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileSystemMasterView(alluxio.master.file.meta.FileSystemMasterView) ArrayList(java.util.ArrayList) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation) PersistFile(alluxio.wire.PersistFile) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 84 with FileDoesNotExistException

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.
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Test(org.junit.Test)

Example 85 with FileDoesNotExistException

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.
    }
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

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