Search in sources :

Example 21 with CreateFileOptions

use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.

the class PermissionCheckTest method verifyCreateFile.

private void verifyCreateFile(TestUser user, String path, boolean recursive) throws Exception {
    try (SetAndRestoreAuthenticatedUser u = new SetAndRestoreAuthenticatedUser(user.getUser())) {
        CreateFileOptions options = CreateFileOptions.defaults().setRecursive(recursive).setOwner(SecurityUtils.getOwnerFromThriftClient()).setGroup(SecurityUtils.getGroupFromThriftClient()).setPersisted(true);
        long fileId = mFileSystemMaster.createFile(new AlluxioURI(path), options);
        FileInfo fileInfo = mFileSystemMaster.getFileInfo(fileId);
        String[] pathComponents = path.split("/");
        Assert.assertEquals(pathComponents[pathComponents.length - 1], fileInfo.getName());
        Assert.assertEquals(user.getUser(), fileInfo.getOwner());
    }
}
Also used : SetAndRestoreAuthenticatedUser(alluxio.SetAndRestoreAuthenticatedUser) CreateFileOptions(alluxio.master.file.options.CreateFileOptions) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI)

Example 22 with CreateFileOptions

use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.

the class FileSystemMaster method loadFileMetadataAndJournal.

/**
   * Loads metadata for the file identified by the given path from UFS into Alluxio.
   *
   * @param inodePath the path for which metadata should be loaded
   * @param resolution the UFS resolution of path
   * @param options the load metadata options
   * @param journalContext the journal context
   * @throws BlockInfoException if an invalid block size is encountered
   * @throws FileDoesNotExistException if there is no UFS path
   * @throws InvalidPathException if invalid path is encountered
   * @throws AccessControlException if permission checking fails or permission setting fails
   * @throws FileAlreadyCompletedException if the file is already completed
   * @throws InvalidFileSizeException if invalid file size is encountered
   * @throws IOException if an I/O error occurs
   */
private void loadFileMetadataAndJournal(LockedInodePath inodePath, MountTable.Resolution resolution, LoadMetadataOptions options, JournalContext journalContext) throws BlockInfoException, FileDoesNotExistException, InvalidPathException, AccessControlException, FileAlreadyCompletedException, InvalidFileSizeException, IOException {
    if (inodePath.fullPathExists()) {
        return;
    }
    AlluxioURI ufsUri = resolution.getUri();
    UnderFileSystem ufs = resolution.getUfs();
    long ufsBlockSizeByte = ufs.getBlockSizeByte(ufsUri.toString());
    long ufsLength = ufs.getFileSize(ufsUri.toString());
    // Metadata loaded from UFS has no TTL set.
    CreateFileOptions createFileOptions = CreateFileOptions.defaults().setBlockSizeBytes(ufsBlockSizeByte).setRecursive(options.isCreateAncestors()).setMetadataLoad(true).setPersisted(true);
    String ufsOwner = ufs.getOwner(ufsUri.toString());
    String ufsGroup = ufs.getGroup(ufsUri.toString());
    short ufsMode = ufs.getMode(ufsUri.toString());
    Mode mode = new Mode(ufsMode);
    if (resolution.getShared()) {
        mode.setOtherBits(mode.getOtherBits().or(mode.getOwnerBits()));
    }
    createFileOptions = createFileOptions.setOwner(ufsOwner).setGroup(ufsGroup).setMode(mode);
    try {
        createFileAndJournal(inodePath, createFileOptions, journalContext);
        CompleteFileOptions completeOptions = CompleteFileOptions.defaults().setUfsLength(ufsLength);
        completeFileAndJournal(inodePath, completeOptions, journalContext);
    } catch (FileAlreadyExistsException e) {
        LOG.error("FileAlreadyExistsException seen unexpectedly.", e);
        throw new RuntimeException(e);
    }
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) FileAlreadyExistsException(alluxio.exception.FileAlreadyExistsException) Mode(alluxio.security.authorization.Mode) CompleteFileOptions(alluxio.master.file.options.CompleteFileOptions) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 23 with CreateFileOptions

