Search in sources :

Example 51 with SRMException

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

the class Storage method listDirectory.

@Override
public List<FileMetaData> listDirectory(SRMUser user, URI surl, final boolean verbose, int offset, int count) throws SRMException {
    try {
        FsPath path = getPath(surl);
        Subject subject = asDcacheUser(user).getSubject();
        Restriction restriction = asDcacheUser(user).getRestriction();
        FmdListPrinter printer = verbose ? new VerboseListPrinter() : new FmdListPrinter();
        Range<Integer> range = offset < Integer.MAX_VALUE - count ? Range.closedOpen(offset, offset + count) : Range.atLeast(offset);
        _listSource.printDirectory(subject, restriction, printer, path, null, range);
        return printer.getResult();
    } 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) 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) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) NotDirCacheException(diskCacheV111.util.NotDirCacheException) FsPath(diskCacheV111.util.FsPath) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Example 52 with SRMException

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

the class SrmHandler method toGetRequestSummaryResponse.

private SrmGetRequestSummaryResponse toGetRequestSummaryResponse(Map<String, ListenableFuture<TRequestSummary>> futureMap) throws InterruptedException, CacheException, NoRouteToCellException {
    boolean hasFailure = false;
    boolean hasSuccess = false;
    List<TRequestSummary> summaries = new ArrayList<>();
    for (Map.Entry<String, ListenableFuture<TRequestSummary>> entry : futureMap.entrySet()) {
        try {
            summaries.add(entry.getValue().get());
            hasSuccess = true;
        } catch (ExecutionException e) {
            Throwable cause = e.getCause();
            if (cause instanceof SRMException) {
                summaries.add(createRequestSummaryFailure(entry.getKey(), ((SRMException) cause).getStatusCode(), cause.getMessage()));
                hasFailure = true;
            } else {
                Throwables.throwIfInstanceOf(cause, CacheException.class);
                Throwables.throwIfInstanceOf(cause, NoRouteToCellException.class);
                Throwables.throwIfUnchecked(e);
                throw new RuntimeException(e);
            }
        }
    }
    TReturnStatus status;
    if (!hasFailure) {
        status = new TReturnStatus(SRM_SUCCESS, "All request statuses have been retrieved.");
    } else if (hasSuccess) {
        status = new TReturnStatus(SRM_PARTIAL_SUCCESS, "Some request statuses have been retrieved.");
    } else {
        status = new TReturnStatus(SRM_FAILURE, "No request statuses have been retrieved.");
    }
    return new SrmGetRequestSummaryResponse(status, new ArrayOfTRequestSummary(summaries.toArray(TRequestSummary[]::new)));
}
Also used : TRequestSummary(org.dcache.srm.v2_2.TRequestSummary) ArrayOfTRequestSummary(org.dcache.srm.v2_2.ArrayOfTRequestSummary) ArrayOfTRequestSummary(org.dcache.srm.v2_2.ArrayOfTRequestSummary) CacheException(diskCacheV111.util.CacheException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayList(java.util.ArrayList) SrmGetRequestSummaryResponse(org.dcache.srm.v2_2.SrmGetRequestSummaryResponse) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) SRMException(org.dcache.srm.SRMException) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ExecutionException(java.util.concurrent.ExecutionException) Map(java.util.Map) Collectors.toMap(java.util.stream.Collectors.toMap) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap)

Aggregations

SRMException (org.dcache.srm.SRMException)52 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)34 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)26 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)25 CacheException (diskCacheV111.util.CacheException)20 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)19 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)17 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)17 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)16 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)16 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)16 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)16 NotDirCacheException (diskCacheV111.util.NotDirCacheException)16 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)14 FsPath (diskCacheV111.util.FsPath)11 NoRouteToCellException (dmg.cells.nucleus.NoRouteToCellException)10 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)8 PnfsHandler (diskCacheV111.util.PnfsHandler)7 Subject (javax.security.auth.Subject)7 ArrayOfString (org.dcache.srm.v2_2.ArrayOfString)7