use of alluxio.master.file.meta.options.MountInfo in project alluxio by Alluxio.
the class MountTable method getMountPoint.
/**
* Returns the closest ancestor mount point the given path is nested under.
*
* @param uri an Alluxio path URI
* @return mount point the given Alluxio path is nested under
* @throws InvalidPathException if an invalid path is encountered
*/
public String getMountPoint(AlluxioURI uri) throws InvalidPathException {
String path = uri.getPath();
String mountPoint = null;
try (LockResource r = new LockResource(mReadLock)) {
for (Map.Entry<String, MountInfo> entry : mMountTable.entrySet()) {
String alluxioPath = entry.getKey();
if (PathUtils.hasPrefix(path, alluxioPath) && (mountPoint == null || PathUtils.hasPrefix(alluxioPath, mountPoint))) {
mountPoint = alluxioPath;
}
}
return mountPoint;
}
}
use of alluxio.master.file.meta.options.MountInfo in project alluxio by Alluxio.
the class MountTable method checkUnderWritableMountPoint.
/**
* Checks to see if a write operation is allowed for the specified Alluxio path, by determining
* if it is under a readonly mount point.
*
* @param alluxioUri an Alluxio path URI
* @throws InvalidPathException if the Alluxio path is invalid
* @throws AccessControlException if the Alluxio path is under a readonly mount point
*/
public void checkUnderWritableMountPoint(AlluxioURI alluxioUri) throws InvalidPathException, AccessControlException {
try (LockResource r = new LockResource(mReadLock)) {
// This will re-acquire the read lock, but that is allowed.
String mountPoint = getMountPoint(alluxioUri);
MountInfo mountInfo = mMountTable.get(mountPoint);
if (mountInfo.getOptions().isReadOnly()) {
throw new AccessControlException(ExceptionMessage.MOUNT_READONLY, alluxioUri, mountPoint);
}
}
}
use of alluxio.master.file.meta.options.MountInfo in project alluxio by Alluxio.
the class MountTable method resolve.
/**
* Resolves the given Alluxio path. If the given Alluxio path is nested under a mount point, the
* resolution maps the Alluxio path to the corresponding UFS path. Otherwise, the resolution is a
* no-op.
*
* @param uri an Alluxio path URI
* @return the {@link Resolution} representing the UFS path
* @throws InvalidPathException if an invalid path is encountered
*/
public Resolution resolve(AlluxioURI uri) throws InvalidPathException {
try (LockResource r = new LockResource(mReadLock)) {
String path = uri.getPath();
LOG.debug("Resolving {}", path);
// This will re-acquire the read lock, but that is allowed.
String mountPoint = getMountPoint(uri);
if (mountPoint != null) {
MountInfo info = mMountTable.get(mountPoint);
AlluxioURI ufsUri = info.getUfsUri();
// TODO(gpang): this ufs should probably be cached.
UnderFileSystem ufs = UnderFileSystem.Factory.get(ufsUri.toString());
ufs.setProperties(info.getOptions().getProperties());
AlluxioURI resolvedUri = ufs.resolveUri(ufsUri, path.substring(mountPoint.length()));
return new Resolution(resolvedUri, ufs, info.getOptions().isShared());
}
return new Resolution(uri, null, false);
}
}
use of alluxio.master.file.meta.options.MountInfo in project alluxio by Alluxio.
the class MountTableTest method getMountTable.
/**
* Tests the method for getting a copy of the current mount table.
*/
@Test
public void getMountTable() throws Exception {
Map<String, MountInfo> mountTable = new HashMap<>(2);
mountTable.put("/mnt/foo", new MountInfo(new AlluxioURI("hdfs://localhost:5678/foo"), MountOptions.defaults()));
mountTable.put("/mnt/bar", new MountInfo(new AlluxioURI("hdfs://localhost:5678/bar"), MountOptions.defaults()));
for (Map.Entry<String, MountInfo> mountPoint : mountTable.entrySet()) {
MountInfo mountInfo = mountPoint.getValue();
mMountTable.add(new AlluxioURI("alluxio://localhost:1234" + mountPoint.getKey()), mountInfo.getUfsUri(), mountInfo.getOptions());
}
Assert.assertEquals(mountTable, mMountTable.getMountTable());
}
use of alluxio.master.file.meta.options.MountInfo in project alluxio by Alluxio.
the class AlluxioMasterRestServiceHandler method getMountPointsInternal.
private Map<String, MountPointInfo> getMountPointsInternal() {
SortedMap<String, MountPointInfo> mountPoints = new TreeMap<>();
for (Map.Entry<String, MountInfo> mountPoint : mFileSystemMaster.getMountTable().entrySet()) {
MountInfo mountInfo = mountPoint.getValue();
MountPointInfo info = new MountPointInfo();
info.setUfsInfo(mountInfo.getUfsUri().toString());
info.setReadOnly(mountInfo.getOptions().isReadOnly());
info.setProperties(mountInfo.getOptions().getProperties());
info.setShared(mountInfo.getOptions().isShared());
mountPoints.put(mountPoint.getKey(), info);
}
return mountPoints;
}
Aggregations