Search in sources :

Example 1 with AccessMask

use of org.dcache.acl.enums.AccessMask in project dcache by dCache.

the class DCacheAwareJdbcFs method getFileLocality.

/**
 * Callout to get pool monitor and check for live (network) status of a file instead of simply
 * its status as recorded in the Chimera database.
 */
private String getFileLocality(PnfsId pnfsId) throws ChimeraFsException {
    FileLocality locality = FileLocality.UNAVAILABLE;
    try {
        Set<FileAttribute> requestedAttributes = EnumSet.of(FileAttribute.TYPE, FileAttribute.SIZE, FileAttribute.STORAGEINFO, FileAttribute.LOCATIONS);
        Set<AccessMask> accessMask = EnumSet.of(AccessMask.READ_DATA);
        FileAttributes attributes = pnfsHandler.getFileAttributes(pnfsId, requestedAttributes, accessMask, false);
        /*
             * TODO improve code to pass in the actual InetAddress of the
             * client so that link net masks do not interfere; note that SRM uses
             * "localhost", so it is not a deviation from existing behavior.
             */
        locality = poolMonitor.getFileLocality(attributes, "localhost");
    } catch (CacheException t) {
        throw new ChimeraFsException("getFileLocality", t);
    }
    return locality.toString();
}
Also used : CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) AccessMask(org.dcache.acl.enums.AccessMask) FileLocality(diskCacheV111.util.FileLocality) FileAttributes(org.dcache.vehicles.FileAttributes) FileAttribute(org.dcache.namespace.FileAttribute)

Example 2 with AccessMask

use of org.dcache.acl.enums.AccessMask in project dcache by dCache.

the class Transfer method readNameSpaceEntryAsync.

private ListenableFuture<Void> readNameSpaceEntryAsync(boolean allowWrite, long timeout) {
    Set<FileAttribute> attr = EnumSet.of(PNFSID, TYPE, STORAGEINFO, SIZE);
    attr.addAll(_additionalAttributes);
    attr.addAll(PoolMgrSelectReadPoolMsg.getRequiredAttributes());
    Set<AccessMask> mask;
    if (allowWrite) {
        mask = EnumSet.of(AccessMask.READ_DATA, AccessMask.WRITE_DATA);
    } else {
        mask = EnumSet.of(AccessMask.READ_DATA);
    }
    PnfsId pnfsId = getPnfsId();
    PnfsGetFileAttributes request;
    if (pnfsId != null) {
        request = new PnfsGetFileAttributes(pnfsId, attr);
        if (_path != null) {
            // Needed for restriction check.
            request.setPnfsPath(_path.toString());
        }
    } else {
        request = new PnfsGetFileAttributes(_path.toString(), attr);
    }
    request.setAccessMask(mask);
    request.setUpdateAtime(true);
    ListenableFuture<PnfsGetFileAttributes> reply = _pnfs.requestAsync(request, timeout);
    setStatusUntil("PnfsManager: Fetching storage info", reply);
    return CellStub.transformAsync(reply, msg -> {
        FileAttributes attributes = msg.getFileAttributes();
        /* We can only transfer regular files.
                   */
        FileType type = attributes.getFileType();
        if (type == FileType.DIR || type == FileType.SPECIAL) {
            throw new NotFileCacheException("Not a regular file");
        }
        /* I/O mode must match completeness of the file.
                   */
        if (!attributes.getStorageInfo().isCreatedOnly()) {
            setWrite(false);
        } else if (allowWrite) {
            setWrite(true);
        } else {
            throw new FileIsNewCacheException();
        }
        setFileAttributes(attributes);
        return immediateFuture(null);
    });
}
Also used : NotFileCacheException(diskCacheV111.util.NotFileCacheException) FileType(org.dcache.namespace.FileType) PnfsId(diskCacheV111.util.PnfsId) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) AccessMask(org.dcache.acl.enums.AccessMask) FileAttributes(org.dcache.vehicles.FileAttributes) PnfsGetFileAttributes(org.dcache.vehicles.PnfsGetFileAttributes) FileAttribute(org.dcache.namespace.FileAttribute)

Example 3 with AccessMask

use of org.dcache.acl.enums.AccessMask in project dcache by dCache.

the class Storage method getFileMetaData.

private FileMetaData getFileMetaData(DcacheUser user, boolean checkReadPermissions, FsPath path) throws SRMException {
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    try {
        /* Fetch file attributes.
             */
        Set<FileAttribute> requestedAttributes = EnumSet.of(TYPE, LOCATIONS);
        requestedAttributes.addAll(DcacheFileMetaData.getKnownAttributes());
        requestedAttributes.addAll(PoolMonitorV5.getRequiredAttributesForFileLocality());
        Set<AccessMask> accessMask = checkReadPermissions ? EnumSet.of(AccessMask.READ_DATA) : EnumSet.noneOf(AccessMask.class);
        FileAttributes attributes = handler.getFileAttributes(path.toString(), requestedAttributes, accessMask, false);
        FileMetaData fmd = new DcacheFileMetaData(attributes);
        /* Determine file locality.
             */
        if (attributes.getFileType() != FileType.DIR) {
            FileLocality locality = _poolMonitor.getFileLocality(attributes, config.getSrmHost());
            fmd.locality = locality.toTFileLocality();
            fmd.isCached = locality.isCached();
        }
        /* Determine space tokens.
             */
        if (_isSpaceManagerEnabled) {
            try {
                GetFileSpaceTokensMessage msg = new GetFileSpaceTokensMessage(attributes.getPnfsId());
                msg = _spaceManagerStub.sendAndWait(msg);
                if (msg.getSpaceTokens() != null) {
                    fmd.spaceTokens = new long[msg.getSpaceTokens().length];
                    System.arraycopy(msg.getSpaceTokens(), 0, fmd.spaceTokens, 0, msg.getSpaceTokens().length);
                }
            } catch (NoRouteToCellException e) {
                /* SpaceManager is optional, so we don't classify this
                     * as an error.
                     */
                _log.info(e.getMessage());
            }
        }
        return fmd;
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException(e.getMessage(), e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException(e.getMessage(), e);
    } catch (CacheException e) {
        throw new SRMException("Could not get storage info by path: " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) PnfsHandler(diskCacheV111.util.PnfsHandler) AccessMask(org.dcache.acl.enums.AccessMask) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) GetFileSpaceTokensMessage(diskCacheV111.services.space.message.GetFileSpaceTokensMessage) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) FileLocality(diskCacheV111.util.FileLocality) FileMetaData(org.dcache.srm.FileMetaData) FileAttribute(org.dcache.namespace.FileAttribute) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

AccessMask (org.dcache.acl.enums.AccessMask)3 FileAttribute (org.dcache.namespace.FileAttribute)3 FileAttributes (org.dcache.vehicles.FileAttributes)3 CacheException (diskCacheV111.util.CacheException)2 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)2 FileLocality (diskCacheV111.util.FileLocality)2 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)2 GetFileSpaceTokensMessage (diskCacheV111.services.space.message.GetFileSpaceTokensMessage)1 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)1 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)1 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)1 NotDirCacheException (diskCacheV111.util.NotDirCacheException)1 NotFileCacheException (diskCacheV111.util.NotFileCacheException)1 PnfsHandler (diskCacheV111.util.PnfsHandler)1 PnfsId (diskCacheV111.util.PnfsId)1 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)1 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)1 FileType (org.dcache.namespace.FileType)1 FileMetaData (org.dcache.srm.FileMetaData)1 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)1