Search in sources :

Example 26 with PermissionDeniedCacheException

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

the class MessageHandler method messageArrived.

public LoginMessage messageArrived(CellMessage envelope, LoginMessage message) throws CacheException {
    ScheduledFuture<?> timeoutTask = scheduleTimeoutTask(envelope);
    try {
        LoginReply login = _loginStrategy.login(message.getSubject());
        message.setSubject(login.getSubject());
        message.setLoginAttributes(login.getLoginAttributes());
    } catch (RuntimeException e) {
        LOGGER.error("Login operation failed", e);
        throw new PermissionDeniedCacheException(e.getMessage());
    } finally {
        timeoutTask.cancel(false);
    }
    return message;
}
Also used : PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) LoginReply(org.dcache.auth.LoginReply)

Example 27 with PermissionDeniedCacheException

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

the class WassPartition method selectPool2Pool.

/* REVISIT: The current implementation is a mix of the read pool
     * selection from ClassicPartition and write pool selection using
     * WASS. Code can probably be shared with ClassicPartition, but
     * since I hope to refine read pool selection, any code
     * duplication should be temporary and it is not worth refactoring
     * ClassicPartition.
     */
@Override
public P2pPair selectPool2Pool(CostModule cm, List<PoolInfo> src, List<PoolInfo> dst, FileAttributes attributes, boolean force) throws CacheException {
    checkState(!src.isEmpty());
    checkState(!dst.isEmpty());
    /* The maximum number of replicas can be limited.
         */
    if (src.size() >= _maxPnfsFileCopies) {
        throw new PermissionDeniedCacheException("P2P denied: already too many copies (" + src.size() + ")");
    }
    /* Randomise order of pools with equal cost. In particular
         * important when cost factors are 0.
         */
    Collections.shuffle(src);
    /* Source pools are only selected by performance cost, because
         * we will only read from the pool
         */
    List<PoolCost> sources = src.stream().map(WassPartition::toPoolCost).sorted(_byPerformanceCost).collect(toList());
    if (!force && isAlertCostExceeded(sources.get(0).performanceCost)) {
        throw new SourceCostException("P2P denied: All source pools are too busy (performance cost > " + _alertCostCut + ")");
    }
    /* The target pool must be below specified cost limits;
         * otherwise we wouldn't be able to read the file afterwards
         * without triggering another p2p.
         */
    double maxTargetCost = (_slope > 0.01) ? _slope * sources.get(0).performanceCost : getCurrentCostCut(cm);
    if (!force && maxTargetCost > 0.0) {
        dst = dst.stream().filter(pool -> toPoolCost(pool).performanceCost < maxTargetCost).collect(toList());
    }
    if (dst.isEmpty()) {
        throw new DestinationCostException("P2P denied: All destination pools are too busy (performance cost > " + maxTargetCost + ")");
    }
    long filesize = attributes.getSize();
    Assumption sourceAssumption = force ? Assumptions.none() : PerformanceCostAssumption.of(_error, _alertCostCut);
    Assumption destinationAssumption = force ? new AvailableSpaceAssumption(filesize) : new AvailableSpaceAssumption(filesize).and(PerformanceCostAssumption.of(_error, maxTargetCost));
    if (_allowSameHostCopy != SameHost.NOTCHECKED) {
        /* Loop over all sources and find the most appropriate
             * destination such that same host constraints are
             * satisfied.
             */
        for (PoolCost source : sources) {
            List<PoolInfo> destinations;
            if (source.host == null) {
                destinations = dst;
            } else {
                destinations = dst.stream().filter(d -> !d.getHostName().equals(source.host)).collect(toList());
            }
            PoolInfo destination = wass.selectByAvailableSpace(destinations, filesize, PoolInfo::getCostInfo);
            if (destination != null) {
                return new P2pPair(new SelectedPool(source.pool, sourceAssumption), new SelectedPool(destination, destinationAssumption));
            }
        }
        /* We could not find a pair on different hosts, what now?
             */
        if (_allowSameHostCopy == SameHost.NEVER) {
            throw new PermissionDeniedCacheException("P2P denied: sameHostCopy is 'never' and no matching pool found");
        }
    }
    PoolInfo destination = wass.selectByAvailableSpace(dst, filesize, PoolInfo::getCostInfo);
    if (destination == null) {
        throw new DestinationCostException("All pools are full");
    }
    return new P2pPair(new SelectedPool(sources.get(0).pool, sourceAssumption), new SelectedPool(destination, destinationAssumption));
}
Also used : SourceCostException(diskCacheV111.util.SourceCostException) Assumption(org.dcache.pool.assumption.Assumption) AvailableSpaceAssumption(org.dcache.pool.assumption.AvailableSpaceAssumption) PerformanceCostAssumption(org.dcache.pool.assumption.PerformanceCostAssumption) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) AvailableSpaceAssumption(org.dcache.pool.assumption.AvailableSpaceAssumption) DestinationCostException(diskCacheV111.util.DestinationCostException)

Example 28 with PermissionDeniedCacheException

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

the class AbstractFtpDoorV1Test method whenRmdPermissionDeniedReply550.

