Search in sources :

Example 1 with TCopyFileRequest

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

the class SRMCopyClientV2 method start.

@Override
public void start() throws Exception {
    checkCredentialValid();
    try {
        // 
        // form the request
        // 
        int len = from.length;
        TCopyFileRequest[] copyFileRequests = new TCopyFileRequest[len];
        for (int i = 0; i < from.length; ++i) {
            java.net.URI source = from[i];
            java.net.URI dest = to[i];
            TCopyFileRequest copyFileRequest = new TCopyFileRequest();
            copyFileRequest.setSourceSURL(new URI(source.toASCIIString()));
            copyFileRequest.setTargetSURL(new URI(dest.toASCIIString()));
            TDirOption dirOption = new TDirOption();
            dirOption.setIsSourceADirectory(false);
            dirOption.setAllLevelRecursive(Boolean.TRUE);
            copyFileRequest.setDirOption(dirOption);
            copyFileRequests[i] = copyFileRequest;
            pendingSurlsMap.put(from[i], i);
        }
        hook = new Thread(this);
        Runtime.getRuntime().addShutdownHook(hook);
        String storagetype = configuration.getStorageType();
        if (storagetype != null) {
            req.setTargetFileStorageType(FileStorageType.fromString(storagetype.toUpperCase()).toTFileStorageType());
        }
        req.setUserRequestDescription(configuration.getUserRequestDescription());
        req.setDesiredTotalRequestTime((int) configuration.getRequestLifetime());
        TRetentionPolicy retentionPolicy = configuration.getRetentionPolicy() != null ? RetentionPolicy.fromString(configuration.getRetentionPolicy()).toTRetentionPolicy() : null;
        TAccessLatency accessLatency = configuration.getAccessLatency() != null ? AccessLatency.fromString(configuration.getAccessLatency()).toTAccessLatency() : null;
        if ((accessLatency != null) && (retentionPolicy == null)) {
            throw new IllegalArgumentException("if access latency is specified, " + "then retention policy have to be specified as well");
        } else if (retentionPolicy != null) {
            TRetentionPolicyInfo retentionPolicyInfo = new TRetentionPolicyInfo(retentionPolicy, accessLatency);
            req.setTargetFileRetentionPolicyInfo(retentionPolicyInfo);
        }
        if (configuration.getOverwriteMode() != null) {
            req.setOverwriteOption(OverwriteMode.fromString(configuration.getOverwriteMode()).toTOverwriteMode());
        }
        req.setArrayOfFileRequests(new ArrayOfTCopyFileRequest(copyFileRequests));
        req.setUserRequestDescription("This is User request description");
        if (configuration.getSpaceToken() != null) {
            req.setTargetSpaceToken(configuration.getSpaceToken());
        }
        configuration.getStorageSystemInfo().ifPresent(req::setSourceStorageSystemInfo);
        SrmCopyResponse resp = srm.srmCopy(req);
        if (resp == null) {
            throw new IOException(" null SrmCopyResponse");
        }
        TReturnStatus rs = resp.getReturnStatus();
        requestToken = resp.getRequestToken();
        dsay(" srm returned requestToken = " + requestToken);
        if (rs == null) {
            throw new IOException(" null TReturnStatus ");
        }
        TStatusCode statusCode = rs.getStatusCode();
        if (statusCode == null) {
            throw new IOException(" null status code");
        }
        if (RequestStatusTool.isFailedRequestStatus(rs) && (statusCode != TStatusCode.SRM_FAILURE || resp.getArrayOfFileStatuses() == null)) {
            String explanation = rs.getExplanation();
            if (explanation != null) {
                throw new IOException("srmCopy submission failed, unexpected or failed status : " + statusCode + " explanation= " + explanation);
            } else {
                throw new IOException("srmCopy submission failed, unexpected or failed status : " + statusCode);
            }
        }
        if (resp.getArrayOfFileStatuses() == null) {
            throw new IOException("srmCopy submission failed, arrayOfFileStatuses is null, status code :" + rs.getStatusCode() + " explanation=" + rs.getExplanation());
        }
        TCopyRequestFileStatus[] arrayOfStatuses = resp.getArrayOfFileStatuses().getStatusArray();
        if (arrayOfStatuses.length != len) {
            throw new IOException("number of SrmCopyRequestFileStatuses " + "is SrmRequestStatus is different from exopected " + len + " received " + arrayOfStatuses.length);
        }
        while (!pendingSurlsMap.isEmpty()) {
            long estimatedWaitInSeconds = 5;
            for (TCopyRequestFileStatus copyRequestFileStatus : arrayOfStatuses) {
                if (copyRequestFileStatus == null) {
                    throw new IOException(" null file status code");
                }
                TReturnStatus fileStatus = copyRequestFileStatus.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");
                }
                URI from_surl = copyRequestFileStatus.getSourceSURL();
                URI to_surl = copyRequestFileStatus.getTargetSURL();
                if (from_surl == null) {
                    throw new IOException("null from_surl");
                }
                if (to_surl == null) {
                    throw new IOException("null to_surl");
                }
                java.net.URI from_surl_uri = new java.net.URI(from_surl.toString());
                java.net.URI to_surl_uri = new java.net.URI(to_surl.toString());
                if (RequestStatusTool.isFailedFileRequestStatus(fileStatus)) {
                    String error = "copy of " + from_surl_uri + " into " + to_surl + " failed, status = " + fileStatusCode + " explanation=" + fileStatus.getExplanation();
                    esay(error);
                    int indx = pendingSurlsMap.remove(from_surl_uri);
                    setReportFailed(from[indx], to[indx], error);
                } else if (fileStatusCode == TStatusCode.SRM_SUCCESS || fileStatusCode == TStatusCode.SRM_DONE) {
                    int indx = pendingSurlsMap.remove(from_surl_uri);
                    say(" copying of " + from_surl_uri + " to " + to_surl_uri + " succeeded");
                    setReportSucceeded(from[indx], to[indx]);
                }
                if (copyRequestFileStatus.getEstimatedWaitTime() != null && copyRequestFileStatus.getEstimatedWaitTime() < estimatedWaitInSeconds && copyRequestFileStatus.getEstimatedWaitTime() >= 1) {
                    estimatedWaitInSeconds = copyRequestFileStatus.getEstimatedWaitTime();
                }
            }
            if (pendingSurlsMap.isEmpty()) {
                dsay("no more pending transfers, breaking the loop");
                Runtime.getRuntime().removeShutdownHook(hook);
                break;
            }
            if (estimatedWaitInSeconds > 60) {
                estimatedWaitInSeconds = 60;
            }
            try {
                say("sleeping " + estimatedWaitInSeconds + " seconds ...");
                Thread.sleep(estimatedWaitInSeconds * 1000);
            } catch (InterruptedException ie) {
            }
            // 
            // check our request
            // 
            SrmStatusOfCopyRequestRequest request = new SrmStatusOfCopyRequestRequest();
            request.setRequestToken(requestToken);
            request.setAuthorizationID(req.getAuthorizationID());
            int expectedResponseLength = pendingSurlsMap.size();
            URI[] surlArrayOfFromSURLs = new URI[expectedResponseLength];
            URI[] surlArrayOfToSURLs = new URI[expectedResponseLength];
            Iterator<Integer> it = pendingSurlsMap.values().iterator();
            for (int i = 0; it.hasNext(); i++) {
                int indx = it.next();
                TCopyFileRequest copyFileRequest = copyFileRequests[indx];
                surlArrayOfFromSURLs[i] = copyFileRequest.getSourceSURL();
                surlArrayOfToSURLs[i] = copyFileRequest.getTargetSURL();
            }
            request.setArrayOfSourceSURLs(new ArrayOfAnyURI(surlArrayOfFromSURLs));
            request.setArrayOfTargetSURLs(new ArrayOfAnyURI(surlArrayOfToSURLs));
            SrmStatusOfCopyRequestResponse copyStatusRequestResponse = srm.srmStatusOfCopyRequest(request);
            if (copyStatusRequestResponse == null) {
                throw new IOException(" null copyStatusRequestResponse");
            }
            if (copyStatusRequestResponse.getArrayOfFileStatuses() == null) {
                throw new IOException("null SrmStatusOfCopyRequestResponse.getArrayOfFileStatuses()");
            }
            arrayOfStatuses = copyStatusRequestResponse.getArrayOfFileStatuses().getStatusArray();
            if (arrayOfStatuses.length != pendingSurlsMap.size()) {
                esay("incorrect number of arrayOfStatuses " + "in SrmStatusOfCopyRequestResponse expected " + expectedResponseLength + " received " + arrayOfStatuses.length);
            }
            TReturnStatus status = copyStatusRequestResponse.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 = "srmCopy update failed, status : " + statusCode + " explanation=" + status.getExplanation();
                esay(error);
                for (int i = 0; i < expectedResponseLength; ++i) {
                    TReturnStatus frstatus = arrayOfStatuses[i].getStatus();
                    if (frstatus != null) {
                        esay("copyFileRequest[" + arrayOfStatuses[i].getSourceSURL() + " , " + arrayOfStatuses[i].getTargetSURL() + "] status=" + frstatus.getStatusCode() + " explanation=" + frstatus.getExplanation());
                        if (!RequestStatusTool.isTransientStateStatus(frstatus)) {
                            pendingSurlsMap.remove(new java.net.URI(arrayOfStatuses[i].getSourceSURL().toString()));
                        }
                    }
                }
                throw new IOException(error);
            }
        }
    } catch (Exception e) {
        try {
            abortAllPendingFiles();
        } catch (Exception e1) {
            edsay(e1.toString());
        }
        throw e;
    } finally {
        report.dumpReport();
        if (!report.everythingAllRight()) {
            report.reportErrors(System.err);
        }
    }
}
Also used : ArrayOfTCopyFileRequest(org.dcache.srm.v2_2.ArrayOfTCopyFileRequest) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) URI(org.apache.axis.types.URI) TRetentionPolicyInfo(org.dcache.srm.v2_2.TRetentionPolicyInfo) SrmStatusOfCopyRequestResponse(org.dcache.srm.v2_2.SrmStatusOfCopyRequestResponse) TCopyRequestFileStatus(org.dcache.srm.v2_2.TCopyRequestFileStatus) SrmCopyResponse(org.dcache.srm.v2_2.SrmCopyResponse) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) TCopyFileRequest(org.dcache.srm.v2_2.TCopyFileRequest) ArrayOfTCopyFileRequest(org.dcache.srm.v2_2.ArrayOfTCopyFileRequest) IOException(java.io.IOException) SrmStatusOfCopyRequestRequest(org.dcache.srm.v2_2.SrmStatusOfCopyRequestRequest) TStatusCode(org.dcache.srm.v2_2.TStatusCode) IOException(java.io.IOException) TDirOption(org.dcache.srm.v2_2.TDirOption) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI)

