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());
}
}
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);
}
}
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());
}
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());
}
Aggregations