Search in sources :

Example 6 with SetAttributeOptions

use of alluxio.master.file.options.SetAttributeOptions 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 7 with SetAttributeOptions

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

the class FileSystemMasterTest method ttlFileFreeReplay.

/**
   * Tests that TTL free of a file is not forgotten across restarts.
   */
@Test
public void ttlFileFreeReplay() throws Exception {
    long blockId = createFileWithSingleBlock(NESTED_FILE_URI);
    Assert.assertEquals(1, mBlockMaster.getBlockInfo(blockId).getLocations().size());
    // Set ttl & operation
    SetAttributeOptions options = SetAttributeOptions.defaults();
    options.setTtl(0);
    options.setTtlAction(TtlAction.FREE);
    mFileSystemMaster.setAttribute(NESTED_FILE_URI, options);
    // Simulate restart.
    stopServices();
    startServices();
    Command heartbeat = mBlockMaster.workerHeartbeat(mWorkerId1, ImmutableMap.of("MEM", (long) Constants.KB), ImmutableList.of(blockId), ImmutableMap.<String, List<Long>>of());
    // Verify the muted Free command on worker1
    Assert.assertEquals(new Command(CommandType.Nothing, ImmutableList.<Long>of()), heartbeat);
    Assert.assertEquals(0, mBlockMaster.getBlockInfo(blockId).getLocations().size());
}
Also used : SetAttributeOptions(alluxio.master.file.options.SetAttributeOptions) FileSystemCommand(alluxio.thrift.FileSystemCommand) Command(alluxio.thrift.Command) Test(org.junit.Test)

Example 8 with SetAttributeOptions

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

the class PermissionCheckTest method setStateSuccess.

@Test
public void setStateSuccess() throws Exception {
    // set unmask
    try (SetAndRestoreConfiguration c = new SetAndRestoreConfiguration(PropertyKey.SECURITY_AUTHORIZATION_PERMISSION_UMASK, "000")) {
        String file = PathUtils.concatPath(TEST_DIR_URI, "testState1");
        verifyCreateFile(TEST_USER_1, file, false);
        SetAttributeOptions expect = getNonDefaultSetState();
        SetAttributeOptions result = verifySetState(TEST_USER_2, file, expect);
        Assert.assertEquals(expect.getTtl(), result.getTtl());
        Assert.assertEquals(expect.getTtlAction(), result.getTtlAction());
        Assert.assertEquals(expect.getPinned(), result.getPinned());
    }
}
Also used : SetAttributeOptions(alluxio.master.file.options.SetAttributeOptions) SetAndRestoreConfiguration(alluxio.SetAndRestoreConfiguration) Test(org.junit.Test)

Example 9 with SetAttributeOptions

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

the class FileSystemMaster method freeAndJournal.

/**
   * Implements free operation.
   * <p>
   * This may write to the journal as free operation may change the pinned state of inodes.
   *
   * @param inodePath inode of the path to free
   * @param options options to free
   * @param journalContext the journal context
   * @throws FileDoesNotExistException if the file does not exist
   * @throws AccessControlException if permission checking fails
   * @throws InvalidPathException if the given path is invalid
   * @throws UnexpectedAlluxioException if the file or directory can not be freed
   */
private void freeAndJournal(LockedInodePath inodePath, FreeOptions options, JournalContext journalContext) throws FileDoesNotExistException, UnexpectedAlluxioException, AccessControlException, InvalidPathException {
    Inode<?> inode = inodePath.getInode();
    if (inode.isDirectory() && !options.isRecursive() && ((InodeDirectory) inode).getNumberOfChildren() > 0) {
        // inode is nonempty, and we don't free a nonempty directory unless recursive is true
        throw new UnexpectedAlluxioException(ExceptionMessage.CANNOT_FREE_NON_EMPTY_DIR.getMessage(mInodeTree.getPath(inode)));
    }
    long opTimeMs = System.currentTimeMillis();
    List<Inode<?>> freeInodes = new ArrayList<>();
    freeInodes.add(inode);
    try (InodeLockList lockList = mInodeTree.lockDescendants(inodePath, InodeTree.LockMode.WRITE)) {
        freeInodes.addAll(lockList.getInodes());
        TempInodePathForDescendant tempInodePath = new TempInodePathForDescendant(inodePath);
        // We go through each inode.
        for (int i = freeInodes.size() - 1; i >= 0; i--) {
            Inode<?> freeInode = freeInodes.get(i);
            if (freeInode.isFile()) {
                if (freeInode.getPersistenceState() != PersistenceState.PERSISTED) {
                    throw new UnexpectedAlluxioException(ExceptionMessage.CANNOT_FREE_NON_PERSISTED_FILE.getMessage(mInodeTree.getPath(freeInode)));
                }
                if (freeInode.isPinned()) {
                    if (!options.isForced()) {
                        throw new UnexpectedAlluxioException(ExceptionMessage.CANNOT_FREE_PINNED_FILE.getMessage(mInodeTree.getPath(freeInode)));
                    }
                    // the path to inode for getPath should already be locked.
                    tempInodePath.setDescendant(freeInode, mInodeTree.getPath(freeInode));
                    SetAttributeOptions setAttributeOptions = SetAttributeOptions.defaults().setRecursive(false).setPinned(false);
                    setAttributeInternal(tempInodePath, false, opTimeMs, setAttributeOptions);
                    journalSetAttribute(tempInodePath, opTimeMs, setAttributeOptions, journalContext);
                }
                // Remove corresponding blocks from workers.
                mBlockMaster.removeBlocks(((InodeFile) freeInode).getBlockIds(), false);
            }
        }
    }
    Metrics.FILES_FREED.inc(freeInodes.size());
}
Also used : SetAttributeOptions(alluxio.master.file.options.SetAttributeOptions) InodeDirectory(alluxio.master.file.meta.InodeDirectory) Inode(alluxio.master.file.meta.Inode) TempInodePathForDescendant(alluxio.master.file.meta.TempInodePathForDescendant) InodeLockList(alluxio.master.file.meta.InodeLockList) UnexpectedAlluxioException(alluxio.exception.UnexpectedAlluxioException) ArrayList(java.util.ArrayList)

Aggregations

SetAttributeOptions (alluxio.master.file.options.SetAttributeOptions)9 Test (org.junit.Test)6 Command (alluxio.thrift.Command)4 FileSystemCommand (alluxio.thrift.FileSystemCommand)4 SetAndRestoreConfiguration (alluxio.SetAndRestoreConfiguration)2 CreateDirectoryOptions (alluxio.master.file.options.CreateDirectoryOptions)2 AlluxioURI (alluxio.AlluxioURI)1 SetAndRestoreAuthenticatedUser (alluxio.SetAndRestoreAuthenticatedUser)1 UnexpectedAlluxioException (alluxio.exception.UnexpectedAlluxioException)1 Inode (alluxio.master.file.meta.Inode)1 InodeDirectory (alluxio.master.file.meta.InodeDirectory)1 InodeLockList (alluxio.master.file.meta.InodeLockList)1 LockedInodePath (alluxio.master.file.meta.LockedInodePath)1 TempInodePathForDescendant (alluxio.master.file.meta.TempInodePathForDescendant)1 FileInfo (alluxio.wire.FileInfo)1 ArrayList (java.util.ArrayList)1