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