Search in sources :

Example 6 with FileMetaData

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

the class CopyFileRequest method runLocalToLocalCopy.

private void runLocalToLocalCopy() throws IllegalStateTransition, SRMException {
    LOGGER.debug("copying from local to local");
    FileMetaData fmd;
    try {
        fmd = getStorage().getFileMetaData(getUser(), getSourceSurl(), true);
    } catch (SRMException srme) {
        try {
            setStateAndStatusCode(State.FAILED, srme.getMessage(), TStatusCode.SRM_INVALID_PATH);
        } catch (IllegalStateTransition ist) {
            LOGGER.error("Illegal State Transition : {}", ist.getMessage());
        }
        return;
    }
    setSize(fmd.size);
    if (getDestinationFileId() == null) {
        addHistoryEvent("Doing name space lookup.");
        LOGGER.debug("calling storage.prepareToPut({})", getLocalDestinationPath());
        CheckedFuture<String, ? extends SRMException> future = getStorage().prepareToPut(getUser(), getDestinationSurl(), size, Objects.toString(getContainerRequest().getTargetAccessLatency(), null), Objects.toString(getContainerRequest().getTargetRetentionPolicy(), null), getSpaceReservationId(), getContainerRequest().isOverwrite());
        future.addListener(new PutCallbacks(getId(), future), directExecutor());
        LOGGER.debug("callbacks.waitResult()");
        return;
    }
    LOGGER.debug("known source size is {}", size);
    try {
        getStorage().localCopy(getUser(), getSourceSurl(), getDestinationFileId());
        getStorage().putDone(getUser(), getDestinationFileId(), getDestinationSurl(), getContainerRequest().isOverwrite());
        setStateToDone();
    } catch (SRMException e) {
        getStorage().abortPut(null, getDestinationFileId(), getDestinationSurl(), e.getMessage());
        throw e;
    }
}
Also used : IllegalStateTransition(org.dcache.srm.scheduler.IllegalStateTransition) SRMException(org.dcache.srm.SRMException) FileMetaData(org.dcache.srm.FileMetaData)

Example 7 with FileMetaData

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

the class LsFileRequest method run.

@Override
public synchronized void run() throws IllegalStateTransition {
    LOGGER.trace("run");
    if (!getState().isFinal()) {
        try {
            LsRequest parent = getContainerRequest();
            long t0 = 0;
            if (LOGGER.isDebugEnabled()) {
                t0 = System.currentTimeMillis();
            }
            String fileId = SRM.getSRM().getUploadFileId(surl);
            TMetaDataPathDetail detail;
            if (fileId != null) {
                // srmPrepareToPut (no srmPutDone is yet called) request for.
                try {
                    FileMetaData fmd = getStorage().getFileMetaData(getUser(), surl, fileId);
                    detail = convertFileMetaDataToTMetaDataPathDetail(surl, fmd, parent.getLongFormat());
                } catch (SRMInvalidPathException e) {
                    detail = new TMetaDataPathDetail();
                    detail.setType(TFileType.FILE);
                }
                detail.setPath(getPath(surl));
                detail.setStatus(new TReturnStatus(TStatusCode.SRM_FILE_BUSY, "The requested SURL is locked by an upload."));
            } else {
                detail = getMetaDataPathDetail(surl, 0, parent.getOffset(), parent.getCount(), parent.getNumOfLevels(), parent.getLongFormat());
            }
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("LsFileRequest.run(), TOOK {}", (System.currentTimeMillis() - t0));
            }
            try {
                getContainerRequest().resetRetryDeltaTime();
            } catch (SRMInvalidRequestException ire) {
                LOGGER.error(ire.toString());
            }
            wlock();
            try {
                metaDataPathDetail = detail;
                if (!getState().isFinal()) {
                    setState(State.DONE, State.DONE.toString());
                }
            } finally {
                wunlock();
            }
        } catch (SRMException e) {
            fail(e.getStatusCode(), e.getMessage());
        } catch (URISyntaxException e) {
            fail(TStatusCode.SRM_FAILURE, e.getMessage());
        } catch (DataAccessException | IllegalStateTransition e) {
            LOGGER.error(e.toString(), e);
            fail(TStatusCode.SRM_INTERNAL_ERROR, e.getMessage());
        }
    }
}
Also used : IllegalStateTransition(org.dcache.srm.scheduler.IllegalStateTransition) 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) URISyntaxException(java.net.URISyntaxException) SRMException(org.dcache.srm.SRMException) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException) FileMetaData(org.dcache.srm.FileMetaData) DataAccessException(org.springframework.dao.DataAccessException)

Example 8 with FileMetaData

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

the class LsFileRequest method getMetaDataPathDetail.

