Search in sources :

Example 11 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException 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 12 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException 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)

Example 13 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class Storage method abortPut.

@Override
public void abortPut(SRMUser user, String localTransferPath, URI surl, String reason) throws SRMException {
    try {
        if (localTransferPath.startsWith("/")) {
            // safe-guard against incompatible file id from earlier versions
            Subject subject = (user == null) ? Subjects.ROOT : asDcacheUser(user).getSubject();
            Restriction restriction = (user == null) ? Restrictions.none() : asDcacheUser(user).getRestriction();
            FsPath actualPnfsPath = getPath(surl);
            PnfsCancelUpload msg = new PnfsCancelUpload(subject, restriction, FsPath.create(localTransferPath), actualPnfsPath, EnumSet.noneOf(FileAttribute.class), "SRM upload aborted: " + reason);
            _pnfsStub.sendAndWait(msg);
            DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
            infoMsg.setSubject(subject);
            infoMsg.setBillingPath(actualPnfsPath.toString());
            infoMsg.setTransaction(CDC.getSession());
            infoMsg.setPnfsId(msg.getPnfsId());
            infoMsg.setResult(CacheException.DEFAULT_ERROR_CODE, reason);
            Origin origin = Subjects.getOrigin(subject);
            if (origin != null) {
                infoMsg.setClient(origin.getAddress().getHostAddress());
            }
            _billingStub.notify(infoMsg);
        }
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied.", e);
    } catch (CacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    } catch (NoRouteToCellException e) {
        throw new SRMInternalErrorException("Communication failure", e);
    }
}
Also used : DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) Origin(org.dcache.auth.Origin) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) PnfsCancelUpload(diskCacheV111.vehicles.PnfsCancelUpload) 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) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) Restriction(org.dcache.auth.attributes.Restriction) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute)

Example 14 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class Storage method prepareToPut.

@Override
public CheckedFuture<String, ? extends SRMException> prepareToPut(final SRMUser srmUser, URI surl, Long size, String accessLatency, String retentionPolicy, String spaceToken, boolean overwrite) {
    try {
        DcacheUser user = asDcacheUser(srmUser);
        Subject subject = user.getSubject();
        Restriction restriction = user.getRestriction();
        FsPath fullPath = getPath(surl);
        if (spaceToken != null) {
            if (!_isSpaceManagerEnabled) {
                return immediateFailedCheckedFuture(new SRMNotSupportedException(SPACEMANAGER_DISABLED_MESSAGE));
            }
            /* This check could and maybe should be done on the SRM side of AbstractStorageElement:
                 * The targetSpaceToken is the same for all SURLs in an srmPrepareToPut request, and the
                 * SRM_EXCEED_ALLOCATION should also be returned if the entire srmPrepareToPut request
                 * is larger than available space in the reservation - that's a check we cannot possibly
                 * to on an individual SURL.
                 */
            try {
                Optional<Space> optionalSpace = spaces.get(spaceToken);
                if (!optionalSpace.isPresent()) {
                    return immediateFailedCheckedFuture(new SRMInvalidRequestException("The space token " + spaceToken + " does not refer to an existing known space reservation."));
                }
                Space space = optionalSpace.get();
                if (space.getExpirationTime() != null && space.getExpirationTime() < System.currentTimeMillis()) {
                    return immediateFailedCheckedFuture(new SRMSpaceLifetimeExpiredException("Space reservation associated with the space token " + spaceToken + " is expired."));
                }
                if (size != null && space.getAvailableSpaceInBytes() < size) {
                    return immediateFailedCheckedFuture(new SRMExceedAllocationException("Space associated with the space token " + spaceToken + " is not enough to hold SURL."));
                }
            } catch (ExecutionException e) {
                return immediateFailedCheckedFuture(new SRMException("Failure while querying space reservation: " + e.getCause().getMessage()));
            }
        }
        AccessLatency al = (accessLatency != null) ? AccessLatency.valueOf(accessLatency) : null;
        RetentionPolicy rp = (retentionPolicy != null) ? RetentionPolicy.valueOf(retentionPolicy) : null;
        EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
        if (overwrite) {
            options.add(CreateOption.OVERWRITE_EXISTING);
        }
        if (config.isRecursiveDirectoryCreation()) {
            options.add(CreateOption.CREATE_PARENTS);
        }
        PnfsCreateUploadPath msg = new PnfsCreateUploadPath(subject, restriction, fullPath, user.getRoot(), size, al, rp, spaceToken, options);
        final SettableFuture<String> future = SettableFuture.create();
        CellStub.addCallback(_pnfsStub.send(msg), new AbstractMessageCallback<PnfsCreateUploadPath>() {

            int failures = 0;

            @Override
            public void success(PnfsCreateUploadPath message) {
                future.set(message.getUploadPath().toString());
            }

            @Override
            public void failure(int rc, Object error) {
                failures++;
                String msg = Objects.toString(error, "");
                switch(rc) {
                    case CacheException.PERMISSION_DENIED:
                        future.setException(new SRMAuthorizationException(msg));
                        break;
                    case CacheException.FILE_EXISTS:
                        future.setException(new SRMDuplicationException(msg));
                        break;
                    case CacheException.FILE_NOT_FOUND:
                    case CacheException.NOT_DIR:
                        future.setException(new SRMInvalidPathException(msg));
                        break;
                    case CacheException.LOCKED:
                        if (failures < 3) {
                            /* Usually due to concurrent uploads to the same non-existing target
                                       * directory. Retry a few times.
                                       */
                            PnfsCreateUploadPath retry = new PnfsCreateUploadPath(subject, restriction, fullPath, user.getRoot(), size, al, rp, spaceToken, options);
                            CellStub.addCallback(_pnfsStub.send(retry), this, _executor);
                        } else {
                            future.setException(new SRMInternalErrorException(msg));
                        }
                        break;
                    case CacheException.TIMEOUT:
                    default:
                        future.setException(new SRMInternalErrorException(msg));
                        break;
                }
            }
        }, _executor);
        return Futures.makeChecked(future, new ToSRMException());
    } catch (SRMAuthorizationException | SRMInvalidPathException e) {
        return immediateFailedCheckedFuture(e);
    }
}
Also used : SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) SRMSpaceLifetimeExpiredException(org.dcache.srm.SRMSpaceLifetimeExpiredException) ExecutionException(java.util.concurrent.ExecutionException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FsPath(diskCacheV111.util.FsPath) Space(diskCacheV111.services.space.Space) TMetaDataSpace(org.dcache.srm.v2_2.TMetaDataSpace) SRMExceedAllocationException(org.dcache.srm.SRMExceedAllocationException) PnfsCreateUploadPath(diskCacheV111.vehicles.PnfsCreateUploadPath) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) AccessLatency(diskCacheV111.util.AccessLatency) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) RetentionPolicy(diskCacheV111.util.RetentionPolicy) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) Subject(javax.security.auth.Subject) Restriction(org.dcache.auth.attributes.Restriction) CreateOption(org.dcache.namespace.CreateOption) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 15 with SRMInternalErrorException

