Search in sources :

Example 1 with SrmStatusOfBringOnlineRequestResponse

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

the class SRMBringOnlineClientV2 method start.

@Override
public void start() throws Exception {
    try {
        int len = from.length;
        String[] SURLS = new String[len];
        TGetFileRequest[] fileRequests = new TGetFileRequest[len];
        for (int i = 0; i < len; ++i) {
            SURLS[i] = from[i].toASCIIString();
            URI uri = new URI(SURLS[i]);
            fileRequests[i] = new TGetFileRequest();
            fileRequests[i].setSourceSURL(uri);
            pendingSurlsToIndex.put(SURLS[i], i);
        }
        hook = new Thread(this);
        Runtime.getRuntime().addShutdownHook(hook);
        SrmBringOnlineRequest srmBringOnlineRequest = new SrmBringOnlineRequest();
        srmBringOnlineRequest.setUserRequestDescription(configuration.getUserRequestDescription());
        srmBringOnlineRequest.setDesiredTotalRequestTime((int) configuration.getRequestLifetime());
        if (configuration.getDesiredLifetime() != null) {
            srmBringOnlineRequest.setDesiredLifeTime(configuration.getDesiredLifetime().intValue());
        }
        TRetentionPolicy rp = configuration.getRetentionPolicy() != null ? RetentionPolicy.fromString(configuration.getRetentionPolicy()).toTRetentionPolicy() : null;
        TAccessLatency al = configuration.getAccessLatency() != null ? AccessLatency.fromString(configuration.getAccessLatency()).toTAccessLatency() : null;
        if ((al != null) && (rp == null)) {
            throw new IllegalArgumentException("if access latency is specified, " + "then retention policy has to be specified as well");
        } else if (rp != null) {
            srmBringOnlineRequest.setTargetFileRetentionPolicyInfo(new TRetentionPolicyInfo(rp, al));
        }
        srmBringOnlineRequest.setArrayOfFileRequests(new ArrayOfTGetFileRequest(fileRequests));
        TAccessPattern ap = null;
        if (configuration.getAccessPattern() != null) {
            ap = TAccessPattern.fromString(configuration.getAccessPattern());
        }
        TConnectionType ct = null;
        if (configuration.getConnectionType() != null) {
            ct = TConnectionType.fromString(configuration.getConnectionType());
        }
        ArrayOfString protocolArray = null;
        if (configuration.getProtocols() != null) {
            protocolArray = new ArrayOfString(configuration.getProtocols());
        }
        ArrayOfString arrayOfClientNetworks = null;
        if (configuration.getArrayOfClientNetworks() != null) {
            arrayOfClientNetworks = new ArrayOfString(configuration.getArrayOfClientNetworks());
        }
        if (ap != null || ct != null || arrayOfClientNetworks != null || protocolArray != null) {
            srmBringOnlineRequest.setTransferParameters(new TTransferParameters(ap, ct, arrayOfClientNetworks, protocolArray));
        }
        configuration.getStorageSystemInfo().ifPresent(srmBringOnlineRequest::setStorageSystemInfo);
        say("calling srmBringOnline");
        SrmBringOnlineResponse response = srm.srmBringOnline(srmBringOnlineRequest);
        say("received response");
        if (response == null) {
            throw new IOException(" null response");
        }
        TReturnStatus status = response.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("srmBringOnline submission failed, unexpected or failed status : " + statusCode + " explanation=" + status.getExplanation());
        }
        requestToken = response.getRequestToken();
        dsay(" srm returned requestToken = " + requestToken);
        if (response.getArrayOfFileStatuses() == null) {
            throw new IOException("returned bringOnlineRequestFileStatuses is an empty array");
        }
        TBringOnlineRequestFileStatus[] bringOnlineRequestFileStatuses = response.getArrayOfFileStatuses().getStatusArray();
        if (bringOnlineRequestFileStatuses.length != len) {
            throw new IOException("incorrect number of TBringOnlineRequestFileStatus" + "in RequestStatus expected " + len + " received " + bringOnlineRequestFileStatuses.length);
        }
        while (!pendingSurlsToIndex.isEmpty()) {
            long estimatedWaitInSeconds = 60;
            for (TBringOnlineRequestFileStatus bringOnlineRequestFileStatus : bringOnlineRequestFileStatuses) {
                URI surl = bringOnlineRequestFileStatus.getSourceSURL();
                if (surl == null) {
                    esay("invalid bringOnlineRequestFileStatus, surl is null");
                    continue;
                }
                String surl_string = surl.toString();
                if (!pendingSurlsToIndex.containsKey(surl_string)) {
                    esay("invalid bringOnlineRequestFileStatus, surl = " + surl_string + " not found");
                    continue;
                }
                TReturnStatus fileStatus = bringOnlineRequestFileStatus.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 = "retrieval of surl " + surl_string + " failed, status = " + fileStatusCode + " explanation=" + fileStatus.getExplanation();
                    esay(error);
                    int indx = pendingSurlsToIndex.remove(surl_string);
                    setReportFailed(from[indx], from[indx], error);
                    continue;
                }
                if (fileStatus.getStatusCode() == TStatusCode.SRM_SUCCESS) {
                    int indx = pendingSurlsToIndex.remove(surl_string);
                    setReportSucceeded(from[indx], from[indx]);
                    System.out.println(from[indx] + " brought online, use request id " + requestToken + " to release");
                    continue;
                }
                Integer estimatedWaitTime = bringOnlineRequestFileStatus.getEstimatedWaitTime();
                if (estimatedWaitTime != null && estimatedWaitTime < estimatedWaitInSeconds && estimatedWaitTime >= 1) {
                    estimatedWaitInSeconds = estimatedWaitTime;
                }
            }
            if (pendingSurlsToIndex.isEmpty()) {
                dsay("no more pending transfers, breaking the loop");
                Runtime.getRuntime().removeShutdownHook(hook);
                break;
            }
            try {
                say("sleeping " + estimatedWaitInSeconds + " seconds ...");
                Thread.sleep(estimatedWaitInSeconds * 1000);
            } catch (InterruptedException ie) {
            }
            SrmStatusOfBringOnlineRequestRequest srmStatusOfBringOnlineRequestRequest = new SrmStatusOfBringOnlineRequestRequest();
            srmStatusOfBringOnlineRequestRequest.setRequestToken(requestToken);
            // we do not know what to expect from the server when
            // no surls are specified int the status update request
            // so we always are sending the list of all pending srm urls
            String[] pendingSurlStrings = pendingSurlsToIndex.keySet().toArray(new String[pendingSurlsToIndex.size()]);
            // 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 = pendingSurlStrings.length;
            URI[] surlArray = new URI[expectedResponseLength];
            for (int i = 0; i < expectedResponseLength; ++i) {
                surlArray[i] = new URI(pendingSurlStrings[i]);
            }
            srmStatusOfBringOnlineRequestRequest.setArrayOfSourceSURLs(new ArrayOfAnyURI(surlArray));
            SrmStatusOfBringOnlineRequestResponse srmStatusOfBringOnlineRequestResponse = srm.srmStatusOfBringOnlineRequest(srmStatusOfBringOnlineRequestRequest);
            if (srmStatusOfBringOnlineRequestResponse == null) {
                throw new IOException(" null srmStatusOfBringOnlineRequestResponse");
            }
            if (srmStatusOfBringOnlineRequestResponse.getArrayOfFileStatuses() == null) {
                esay("incorrect number of RequestFileStatuses");
                throw new IOException("incorrect number of RequestFileStatuses");
            }
            bringOnlineRequestFileStatuses = srmStatusOfBringOnlineRequestResponse.getArrayOfFileStatuses().getStatusArray();
            if (bringOnlineRequestFileStatuses == null || bringOnlineRequestFileStatuses.length != expectedResponseLength) {
                esay("incorrect number of RequestFileStatuses");
                throw new IOException("incorrect number of RequestFileStatuses");
            }
            status = srmStatusOfBringOnlineRequestResponse.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)) {
                String error = "srmBringOnline update failed, status : " + statusCode + " explanation=" + status.getExplanation();
                esay(error);
                for (int i = 0; i < expectedResponseLength; ++i) {
                    TReturnStatus frstatus = bringOnlineRequestFileStatuses[i].getStatus();
                    if (frstatus != null) {
                        if (!RequestStatusTool.isTransientStateStatus(frstatus)) {
                            int indx = pendingSurlsToIndex.remove(bringOnlineRequestFileStatuses[i].getSourceSURL().toString());
                            setReportFailed(from[indx], from[indx], error);
                        }
                        esay("BringOnlineFileRequest[" + bringOnlineRequestFileStatuses[i].getSourceSURL() + "] status=" + frstatus.getStatusCode() + " explanation=" + frstatus.getExplanation());
                    }
                }
                throw new IOException(error);
            }
        }
    } catch (Exception e) {
        esay(e.toString());
    } finally {
        report.dumpReport();
        if (!report.everythingAllRight()) {
            report.reportErrors(System.err);
            System.exit(1);
        }
    }
}
Also used : ArrayOfTGetFileRequest(org.dcache.srm.v2_2.ArrayOfTGetFileRequest) TAccessPattern(org.dcache.srm.v2_2.TAccessPattern) TBringOnlineRequestFileStatus(org.dcache.srm.v2_2.TBringOnlineRequestFileStatus) SrmBringOnlineRequest(org.dcache.srm.v2_2.SrmBringOnlineRequest) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) TTransferParameters(org.dcache.srm.v2_2.TTransferParameters) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) URI(org.apache.axis.types.URI) SrmStatusOfBringOnlineRequestResponse(org.dcache.srm.v2_2.SrmStatusOfBringOnlineRequestResponse) SrmStatusOfBringOnlineRequestRequest(org.dcache.srm.v2_2.SrmStatusOfBringOnlineRequestRequest) TRetentionPolicyInfo(org.dcache.srm.v2_2.TRetentionPolicyInfo) TConnectionType(org.dcache.srm.v2_2.TConnectionType) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) TGetFileRequest(org.dcache.srm.v2_2.TGetFileRequest) ArrayOfTGetFileRequest(org.dcache.srm.v2_2.ArrayOfTGetFileRequest) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) IOException(java.io.IOException) TStatusCode(org.dcache.srm.v2_2.TStatusCode) IOException(java.io.IOException) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) SrmBringOnlineResponse(org.dcache.srm.v2_2.SrmBringOnlineResponse) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Example 2 with SrmStatusOfBringOnlineRequestResponse

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

