Search in sources :

Example 1 with ArrayOfTGetRequestFileStatus

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

the class RemoteTurlGetterV2 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 (srmPrepareToGetResponse == null) {
            throw new IOException(" null srmPrepareToGetResponse");
        }
        TReturnStatus status = srmPrepareToGetResponse.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("srmPrepareToGet submission failed, unexpected or failed status : " + statusCode + " explanation=" + status.getExplanation());
        }
        requestToken = srmPrepareToGetResponse.getRequestToken();
        LOGGER.debug(" srm returned requestToken = {}", requestToken);
        ArrayOfTGetRequestFileStatus arrayOfTGetRequestFileStatus = srmPrepareToGetResponse.getArrayOfFileStatuses();
        if (arrayOfTGetRequestFileStatus == null) {
            throw new IOException("returned GetRequestFileStatuses is an empty array");
        }
        TGetRequestFileStatus[] getRequestFileStatuses = arrayOfTGetRequestFileStatus.getStatusArray();
        if (getRequestFileStatuses == null) {
            throw new IOException("returned GetRequestFileStatuses is an empty array");
        }
        if (getRequestFileStatuses.length != len) {
            throw new IOException("incorrect number of GetRequestFileStatuses" + "in RequestStatus expected " + len + " received " + getRequestFileStatuses.length);
        }
        boolean haveCompletedFileRequests = false;
        while (!pendingSurlsToIndex.isEmpty()) {
            long estimatedWaitInSeconds = Integer.MAX_VALUE;
            for (TGetRequestFileStatus getRequestFileStatus : getRequestFileStatuses) {
                URI surl = getRequestFileStatus.getSourceSURL();
                if (surl == null) {
                    LOGGER.error("invalid getRequestFileStatus, surl is null");
                    continue;
                }
                String surl_string = surl.toString();
                if (!pendingSurlsToIndex.containsKey(surl_string)) {
                    LOGGER.error("invalid getRequestFileStatus, surl = {} not found", surl_string);
                    continue;
                }
                TReturnStatus fileStatus = getRequestFileStatus.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 (getRequestFileStatus.getTransferURL() != null) {
                    String transferUrl = getRequestFileStatus.getTransferURL().toString();
                    int indx = pendingSurlsToIndex.remove(surl_string);
                    long size = 0;
                    if (getRequestFileStatus.getFileSize() != null) {
                        size = getRequestFileStatus.getFileSize().longValue();
                    } else {
                        LOGGER.error("size is not set in FileStatus for SURL={}", SURLs[indx]);
                    }
                    notifyOfTURL(SURLs[indx], transferUrl, requestToken, null, size);
                    haveCompletedFileRequests = true;
                    continue;
                }
                if (getRequestFileStatus.getEstimatedWaitTime() != null && getRequestFileStatus.getEstimatedWaitTime() < estimatedWaitInSeconds && getRequestFileStatus.getEstimatedWaitTime() >= 1) {
                    estimatedWaitInSeconds = getRequestFileStatus.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) {
            }
            SrmStatusOfGetRequestRequest srmStatusOfGetRequestRequest = new SrmStatusOfGetRequestRequest();
            srmStatusOfGetRequestRequest.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 surl = new URI(pendingSurlStrings[i]);
                    surlArray[i] = surl;
                }
                srmStatusOfGetRequestRequest.setArrayOfSourceSURLs(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;
                }
                srmStatusOfGetRequestRequest.setArrayOfSourceSURLs(new ArrayOfAnyURI(surlArray));
            }
            SrmStatusOfGetRequestResponse srmStatusOfGetRequestResponse = srmv2.srmStatusOfGetRequest(srmStatusOfGetRequestRequest);
            if (srmStatusOfGetRequestResponse == null) {
                throw new IOException(" null srmStatusOfGetRequestResponse");
            }
            arrayOfTGetRequestFileStatus = srmStatusOfGetRequestResponse.getArrayOfFileStatuses();
            if (arrayOfTGetRequestFileStatus == null) {
                LOGGER.error("incorrect number of RequestFileStatuses");
                throw new IOException("incorrect number of RequestFileStatuses");
            }
            getRequestFileStatuses = arrayOfTGetRequestFileStatus.getStatusArray();
            if (getRequestFileStatuses == null || getRequestFileStatuses.length != expectedResponseLength) {
                LOGGER.error("incorrect number of RequestFileStatuses");
                throw new IOException("incorrect number of RequestFileStatuses");
            }
            status = srmStatusOfGetRequestResponse.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("srmPrepareToGet update failed, unexpected or failed status : " + statusCode + " explanation=" + status.getExplanation());
            }
        }
    } catch (IOException e) {
        LOGGER.error(e.toString());
        notifyOfFailure(e);
    }
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) 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) SrmStatusOfGetRequestResponse(org.dcache.srm.v2_2.SrmStatusOfGetRequestResponse) ArrayOfTGetRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTGetRequestFileStatus) ArrayOfTGetRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTGetRequestFileStatus) TGetRequestFileStatus(org.dcache.srm.v2_2.TGetRequestFileStatus) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) SrmStatusOfGetRequestRequest(org.dcache.srm.v2_2.SrmStatusOfGetRequestRequest)

Example 2 with ArrayOfTGetRequestFileStatus

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

the class GetRequest method getSrmStatusOfGetRequestResponse.

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

Example 3 with ArrayOfTGetRequestFileStatus

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

the class GetRequest method getSrmPrepareToGetResponse.

private final SrmPrepareToGetResponse getSrmPrepareToGetResponse() throws SRMInvalidRequestException {
    SrmPrepareToGetResponse response = new SrmPrepareToGetResponse();
    response.setReturnStatus(getTReturnStatus());
    response.setRequestToken(getTRequestToken());
    response.setArrayOfFileStatuses(new ArrayOfTGetRequestFileStatus(getArrayOfTGetRequestFileStatus()));
    response.setRemainingTotalRequestTime(getRemainingLifetimeIn(TimeUnit.SECONDS));
    return response;
}
Also used : ArrayOfTGetRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTGetRequestFileStatus) SrmPrepareToGetResponse(org.dcache.srm.v2_2.SrmPrepareToGetResponse)

Aggregations

ArrayOfTGetRequestFileStatus (org.dcache.srm.v2_2.ArrayOfTGetRequestFileStatus)3 SrmStatusOfGetRequestResponse (org.dcache.srm.v2_2.SrmStatusOfGetRequestResponse)2 TGetRequestFileStatus (org.dcache.srm.v2_2.TGetRequestFileStatus)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 SrmPrepareToGetResponse (org.dcache.srm.v2_2.SrmPrepareToGetResponse)1 SrmStatusOfGetRequestRequest (org.dcache.srm.v2_2.SrmStatusOfGetRequestRequest)1 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)1 TStatusCode (org.dcache.srm.v2_2.TStatusCode)1