use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.

the class ReservationCaches method buildOwnerDescriptionLookupCache.

/**
 * Builds a loading cache for looking up space tokens by owner and description.
 */
public static LoadingCache<GetSpaceTokensKey, long[]> buildOwnerDescriptionLookupCache(CellStub spaceManager, Executor executor) {
    return CacheBuilder.newBuilder().maximumSize(1000).expireAfterWrite(30, SECONDS).refreshAfterWrite(10, SECONDS).recordStats().build(new CacheLoader<GetSpaceTokensKey, long[]>() {

        @Override
        public long[] load(GetSpaceTokensKey key) throws Exception {
            try {
                return spaceManager.sendAndWait(createRequest(key)).getSpaceTokens();
            } catch (TimeoutCacheException e) {
                throw new SRMInternalErrorException("Space manager timeout", e);
            } catch (InterruptedException e) {
                throw new SRMInternalErrorException("Operation interrupted", e);
            } catch (CacheException e) {
                LOGGER.warn("GetSpaceTokens failed with rc={} error={}", e.getRc(), e.getMessage());
                throw new SRMException("GetSpaceTokens failed with rc=" + e.getRc() + " error=" + e.getMessage(), e);
            }
        }

        private GetSpaceTokens createRequest(GetSpaceTokensKey key) {
            GetSpaceTokens message = new GetSpaceTokens(key.description);
            message.setSubject(new Subject(true, key.principals, Collections.emptySet(), Collections.emptySet()));
            return message;
        }

        @Override
        public ListenableFuture<long[]> reload(GetSpaceTokensKey key, long[] oldValue) throws Exception {
            final SettableFuture<long[]> future = SettableFuture.create();
            CellStub.addCallback(spaceManager.send(createRequest(key)), new AbstractMessageCallback<GetSpaceTokens>() {

                @Override
                public void success(GetSpaceTokens message) {
                    future.set(message.getSpaceTokens());
                }

                @Override
                public void failure(int rc, Object error) {
                    CacheException exception = CacheExceptionFactory.exceptionOf(rc, Objects.toString(error, null));
                    future.setException(exception);
                }
            }, executor);
            return future;
        }
    });
}
Also used : SettableFuture(com.google.common.util.concurrent.SettableFuture) CacheException(diskCacheV111.util.CacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) CacheException(diskCacheV111.util.CacheException) SRMException(org.dcache.srm.SRMException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) Subject(javax.security.auth.Subject) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) GetSpaceTokens(diskCacheV111.services.space.message.GetSpaceTokens) SRMException(org.dcache.srm.SRMException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) AbstractMessageCallback(org.dcache.cells.AbstractMessageCallback) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)46 SRMException (org.dcache.srm.SRMException)34 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)26 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)21 CacheException (diskCacheV111.util.CacheException)20 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)19 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)18 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)17 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)17 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)17 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)17 NotDirCacheException (diskCacheV111.util.NotDirCacheException)17 FsPath (diskCacheV111.util.FsPath)13 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)13 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)10 Subject (javax.security.auth.Subject)10 URI (java.net.URI)9 PnfsHandler (diskCacheV111.util.PnfsHandler)8 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)7 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)6