Search in sources :

Example 1 with TMetaDataPathDetail

use of org.dcache.srm.v2_2.TMetaDataPathDetail in project dcache by dCache.

the class LsFileRequest method convertFileMetaDataToTMetaDataPathDetail.

private TMetaDataPathDetail convertFileMetaDataToTMetaDataPathDetail(final URI path, final FileMetaData fmd, final boolean verbose) throws SRMException {
    TMetaDataPathDetail metaDataPathDetail = new TMetaDataPathDetail();
    metaDataPathDetail.setPath(getPath(path));
    metaDataPathDetail.setLifetimeAssigned(-1);
    metaDataPathDetail.setLifetimeLeft(-1);
    metaDataPathDetail.setSize(new UnsignedLong(fmd.size));
    if (fmd.isDirectory) {
        metaDataPathDetail.setType(TFileType.DIRECTORY);
    } else if (fmd.isLink) {
        metaDataPathDetail.setType(TFileType.LINK);
    } else if (fmd.isRegular) {
        metaDataPathDetail.setType(TFileType.FILE);
    } else {
        LOGGER.debug("file type is Unknown");
    }
    if (verbose) {
        // TODO: this needs to be rewritten to
        // take the ACLs into account.
        TUserPermission userPermission = new TUserPermission();
        userPermission.setUserID(fmd.owner);
        int userPerm = (fmd.permMode >> 6) & 7;
        userPermission.setMode(maskToTPermissionMode(userPerm));
        metaDataPathDetail.setOwnerPermission(userPermission);
        TGroupPermission groupPermission = new TGroupPermission();
        groupPermission.setGroupID(fmd.group);
        int groupPerm = (fmd.permMode >> 3) & 7;
        groupPermission.setMode(maskToTPermissionMode(groupPerm));
        metaDataPathDetail.setGroupPermission(groupPermission);
        metaDataPathDetail.setOtherPermission(maskToTPermissionMode(fmd.permMode & 7));
        GregorianCalendar td = new GregorianCalendar();
        td.setTimeInMillis(fmd.creationTime);
        metaDataPathDetail.setCreatedAtTime(td);
        td = new GregorianCalendar();
        td.setTimeInMillis(fmd.lastModificationTime);
        metaDataPathDetail.setLastModificationTime(td);
        if (fmd.checksumType != null && fmd.checksumValue != null) {
            metaDataPathDetail.setCheckSumType(fmd.checksumType);
            metaDataPathDetail.setCheckSumValue(fmd.checksumValue);
        }
        metaDataPathDetail.setFileStorageType(TFileStorageType.PERMANENT);
        if (!fmd.isPermanent) {
            if (fmd.isPinned) {
                metaDataPathDetail.setFileStorageType(TFileStorageType.DURABLE);
            } else {
                metaDataPathDetail.setFileStorageType(TFileStorageType.VOLATILE);
            }
        }
        metaDataPathDetail.setFileLocality(fmd.locality);
        if (fmd.retentionPolicyInfo != null) {
            TAccessLatency al = fmd.retentionPolicyInfo.getAccessLatency();
            TRetentionPolicy rp = fmd.retentionPolicyInfo.getRetentionPolicy();
            metaDataPathDetail.setRetentionPolicyInfo(new TRetentionPolicyInfo(rp, al));
        }
        if (fmd.spaceTokens != null) {
            if (fmd.spaceTokens.length > 0) {
                ArrayOfString arrayOfSpaceTokens = new ArrayOfString(new String[fmd.spaceTokens.length]);
                for (int st = 0; st < fmd.spaceTokens.length; st++) {
                    arrayOfSpaceTokens.setStringArray(st, String.valueOf(fmd.spaceTokens[st]));
                }
                metaDataPathDetail.setArrayOfSpaceTokens(arrayOfSpaceTokens);
            }
        }
    }
    metaDataPathDetail.setStatus(new TReturnStatus(TStatusCode.SRM_SUCCESS, null));
    return metaDataPathDetail;
}
Also used : TRetentionPolicyInfo(org.dcache.srm.v2_2.TRetentionPolicyInfo) UnsignedLong(org.apache.axis.types.UnsignedLong) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) GregorianCalendar(java.util.GregorianCalendar) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) TUserPermission(org.dcache.srm.v2_2.TUserPermission) TGroupPermission(org.dcache.srm.v2_2.TGroupPermission)

Example 2 with TMetaDataPathDetail

use of org.dcache.srm.v2_2.TMetaDataPathDetail in project dcache by dCache.

the class LsFileRequest method getMetaDataPathDetail.