the class BringOnlineRequest method getSrmStatusOfBringOnlineRequestResponse.

public final SrmStatusOfBringOnlineRequestResponse getSrmStatusOfBringOnlineRequestResponse(org.apache.axis.types.URI[] surls) throws SRMInvalidRequestException {
    SrmStatusOfBringOnlineRequestResponse response = new SrmStatusOfBringOnlineRequestResponse();
    response.setReturnStatus(getTReturnStatus());
    TBringOnlineRequestFileStatus[] statusArray = getArrayOfTBringOnlineRequestFileStatus(surls);
    response.setArrayOfFileStatuses(new ArrayOfTBringOnlineRequestFileStatus(statusArray));
    if (LOGGER.isDebugEnabled()) {
        StringBuilder sb = new StringBuilder("getSrmStatusOfBringOnlineRequestResponse:");
        sb.append(" StatusCode = ").append(response.getReturnStatus().getStatusCode());
        if (statusArray.length > 0) {
            sb.append(" FileStatusCodes =");
        }
        Arrays.stream(statusArray).map(s -> s.getStatus().getStatusCode()).collect(Collectors.groupingBy(Function.identity(), Collectors.counting())).forEach((k, v) -> sb.append(" ").append(k).append(" (").append(v).append(" times)"));
        LOGGER.debug(sb.toString());
    }
    response.setRemainingTotalRequestTime(getRemainingLifetimeIn(TimeUnit.SECONDS));
    return response;
}
Also used : ArrayOfTBringOnlineRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTBringOnlineRequestFileStatus) ArrayOfTBringOnlineRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTBringOnlineRequestFileStatus) TBringOnlineRequestFileStatus(org.dcache.srm.v2_2.TBringOnlineRequestFileStatus) SrmStatusOfBringOnlineRequestResponse(org.dcache.srm.v2_2.SrmStatusOfBringOnlineRequestResponse)

