Search in sources :

Example 1 with SRMTooManyResultsException

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

use of org.dcache.srm.SRMTooManyResultsException 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 3 with SRMTooManyResultsException

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

the class TStatusCodes method checkSuccess.

public static void checkSuccess(TReturnStatus returnStatus, TStatusCode... success) throws SRMException {
    TStatusCode statusCode = returnStatus.getStatusCode();
    String explanation = returnStatus.getExplanation();
    if (asList(success).contains(statusCode)) {
        return;
    }
    if (explanation == null) {
        explanation = "Operation failed with " + returnStatus.getStatusCode();
    }
    if (statusCode == TStatusCode.SRM_FAILURE) {
        throw new SRMException(explanation);
    } else if (statusCode == TStatusCode.SRM_PARTIAL_SUCCESS) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_AUTHENTICATION_FAILURE) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_AUTHORIZATION_FAILURE) {
        throw new SRMAuthorizationException(explanation);
    } else if (statusCode == TStatusCode.SRM_INVALID_REQUEST) {
        throw new SRMInvalidRequestException(explanation);
    } else if (statusCode == TStatusCode.SRM_INVALID_PATH) {
        throw new SRMInvalidPathException(explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_LIFETIME_EXPIRED) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_SPACE_LIFETIME_EXPIRED) {
        throw new SRMSpaceLifetimeExpiredException(explanation);
    } else if (statusCode == TStatusCode.SRM_EXCEED_ALLOCATION) {
        throw new SRMExceedAllocationException(explanation);
    } else if (statusCode == TStatusCode.SRM_NO_USER_SPACE) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_NO_FREE_SPACE) {
        throw new SRMNoFreeSpaceException(explanation);
    } else if (statusCode == TStatusCode.SRM_DUPLICATION_ERROR) {
        throw new SRMDuplicationException(explanation);
    } else if (statusCode == TStatusCode.SRM_NON_EMPTY_DIRECTORY) {
        throw new SRMNonEmptyDirectoryException(explanation);
    } else if (statusCode == TStatusCode.SRM_TOO_MANY_RESULTS) {
        throw new SRMTooManyResultsException(explanation);
    } else if (statusCode == TStatusCode.SRM_INTERNAL_ERROR) {
        throw new SRMInternalErrorException(explanation);
    } else if (statusCode == TStatusCode.SRM_FATAL_INTERNAL_ERROR) {
        throw new SRMInternalErrorException(explanation);
    } else if (statusCode == TStatusCode.SRM_NOT_SUPPORTED) {
        throw new SRMNotSupportedException(explanation);
    } else if (statusCode == TStatusCode.SRM_REQUEST_QUEUED) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_REQUEST_INPROGRESS) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_ABORTED) {
        throw new SRMAbortedException(explanation);
    } else if (statusCode == TStatusCode.SRM_RELEASED) {
        throw new SRMReleasedException(explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_PINNED) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_IN_CACHE) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_SPACE_AVAILABLE) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_LOWER_SPACE_GRANTED) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_REQUEST_TIMED_OUT) {
        throw new SRMRequestTimedOutException(explanation);
    } else if (statusCode == TStatusCode.SRM_LAST_COPY) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_BUSY) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_LOST) {
        throw new SRMOtherException(statusCode, explanation);
    } else if (statusCode == TStatusCode.SRM_FILE_UNAVAILABLE) {
        throw new SRMFileUnvailableException(explanation);
    } else if (statusCode == TStatusCode.SRM_CUSTOM_STATUS) {
        throw new SRMOtherException(statusCode, explanation);
    } else {
        throw new SRMOtherException(statusCode, explanation);
    }
}
Also used : SRMExceedAllocationException(org.dcache.srm.SRMExceedAllocationException) SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) SRMNonEmptyDirectoryException(org.dcache.srm.SRMNonEmptyDirectoryException) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) SRMAbortedException(org.dcache.srm.SRMAbortedException) TStatusCode(org.dcache.srm.v2_2.TStatusCode) SRMTooManyResultsException(org.dcache.srm.SRMTooManyResultsException) SRMRequestTimedOutException(org.dcache.srm.SRMRequestTimedOutException) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) SRMFileUnvailableException(org.dcache.srm.SRMFileUnvailableException) SRMReleasedException(org.dcache.srm.SRMReleasedException) SRMOtherException(org.dcache.srm.SRMOtherException) SRMSpaceLifetimeExpiredException(org.dcache.srm.SRMSpaceLifetimeExpiredException) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException) SRMNoFreeSpaceException(org.dcache.srm.SRMNoFreeSpaceException) SRMDuplicationException(org.dcache.srm.SRMDuplicationException)

Aggregations

SRMTooManyResultsException (org.dcache.srm.SRMTooManyResultsException)3 URI (java.net.URI)2 LinkedList (java.util.LinkedList)2 FileMetaData (org.dcache.srm.FileMetaData)2 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)2 SRMException (org.dcache.srm.SRMException)2 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)2 ArrayOfTMetaDataPathDetail (org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail)2 TMetaDataPathDetail (org.dcache.srm.v2_2.TMetaDataPathDetail)2 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)2 SRMAbortedException (org.dcache.srm.SRMAbortedException)1 SRMDuplicationException (org.dcache.srm.SRMDuplicationException)1 SRMExceedAllocationException (org.dcache.srm.SRMExceedAllocationException)1 SRMFileUnvailableException (org.dcache.srm.SRMFileUnvailableException)1 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 SRMNoFreeSpaceException (org.dcache.srm.SRMNoFreeSpaceException)1 SRMNonEmptyDirectoryException (org.dcache.srm.SRMNonEmptyDirectoryException)1 SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)1 SRMOtherException (org.dcache.srm.SRMOtherException)1