Search in sources :

Example 1 with TSURLLifetimeReturnStatus

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

the class SRMExtendFileLifeTimeClientV2 method start.

@Override
public void start() throws Exception {
    checkCredentialValid();
    ArrayOfAnyURI surlarray = new ArrayOfAnyURI();
    URI[] uriarray = new URI[surls.length];
    URI uri;
    for (int i = 0; i < uriarray.length; i++) {
        uri = new URI(surl_strings[i]);
        uriarray[i] = uri;
    }
    surlarray.setUrlArray(uriarray);
    SrmExtendFileLifeTimeRequest req = new SrmExtendFileLifeTimeRequest();
    req.setArrayOfSURLs(surlarray);
    req.setRequestToken(configuration.getExtendFileLifetimeRequestToken());
    req.setNewFileLifeTime(configuration.getNewFileLifetime());
    req.setNewPinLifeTime(configuration.getNewPinLifetime());
    SrmExtendFileLifeTimeResponse resp = srm.srmExtendFileLifeTime(req);
    if (resp == null) {
        esay("Received null SrmExtendFileLifeTimeResponse");
        System.exit(1);
    }
    try {
        TReturnStatus rs = resp.getReturnStatus();
        if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS || configuration.isDebug()) {
            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) {
                if (resp.getArrayOfFileStatuses().getStatusArray() != null) {
                    for (int i = 0; i < resp.getArrayOfFileStatuses().getStatusArray().length; i++) {
                        TSURLLifetimeReturnStatus t = resp.getArrayOfFileStatuses().getStatusArray()[i];
                        sb.append("surl[").append(i).append("] ").append(t.getSurl()).append("\n");
                        sb.append("\tReturn code: ").append(t.getStatus().getStatusCode().toString()).append("\n");
                        sb.append("\tExplanation: ").append(t.getStatus().getExplanation()).append("\n");
                        sb.append("\t\tfilelifetime=").append(t.getFileLifetime()).append("\n");
                        sb.append("\t\tpinlifetime=").append(t.getPinLifetime()).append("\n");
                    }
                } else {
                    sb.append("array of file statuse is null\n");
                }
            } else {
                sb.append("array of file statuse is null\n");
            }
            if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
                esay(sb.toString());
                System.exit(1);
            } else {
                say(sb.toString());
            }
        } else {
            System.exit(0);
        }
    } catch (Exception e) {
        e.printStackTrace();
        System.exit(1);
    }
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmExtendFileLifeTimeRequest(org.dcache.srm.v2_2.SrmExtendFileLifeTimeRequest) TSURLLifetimeReturnStatus(org.dcache.srm.v2_2.TSURLLifetimeReturnStatus) URI(org.apache.axis.types.URI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) TStatusCode(org.dcache.srm.v2_2.TStatusCode) SrmExtendFileLifeTimeResponse(org.dcache.srm.v2_2.SrmExtendFileLifeTimeResponse)

Example 2 with TSURLLifetimeReturnStatus

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

the class SrmExtendFileLifeTime method extendSurlLifeTime.

private SrmExtendFileLifeTimeResponse extendSurlLifeTime(org.apache.axis.types.URI[] surls, int newFileLifetime) throws SRMInternalErrorException {
    long newLifetimeInMillis = toMillis(newFileLifetime, Long.MAX_VALUE);
    int len = surls.length;
    TSURLLifetimeReturnStatus[] surlStatus = new TSURLLifetimeReturnStatus[len];
    for (int i = 0; i < len; ++i) {
        surlStatus[i] = extendSurlLifeTime(surls[i], newLifetimeInMillis);
    }
    return new SrmExtendFileLifeTimeResponse(getSummaryReturnStatus(surlStatus), new ArrayOfTSURLLifetimeReturnStatus(surlStatus));
}
Also used : ArrayOfTSURLLifetimeReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLLifetimeReturnStatus) TSURLLifetimeReturnStatus(org.dcache.srm.v2_2.TSURLLifetimeReturnStatus) ArrayOfTSURLLifetimeReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLLifetimeReturnStatus) SrmExtendFileLifeTimeResponse(org.dcache.srm.v2_2.SrmExtendFileLifeTimeResponse)

Example 3 with TSURLLifetimeReturnStatus

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

the class SrmExtendFileLifeTime method extendSurlLifeTime.

private TSURLLifetimeReturnStatus extendSurlLifeTime(org.apache.axis.types.URI surl, long newLifetimeInMillis) throws SRMInternalErrorException {
    TSURLLifetimeReturnStatus status = new TSURLLifetimeReturnStatus();
    status.setSurl(surl);
    TReturnStatus returnStatus;
    try {
        long lifetimeLeftInMillis = storage.srmExtendSurlLifetime(user, URI.create(surl.toString()), newLifetimeInMillis);
        status.setFileLifetime(toSeconds(lifetimeLeftInMillis));
        returnStatus = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
    } catch (SRMInternalErrorException e) {
        throw new SRMInternalErrorException("File lifetime extension failed for SURL " + surl + ": " + e.getMessage(), e);
    } catch (SRMException e) {
        returnStatus = new TReturnStatus(TStatusCode.SRM_FAILURE, e.toString());
    }
    status.setStatus(returnStatus);
    return status;
}
Also used : SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) TSURLLifetimeReturnStatus(org.dcache.srm.v2_2.TSURLLifetimeReturnStatus) ArrayOfTSURLLifetimeReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLLifetimeReturnStatus)

