Search in sources :

Example 1 with TReturnStatus

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

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

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

the class LsFileRequest method getReturnStatus.

@Override
protected TReturnStatus getReturnStatus() {
    String description = latestHistoryEvent();
    TStatusCode statusCode = getStatusCode();
    if (statusCode != null) {
        return new TReturnStatus(statusCode, description);
    }
    switch(getState()) {
        case DONE:
        case READY:
            return new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
        case FAILED:
            return new TReturnStatus(TStatusCode.SRM_FAILURE, description);
        case CANCELED:
            return new TReturnStatus(TStatusCode.SRM_ABORTED, description);
        case INPROGRESS:
        case RQUEUED:
            return new TReturnStatus(TStatusCode.SRM_REQUEST_INPROGRESS, description);
        default:
            return new TReturnStatus(TStatusCode.SRM_REQUEST_QUEUED, description);
    }
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) TStatusCode(org.dcache.srm.v2_2.TStatusCode)

Example 4 with TReturnStatus

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

the class PutFileRequest method getReturnStatus.

@Override
protected TReturnStatus getReturnStatus() {
    String description = latestHistoryEvent();
    TStatusCode statusCode = getStatusCode();
    if (statusCode != null) {
        if (statusCode == TStatusCode.SRM_SUCCESS || statusCode == TStatusCode.SRM_SPACE_AVAILABLE) {
            description = null;
        }
        return new TReturnStatus(statusCode, description);
    }
    switch(getState()) {
        case UNSCHEDULED:
        case QUEUED:
            return new TReturnStatus(TStatusCode.SRM_REQUEST_QUEUED, description);
        case READY:
        case TRANSFERRING:
            return new TReturnStatus(TStatusCode.SRM_SPACE_AVAILABLE, null);
        case DONE:
            // REVISIT: Spec doesn't allow this for statusOfPut
            return new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
        case CANCELED:
            return new TReturnStatus(TStatusCode.SRM_ABORTED, description);
        case FAILED:
            return new TReturnStatus(TStatusCode.SRM_FAILURE, description);
        default:
            return new TReturnStatus(TStatusCode.SRM_REQUEST_INPROGRESS, description);
    }
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) TStatusCode(org.dcache.srm.v2_2.TStatusCode)

Example 5 with TReturnStatus

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

the class PutRequest method abort.

/**
 * this callbacks are given to storage.prepareToPut storage.prepareToPut calls methods of
 * callbacks to indicate progress
 */
@Override
public TReturnStatus abort(String reason) {
    wlock();
    try {
        /* [ SRM 2.2, 5.11.2 ]
             *
             * a) srmAbortRequest terminates all files in the request regardless of the file
             *    state. Remove files from the queue, and release cached files if a limited
             *    lifetime is associated with the file.
             * c) Abort must be allowed to all requests with requestToken.
             * f) When aborting srmPrepareToPut request before srmPutDone and before the file
             *    transfer, the SURL must not exist as the result of the successful abort on
             *    the SURL. Any srmRm request on the SURL must fail.
             * g) When aborting srmPrepareToPut request before srmPutDone and after the file
             *    transfer, the SURL may exist, and a srmRm request on the SURL may remove
             *    the requested SURL.
             * h) When aborting srmPrepareToPut request after srmPutDone, it must be failed
             *    for those files. An explicit srmRm is required to remove those successfully
             *   completed files for srmPrepareToPut.
             * i) When duplicate abort request is issued on the same request, SRM_SUCCESS
             *    may be returned to all duplicate abort requests and no operations on
             *    duplicate abort requests are performed.
             */
        boolean hasSuccess = false;
        boolean hasFailure = false;
        boolean hasCompleted = false;
        updateStatus();
        State state = getState();
        if (!state.isFinal()) {
            for (PutFileRequest file : getFileRequests()) {
                try {
                    file.abort(reason);
                    hasSuccess = true;
                } catch (SRMException e) {
                    hasFailure = true;
                } catch (IllegalStateTransition e) {
                    if (e.getFromState() == State.DONE) {
                        hasCompleted = true;
                    }
                    hasFailure = true;
                }
            }
            try {
                setStateAndStatusCode(State.CANCELED, "Request aborted", TStatusCode.SRM_ABORTED);
            } catch (IllegalStateTransition e) {
                hasFailure = true;
            }
        } else if (state == State.DONE) {
            return new TReturnStatus(TStatusCode.SRM_FAILURE, "Put request completed successfully and cannot be aborted");
        }
        TReturnStatus returnStatus = getSummaryReturnStatus(hasFailure, hasSuccess);
        if (hasCompleted) {
            returnStatus = new TReturnStatus(returnStatus.getStatusCode(), "Some SURLs have completed successfully and cannot be aborted");
        }
        return returnStatus;
    } finally {
        wunlock();
    }
}
Also used : IllegalStateTransition(org.dcache.srm.scheduler.IllegalStateTransition) SRMException(org.dcache.srm.SRMException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) State(org.dcache.srm.scheduler.State)

Aggregations

TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)117 URI (org.apache.axis.types.URI)28 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)28 TStatusCode (org.dcache.srm.v2_2.TStatusCode)27 SRMException (org.dcache.srm.SRMException)19 ArrayOfString (org.dcache.srm.v2_2.ArrayOfString)19 IOException (java.io.IOException)18 URI (java.net.URI)17 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)17 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)16 SRMAuthorizationException (org.dcache.srm.SRMAuthorizationException)13 TSURLReturnStatus (org.dcache.srm.v2_2.TSURLReturnStatus)12 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)11 ArrayOfTSURLReturnStatus (org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus)8 SrmReleaseFilesResponse (org.dcache.srm.v2_2.SrmReleaseFilesResponse)8 TRetentionPolicyInfo (org.dcache.srm.v2_2.TRetentionPolicyInfo)8 UnsignedLong (org.apache.axis.types.UnsignedLong)7 SrmAbortFilesResponse (org.dcache.srm.v2_2.SrmAbortFilesResponse)7 TMetaDataPathDetail (org.dcache.srm.v2_2.TMetaDataPathDetail)7 FileMetaData (org.dcache.srm.FileMetaData)6