Example 3 with SrmStatusOfBringOnlineRequestResponse

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

the class SrmStatusOfBringOnlineRequest method getFailedResponse.

public static final SrmStatusOfBringOnlineRequestResponse getFailedResponse(String error, TStatusCode statusCode) {
    TReturnStatus status = new TReturnStatus(statusCode, error);
    SrmStatusOfBringOnlineRequestResponse srmPrepareToGetResponse = new SrmStatusOfBringOnlineRequestResponse();
    srmPrepareToGetResponse.setReturnStatus(status);
    return srmPrepareToGetResponse;
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SrmStatusOfBringOnlineRequestResponse(org.dcache.srm.v2_2.SrmStatusOfBringOnlineRequestResponse)

Aggregations

SrmStatusOfBringOnlineRequestResponse (org.dcache.srm.v2_2.SrmStatusOfBringOnlineRequestResponse)3 TBringOnlineRequestFileStatus (org.dcache.srm.v2_2.TBringOnlineRequestFileStatus)2 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)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 ArrayOfTBringOnlineRequestFileStatus (org.dcache.srm.v2_2.ArrayOfTBringOnlineRequestFileStatus)1 ArrayOfTGetFileRequest (org.dcache.srm.v2_2.ArrayOfTGetFileRequest)1 SrmBringOnlineRequest (org.dcache.srm.v2_2.SrmBringOnlineRequest)1 SrmBringOnlineResponse (org.dcache.srm.v2_2.SrmBringOnlineResponse)1 SrmStatusOfBringOnlineRequestRequest (org.dcache.srm.v2_2.SrmStatusOfBringOnlineRequestRequest)1 TAccessLatency (org.dcache.srm.v2_2.TAccessLatency)1 TAccessPattern (org.dcache.srm.v2_2.TAccessPattern)1 TConnectionType (org.dcache.srm.v2_2.TConnectionType)1 TGetFileRequest (org.dcache.srm.v2_2.TGetFileRequest)1 TRetentionPolicy (org.dcache.srm.v2_2.TRetentionPolicy)1 TRetentionPolicyInfo (org.dcache.srm.v2_2.TRetentionPolicyInfo)1 TStatusCode (org.dcache.srm.v2_2.TStatusCode)1 TTransferParameters (org.dcache.srm.v2_2.TTransferParameters)1