Search in sources :

Example 1 with SRM_ABORTED

use of org.dcache.srm.v2_2.TStatusCode.SRM_ABORTED in project dcache by dCache.

the class SrmRm method srmRm.

private SrmRmResponse srmRm() throws DataAccessException, InterruptedException, SRMInternalErrorException, SRMInvalidRequestException {
    if (request.getArrayOfSURLs() == null) {
        throw new SRMInvalidRequestException("arrayOfSURLs is empty");
    }
    org.apache.axis.types.URI[] surls = request.getArrayOfSURLs().getUrlArray();
    if (surls == null || surls.length == 0) {
        throw new SRMInvalidRequestException("arrayOfSURLs is empty");
    }
    TSURLReturnStatus[] returnStatuses = new TSURLReturnStatus[surls.length];
    Semaphore semaphore = new Semaphore(sizeOfSingleRemoveBatch);
    for (int i = 0; i < surls.length; i++) {
        semaphore.acquire();
        returnStatuses[i] = new TSURLReturnStatus(surls[i], null);
        URI surl = URI.create(surls[i].toString());
        storage.removeFile(user, surl, new Callback(semaphore, returnStatuses[i]));
    }
    semaphore.acquire(sizeOfSingleRemoveBatch);
    for (int i = 0; i < surls.length; i++) {
        TSURLReturnStatus returnStatus = returnStatuses[i];
        if (returnStatus.getStatus().getStatusCode() == TStatusCode.SRM_INTERNAL_ERROR) {
            throw new SRMInternalErrorException(returnStatus.getStatus().getExplanation());
        }
        if (returnStatus.getStatus().getStatusCode() == TStatusCode.SRM_SUCCESS || returnStatus.getStatus().getStatusCode() == TStatusCode.SRM_INVALID_PATH) {
            // [SRM 2.2, 4.3.2, e)] srmRm aborts the SURLs from srmPrepareToPut requests not yet
            // in SRM_PUT_DONE state, and must set its file status as SRM_ABORTED.
            // 
            // [SRM 2.2, 4.3.2, f)] srmRm must remove SURLs even if the statuses of the SURLs
            // are SRM_FILE_BUSY. In this case, operations such as srmPrepareToPut or srmCopy
            // that holds the SURL status as SRM_FILE_BUSY must return SRM_INVALID_PATH upon
            // status request or srmPutDone.
            // 
            // It seems the SRM specs is undecided about whether to move put requests to
            // SRM_ABORTED or SRM_INVALID_PATH. We choose SRM_ABORTED as it seems like the saner
            // of the two options.
            // [SRM 2.2, 4.3.2, d)] srmLs,srmPrepareToGet or srmBringOnline must not find these
            // removed files any more. It must set file requests on SURL from srmPrepareToGet
            // as SRM_ABORTED.
            URI surl = URI.create(surls[i].toString());
            try {
                if (srm.abortTransfers(surl, "File was deleted by request " + JDC.getSession() + ".")) {
                    returnStatus.setStatus(new TReturnStatus(TStatusCode.SRM_SUCCESS, "Upload was aborted."));
                }
            } catch (SRMException e) {
                returnStatus.setStatus(new TReturnStatus(e.getStatusCode(), e.getMessage()));
            }
        }
    }
    return new SrmRmResponse(ReturnStatuses.getSummaryReturnStatus(returnStatuses), new ArrayOfTSURLReturnStatus(returnStatuses));
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) Semaphore(java.util.concurrent.Semaphore) URI(java.net.URI) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) RemoveFileCallback(org.dcache.srm.RemoveFileCallback) SRMException(org.dcache.srm.SRMException) ArrayOfTSURLReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus) TSURLReturnStatus(org.dcache.srm.v2_2.TSURLReturnStatus) ArrayOfTSURLReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus) SrmRmResponse(org.dcache.srm.v2_2.SrmRmResponse) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Aggregations

URI (java.net.URI)1 Semaphore (java.util.concurrent.Semaphore)1 RemoveFileCallback (org.dcache.srm.RemoveFileCallback)1 SRMException (org.dcache.srm.SRMException)1 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 ArrayOfTSURLReturnStatus (org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus)1 SrmRmResponse (org.dcache.srm.v2_2.SrmRmResponse)1 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)1 TSURLReturnStatus (org.dcache.srm.v2_2.TSURLReturnStatus)1