Search in sources :

Example 41 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class LineageMaster method reinitializeFile.

/**
   * Reinitializes the file when the file is lost or not completed.
   *
   * @param path the path to the file
   * @param blockSizeBytes the block size
   * @param ttl the TTL
   * @param ttlAction action to perform on ttl expiry
   * @return the id of the reinitialized file when the file is lost or not completed, -1 otherwise
   * @throws InvalidPathException the file path is invalid
   * @throws LineageDoesNotExistException when the file does not exist
   * @throws AccessControlException if permission checking fails
   * @throws FileDoesNotExistException if the path does not exist
   */
public synchronized long reinitializeFile(String path, long blockSizeBytes, long ttl, TtlAction ttlAction) throws InvalidPathException, LineageDoesNotExistException, AccessControlException, FileDoesNotExistException {
    long fileId = mFileSystemMaster.getFileId(new AlluxioURI(path));
    FileInfo fileInfo;
    try {
        fileInfo = mFileSystemMaster.getFileInfo(fileId);
        if (!fileInfo.isCompleted() || mFileSystemMaster.getLostFiles().contains(fileId)) {
            LOG.info("Recreate the file {} with block size of {} bytes", path, blockSizeBytes);
            return mFileSystemMaster.reinitializeFile(new AlluxioURI(path), blockSizeBytes, ttl, ttlAction);
        }
    } catch (FileDoesNotExistException e) {
        throw new LineageDoesNotExistException(ExceptionMessage.MISSING_REINITIALIZE_FILE.getMessage(path));
    }
    return -1;
}
Also used : FileDoesNotExistException(alluxio.exception.FileDoesNotExistException) FileInfo(alluxio.wire.FileInfo) LineageDoesNotExistException(alluxio.exception.LineageDoesNotExistException) AlluxioURI(alluxio.AlluxioURI)

Example 42 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class FileSystemMasterTest method ttlFileDelete.

/**
   * Tests that an exception is in the
   * {@link FileSystemMaster#createFile(AlluxioURI, CreateFileOptions)} with a TTL set in the
   * {@link CreateFileOptions} after the TTL check was done once.
   */
@Test
public void ttlFileDelete() throws Exception {
    CreateFileOptions options = CreateFileOptions.defaults().setBlockSizeBytes(Constants.KB).setRecursive(true).setTtl(0);
    long fileId = mFileSystemMaster.createFile(NESTED_FILE_URI, options);
    FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
    Assert.assertEquals(fileInfo.getFileId(), fileId);
    HeartbeatScheduler.execute(HeartbeatContext.MASTER_TTL_CHECK);
    mThrown.expect(FileDoesNotExistException.class);
    mFileSystemMaster.getFileInfo(fileId);
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) FileInfo(alluxio.wire.FileInfo) Test(org.junit.Test)

Example 43 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class PermissionCheckTest method verifyRename.

private void verifyRename(TestUser user, String srcPath, String dstPath) throws Exception {
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(user.getUser())) {
        String fileOwner = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(srcPath))).getOwner();
        mFileSystemMaster.rename(new AlluxioURI(srcPath), new AlluxioURI(dstPath), RenameOptions.defaults());
        Assert.assertEquals(-1, mFileSystemMaster.getFileId(new AlluxioURI(srcPath)));
        FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(dstPath)));
        String[] pathComponents = dstPath.split("/");
        Assert.assertEquals(pathComponents[pathComponents.length - 1], fileInfo.getName());
        Assert.assertEquals(fileOwner, fileInfo.getOwner());
    }
}
Also used : SetAndRestoreAuthenticatedUser(alluxio.SetAndRestoreAuthenticatedUser) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI)

Example 44 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class PermissionCheckTest method verifySetAcl.

private void verifySetAcl(TestUser runUser, String path, String owner, String group, short mode, boolean recursive) throws Exception {
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(runUser.getUser())) {
        SetAttributeOptions options = SetAttributeOptions.defaults().setOwner(owner).setGroup(group).setMode(mode).setRecursive(recursive);
        mFileSystemMaster.setAttribute(new AlluxioURI(path), options);
    }
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(TEST_USER_ADMIN.getUser())) {
        FileInfo fileInfo = mFileSystemMaster.getFileInfo(mFileSystemMaster.getFileId(new AlluxioURI(path)));
        if (owner != null) {
            Assert.assertEquals(owner, fileInfo.getOwner());
        }
        if (group != null) {
            Assert.assertEquals(group, fileInfo.getGroup());
        }
        if (mode != -1) {
            Assert.assertEquals(mode, fileInfo.getMode());
        }
    }
}
Also used : SetAndRestoreAuthenticatedUser(alluxio.SetAndRestoreAuthenticatedUser) SetAttributeOptions(alluxio.master.file.options.SetAttributeOptions) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI)

Example 45 with FileInfo

use of alluxio.wire.FileInfo in project alluxio by Alluxio.

the class DefaultAsyncPersistHandlerTest method scheduleAsyncPersist.

@Test
public void scheduleAsyncPersist() 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))));
    Mockito.when(mFileSystemMaster.getFileBlockInfoList(path)).thenReturn(blockInfoList);
    Mockito.when(mFileSystemMaster.getFileId(path)).thenReturn(fileId);
    Mockito.when(mFileSystemMaster.getPath(fileId)).thenReturn(path);
    Mockito.when(mFileSystemMaster.getFileInfo(fileId)).thenReturn(new FileInfo().setLength(1).setCompleted(true));
    handler.scheduleAsyncPersistence(path);
    List<PersistFile> persistFiles = handler.pollFilesToPersist(workerId);
    Assert.assertEquals(1, persistFiles.size());
    Assert.assertEquals(Lists.newArrayList(blockId), persistFiles.get(0).getBlockIds());
}
Also used : PersistFile(alluxio.thrift.PersistFile) FileSystemMasterView(alluxio.master.file.meta.FileSystemMasterView) FileInfo(alluxio.wire.FileInfo) BlockInfo(alluxio.wire.BlockInfo) FileBlockInfo(alluxio.wire.FileBlockInfo) ArrayList(java.util.ArrayList) FileBlockInfo(alluxio.wire.FileBlockInfo) BlockLocation(alluxio.wire.BlockLocation) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

FileInfo (alluxio.wire.FileInfo)81 AlluxioURI (alluxio.AlluxioURI)60 Test (org.junit.Test)54 URIStatus (alluxio.client.file.URIStatus)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 CreateFileOptions (alluxio.master.file.options.CreateFileOptions)9 ArrayList (java.util.ArrayList)9 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 RestApiTest (alluxio.rest.RestApiTest)7 TestCase (alluxio.rest.TestCase)7 SetAndRestoreAuthenticatedUser (alluxio.SetAndRestoreAuthenticatedUser)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 FileSystemMaster (alluxio.master.file.FileSystemMaster)4 CreateOptions (alluxio.underfs.options.CreateOptions)4 OutputStream (java.io.OutputStream)4 InvalidPathException (alluxio.exception.InvalidPathException)3 FileSystemMasterView (alluxio.master.file.meta.FileSystemMasterView)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)3 FileBlockInfo (alluxio.wire.FileBlockInfo)3 IOException (java.io.IOException)3