protected final TMetaDataPathDetail getMetaDataPathDetail(URI surl, int depth, long offset, long count, int recursionDepth, boolean longFormat) throws SRMException, URISyntaxException {
    FileMetaData fmd = getStorage().getFileMetaData(getUser(), surl, false);
    TMetaDataPathDetail aMetaDataPathDetail = convertFileMetaDataToTMetaDataPathDetail(surl, fmd, longFormat);
    if (!getContainerRequest().increaseResultsNumAndContinue()) {
        return aMetaDataPathDetail;
    }
    if (fmd.isDirectory && depth < recursionDepth) {
        if (recursionDepth == 1) {
            // 
            // for simplicity break up code into two blocks - one block
            // works for the simple case recursionDepth=1, the other
            // block works for recursionDepth>1
            // there is a bit of code duplication, but code is
            // relatively straightforward this way
            // 
            getMetaDataPathDetail(aMetaDataPathDetail, offset, count, longFormat);
        } else {
            getRecursiveMetaDataPathDetail(aMetaDataPathDetail, fmd, depth, offset, count, recursionDepth, longFormat);
        }
    }
    return aMetaDataPathDetail;
}
Also used : ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) FileMetaData(org.dcache.srm.FileMetaData)

Example 3 with TMetaDataPathDetail

use of org.dcache.srm.v2_2.TMetaDataPathDetail in project dcache by dCache.

the class LsFileRequest method getMetaDataPathDetail.

protected TMetaDataPathDetail getMetaDataPathDetail() throws SRMInvalidRequestException {
    rlock();
    try {
        if (metaDataPathDetail != null) {
            return metaDataPathDetail;
        }
        if (getState() == State.DONE) {
            /* If the request has been processed yet metaDataPathDetail
                 * is null then the information is no longer known.  This
                 * can happen if the information has been delivered to the
                 * client, this Request has been garbage collected, and the
                 * request was fetched back from the database to process a
                 * StatusOfLsRequest request.
                 */
            throw new SRMInvalidRequestException("Response no longer available.");
        }
        TMetaDataPathDetail detail = new TMetaDataPathDetail();
        detail.setPath(getPath(surl));
        detail.setStatus(getReturnStatus());
        return detail;
    } finally {
        runlock();
    }
}
Also used : ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail) TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 4 with TMetaDataPathDetail

use of org.dcache.srm.v2_2.TMetaDataPathDetail 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 5 with TMetaDataPathDetail

use of org.dcache.srm.v2_2.TMetaDataPathDetail in project dcache by dCache.

the class AxisSrmFileSystem method doList.

private TMetaDataPathDetail[] doList(URI surl, boolean verbose) throws RemoteException, SRMException, InterruptedException {
    int offset = 0;
    int count = maxLsResponse;
    TMetaDataPathDetail[] list = {};
    do {
        TMetaDataPathDetail detail = list(surl, verbose, offset, count);
        checkValidPath(detail.getType() == TFileType.DIRECTORY, "Not a directory");
        offset += count;
        TMetaDataPathDetail[] pathDetailArray = detail.getArrayOfSubPaths() == null ? null : detail.getArrayOfSubPaths().getPathDetailArray();
        if (pathDetailArray != null) {
            list = concat(list, pathDetailArray, TMetaDataPathDetail.class);
        }
    } while (list.length == offset);
    return list;
}
Also used : TMetaDataPathDetail(org.dcache.srm.v2_2.TMetaDataPathDetail) ArrayOfTMetaDataPathDetail(org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail)

Aggregations

TMetaDataPathDetail (org.dcache.srm.v2_2.TMetaDataPathDetail)12 ArrayOfTMetaDataPathDetail (org.dcache.srm.v2_2.ArrayOfTMetaDataPathDetail)11 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)6 FileMetaData (org.dcache.srm.FileMetaData)4 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)4 ArrayOfString (org.dcache.srm.v2_2.ArrayOfString)3 SrmLsRequest (org.dcache.srm.v2_2.SrmLsRequest)3 SrmLsResponse (org.dcache.srm.v2_2.SrmLsResponse)3 SrmStatusOfLsRequestRequest (org.dcache.srm.v2_2.SrmStatusOfLsRequestRequest)3 SrmStatusOfLsRequestResponse (org.dcache.srm.v2_2.SrmStatusOfLsRequestResponse)3 URI (java.net.URI)2 LinkedList (java.util.LinkedList)2 URI (org.apache.axis.types.URI)2 UnsignedLong (org.apache.axis.types.UnsignedLong)2 SRMException (org.dcache.srm.SRMException)2 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)2 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)2 SRMTooManyResultsException (org.dcache.srm.SRMTooManyResultsException)2 IllegalStateTransition (org.dcache.srm.scheduler.IllegalStateTransition)2 TAccessLatency (org.dcache.srm.v2_2.TAccessLatency)2