Search in sources :

Example 21 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class OSSUnderStorageCluster method cleanup.

@Override
public void cleanup() throws IOException {
    UnderFileSystem ufs = UnderFileSystem.Factory.get(mBaseDir);
    ufs.deleteDirectory(mBaseDir, DeleteOptions.defaults().setRecursive(true));
    mBaseDir = PathUtils.concatPath(mOSSBucket, UUID.randomUUID());
}
Also used : UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 22 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class SwiftUnderStorageCluster method cleanup.

@Override
public void cleanup() throws IOException {
    String oldDir = mBaseDir;
    mBaseDir = PathUtils.concatPath(mSwiftContainer, UUID.randomUUID());
    UnderFileSystem ufs = UnderFileSystem.Factory.get(mBaseDir);
    if (!ufs.deleteDirectory(oldDir, DeleteOptions.defaults().setRecursive(true))) {
        throw new IOException(String.format("Unable to cleanup SwiftUnderFileSystem when deleting directory %s", oldDir));
    }
}
Also used : IOException(java.io.IOException) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 23 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class UnderFileSystemUtils method touch.

/**
   * Creates an empty file.
   *
   * @param path path to the file
   * @throws IOException if the file cannot be created
   */
public static void touch(final String path) throws IOException {
    UnderFileSystem ufs = UnderFileSystem.Factory.get(path);
    OutputStream os = ufs.create(path);
    os.close();
}
Also used : OutputStream(java.io.OutputStream) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 24 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class DefaultFileSystemMaster method setUfsAcl.

private void setUfsAcl(LockedInodePath inodePath) throws InvalidPathException, AccessControlException {
    Inode inode = inodePath.getInodeOrNull();
    checkUfsMode(inodePath.getUri(), OperationType.WRITE);
    MountTable.Resolution resolution = mMountTable.resolve(inodePath.getUri());
    String ufsUri = resolution.getUri().toString();
    try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
        UnderFileSystem ufs = ufsResource.get();
        if (ufs.isObjectStorage()) {
            LOG.warn("SetACL is not supported to object storage UFS via Alluxio. " + "UFS: " + ufsUri + ". This has no effect on the underlying object.");
        } else {
            try {
                List<AclEntry> entries = new ArrayList<>(inode.getACL().getEntries());
                if (inode.isDirectory()) {
                    entries.addAll(inode.asDirectory().getDefaultACL().getEntries());
                }
                ufs.setAclEntries(ufsUri, entries);
            } catch (IOException e) {
                throw new AccessControlException("Could not setAcl for UFS file: " + ufsUri);
            }
        }
    }
}
Also used : Inode(alluxio.master.file.meta.Inode) AclEntry(alluxio.security.authorization.AclEntry) SetAclEntry(alluxio.proto.journal.File.SetAclEntry) ArrayList(java.util.ArrayList) AccessControlException(alluxio.exception.AccessControlException) IOException(java.io.IOException) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem)

Example 25 with UnderFileSystem

use of alluxio.underfs.UnderFileSystem in project alluxio by Alluxio.

the class DefaultFileSystemMaster method renameInternal.

/**
 * Implements renaming.
 *
 * @param rpcContext the rpc context
 * @param srcInodePath the path of the rename source
 * @param dstInodePath the path to the rename destination
 * @param replayed whether the operation is a result of replaying the journal
 * @param context method options
 */
