Search in sources :

Example 16 with TimeoutCacheException

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

the class DelegationHandler method login.

private Subject login() throws DelegationException {
    try {
        Subject subject = new Subject();
        X509Certificate[] chain = Axis.getCertificateChain().orElseThrow(() -> new DelegationException("User supplied no certificate."));
        subject.getPublicCredentials().add(cf.generateCertPath(asList(chain)));
        subject.getPrincipals().add(new Origin(InetAddresses.forUriString(Axis.getRemoteAddress())));
        return loginStrategy.login(subject).getSubject();
    } catch (CertificateException e) {
        throw new DelegationException("Failed to process certificate chain.");
    } catch (PermissionDeniedCacheException e) {
        throw new DelegationException("User is not authorized.");
    } catch (TimeoutCacheException e) {
        throw new DelegationException("Internal timeout.");
    } catch (CacheException e) {
        throw new DelegationException(e.getMessage());
    }
}
Also used : Origin(org.dcache.auth.Origin) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) CacheException(diskCacheV111.util.CacheException) DelegationException(org.dcache.delegation.gridsite2.DelegationException) CertificateException(java.security.cert.CertificateException) Subject(javax.security.auth.Subject) X509Certificate(java.security.cert.X509Certificate) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 17 with TimeoutCacheException

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

the class WriteHandleImpl method commit.