private void getMetaDataPathDetail(TMetaDataPathDetail metaDataPathDetail, long offset, long count, boolean longFormat) throws SRMException, URISyntaxException {
    List<FileMetaData> directoryList;
    // 
    // simplify things for the most common case when people perform
    // ls on directory w/o specifying recursionDepth
    // 
    URI surl = new URI(null, null, metaDataPathDetail.getPath(), null);
    directoryList = getStorage().listDirectory(getUser(), surl, longFormat, (int) offset, (int) count);
    getContainerRequest().setCounter(offset);
    List<TMetaDataPathDetail> metadataPathDetailList = new LinkedList<>();
    for (FileMetaData md : directoryList) {
        URI subpath = new URI(null, null, md.SURL, null);
        TMetaDataPathDetail dirMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(subpath, md, longFormat);
        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();
    }
    metaDataPathDetail.setArrayOfSubPaths(new ArrayOfTMetaDataPathDetail(metadataPathDetailList.toArray(TMetaDataPathDetail[]::new)));
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) URI(java.net.URI) FileMetaData(org.dcache.srm.FileMetaData) LinkedList(java.util.LinkedList) SRMTooManyResultsException(org.dcache.srm.SRMTooManyResultsException)

Example 9 with FileMetaData

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

the class Storage method getFileMetaData.

private FileMetaData getFileMetaData(DcacheUser user, boolean checkReadPermissions, FsPath path) throws SRMException {
    PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
    try {
        /* Fetch file attributes.
             */
        Set<FileAttribute> requestedAttributes = EnumSet.of(TYPE, LOCATIONS);
        requestedAttributes.addAll(DcacheFileMetaData.getKnownAttributes());
        requestedAttributes.addAll(PoolMonitorV5.getRequiredAttributesForFileLocality());
        Set<AccessMask> accessMask = checkReadPermissions ? EnumSet.of(AccessMask.READ_DATA) : EnumSet.noneOf(AccessMask.class);
        FileAttributes attributes = handler.getFileAttributes(path.toString(), requestedAttributes, accessMask, false);
        FileMetaData fmd = new DcacheFileMetaData(attributes);
        /* Determine file locality.
             */
        if (attributes.getFileType() != FileType.DIR) {
            FileLocality locality = _poolMonitor.getFileLocality(attributes, config.getSrmHost());
            fmd.locality = locality.toTFileLocality();
            fmd.isCached = locality.isCached();
        }
        /* Determine space tokens.
             */
        if (_isSpaceManagerEnabled) {
            try {
                GetFileSpaceTokensMessage msg = new GetFileSpaceTokensMessage(attributes.getPnfsId());
                msg = _spaceManagerStub.sendAndWait(msg);
                if (msg.getSpaceTokens() != null) {
                    fmd.spaceTokens = new long[msg.getSpaceTokens().length];
                    System.arraycopy(msg.getSpaceTokens(), 0, fmd.spaceTokens, 0, msg.getSpaceTokens().length);
                }
            } catch (NoRouteToCellException e) {
                /* SpaceManager is optional, so we don't classify this
                     * as an error.
                     */
                _log.info(e.getMessage());
            }
        }
        return fmd;
    } catch (TimeoutCacheException e) {
        throw new SRMInternalErrorException(e.getMessage(), e);
    } catch (PermissionDeniedCacheException e) {
        throw new SRMAuthorizationException(e.getMessage(), e);
    } catch (FileNotFoundCacheException e) {
        throw new SRMInvalidPathException(e.getMessage(), e);
    } catch (CacheException e) {
        throw new SRMException("Could not get storage info by path: " + e.getMessage(), e);
    } catch (InterruptedException e) {
        throw new SRMInternalErrorException("Operation interrupted", e);
    }
}
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) AccessMask(org.dcache.acl.enums.AccessMask) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) PermissionDeniedCacheException(diskCacheV111.util.PermissionDeniedCacheException) SRMException(org.dcache.srm.SRMException) GetFileSpaceTokensMessage(diskCacheV111.services.space.message.GetFileSpaceTokensMessage) NoRouteToCellException(dmg.cells.nucleus.NoRouteToCellException) FileNotFoundCacheException(diskCacheV111.util.FileNotFoundCacheException) FileAttributes(org.dcache.vehicles.FileAttributes) FileLocality(diskCacheV111.util.FileLocality) FileMetaData(org.dcache.srm.FileMetaData) FileAttribute(org.dcache.namespace.FileAttribute) TimeoutCacheException(diskCacheV111.util.TimeoutCacheException)

Aggregations

FileMetaData (org.dcache.srm.FileMetaData)9 SRMException (org.dcache.srm.SRMException)6 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)6 URI (java.net.URI)5 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)5 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)4 ArrayOfTMetaDataPathDetail (org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail)4 TMetaDataPathDetail (org.dcache.srm.v2_2.TMetaDataPathDetail)4 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)3 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)3 LinkedList (java.util.LinkedList)2 SRMTooManyResultsException (org.dcache.srm.SRMTooManyResultsException)2 IllegalStateTransition (org.dcache.srm.scheduler.IllegalStateTransition)2 ArrayOfString (org.dcache.srm.v2_2.ArrayOfString)2 TPermissionMode (org.dcache.srm.v2_2.TPermissionMode)2 GetFileSpaceTokensMessage (diskCacheV111.services.space.message.GetFileSpaceTokensMessage)1 CacheException (diskCacheV111.util.CacheException)1 FileCorruptedCacheException (diskCacheV111.util.FileCorruptedCacheException)1 FileExistsCacheException (diskCacheV111.util.FileExistsCacheException)1 FileIsNewCacheException (diskCacheV111.util.FileIsNewCacheException)1