private void renameInternal(RpcContext rpcContext, LockedInodePath srcInodePath, LockedInodePath dstInodePath, boolean replayed, RenameContext context) throws FileDoesNotExistException, InvalidPathException, IOException, AccessControlException {
    // Rename logic:
    // 1. Change the source inode name to the destination name.
    // 2. Insert the source inode into the destination parent.
    // 3. Do UFS operations if necessary.
    // 4. Remove the source inode (reverting the name) from the source parent.
    // 5. Set the last modification times for both source and destination parent inodes.
    Inode srcInode = srcInodePath.getInode();
    AlluxioURI srcPath = srcInodePath.getUri();
    AlluxioURI dstPath = dstInodePath.getUri();
    InodeDirectory srcParentInode = srcInodePath.getParentInodeDirectory();
    InodeDirectory dstParentInode = dstInodePath.getParentInodeDirectory();
    String srcName = srcPath.getName();
    String dstName = dstPath.getName();
    LOG.debug("Renaming {} to {}", srcPath, dstPath);
    if (dstInodePath.fullPathExists()) {
        throw new InvalidPathException("Destination path: " + dstPath + " already exists.");
    }
    mInodeTree.rename(rpcContext, RenameEntry.newBuilder().setId(srcInode.getId()).setOpTimeMs(context.getOperationTimeMs()).setNewParentId(dstParentInode.getId()).setNewName(dstName).setPath(srcPath.getPath()).setNewPath(dstPath.getPath()).build());
    // If the source file is persisted, rename it in the UFS.
    try {
        if (!replayed && srcInode.isPersisted()) {
            // Check if ufs is writable
            checkUfsMode(srcPath, OperationType.WRITE);
            checkUfsMode(dstPath, OperationType.WRITE);
            MountTable.Resolution resolution = mMountTable.resolve(srcPath);
            // Persist ancestor directories from top to the bottom. We cannot use recursive create
            // parents here because the permission for the ancestors can be different.
            // inodes from the same mount point as the dst
            Stack<InodeDirectory> sameMountDirs = new Stack<>();
            List<Inode> dstInodeList = dstInodePath.getInodeList();
            for (int i = dstInodeList.size() - 1; i >= 0; i--) {
                // Since dstInodePath is guaranteed not to be a full path, all inodes in the incomplete
                // path are guaranteed to be a directory.
                InodeDirectory dir = dstInodeList.get(i).asDirectory();
                sameMountDirs.push(dir);
                if (dir.isMountPoint()) {
                    break;
                }
            }
            while (!sameMountDirs.empty()) {
                InodeDirectory dir = sameMountDirs.pop();
                if (!dir.isPersisted()) {
                    mInodeTree.syncPersistExistingDirectory(rpcContext, dir);
                }
            }
            String ufsSrcPath = resolution.getUri().toString();
            try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
                UnderFileSystem ufs = ufsResource.get();
                String ufsDstUri = mMountTable.resolve(dstPath).getUri().toString();
                boolean success;
                if (srcInode.isFile()) {
                    success = ufs.renameRenamableFile(ufsSrcPath, ufsDstUri);
                } else {
                    success = ufs.renameRenamableDirectory(ufsSrcPath, ufsDstUri);
                }
                if (!success) {
                    throw new IOException(ExceptionMessage.FAILED_UFS_RENAME.getMessage(ufsSrcPath, ufsDstUri));
                }
            }
            // The destination was persisted in ufs.
            mUfsAbsentPathCache.processExisting(dstPath);
        }
    } catch (Throwable t) {
        // On failure, revert changes and throw exception.
        mInodeTree.rename(rpcContext, RenameEntry.newBuilder().setId(srcInode.getId()).setOpTimeMs(context.getOperationTimeMs()).setNewName(srcName).setNewParentId(srcParentInode.getId()).setPath(dstPath.getPath()).setNewPath(srcPath.getPath()).build());
        throw t;
    }
    Metrics.PATHS_RENAMED.inc();
}
Also used : IOException(java.io.IOException) MountTable(alluxio.master.file.meta.MountTable) InvalidPathException(alluxio.exception.InvalidPathException) Fingerprint(alluxio.underfs.Fingerprint) Stack(java.util.Stack) InodeDirectory(alluxio.master.file.meta.InodeDirectory) Inode(alluxio.master.file.meta.Inode) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Aggregations

UnderFileSystem (alluxio.underfs.UnderFileSystem)123 AlluxioURI (alluxio.AlluxioURI)59 Test (org.junit.Test)44 IOException (java.io.IOException)37 MountTable (alluxio.master.file.meta.MountTable)24 URIStatus (alluxio.client.file.URIStatus)17 Mode (alluxio.security.authorization.Mode)15 UfsManager (alluxio.underfs.UfsManager)13 UfsStatus (alluxio.underfs.UfsStatus)13 InvalidPathException (alluxio.exception.InvalidPathException)12 Inode (alluxio.master.file.meta.Inode)12 OutputStream (java.io.OutputStream)12 ArrayList (java.util.ArrayList)12 BaseIntegrationTest (alluxio.testutils.BaseIntegrationTest)11 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)9 AccessControlException (alluxio.exception.AccessControlException)8 BlockInfoException (alluxio.exception.BlockInfoException)7 FileDoesNotExistException (alluxio.exception.FileDoesNotExistException)7 InodeDirectory (alluxio.master.file.meta.InodeDirectory)7 InodeFile (alluxio.master.file.meta.InodeFile)7