Search in sources :

Example 1 with ArrayOfTPutRequestFileStatus

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

the class PutRequest method getSrmStatusOfPutRequestResponse.

public final SrmStatusOfPutRequestResponse getSrmStatusOfPutRequestResponse(org.apache.axis.types.URI[] surls) throws SRMFileRequestNotFoundException, SRMInvalidRequestException {
    SrmStatusOfPutRequestResponse response = new SrmStatusOfPutRequestResponse();
    response.setReturnStatus(getTReturnStatus());
    TPutRequestFileStatus[] statusArray = getArrayOfTPutRequestFileStatus(surls);
    if (LOGGER.isDebugEnabled()) {
        StringBuilder s = new StringBuilder("getSrmStatusOfPutRequestResponse:");
        s.append(" StatusCode = ").append(response.getReturnStatus().getStatusCode());
        for (TPutRequestFileStatus fs : statusArray) {
            s.append(" FileStatusCode = ").append(fs.getStatus().getStatusCode());
        }
        LOGGER.debug(s.toString());
    }
    response.setArrayOfFileStatuses(new ArrayOfTPutRequestFileStatus(statusArray));
    response.setRemainingTotalRequestTime(getRemainingLifetimeIn(TimeUnit.SECONDS));
    return response;
}
Also used : TPutRequestFileStatus(org.dcache.srm.v2_2.TPutRequestFileStatus) ArrayOfTPutRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus) SrmStatusOfPutRequestResponse(org.dcache.srm.v2_2.SrmStatusOfPutRequestResponse) ArrayOfTPutRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus)

Example 2 with ArrayOfTPutRequestFileStatus

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

the class RemoteTurlPutterV2 method run.

