Search in sources :

Example 1 with SrmRmResponse

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

the class SRMRmClientV2 method start.

@Override
public void start() throws Exception {
    checkCredentialValid();
    SrmRmRequest req = new SrmRmRequest();
    URI[] uris = new URI[surls.length];
    for (int i = 0; i < surls.length; ++i) {
        uris[i] = new URI(surl_strings[i]);
    }
    req.setArrayOfSURLs(new ArrayOfAnyURI(uris));
    configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
    SrmRmResponse resp = srm.srmRm(req);
    TReturnStatus rs = resp.getReturnStatus();
    if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
        TStatusCode rc = rs.getStatusCode();
        StringBuilder sb = new StringBuilder();
        sb.append("Return code: ").append(rc.toString()).append("\n");
        sb.append("Explanation: ").append(rs.getExplanation()).append("\n");
        if (resp.getArrayOfFileStatuses() != null) {
            TSURLReturnStatus[] arrayOfStatuses = resp.getArrayOfFileStatuses().getStatusArray();
            if (arrayOfStatuses != null) {
                for (int i = 0; i < arrayOfStatuses.length; i++) {
                    if (arrayOfStatuses[i] != null) {
                        sb.append("file#").append(i).append(" : ");
                        if (arrayOfStatuses[i].getSurl() != null) {
                            sb.append(arrayOfStatuses[i].getSurl());
                        }
                        if (arrayOfStatuses[i].getStatus() != null) {
                            sb.append(", ");
                            sb.append(arrayOfStatuses[i].getStatus().getStatusCode());
                            sb.append(", \"");
                            sb.append(arrayOfStatuses[i].getStatus().getExplanation());
                            sb.append("\"");
                        }
                        sb.append('\n');
                    }
                }
            }
        }
        System.out.println(sb.toString());
        System.exit(1);
    }
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) TSURLReturnStatus(org.dcache.srm.v2_2.TSURLReturnStatus) SrmRmResponse(org.dcache.srm.v2_2.SrmRmResponse) URI(org.apache.axis.types.URI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) SrmRmRequest(org.dcache.srm.v2_2.SrmRmRequest) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) TStatusCode(org.dcache.srm.v2_2.TStatusCode)

Example 2 with SrmRmResponse

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

Example 3 with SrmRmResponse

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

the class SrmRm method getResponse.

public static final SrmRmResponse getResponse(String error, TStatusCode statusCode) {
    SrmRmResponse response = new SrmRmResponse();
    response.setReturnStatus(new TReturnStatus(statusCode, error));
    return response;
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmRmResponse(org.dcache.srm.v2_2.SrmRmResponse)

Aggregations

SrmRmResponse (org.dcache.srm.v2_2.SrmRmResponse)3 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)3 TSURLReturnStatus (org.dcache.srm.v2_2.TSURLReturnStatus)2 URI (java.net.URI)1 Semaphore (java.util.concurrent.Semaphore)1 URI (org.apache.axis.types.URI)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 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)1 ArrayOfTSURLReturnStatus (org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus)1 SrmRmRequest (org.dcache.srm.v2_2.SrmRmRequest)1 TStatusCode (org.dcache.srm.v2_2.TStatusCode)1