Search in sources :

Example 11 with TimeoutCacheException

use of diskCacheV111.util.TimeoutCacheException in project dcache by dCache.

the class Storage method listDirectory.

@Override
public List<URI> listDirectory(SRMUser user, URI surl, FileMetaData fileMetaData) throws SRMException {
    final FsPath path = getPath(surl);
    final List<URI> result = new ArrayList<>();
    final String base = addTrailingSlash(surl.toString());
    Subject subject = asDcacheUser(user).getSubject();
    Restriction restriction = asDcacheUser(user).getRestriction();
    DirectoryListPrinter printer = new DirectoryListPrinter() {

        @Override
        public Set<FileAttribute> getRequiredAttributes() {
            return EnumSet.noneOf(FileAttribute.class);
        }

        @Override
        public void print(FsPath dir, FileAttributes dirAttr, DirectoryEntry entry) {
            result.add(URI.create(base + entry.getName()));
        }
    };
    try {
        _listSource.printDirectory(subject, restriction, printer, path, null, Range.<Integer>all());
        return result;
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Internal name space timeout", e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("List aborted by administrator", e);
    } catch (NotDirCacheException e) {
        throw new SRMInvalidPathException("Not a directory", e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("No such file or directory", e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied", e);
    } catch (CacheException e) {
        throw new SRMException(String.format("List failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) DirectoryListPrinter(org.dcache.util.list.DirectoryListPrinter) 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) ArrayList(java.util.ArrayList) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) DirectoryEntry(org.dcache.util.list.DirectoryEntry) URI(java.net.URI) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 12 with TimeoutCacheException

use of diskCacheV111.util.TimeoutCacheException in project dcache by dCache.

the class Storage method listSubdirectoriesRecursivelyForDelete.

/**
 * Adds transitive subdirectories of {@code dir} to {@code result}.
 *
 * @param subject    Issuer of rmdir
 * @param dir        Path to directory
 * @param attributes File attributes of {@code dir}
 * @param result     List that subdirectories are added to
 * @throws SRMAuthorizationException     if {@code subject} is not authorized to list {@code
 *                                       dir} or not authorized to list or delete any of its
 *                                       transitive subdirectories.
 * @throws SRMNonEmptyDirectoryException if {@code dir} or any of its transitive subdirectories
 *                                       contains non-directory entries.
 * @throws SRMInternalErrorException     in case of transient errors.
 * @throws SRMInvalidPathException       if {@code dir} is not a directory.
 * @throws SRMException                  in case of other errors.
 */
private void listSubdirectoriesRecursivelyForDelete(Subject subject, Restriction restriction, FsPath dir, FileAttributes attributes, List<FsPath> result) throws SRMException {
    List<DirectoryEntry> children = new ArrayList<>();
    try (DirectoryStream list = _listSource.list(subject, restriction, dir, null, Range.<Integer>all(), attributesRequiredForRmdir)) {
        for (DirectoryEntry child : list) {
            FileAttributes childAttributes = child.getFileAttributes();
            AccessType canDelete = permissionHandler.canDeleteDir(subject, attributes, childAttributes);
            if (canDelete != AccessType.ACCESS_ALLOWED) {
                throw new SRMAuthorizationException(dir + "/" + child.getName() + " (permission denied)");
            }
            if (childAttributes.getFileType() != FileType.DIR) {
                throw new SRMNonEmptyDirectoryException(dir + "/" + child.getName() + " (not empty)");
            }
            children.add(child);
        }
    } catch (NotDirCacheException e) {
        throw new SRMInvalidPathException(dir + " (not a directory)", e);
    } catch (FileNotFoundCacheException ignored) {
    // Somebody removed the directory before we could.
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException(dir + " (permission denied)", e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Name space timeout", e);
    } catch (CacheException e) {
        throw new SRMException(dir + " (" + e.getMessage() + ")");
    }
    // Result list uses post-order so directories will be deleted bottom-up.
    for (DirectoryEntry child : children) {
        FsPath path = dir.child(child.getName());
        listSubdirectoriesRecursivelyForDelete(subject, restriction, path, child.getFileAttributes(), result);
        result.add(path);
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMNonEmptyDirectoryException(org.dcache.srm.SRMNonEmptyDirectoryException) 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) ArrayList(java.util.ArrayList) DirectoryStream(org.dcache.util.list.DirectoryStream) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) DirectoryEntry(org.dcache.util.list.DirectoryEntry) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) AccessType(org.dcache.acl.enums.AccessType) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) FsPath(diskCacheV111.util.FsPath)

Example 13 with TimeoutCacheException

use of diskCacheV111.util.TimeoutCacheException in project dcache by dCache.

the class Storage method createDirectory.

@Override
public void createDirectory(SRMUser abstractUser, URI surl) throws SRMException {
    _log.debug("Storage.createDirectory");
    DcacheUser user = asDcacheUser(abstractUser);
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    try {
        handler.createPnfsDirectory(getPath(surl).toString());
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Internal name space timeout", e);
    } catch (NotDirCacheException e) {
        throw new SRMInvalidPathException("Parent path is not a directory", e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("Parent path does not exist", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException("File exists");
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (CacheException e) {
        _log.error("Failed to create directory {}: {}", surl, e.getMessage());
        throw new SRMException(String.format("Failed to create directory [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
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) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 14 with TimeoutCacheException

use of diskCacheV111.util.TimeoutCacheException in project dcache by dCache.

the class Storage method srmGetSpaceMetaData.

/**
 * @param spaceTokens
 * @return
 * @throws SRMException
 */
@Override
public TMetaDataSpace[] srmGetSpaceMetaData(SRMUser user, String[] spaceTokens) throws SRMException {
    guardSpaceManagerEnabled();
    GetSpaceMetaData getSpaces = new GetSpaceMetaData(spaceTokens);
    try {
        getSpaces = _spaceManagerStub.sendAndWait(getSpaces);
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Space manager timeout", e);
    } catch (NoRouteToCellException e) {
        throw new SRMNotSupportedException("Space manager is unavailable", e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (CacheException e) {
        _log.warn("GetSpaceMetaData failed with rc={} error={}", e.getRc(), e.getMessage());
        throw new SRMException("Space manager failure: " + e.getMessage(), e);
    }
    Space[] spaces = getSpaces.getSpaces();
    TMetaDataSpace[] spaceMetaDatas = new TMetaDataSpace[spaces.length];
    for (int i = 0; i < spaceMetaDatas.length; ++i) {
        Space space = spaces[i];
        TMetaDataSpace metaDataSpace = new TMetaDataSpace();
        TReturnStatus status;
        if (space != null) {
            Long expirationTime = space.getExpirationTime();
            if (expirationTime == null) {
                metaDataSpace.setLifetimeAssigned(-1);
                metaDataSpace.setLifetimeLeft(-1);
            } else {
                long lifetimeleft = Math.max(0, MILLISECONDS.toSeconds(expirationTime - System.currentTimeMillis()));
                metaDataSpace.setLifetimeAssigned((int) MILLISECONDS.toSeconds(expirationTime - space.getCreationTime()));
                metaDataSpace.setLifetimeLeft((int) lifetimeleft);
            }
            RetentionPolicy retentionPolicy = space.getRetentionPolicy();
            TRetentionPolicy policy = retentionPolicy.equals(RetentionPolicy.CUSTODIAL) ? TRetentionPolicy.CUSTODIAL : retentionPolicy.equals(RetentionPolicy.OUTPUT) ? TRetentionPolicy.OUTPUT : TRetentionPolicy.REPLICA;
            AccessLatency accessLatency = space.getAccessLatency();
            TAccessLatency latency = accessLatency.equals(AccessLatency.ONLINE) ? TAccessLatency.ONLINE : TAccessLatency.NEARLINE;
            UnsignedLong totalSize = new UnsignedLong(space.getSizeInBytes());
            UnsignedLong unusedSize = new UnsignedLong(space.getSizeInBytes() - space.getUsedSizeInBytes());
            metaDataSpace.setRetentionPolicyInfo(new TRetentionPolicyInfo(policy, latency));
            metaDataSpace.setTotalSize(totalSize);
            metaDataSpace.setGuaranteedSize(totalSize);
            metaDataSpace.setUnusedSize(unusedSize);
            SpaceState spaceState = space.getState();
            switch(spaceState) {
                case RESERVED:
                    status = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
                    break;
                case EXPIRED:
                    status = new TReturnStatus(TStatusCode.SRM_SPACE_LIFETIME_EXPIRED, "The lifetime on the space that is associated with the spaceToken has expired already");
                    break;
                default:
                    status = new TReturnStatus(TStatusCode.SRM_FAILURE, "Space has been released");
                    break;
            }
            metaDataSpace.setOwner("VoGroup=" + space.getVoGroup() + " VoRole=" + space.getVoRole());
        } else {
            status = new TReturnStatus(TStatusCode.SRM_INVALID_REQUEST, "No such space");
        }
        metaDataSpace.setStatus(status);
        metaDataSpace.setSpaceToken(spaceTokens[i]);
        spaceMetaDatas[i] = metaDataSpace;
    }
    return spaceMetaDatas;
}
Also used : GetSpaceMetaData(diskCacheV111.services.space.message.GetSpaceMetaData) Space(diskCacheV111.services.space.Space) TMetaDataSpace(org.dcache.srm.v2_2.TMetaDataSpace) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) AccessLatency(diskCacheV111.util.AccessLatency) UnsignedLong(org.apache.axis.types.UnsignedLong) 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) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) RetentionPolicy(diskCacheV111.util.RetentionPolicy) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) TRetentionPolicyInfo(org.dcache.srm.v2_2.TRetentionPolicyInfo) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) SpaceState(diskCacheV111.services.space.SpaceState) UnsignedLong(org.apache.axis.types.UnsignedLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) TMetaDataSpace(org.dcache.srm.v2_2.TMetaDataSpace) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 15 with TimeoutCacheException

use of diskCacheV111.util.TimeoutCacheException in project dcache by dCache.

the class Storage method removeDirectory.

@Override
public void removeDirectory(SRMUser user, URI surl, boolean recursive) throws SRMException {
    Subject subject = asDcacheUser(user).getSubject();
    Restriction restriction = asDcacheUser(user).getRestriction();
    FsPath path = getPath(surl);
    if (path.isRoot()) {
        throw new SRMAuthorizationException("Permission denied");
    }
    if (recursive) {
        removeSubdirectories(subject, restriction, path);
    }
    try {
        PnfsHandler pnfs = new PnfsHandler(_pnfs, subject, restriction);
        pnfs.deletePnfsEntry(path.toString(), EnumSet.of(FileType.DIR));
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Name space timeout");
    } catch (FileNotFoundCacheException ignored) {
        throw new SRMInvalidPathException("No such file or directory");
    } catch (NotDirCacheException e) {
        throw new SRMInvalidPathException("Not a directory");
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied", e);
    } catch (CacheException e) {
        try {
            int count = _listSource.printDirectory(subject, restriction, new NullListPrinter(), path, null, Range.<Integer>all());
            if (count > 0) {
                throw new SRMNonEmptyDirectoryException("Directory is not empty", e);
            }
        } catch (InterruptedException | CacheException suppressed) {
            e.addSuppressed(suppressed);
        }
        _log.error("Failed to delete {}: {}", path, e.getMessage());
        throw new SRMException("Name space failure (" + e.getMessage() + ")", e);
    }
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) NullListPrinter(org.dcache.util.list.NullListPrinter) 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) SRMNonEmptyDirectoryException(org.dcache.srm.SRMNonEmptyDirectoryException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) PnfsHandler(diskCacheV111.util.PnfsHandler) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)44 CacheException (diskCacheV111.util.CacheException)42 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)25 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)25 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)20 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)18 NotDirCacheException (diskCacheV111.util.NotDirCacheException)17 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)15 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)15 SRMException (org.dcache.srm.SRMException)15 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)15 FsPath (diskCacheV111.util.FsPath)14 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)11 Subject (javax.security.auth.Subject)10 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)10 PnfsHandler (diskCacheV111.util.PnfsHandler)8 Restriction (org.dcache.auth.attributes.Restriction)7 FileAttributes (org.dcache.vehicles.FileAttributes)7 NotFileCacheException (diskCacheV111.util.NotFileCacheException)6 InetSocketAddress (java.net.InetSocketAddress)4