@Override
public synchronized void commit() throws IllegalStateException, InterruptedException, CacheException {
    if (_state != HandleState.OPEN) {
        throw new IllegalStateException("Handle is closed");
    }
    try {
        _entry.setLastAccessTime((_atime == null) ? System.currentTimeMillis() : _atime);
        _fileAttributes.setCreationTime(System.currentTimeMillis());
        _fileAttributes.setAccessTime(System.currentTimeMillis());
        long length = _entry.getReplicaSize();
        verifyFileSize(length);
        _fileAttributes.setSize(length);
        boolean namespaceUpdated = false;
        do {
            /*
                 * We may run into timeout if PnfsManager or network is down.
                 * (NOTICE, that PnfsHandler converts NoRouteToCell into Timeout exception)
                 * In such situations we should re-try the request. If timeout exception
                 * is propagated, then file will be stored in error state, to recover it
                 * during the next restart.
                 */
            try {
                registerFileAttributesInNameSpace();
                namespaceUpdated = true;
            } catch (TimeoutCacheException e) {
                LOGGER.warn("Failed to update namespace: {}. Retrying in 15 s", e.getMessage());
                TimeUnit.SECONDS.sleep(15);
            }
        } while (!namespaceUpdated);
        _entry.update("Committing new file", r -> {
            r.setFileAttributes(_fileAttributes);
            /* In several situations, dCache requests a CACHED file
                 * without having any sticky flags on it. Such files are
                 * subject to immediate garbage collection if we are short on
                 * disk space. Thus to give other clients time to access the
                 * file, we mark it sticky for a short amount of time.
                 */
            if (_targetState == ReplicaState.CACHED && _stickyRecords.isEmpty()) {
                long now = System.currentTimeMillis();
                r.setSticky("self", now + HOLD_TIME, false);
            }
            /* Move entry to target state.
                 */
            for (StickyRecord record : _stickyRecords) {
                r.setSticky(record.owner(), record.expire(), false);
            }
            return r.setState(_targetState);
        });
        setState(HandleState.COMMITTED);
    } catch (CacheException e) {
        /* If any of the PNFS operations return FILE_NOT_FOUND,
             * then we change the target state and the close method
             * will take care of removing the file.
             */
        if (e.getRc() == CacheException.FILE_NOT_FOUND) {
            _targetState = ReplicaState.REMOVED;
        }
        throw e;
    }
}
Also used : StickyRecord(org.dcache.pool.repository.StickyRecord) CacheException(diskCacheV111.util.CacheException) FileCorruptedCacheException(diskCacheV111.util.FileCorruptedCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 18 with TimeoutCacheException

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

the class AbstractFtpDoorV1 method ftp_mkd.

@Help("MKD <SP> <path> - Create a directory.")
public void ftp_mkd(String arg) throws FTPCommandException {
    /**
     * MKD
     *   257
     *   500, 501, 502, 421, 530, 550
     */
    checkLoggedIn(FORBID_ANONYMOUS_USER);
    checkFTPCommand(!arg.isEmpty(), 500, "Missing path argument");
    FsPath path = absolutePath(arg);
    String properDirectoryStringReply = path.stripPrefix(_doorRootPath).replaceAll("\"", "\"\"");
    try {
        _pnfs.createPnfsDirectory(path.toString());
        /*
               From RFC 959
               ....., upon successful completion of an MKD
               command, the server should return a line of the form:

               257<space>"<directory-name>"<space><commentary>

                That is, the server will tell the user what string to use when
                referring to the created  directory.  The directory name can
                contain any character; embedded double-quotes should be escaped by
                double-quotes (the "quote-doubling" convention).

                For example, a user connects to the directory /usr/dm, and creates
                a subdirectory, named pathname:

                CWD /usr/dm
                200 directory changed to /usr/dm
                MKD pathname
                257 "/usr/dm/pathname" directory created

                An example with an embedded double quote:

                MKD foo"bar
                257 "/usr/dm/foo""bar" directory created
                CWD /usr/dm/foo"bar
                200 directory changed to /usr/dm/foo"bar
            */
        reply("257 \"" + properDirectoryStringReply + "\" directory created");
    } catch (PermissionDeniedCacheException e) {
        throw new FTPCommandException(550, "Permission denied");
    } catch (FileExistsCacheException e) {
        throw new FTPCommandException(550, "\"" + properDirectoryStringReply + "\" directory already exists");
    } catch (TimeoutCacheException e) {
        throw new FTPCommandException(451, "Internal timeout, reason:" + e);
    } catch (CacheException e) {
        throw new FTPCommandException(550, "Cannot create directory, reason:" + e);
    }
}
Also used : PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) MissingResourceCacheException(diskCacheV111.util.MissingResourceCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotFileCacheException(diskCacheV111.util.NotFileCacheException) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) FileExistsCacheException(diskCacheV111.util.FileExistsCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 19 with TimeoutCacheException

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

the class PoolDataRequestProcessor method process.

@Override
protected PoolInfoWrapper process(String key, PoolDataRequestMessage message, long sent) {
    Serializable errorObject = message.getErrorObject();
    if (errorObject != null) {
        LOGGER.warn("Problem with retrieval of pool data for {}: {}.", key, errorObject.toString());
        return null;
    }
    PoolData poolData = message.getData();
    CellData cellData = poolData == null ? null : poolData.getCellData();
    if (cellData != null) {
        cellData.setRoundTripTime(System.currentTimeMillis() - sent);
    }
    PoolInfoWrapper info = new PoolInfoWrapper();
    info.setKey(key);
    /*
         *  NB:  the counts histogram for file lifetime will be added
         *  by the historical data method below.
         */
    info.setInfo(poolData);
    try {
        handler.addHistoricalData(info);
    } catch (NoRouteToCellException | InterruptedException | TimeoutCacheException e) {
        LOGGER.debug("Could not add historical data for {}: {}.", key, e.getMessage());
    } catch (CacheException e) {
        LOGGER.error("Could not add historical data for {}: {}.", key, e.getMessage());
    }
    return info;
}
Also used : Serializable(java.io.Serializable) PoolInfoWrapper(org.dcache.pool.json.PoolInfoWrapper) CacheException(diskCacheV111.util.CacheException) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) PoolData(org.dcache.pool.json.PoolData) CellData(org.dcache.cells.json.CellData) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 20 with TimeoutCacheException

use of diskCacheV111.util.TimeoutCacheException 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

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