@Override
public void run() {
    if (number_of_file_reqs == 0) {
        LOGGER.debug("number_of_file_reqs is 0, nothing to do");
        return;
    }
    try {
        int len = SURLs.length;
        if (srmPrepareToPutResponse == null) {
            throw new IOException(" null srmPrepareToPutResponse");
        }
        TReturnStatus status = srmPrepareToPutResponse.getReturnStatus();
        if (status == null) {
            throw new IOException(" null return status");
        }
        TStatusCode statusCode = status.getStatusCode();
        if (statusCode == null) {
            throw new IOException(" null status code");
        }
        if (RequestStatusTool.isFailedRequestStatus(status)) {
            throw new IOException("srmPrepareToPut submission failed, unexpected or failed status : " + statusCode + " explanation=" + status.getExplanation());
        }
        requestToken = srmPrepareToPutResponse.getRequestToken();
        LOGGER.debug(" srm returned requestToken = {} one of remote surls = {}", requestToken, SURLs[0]);
        ArrayOfTPutRequestFileStatus arrayOfTPutRequestFileStatus = srmPrepareToPutResponse.getArrayOfFileStatuses();
        if (arrayOfTPutRequestFileStatus == null) {
            throw new IOException("returned PutRequestFileStatuses is an empty array");
        }
        TPutRequestFileStatus[] putRequestFileStatuses = arrayOfTPutRequestFileStatus.getStatusArray();
        if (putRequestFileStatuses == null) {
            throw new IOException("returned PutRequestFileStatuses is an empty array");
        }
        if (putRequestFileStatuses.length != len) {
            throw new IOException("incorrect number of GetRequestFileStatuses" + "in RequestStatus expected " + len + " received " + putRequestFileStatuses.length);
        }
        boolean haveCompletedFileRequests = false;
        while (!pendingSurlsToIndex.isEmpty()) {
            long estimatedWaitInSeconds = Integer.MAX_VALUE;
            for (TPutRequestFileStatus putRequestFileStatus : putRequestFileStatuses) {
                URI surl = putRequestFileStatus.getSURL();
                if (surl == null) {
                    LOGGER.error("invalid putRequestFileStatus, surl is null");
                    continue;
                }
                String surl_string = surl.toString();
                if (!pendingSurlsToIndex.containsKey(surl_string)) {
                    LOGGER.error("invalid putRequestFileStatus, surl = {} not found", surl_string);
                    continue;
                }
                TReturnStatus fileStatus = putRequestFileStatus.getStatus();
                if (fileStatus == null) {
                    throw new IOException(" null file return status");
                }
                TStatusCode fileStatusCode = fileStatus.getStatusCode();
                if (fileStatusCode == null) {
                    throw new IOException(" null file status code");
                }
                if (RequestStatusTool.isFailedFileRequestStatus(fileStatus)) {
                    String error = "retreval of surl " + surl_string + " failed, status = " + fileStatusCode + " explanation=" + fileStatus.getExplanation();
                    LOGGER.error(error);
                    int indx = pendingSurlsToIndex.remove(surl_string);
                    notifyOfFailure(SURLs[indx], error, requestToken, null);
                    haveCompletedFileRequests = true;
                    continue;
                }
                if (putRequestFileStatus.getTransferURL() != null) {
                    String turl = putRequestFileStatus.getTransferURL().toString();
                    int indx = pendingSurlsToIndex.remove(surl_string);
                    // in case of put we do not need the size from the destination
                    notifyOfTURL(SURLs[indx], turl, requestToken, null, null);
                    continue;
                }
                if (putRequestFileStatus.getEstimatedWaitTime() != null && putRequestFileStatus.getEstimatedWaitTime() < estimatedWaitInSeconds && putRequestFileStatus.getEstimatedWaitTime() >= 1) {
                    estimatedWaitInSeconds = putRequestFileStatus.getEstimatedWaitTime();
                }
            }
            if (pendingSurlsToIndex.isEmpty()) {
                LOGGER.debug("no more pending transfers, breaking the loop");
                break;
            }
            // do not wait longer then 60 seconds
            if (estimatedWaitInSeconds > 60) {
                estimatedWaitInSeconds = 60;
            }
            try {
                LOGGER.debug("sleeping {} seconds ...", estimatedWaitInSeconds);
                Thread.sleep(estimatedWaitInSeconds * 1000);
            } catch (InterruptedException ie) {
            }
            SrmStatusOfPutRequestRequest srmStatusOfPutRequestRequest = new SrmStatusOfPutRequestRequest();
            srmStatusOfPutRequestRequest.setRequestToken(requestToken);
            // if we do not have completed file requests
            // we want to get status for all files
            // we do not need to specify any surls
            int expectedResponseLength;
            if (haveCompletedFileRequests) {
                String[] pendingSurlStrings = pendingSurlsToIndex.keySet().toArray(String[]::new);
                expectedResponseLength = pendingSurlStrings.length;
                URI[] surlArray = new URI[expectedResponseLength];
                for (int i = 0; i < expectedResponseLength; ++i) {
                    URI uri = new URI(pendingSurlStrings[i]);
                    surlArray[i] = uri;
                }
                srmStatusOfPutRequestRequest.setArrayOfTargetSURLs(new ArrayOfAnyURI(surlArray));
            } else {
                expectedResponseLength = SURLs.length;
                URI[] surlArray = new URI[expectedResponseLength];
                for (int i = 0; i < expectedResponseLength; ++i) {
                    URI surl = new URI(SURLs[i]);
                    surlArray[i] = surl;
                }
                srmStatusOfPutRequestRequest.setArrayOfTargetSURLs(new ArrayOfAnyURI(surlArray));
            }
            SrmStatusOfPutRequestResponse srmStatusOfPutRequestResponse = srmv2.srmStatusOfPutRequest(srmStatusOfPutRequestRequest);
            if (srmStatusOfPutRequestResponse == null) {
                throw new IOException(" null srmStatusOfPutRequestResponse");
            }
            arrayOfTPutRequestFileStatus = srmStatusOfPutRequestResponse.getArrayOfFileStatuses();
            if (arrayOfTPutRequestFileStatus == null) {
                throw new IOException("incorrect number of RequestFileStatuses");
            }
            putRequestFileStatuses = arrayOfTPutRequestFileStatus.getStatusArray();
            if (putRequestFileStatuses == null || putRequestFileStatuses.length != expectedResponseLength) {
                LOGGER.error("incorrect number of RequestFileStatuses");
                throw new IOException("incorrect number of RequestFileStatuses");
            }
            status = srmStatusOfPutRequestResponse.getReturnStatus();
            if (status == null) {
                throw new IOException(" null return status");
            }
            statusCode = status.getStatusCode();
            if (statusCode == null) {
                throw new IOException(" null status code");
            }
            if (RequestStatusTool.isFailedRequestStatus(status)) {
                throw new IOException("srmPrepareToPut update failed, unexpected or failed status : " + statusCode + " explanation=" + status.getExplanation());
            }
        }
    } catch (IOException ioe) {
        LOGGER.error(ioe.toString());
        notifyOfFailure(ioe);
    }
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmStatusOfPutRequestResponse(org.dcache.srm.v2_2.SrmStatusOfPutRequestResponse) IOException(java.io.IOException) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) URI(org.apache.axis.types.URI) TStatusCode(org.dcache.srm.v2_2.TStatusCode) SrmStatusOfPutRequestRequest(org.dcache.srm.v2_2.SrmStatusOfPutRequestRequest) TPutRequestFileStatus(org.dcache.srm.v2_2.TPutRequestFileStatus) ArrayOfTPutRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus) ArrayOfTPutRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Example 3 with ArrayOfTPutRequestFileStatus

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

the class PutRequest method getSrmPrepareToPutResponse.

private final SrmPrepareToPutResponse getSrmPrepareToPutResponse() throws SRMInvalidRequestException {
    SrmPrepareToPutResponse response = new SrmPrepareToPutResponse();
    response.setReturnStatus(getTReturnStatus());
    response.setRequestToken(getTRequestToken());
    response.setArrayOfFileStatuses(new ArrayOfTPutRequestFileStatus(getArrayOfTPutRequestFileStatus()));
    response.setRemainingTotalRequestTime(getRemainingLifetimeIn(TimeUnit.SECONDS));
    return response;
}
Also used : ArrayOfTPutRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus) SrmPrepareToPutResponse(org.dcache.srm.v2_2.SrmPrepareToPutResponse)

Aggregations

ArrayOfTPutRequestFileStatus (org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus)3 SrmStatusOfPutRequestResponse (org.dcache.srm.v2_2.SrmStatusOfPutRequestResponse)2 TPutRequestFileStatus (org.dcache.srm.v2_2.TPutRequestFileStatus)2 IOException (java.io.IOException)1 URI (org.apache.axis.types.URI)1 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)1 ArrayOfString (org.dcache.srm.v2_2.ArrayOfString)1 SrmPrepareToPutResponse (org.dcache.srm.v2_2.SrmPrepareToPutResponse)1 SrmStatusOfPutRequestRequest (org.dcache.srm.v2_2.SrmStatusOfPutRequestRequest)1 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)1 TStatusCode (org.dcache.srm.v2_2.TStatusCode)1