Search in sources :

Example 1 with FileMetaData

use of org.dcache.srm.FileMetaData 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 2 with FileMetaData

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

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

the class SrmSetPermission method srmSetPermission.

private SrmSetPermissionResponse srmSetPermission() throws SRMException {
    URI surl = URI.create(request.getSURL().toString());
    FileMetaData fmd = storage.getFileMetaData(user, surl, false);
    TPermissionType permissionType = request.getPermissionType();
    if (permissionType == TPermissionType.REMOVE) {
        /* [ SRM 2.2, 3.1.2 ]
             *
             * h) If TPermissionType is REMOVE, then the TPermissionMode must be ignored.
             *
             * We interpret this requirement to apply to user and group ACLs only. Since
             * we don't support these, we don't support REMOVE.
             */
        return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
    }
    TPermissionMode ownerMode = request.getOwnerPermission();
    TPermissionMode otherMode = request.getOtherPermission();
    TPermissionMode groupMode = null;
    ArrayOfTUserPermission userPermissions = request.getArrayOfUserPermissions();
    if (userPermissions != null) {
        return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
    }
    ArrayOfTGroupPermission groupPermissions = request.getArrayOfGroupPermissions();
    if (groupPermissions != null && groupPermissions.getGroupPermissionArray() != null) {
        switch(groupPermissions.getGroupPermissionArray().length) {
            case 0:
                break;
            case 1:
                TGroupPermission permission = groupPermissions.getGroupPermissionArray()[0];
                String group = permission.getGroupID();
                if (!group.equals("-") && !group.equals(fmd.group)) {
                    /* The dash is a special dCache convention used by our own SRM client to
                         * indicate that the POSIX group permissions should be updated.
                         */
                    return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
                }
                groupMode = permission.getMode();
                break;
            default:
                return getFailedResponse(ACL_NOT_SUPPORTED, TStatusCode.SRM_NOT_SUPPORTED);
        }
    }
    fmd.permMode = toNewPermissions(fmd.permMode, permissionType, ownerMode, groupMode, otherMode);
    storage.setFileMetaData(user, surl, fmd);
    return new SrmSetPermissionResponse(new TReturnStatus(TStatusCode.SRM_SUCCESS, null));
}
Also used : TPermissionType(org.dcache.srm.v2_2.TPermissionType) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfTUserPermission(org.dcache.srm.v2_2.ArrayOfTUserPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) TGroupPermission(org.dcache.srm.v2_2.TGroupPermission) ArrayOfTGroupPermission(org.dcache.srm.v2_2.ArrayOfTGroupPermission) TPermissionMode(org.dcache.srm.v2_2.TPermissionMode) URI(java.net.URI) SrmSetPermissionResponse(org.dcache.srm.v2_2.SrmSetPermissionResponse) FileMetaData(org.dcache.srm.FileMetaData)

Example 4 with FileMetaData

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

the class SrmGetPermission method srmGetPermission.