Example 2 with TCopyFileRequest

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

the class SrmCopy method srmCopy.

private SrmCopyResponse srmCopy() throws SRMInvalidRequestException, SRMNotSupportedException, SRMInternalErrorException {
    TCopyFileRequest[] arrayOfFileRequests = getFileRequests(request);
    long lifetime = Lifetimes.calculateLifetime(request.getDesiredTotalRequestTime(), configuration.getCopyLifetime());
    String spaceToken = request.getTargetSpaceToken();
    URI[] from_urls = new URI[arrayOfFileRequests.length];
    URI[] to_urls = new URI[arrayOfFileRequests.length];
    for (int i = 0; i < arrayOfFileRequests.length; i++) {
        from_urls[i] = URI.create(arrayOfFileRequests[i].getSourceSURL().toString());
        to_urls[i] = URI.create(arrayOfFileRequests[i].getTargetSURL().toString());
    }
    TRetentionPolicy targetRetentionPolicy = null;
    TAccessLatency targetAccessLatency = null;
    if (request.getTargetFileRetentionPolicyInfo() != null) {
        targetRetentionPolicy = request.getTargetFileRetentionPolicyInfo().getRetentionPolicy();
        targetAccessLatency = request.getTargetFileRetentionPolicyInfo().getAccessLatency();
    }
    TOverwriteMode overwriteMode = getOverwriteMode(request);
    ImmutableMap<String, String> extraInfo = getExtraInfo(request);
    credential.acceptAlternative(extraInfo.get("credential"));
    CopyRequest r = new CopyRequest(srm.getSrmId(), user, credential.getId(), from_urls, to_urls, spaceToken, lifetime, configuration.getCopyMaxPollPeriod(), request.getTargetFileStorageType(), targetRetentionPolicy, targetAccessLatency, request.getUserRequestDescription(), clientHost, overwriteMode, extraInfo);
    try (JDC ignored = r.applyJdc()) {
        srm.acceptNewJob(r);
        return r.getSrmCopyResponse();
    } catch (IllegalStateTransition e) {
        throw new SRMInternalErrorException("Scheduling failure", e);
    }
}
Also used : IllegalStateTransition(org.dcache.srm.scheduler.IllegalStateTransition) SrmCopyRequest(org.dcache.srm.v2_2.SrmCopyRequest) CopyRequest(org.dcache.srm.request.CopyRequest) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) JDC(org.dcache.srm.util.JDC) TCopyFileRequest(org.dcache.srm.v2_2.TCopyFileRequest) TOverwriteMode(org.dcache.srm.v2_2.TOverwriteMode) URI(java.net.URI) SRMInternalErrorException(org.dcache.srm.SRMInternalErrorException) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency)

