Search in sources :

Example 1 with SRMInvalidPathException

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

the class LsFileRequest method getRecursiveMetaDataPathDetail.

private void getRecursiveMetaDataPathDetail(TMetaDataPathDetail metaDataPathDetail, FileMetaData fmd, int depth, long offset, long count, int recursionDepth, boolean longFormat) throws SRMException, URISyntaxException {
    if (!fmd.isDirectory || depth >= recursionDepth) {
        return;
    }
    List<FileMetaData> directoryList;
    URI surl = new URI(null, null, metaDataPathDetail.getPath(), null);
    // rely on our own counting
    if (offset == 0) {
        // 
        // if offset=0, trivial case, just grab information w/ verbosity level
        // provided by the user
        // 
        directoryList = getStorage().listDirectory(getUser(), surl, longFormat, 0, (int) count);
    } else {
        // 
        // if offset!=0, we loop over direntries in non-verbose mode until
        // we hit offset, then start getting information with verbosity
        // level specified by the user by calling getStorage().getFileMetaData on
        // each entry
        // 
        directoryList = getStorage().listDirectory(getUser(), surl, false, 0, Integer.MAX_VALUE);
    }
    // 
    // sort list such that directories are at the end of the list after
    // sorting. The intent is to leave the recursion calls at the
    // end of the tree, so we have less chance to even get there
    // 
    Collections.sort(directoryList, DIRECTORY_LAST_ORDER);
    List<TMetaDataPathDetail> metadataPathDetailList = new LinkedList<>();
    for (FileMetaData md : directoryList) {
        URI subpath = new URI(null, null, md.SURL, null);
        TMetaDataPathDetail dirMetaDataPathDetail;
        if (offset == 0) {
            dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, md, longFormat);
        } else {
            FileMetaData fileMetaData = md;
            if (!getContainerRequest().shouldSkipThisRecord()) {
                if (longFormat) {
                    fileMetaData = getStorage().getFileMetaData(getUser(), subpath, false);
                }
                dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, fileMetaData, longFormat);
            } else {
                // 
                // skip this record - meaning count it, and request only minimal details, do not store it
                // 
                dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, fileMetaData, false);
            }
        }
        if (!getContainerRequest().shouldSkipThisRecord()) {
            metadataPathDetailList.add(dirMetaDataPathDetail);
            try {
                if (!getContainerRequest().increaseResultsNumAndContinue()) {
                    break;
                }
            } catch (SRMTooManyResultsException e) {
                metaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage()));
                break;
            }
        }
        // 
        // increment global entries counter
        // 
        getContainerRequest().incrementGlobalEntryCounter();
        if (md.isDirectory) {
            try {
                getRecursiveMetaDataPathDetail(dirMetaDataPathDetail, md, depth + 1, offset, count, recursionDepth, longFormat);
            } catch (SRMException e) {
                String msg = e.getMessage();
                if (e instanceof SRMAuthorizationException) {
                    dirMetaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, msg));
                } else if (e instanceof SRMInvalidPathException) {
                    dirMetaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_INVALID_PATH, msg));
                } else {
                    dirMetaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_FAILURE, msg));
                }
            }
        }
    }
    metaDataPathDetail.setArrayOfSubPaths(new ArrayOfTMetaDataPathDetail(metadataPathDetailList.toArray(TMetaDataPathDetail[]::new)));
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) URI(java.net.URI) LinkedList(java.util.LinkedList) SRMTooManyResultsException(org.dcache.srm.SRMTooManyResultsException) SRMException(org.dcache.srm.SRMException) ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) FileMetaData(org.dcache.srm.FileMetaData)

Example 2 with SRMInvalidPathException

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

the class PinCompanion method fail.

private void fail(int rc, String error) {
    switch(rc) {
        case FILE_NOT_FOUND:
            setException(new SRMInvalidPathException("No such file."));
            break;
        case FILE_NOT_IN_REPOSITORY:
            _log.warn("Pinning failed for {} ({})", _path, error);
            setException(new SRMFileUnvailableException(error));
            break;
        case PERMISSION_DENIED:
            _log.warn("Pinning failed for {} ({})", _path, error);
            setException(new SRMAuthorizationException(error));
            break;
        case TIMEOUT:
            _log.info("Pinning failed: {}", error);
            setException(new SRMInternalErrorException("Pin operation timed out"));
            break;
        default:
            _log.error("Pinning failed for {} [rc={},msg={}].", _path, rc, error);
            String reason = String.format("Failed to pin file [rc=%d,msg=%s].", rc, error);
            setException(new SRMException(reason));
            break;
    }
    _state = new FailedState();
}
Also used : SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMException(org.dcache.srm.SRMException) SRMFileUnvailableException(org.dcache.srm.SRMFileUnvailableException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException)

Example 3 with SRMInvalidPathException

use of org.dcache.srm.SRMInvalidPathException 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 4 with SRMInvalidPathException

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

Example 5 with SRMInvalidPathException

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

the class Storage method checkWritePrivileges.

/**
 * Ensures that the user has write privileges for a path. That includes checking lookup
 * privileges. The file must exist for the call to succeed.
 *
 * @param user The user ID
 * @param surl The path to the file
 * @throws SRMAuthorizationException if the user lacks write privileges for this path.
 * @throws SRMInvalidPathException   if the file does not exist
 * @throws SRMInternalErrorException for transient errors
 * @throws SRMException              for other errors
 */
private void checkWritePrivileges(SRMUser user, URI surl) throws SRMException {
    try {
        DcacheUser dCacheUser = asDcacheUser(user);
        FsPath path = getPath(surl);
        PnfsHandler handler = new PnfsHandler(_pnfs, dCacheUser.getSubject(), dCacheUser.getRestriction());
        handler.getFileAttributes(path.toString(), EnumSet.noneOf(FileAttribute.class), EnumSet.of(AccessMask.WRITE_DATA), false);
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException("Internal name space timeout", e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException("Parent path does not exist", e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException("Permission denied");
    } catch (CacheException e) {
        throw new SRMException(String.format("Operation failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
    }
}
Also used : SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMException(org.dcache.srm.SRMException) 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) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) PnfsHandler(diskCacheV111.util.PnfsHandler) FsPath(diskCacheV111.util.FsPath) FileAttribute(org.dcache.namespace.FileAttribute) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)26 SRMException (org.dcache.srm.SRMException)25 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)24 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)21 CacheException (diskCacheV111.util.CacheException)13 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)13 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)13 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)13 FileNotFoundCacheException (diskCacheV111.util.FileNotFoundCacheException)13 NotDirCacheException (diskCacheV111.util.NotDirCacheException)13 PermissionDeniedCacheException (diskCacheV111.util.PermissionDeniedCacheException)13 TimeoutCacheException (diskCacheV111.util.TimeoutCacheException)13 FsPath (diskCacheV111.util.FsPath)11 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)11 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)9 PnfsHandler (diskCacheV111.util.PnfsHandler)8 URI (java.net.URI)6 Subject (javax.security.auth.Subject)6 Restriction (org.dcache.auth.attributes.Restriction)6 FileMetaData (org.dcache.srm.FileMetaData)6