Search in sources :

Example 1 with TCopyRequestFileStatus

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

the class CopyFileRequest method getTCopyRequestFileStatus.

public TCopyRequestFileStatus getTCopyRequestFileStatus() throws SRMInvalidRequestException {
    TCopyRequestFileStatus copyRequestFileStatus = new TCopyRequestFileStatus();
    copyRequestFileStatus.setFileSize(new UnsignedLong(size));
    copyRequestFileStatus.setEstimatedWaitTime(getContainerRequest().getRetryDeltaTime());
    copyRequestFileStatus.setRemainingFileLifetime((int) (getRemainingLifetime() / 1000));
    org.apache.axis.types.URI sourceSurl;
    org.apache.axis.types.URI destinationSurl;
    try {
        sourceSurl = new org.apache.axis.types.URI(getDestinationSurl().toASCIIString());
    } catch (org.apache.axis.types.URI.MalformedURIException e) {
        LOGGER.error(e.toString());
        throw new SRMInvalidRequestException("wrong SURL format: " + getDestinationSurl());
    }
    try {
        destinationSurl = new org.apache.axis.types.URI(getSourceSurl().toASCIIString());
    } catch (org.apache.axis.types.URI.MalformedURIException e) {
        LOGGER.error(e.toString());
        throw new SRMInvalidRequestException("wrong SURL format: " + getSourceSurl());
    }
    copyRequestFileStatus.setSourceSURL(destinationSurl);
    copyRequestFileStatus.setTargetSURL(sourceSurl);
    TReturnStatus returnStatus = getReturnStatus();
    if (TStatusCode.SRM_SPACE_LIFETIME_EXPIRED.equals(returnStatus.getStatusCode())) {
        returnStatus = new TReturnStatus(TStatusCode.SRM_FAILURE, null);
    }
    copyRequestFileStatus.setStatus(returnStatus);
    return copyRequestFileStatus;
}
Also used : UnsignedLong(org.apache.axis.types.UnsignedLong) TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) TCopyRequestFileStatus(org.dcache.srm.v2_2.TCopyRequestFileStatus) URI(java.net.URI) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 2 with TCopyRequestFileStatus

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

the class CopyRequest method getArrayOfTCopyRequestFileStatuses.

public final TCopyRequestFileStatus[] getArrayOfTCopyRequestFileStatuses(org.apache.axis.types.URI[] fromurls, org.apache.axis.types.URI[] tourls) throws SRMInvalidRequestException {
    if (fromurls == null && tourls == null) {
        return getArrayOfTCopyRequestFileStatuses();
    }
    checkArgument(fromurls != null && tourls != null && fromurls.length == tourls.length);
    int len = fromurls.length;
    TCopyRequestFileStatus[] copyRequestFileStatuses = new TCopyRequestFileStatus[len];
    for (int i = 0; i < len; ++i) {
        try {
            copyRequestFileStatuses[i] = getFileRequestBySurls(fromurls[i].toString(), tourls[i].toString()).getTCopyRequestFileStatus();
        } catch (SRMInvalidPathException e) {
            copyRequestFileStatuses[i] = new TCopyRequestFileStatus(fromurls[i], tourls[i], new TReturnStatus(TStatusCode.SRM_INVALID_PATH, "No such file request"), null, null, null);
        }
    }
    return copyRequestFileStatuses;
}
Also used : TReturnStatus(org.dcache.srm.v2_2.TReturnStatus) SRMInvalidPathException(org.dcache.srm.SRMInvalidPathException) TCopyRequestFileStatus(org.dcache.srm.v2_2.TCopyRequestFileStatus) ArrayOfTCopyRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTCopyRequestFileStatus)

Example 3 with TCopyRequestFileStatus

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

the class CopyRequest method getSrmStatusOfCopyRequest.

public final SrmStatusOfCopyRequestResponse getSrmStatusOfCopyRequest(org.apache.axis.types.URI[] fromurls, org.apache.axis.types.URI[] tourls) throws SRMInvalidRequestException {
    SrmStatusOfCopyRequestResponse response = new SrmStatusOfCopyRequestResponse();
    response.setReturnStatus(getTReturnStatus());
    TCopyRequestFileStatus[] fileStatuses = getArrayOfTCopyRequestFileStatuses(fromurls, tourls);
    response.setArrayOfFileStatuses(new ArrayOfTCopyRequestFileStatus(fileStatuses));
    response.setRemainingTotalRequestTime(getRemainingLifetimeIn(TimeUnit.SECONDS));
    return response;
}
Also used : SrmStatusOfCopyRequestResponse(org.dcache.srm.v2_2.SrmStatusOfCopyRequestResponse) ArrayOfTCopyRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTCopyRequestFileStatus) TCopyRequestFileStatus(org.dcache.srm.v2_2.TCopyRequestFileStatus) ArrayOfTCopyRequestFileStatus(org.dcache.srm.v2_2.ArrayOfTCopyRequestFileStatus)

Example 4 with TCopyRequestFileStatus

use of org.dcache.srm.v2_2.TCopyRequestFileStatus 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)

Aggregations

TCopyRequestFileStatus (org.dcache.srm.v2_2.TCopyRequestFileStatus)4 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)3 ArrayOfTCopyRequestFileStatus (org.dcache.srm.v2_2.ArrayOfTCopyRequestFileStatus)2 SrmStatusOfCopyRequestResponse (org.dcache.srm.v2_2.SrmStatusOfCopyRequestResponse)2 IOException (java.io.IOException)1 URI (java.net.URI)1 URI (org.apache.axis.types.URI)1 UnsignedLong (org.apache.axis.types.UnsignedLong)1 SRMInvalidPathException (org.dcache.srm.SRMInvalidPathException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)1 ArrayOfTCopyFileRequest (org.dcache.srm.v2_2.ArrayOfTCopyFileRequest)1 SrmCopyResponse (org.dcache.srm.v2_2.SrmCopyResponse)1 SrmStatusOfCopyRequestRequest (org.dcache.srm.v2_2.SrmStatusOfCopyRequestRequest)1 TAccessLatency (org.dcache.srm.v2_2.TAccessLatency)1 TCopyFileRequest (org.dcache.srm.v2_2.TCopyFileRequest)1 TDirOption (org.dcache.srm.v2_2.TDirOption)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