Aggregations

TAccessLatency (org.dcache.srm.v2_2.TAccessLatency)2 TCopyFileRequest (org.dcache.srm.v2_2.TCopyFileRequest)2 TRetentionPolicy (org.dcache.srm.v2_2.TRetentionPolicy)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URI (org.apache.axis.types.URI)1 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)1 CopyRequest (org.dcache.srm.request.CopyRequest)1 IllegalStateTransition (org.dcache.srm.scheduler.IllegalStateTransition)1 JDC (org.dcache.srm.util.JDC)1 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)1 ArrayOfTCopyFileRequest (org.dcache.srm.v2_2.ArrayOfTCopyFileRequest)1 SrmCopyRequest (org.dcache.srm.v2_2.SrmCopyRequest)1 SrmCopyResponse (org.dcache.srm.v2_2.SrmCopyResponse)1 SrmStatusOfCopyRequestRequest (org.dcache.srm.v2_2.SrmStatusOfCopyRequestRequest)1 SrmStatusOfCopyRequestResponse (org.dcache.srm.v2_2.SrmStatusOfCopyRequestResponse)1 TCopyRequestFileStatus (org.dcache.srm.v2_2.TCopyRequestFileStatus)1 TDirOption (org.dcache.srm.v2_2.TDirOption)1 TOverwriteMode (org.dcache.srm.v2_2.TOverwriteMode)1 TRetentionPolicyInfo (org.dcache.srm.v2_2.TRetentionPolicyInfo)1