Search in sources :

Example 1 with MountInfo

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;
    }
}
Also used : LockResource(alluxio.resource.LockResource) MountInfo(alluxio.master.file.meta.options.MountInfo) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with MountInfo

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);
        }
    }
}
Also used : LockResource(alluxio.resource.LockResource) AccessControlException(alluxio.exception.AccessControlException) MountInfo(alluxio.master.file.meta.options.MountInfo)

Example 3 with MountInfo

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);
    }
}
Also used : LockResource(alluxio.resource.LockResource) MountInfo(alluxio.master.file.meta.options.MountInfo) UnderFileSystem(alluxio.underfs.UnderFileSystem) AlluxioURI(alluxio.AlluxioURI)

Example 4 with MountInfo

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());
}
Also used : HashMap(java.util.HashMap) MountInfo(alluxio.master.file.meta.options.MountInfo) Map(java.util.Map) HashMap(java.util.HashMap) AlluxioURI(alluxio.AlluxioURI) Test(org.junit.Test)

Example 5 with MountInfo

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;
}
Also used : MountPointInfo(alluxio.wire.MountPointInfo) TreeMap(java.util.TreeMap) MountInfo(alluxio.master.file.meta.options.MountInfo) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

MountInfo (alluxio.master.file.meta.options.MountInfo)7 Map (java.util.Map)5 LockResource (alluxio.resource.LockResource)4 HashMap (java.util.HashMap)4 AlluxioURI (alluxio.AlluxioURI)3 AccessControlException (alluxio.exception.AccessControlException)1 FileAlreadyExistsException (alluxio.exception.FileAlreadyExistsException)1 InvalidPathException (alluxio.exception.InvalidPathException)1 AddMountPointEntry (alluxio.proto.journal.File.AddMountPointEntry)1 Journal (alluxio.proto.journal.Journal)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1 MountPointInfo (alluxio.wire.MountPointInfo)1 ArrayList (java.util.ArrayList)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 Test (org.junit.Test)1