use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.

the class FileSystemMasterIntegrationTest method lastModificationTimeCreateFile.

@Test
public void lastModificationTimeCreateFile() throws Exception {
    mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryOptions.defaults());
    long opTimeMs = TEST_TIME_MS;
    CreateFileOptions options = CreateFileOptions.defaults().setOperationTimeMs(opTimeMs);
    try (LockedInodePath inodePath = mInodeTree.lockInodePath(new AlluxioURI("/testFolder/testFile"), InodeTree.LockMode.WRITE)) {
        mFsMaster.createFileInternal(inodePath, options);
    }
    FileInfo folderInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder")));
    Assert.assertEquals(opTimeMs, folderInfo.getLastModificationTimeMs());
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) LockedInodePath(alluxio.master.file.meta.LockedInodePath) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 24 with CreateFileOptions

use of alluxio.master.file.options.CreateFileOptions in project alluxio by Alluxio.

the class FileSystemMasterIntegrationTest method ttlExpiredCreateFileWithFreeActionTest.

@Test
public void ttlExpiredCreateFileWithFreeActionTest() throws Exception {
    mFsMaster.createDirectory(new AlluxioURI("/testFolder"), CreateDirectoryOptions.defaults());
    long ttl = 1;
    CreateFileOptions options = CreateFileOptions.defaults().setPersisted(true).setTtl(ttl).setTtlAction(TtlAction.FREE);
    long fileId = mFsMaster.createFile(new AlluxioURI("/testFolder/testFile1"), options);
    FileInfo folderInfo = mFsMaster.getFileInfo(mFsMaster.getFileId(new AlluxioURI("/testFolder/testFile1")));
    Assert.assertEquals(fileId, folderInfo.getFileId());
    Assert.assertEquals(ttl, folderInfo.getTtl());
    Assert.assertEquals(TtlAction.FREE, folderInfo.getTtlAction());
    // Sleep for the ttl expiration.
    CommonUtils.sleepMs(2 * TTL_CHECKER_INTERVAL_MS);
    HeartbeatScheduler.await(HeartbeatContext.MASTER_TTL_CHECK, 10, TimeUnit.SECONDS);
    HeartbeatScheduler.schedule(HeartbeatContext.MASTER_TTL_CHECK);
    HeartbeatScheduler.await(HeartbeatContext.MASTER_TTL_CHECK, 10, TimeUnit.SECONDS);
    FileInfo fileInfo = mFsMaster.getFileInfo(fileId);
    Assert.assertEquals(Constants.NO_TTL, fileInfo.getTtl());
    Assert.assertEquals(TtlAction.DELETE, fileInfo.getTtlAction());
}
Also used : CreateFileOptions(alluxio.master.file.options.CreateFileOptions) FileInfo(alluxio.wire.FileInfo) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Aggregations

CreateFileOptions (alluxio.master.file.options.CreateFileOptions)24 Test (org.junit.Test)20 AlluxioURI (alluxio.AlluxioURI)13 FileInfo (alluxio.wire.FileInfo)9 CreateDirectoryOptions (alluxio.master.file.options.CreateDirectoryOptions)4 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)3 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)3 LockedInodePath (alluxio.master.file.meta.LockedInodePath)2 Mode (alluxio.security.authorization.Mode)2 UnderFileSystem (alluxio.underfs.UnderFileSystem)2 ArrayList (java.util.ArrayList)2 SetAndRestoreAuthenticatedUser (alluxio.SetAndRestoreAuthenticatedUser)1 BlockInfoException (alluxio.exception.BlockInfoException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 CompleteFileOptions (alluxio.master.file.options.CompleteFileOptions)1 RenameOptions (alluxio.master.file.options.RenameOptions)1 MkdirsOptions (alluxio.underfs.options.MkdirsOptions)1 HashSet (java.util.HashSet)1