@Test
public void whenRmdPermissionDeniedReply550() throws Exception {
    doCallRealMethod().when(door).ftp_rmd(anyString());
    doThrow(new PermissionDeniedCacheException("Permission denied")).when(pnfs).deletePnfsEntry("/pathRoot/cwd/" + OLD_DIR, EnumSet.of(FileType.DIR));
    thrown.expectCode(550);
    door.ftp_rmd(OLD_DIR);
}
Also used : PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) Test(org.junit.Test)

Example 29 with PermissionDeniedCacheException

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

the class Storage method putDone.

@Override
public void putDone(SRMUser user, String localTransferPath, URI surl, boolean overwrite) throws SRMException {
    try {
        Subject subject = asDcacheUser(user).getSubject();
        Restriction restriction = asDcacheUser(user).getRestriction();
        FsPath fullPath = getPath(surl);
        checkNonBrokenUpload(localTransferPath);
        EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
        if (overwrite) {
            options.add(CreateOption.OVERWRITE_EXISTING);
        }
        PnfsCommitUpload msg = new PnfsCommitUpload(subject, restriction, FsPath.create(localTransferPath), fullPath, options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
        msg = _pnfsStub.sendAndWait(msg);
        DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
        infoMsg.setSubject(subject);
        infoMsg.setBillingPath(fullPath.toString());
        infoMsg.setTransferPath(localTransferPath);
        infoMsg.setTransaction(CDC.getSession());
        infoMsg.setPnfsId(msg.getFileAttributes().getPnfsId());
        infoMsg.setResult(0, "");
        infoMsg.setFileSize(msg.getFileAttributes().getSizeIfPresent().orElse(0L));
        infoMsg.setStorageInfo(msg.getFileAttributes().getStorageInfo());
        Origin origin = Subjects.getOrigin(subject);
        if (origin != null) {
            infoMsg.setClient(origin.getAddress().getHostAddress());
        }
        _billingStub.notify(infoMsg);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException(e.getMessage(), e);
    } catch (FileIsNewCacheException | FileCorruptedCacheException e) {
        throw new SRMException(e.getMessage(), e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied.", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException(surl + " exists.", 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("Internal communication failure", e);
    }
}
Also used : DoorRequestInfoMessage(diskCacheV111.vehicles.DoorRequestInfoMessage) Origin(org.dcache.auth.Origin) 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) 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) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileIsNewCacheException(diskCacheV111.util.FileIsNewCacheException) CreateOption(org.dcache.namespace.CreateOption) PnfsCommitUpload(diskCacheV111.vehicles.PnfsCommitUpload) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FsPath(diskCacheV111.util.FsPath)

Example 30 with PermissionDeniedCacheException

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

the class Storage method moveEntry.

@Override
public void moveEntry(SRMUser abstractUser, URI from, URI to) throws SRMException {
    DcacheUser user = asDcacheUser(abstractUser);
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    FsPath fromPath = getPath(from);
    FsPath toPath = getPath(to);
    try {
        try {
            FileAttributes attr = handler.getFileAttributes(toPath.toString(), EnumSet.of(TYPE));
            /* We now know the destination exists. In case the
                 * source and destination names are identical, we
                 * silently ignore the request.
                 */
            if (fromPath.equals(toPath)) {
                return;
            }
            if (attr.getFileType() != FileType.DIR) {
                throw new SRMDuplicationException("Destination exists");
            }
            toPath = toPath.child(fromPath.name());
        } catch (FileNotFoundCacheException e) {
        /* Destination name does not exist; not a problem.
                 */
        }
        handler.renameEntry(fromPath.toString(), toPath.toString(), false);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("No such file or directory", e);
    } catch (FileExistsCacheException e) {
        throw new SRMDuplicationException("Destination exists", e);
    } catch (NotDirCacheException e) {
        /* The parent of the target name did not exist or was not
             * a directory.
             */
        FsPath parent = toPath.parent();
        throw new SRMInvalidPathException("No such directory: " + parent, e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (TimeoutCacheException e) {
        _log.error("Failed to rename {} due to timeout", fromPath);
        throw new SRMInternalErrorException("Internal name space timeout");
    } catch (CacheException e) {
        _log.error("Failed to rename {}: {}", fromPath, e.getMessage());
        throw new SRMException(String.format("Rename failed [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) FileAttributes(org.dcache.vehicles.FileAttributes) NotDirCacheException(diskCacheV111.util.NotDirCacheException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)87 CacheException (diskCacheV111.util.CacheException)68 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)54 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)47 NotDirCacheException (diskCacheV111.util.NotDirCacheException)41 FsPath (diskCacheV111.util.FsPath)40 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)34 NotFileCacheException (diskCacheV111.util.NotFileCacheException)33 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)30 FileAttributes (org.dcache.vehicles.FileAttributes)28 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)26 Subject (javax.security.auth.Subject)21 NoAttributeCacheException (diskCacheV111.util.NoAttributeCacheException)18 AttributeExistsCacheException (diskCacheV111.util.AttributeExistsCacheException)17 FileAttribute (org.dcache.namespace.FileAttribute)17 InvalidMessageCacheException (diskCacheV111.util.InvalidMessageCacheException)15 PnfsHandler (diskCacheV111.util.PnfsHandler)15 IOException (java.io.IOException)15 LockedCacheException (diskCacheV111.util.LockedCacheException)14 MissingResourceCacheException (diskCacheV111.util.MissingResourceCacheException)14