Example 4 with TSURLLifetimeReturnStatus

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

the class SrmExtendFileLifeTime method extendTurlOrPinLifeTime.

private TSURLLifetimeReturnStatus extendTurlOrPinLifeTime(ContainerRequest<?> request, org.apache.axis.types.URI surl, long newLifetimeInMillis) throws SRMInternalErrorException {
    TSURLLifetimeReturnStatus status = new TSURLLifetimeReturnStatus();
    status.setSurl(surl);
    TReturnStatus returnStatus;
    try {
        FileRequest<?> fileRequest = request.getFileRequestBySurl(URI.create(surl.toString()));
        long lifetimeLeftMillis = fileRequest.extendLifetime(newLifetimeInMillis);
        status.setPinLifetime(toSeconds(lifetimeLeftMillis));
        returnStatus = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
    } catch (SRMFileRequestNotFoundException e) {
        returnStatus = new TReturnStatus(TStatusCode.SRM_INVALID_PATH, "SURL does match any existing file request associated with the request token");
    } catch (SRMInvalidRequestException e) {
        returnStatus = new TReturnStatus(TStatusCode.SRM_INVALID_REQUEST, "TURL is no longer valid and cannot be extended");
    } catch (SRMReleasedException e) {
        returnStatus = new TReturnStatus(TStatusCode.SRM_RELEASED, "TURL has been released and cannot be extended");
    } catch (SRMAbortedException e) {
        returnStatus = new TReturnStatus(TStatusCode.SRM_ABORTED, "TURL has been aborted and cannot be extended");
    } catch (SRMInternalErrorException e) {
        throw new SRMInternalErrorException("File lifetime extension failed for request " + request.getClientRequestId() + " with SURL " + surl + ": " + e.getMessage(), e);
    } catch (SRMException e) {
        LOGGER.warn("File lifetime extension failed for request {} with SURL {}: {}", request.getClientRequestId(), surl, e.getMessage());
        returnStatus = new TReturnStatus(TStatusCode.SRM_FAILURE, "TURL for request " + request.getClientRequestId() + " with SURL " + surl + " cannot be extended: " + e.getMessage());
    }
    status.setStatus(returnStatus);
    return status;
}
Also used : SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) SRMException(org.dcache.srm.SRMException) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SRMFileRequestNotFoundException(org.dcache.srm.SRMFileRequestNotFoundException) SRMReleasedException(org.dcache.srm.SRMReleasedException) SRMAbortedException(org.dcache.srm.SRMAbortedException) TSURLLifetimeReturnStatus(org.dcache.srm.v2_2.TSURLLifetimeReturnStatus) ArrayOfTSURLLifetimeReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLLifetimeReturnStatus) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 5 with TSURLLifetimeReturnStatus

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

the class SrmExtendFileLifeTime method extendTurlOrPinLifeTime.

private SrmExtendFileLifeTimeResponse extendTurlOrPinLifeTime(String requestToken, org.apache.axis.types.URI[] surls, int newLifetime) throws SRMInvalidRequestException, SRMInternalErrorException {
    ContainerRequest<?> containerRequest = Request.getRequest(requestToken, ContainerRequest.class);
    try (JDC ignored = containerRequest.applyJdc()) {
        long maxLifetime = getMaxLifetime(containerRequest);
        long newLifetimeInMillis = toMillis(newLifetime, maxLifetime);
        int len = surls.length;
        TSURLLifetimeReturnStatus[] surlStatus = new TSURLLifetimeReturnStatus[len];
        for (int i = 0; i < len; ++i) {
            surlStatus[i] = extendTurlOrPinLifeTime(containerRequest, surls[i], newLifetimeInMillis);
        }
        return new SrmExtendFileLifeTimeResponse(getSummaryReturnStatus(surlStatus), new ArrayOfTSURLLifetimeReturnStatus(surlStatus));
    }
}
Also used : ArrayOfTSURLLifetimeReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLLifetimeReturnStatus) JDC(org.dcache.srm.util.JDC) TSURLLifetimeReturnStatus(org.dcache.srm.v2_2.TSURLLifetimeReturnStatus) ArrayOfTSURLLifetimeReturnStatus(org.dcache.srm.v2_2.ArrayOfTSURLLifetimeReturnStatus) SrmExtendFileLifeTimeResponse(org.dcache.srm.v2_2.SrmExtendFileLifeTimeResponse)

Aggregations

TSURLLifetimeReturnStatus (org.dcache.srm.v2_2.TSURLLifetimeReturnStatus)5 ArrayOfTSURLLifetimeReturnStatus (org.dcache.srm.v2_2.ArrayOfTSURLLifetimeReturnStatus)4 SrmExtendFileLifeTimeResponse (org.dcache.srm.v2_2.SrmExtendFileLifeTimeResponse)3 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)3 SRMException (org.dcache.srm.SRMException)2 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)2 URI (org.apache.axis.types.URI)1 SRMAbortedException (org.dcache.srm.SRMAbortedException)1 SRMFileRequestNotFoundException (org.dcache.srm.SRMFileRequestNotFoundException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 SRMReleasedException (org.dcache.srm.SRMReleasedException)1 JDC (org.dcache.srm.util.JDC)1 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)1 SrmExtendFileLifeTimeRequest (org.dcache.srm.v2_2.SrmExtendFileLifeTimeRequest)1 TStatusCode (org.dcache.srm.v2_2.TStatusCode)1