private SrmGetPermissionResponse srmGetPermission() throws SRMInvalidRequestException, SRMInternalErrorException {
    org.apache.axis.types.URI[] surls = request.getArrayOfSURLs().getUrlArray();
    if (surls == null || surls.length == 0) {
        throw new SRMInvalidRequestException("arrayOfSURLs is empty");
    }
    int length = surls.length;
    TPermissionReturn[] permissionsArray = new TPermissionReturn[length];
    boolean hasFailure = false;
    boolean hasSuccess = false;
    for (int i = 0; i < length; i++) {
        TPermissionReturn p = new TPermissionReturn();
        TReturnStatus returnStatus;
        try {
            FileMetaData fmd = storage.getFileMetaData(user, URI.create(surls[i].toString()), false);
            copyPermissions(fmd, p);
            returnStatus = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
            hasSuccess = true;
        } catch (SRMInternalErrorException e) {
            throw e;
        } catch (SRMAuthorizationException e) {
            returnStatus = new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
            hasFailure = true;
        } catch (SRMInvalidPathException e) {
            returnStatus = new TReturnStatus(TStatusCode.SRM_INVALID_PATH, e.getMessage());
            hasFailure = true;
        } catch (SRMException e) {
            LOGGER.warn(e.toString());
            returnStatus = new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage());
            hasFailure = true;
        }
        p.setSurl(surls[i]);
        p.setStatus(returnStatus);
        permissionsArray[i] = p;
    }
    return new SrmGetPermissionResponse(getSummaryReturnStatus(hasFailure, hasSuccess), new ArrayOfTPermissionReturn(permissionsArray));
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmGetPermissionResponse(org.dcache.srm.v2_2.SrmGetPermissionResponse) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) URI(java.net.URI) TPermissionReturn(org.dcache.srm.v2_2.TPermissionReturn) ArrayOfTPermissionReturn(org.dcache.srm.v2_2.ArrayOfTPermissionReturn) ArrayOfTPermissionReturn(org.dcache.srm.v2_2.ArrayOfTPermissionReturn) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException) FileMetaData(org.dcache.srm.FileMetaData)

Example 5 with FileMetaData

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

the class SrmCheckPermission method srmCheckPermission.

private SrmCheckPermissionResponse srmCheckPermission() throws SRMInternalErrorException, SRMInvalidRequestException {
    org.apache.axis.types.URI[] surls = request.getArrayOfSURLs().getUrlArray();
    if (surls == null || surls.length == 0) {
        throw new SRMInvalidRequestException("arrayOfSURLs is empty");
    }
    int length = surls.length;
    TSURLPermissionReturn[] permissions = new TSURLPermissionReturn[length];
    boolean hasSuccess = false;
    boolean hasFailure = false;
    for (int i = 0; i < length; i++) {
        TReturnStatus returnStatus;
        TPermissionMode pm = null;
        try {
            FileMetaData fmd = storage.getFileMetaData(user, URI.create(surls[i].toString()), false);
            int mode = fmd.permMode;
            if (fmd.isOwner(user)) {
                pm = PermissionMaskToTPermissionMode.maskToTPermissionMode(((mode >> 6) & 0x7));
            } else if (fmd.isGroupMember(user)) {
                pm = PermissionMaskToTPermissionMode.maskToTPermissionMode(((mode >> 3) & 0x7));
            } else {
                pm = PermissionMaskToTPermissionMode.maskToTPermissionMode((mode & 0x7));
            }
            returnStatus = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
            hasSuccess = true;
        } catch (SRMInternalErrorException e) {
            throw e;
        } catch (SRMInvalidPathException e) {
            returnStatus = new TReturnStatus(TStatusCode.SRM_INVALID_PATH, e.getMessage());
            hasFailure = true;
        } catch (SRMAuthorizationException e) {
            returnStatus = new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
            hasFailure = true;
        } catch (SRMException e) {
            LOGGER.warn(e.toString());
            returnStatus = new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage());
            hasFailure = true;
        }
        permissions[i] = new TSURLPermissionReturn(surls[i], returnStatus, pm);
    }
    return new SrmCheckPermissionResponse(ReturnStatuses.getSummaryReturnStatus(hasFailure, hasSuccess), new ArrayOfTSURLPermissionReturn(permissions));
}
Also used : SRMAuthorizationException(org.dcache.srm.SRMAuthorizationException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) ArrayOfTSURLPermissionReturn(org.dcache.srm.v2_2.ArrayOfTSURLPermissionReturn) TSURLPermissionReturn(org.dcache.srm.v2_2.TSURLPermissionReturn) ArrayOfTSURLPermissionReturn(org.dcache.srm.v2_2.ArrayOfTSURLPermissionReturn) TPermissionMode(org.dcache.srm.v2_2.TPermissionMode) URI(java.net.URI) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) SrmCheckPermissionResponse(org.dcache.srm.v2_2.SrmCheckPermissionResponse) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException) FileMetaData(org.dcache.srm.FileMetaData)

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