Search in sources :

Example 1 with UfsMode

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

the class DefaultFileSystemMaster method checkUfsMode.

/**
 * Check if the specified operation type is allowed to the ufs.
 *
 * @param alluxioPath the Alluxio path
 * @param opType the operation type
 */
private void checkUfsMode(AlluxioURI alluxioPath, OperationType opType) throws AccessControlException, InvalidPathException {
    MountTable.Resolution resolution = mMountTable.resolve(alluxioPath);
    try (CloseableResource<UnderFileSystem> ufsResource = resolution.acquireUfsResource()) {
        UnderFileSystem ufs = ufsResource.get();
        UfsMode ufsMode = ufs.getOperationMode(mUfsManager.getPhysicalUfsState(ufs.getPhysicalStores()));
        switch(ufsMode) {
            case NO_ACCESS:
                throw new AccessControlException(ExceptionMessage.UFS_OP_NOT_ALLOWED.getMessage(opType, resolution.getUri(), UfsMode.NO_ACCESS));
            case READ_ONLY:
                if (opType == OperationType.WRITE) {
                    throw new AccessControlException(ExceptionMessage.UFS_OP_NOT_ALLOWED.getMessage(opType, resolution.getUri(), UfsMode.READ_ONLY));
                }
                break;
            default:
                // All operations are allowed
                break;
        }
    }
}
Also used : AccessControlException(alluxio.exception.AccessControlException) MountTable(alluxio.master.file.meta.MountTable) UnderFileSystem(alluxio.underfs.UnderFileSystem) UfsMode(alluxio.underfs.UfsMode)

Example 2 with UfsMode

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

the class FileSystemMasterClientServiceHandler method updateUfsMode.

@Override
public void updateUfsMode(UpdateUfsModePRequest request, StreamObserver<UpdateUfsModePResponse> responseObserver) {
    RpcUtils.call(LOG, () -> {
        UfsMode ufsMode;
        switch(request.getOptions().getUfsMode()) {
            case NO_ACCESS:
                ufsMode = UfsMode.NO_ACCESS;
                break;
            case READ_ONLY:
                ufsMode = UfsMode.READ_ONLY;
                break;
            default:
                ufsMode = UfsMode.READ_WRITE;
                break;
        }
        mFileSystemMaster.updateUfsMode(new AlluxioURI(request.getUfsPath()), ufsMode);
        return UpdateUfsModePResponse.newBuilder().build();
    }, "UpdateUfsMode", "request=%s", responseObserver, request);
}
Also used : UfsMode(alluxio.underfs.UfsMode) AlluxioURI(alluxio.AlluxioURI)

Aggregations

UfsMode (alluxio.underfs.UfsMode)2 AlluxioURI (alluxio.AlluxioURI)1 AccessControlException (alluxio.exception.AccessControlException)1 MountTable (alluxio.master.file.meta.MountTable)1 UnderFileSystem (alluxio.underfs.UnderFileSystem)1