Search in sources :

Example 1 with SrmPrepareToPutResponse

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

the class PutRequest method getSrmPrepareToPutResponse.

/**
 * Waits for up to timeout milliseconds for the request to reach a non-queued state and then
 * returns the current SrmPrepareToPutResponse for this PutRequest.
 */
public final SrmPrepareToPutResponse getSrmPrepareToPutResponse(long timeout) throws InterruptedException, SRMInvalidRequestException {
    /* To avoid a race condition between us querying the current
         * response and us waiting for a state change notification,
         * the notification scheme is counter based. This guarantees
         * that we do not loose any notifications. A simple lock
         * around the whole loop would not have worked, as the call to
         * getSrmPrepareToPutResponse may itself trigger a state
         * change and thus cause a deadlock when the state change is
         * signaled.
         */
    Date deadline = getDateRelativeToNow(timeout);
    int counter = _stateChangeCounter.get();
    tryToReady();
    SrmPrepareToPutResponse response = getSrmPrepareToPutResponse();
    while (response.getReturnStatus().getStatusCode().isProcessing() && deadline.after(new Date()) && _stateChangeCounter.awaitChangeUntil(counter, deadline)) {
        counter = _stateChangeCounter.get();
        tryToReady();
        response = getSrmPrepareToPutResponse();
    }
    response.setRemainingTotalRequestTime(getRemainingLifetimeIn(TimeUnit.SECONDS));
    return response;
}
Also used : SrmPrepareToPutResponse(org.dcache.srm.v2_2.SrmPrepareToPutResponse) Date(java.util.Date)

Example 2 with SrmPrepareToPutResponse

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

the class SrmPrepareToPut method srmPrepareToPut.

private SrmPrepareToPutResponse srmPrepareToPut() throws IllegalStateTransition, InterruptedException, SRMNotSupportedException, SRMInvalidRequestException, SRMInternalErrorException {
    checkFileStorageType(request, TFileStorageType.PERMANENT);
    String[] protocols = getProtocols();
    String clientHost = getClientHost(request).orElse(this.clientHost);
    String spaceToken = request.getTargetSpaceToken();
    TRetentionPolicy retentionPolicy = null;
    TAccessLatency accessLatency = null;
    if (request.getTargetFileRetentionPolicyInfo() != null) {
        retentionPolicy = request.getTargetFileRetentionPolicyInfo().getRetentionPolicy();
        accessLatency = request.getTargetFileRetentionPolicyInfo().getAccessLatency();
    }
    TPutFileRequest[] fileRequests = getFileRequests(request);
    // assume transfers will take place in parallel
    long effectiveSize = largestFileOf(fileRequests);
    long lifetime = Lifetimes.calculateLifetime(request.getDesiredTotalRequestTime(), effectiveSize, configuration.getMaximumClientAssumedBandwidth(), configuration.getPutLifetime());
    TOverwriteMode overwriteMode = getOverwriteMode(request);
    String[] supportedProtocols = storage.supportedPutProtocols();
    boolean isAnyProtocolSupported = any(asList(protocols), in(asList(supportedProtocols)));
    if (!isAnyProtocolSupported) {
        throw new SRMNotSupportedException("Protocol(s) not supported: " + Arrays.toString(protocols));
    }
    URI[] surls = new URI[fileRequests.length];
    Long[] sizes = new Long[fileRequests.length];
    boolean[] wantPermanent = new boolean[fileRequests.length];
    for (int i = 0; i < fileRequests.length; ++i) {
        TPutFileRequest fileRequest = fileRequests[i];
        if (fileRequest == null) {
            throw new SRMInvalidRequestException("file request #" + (i + 1) + " is null.");
        }
        if (fileRequest.getTargetSURL() == null) {
            throw new SRMInvalidRequestException("surl of file request #" + (i + 1) + " is null.");
        }
        URI surl = URI.create(fileRequest.getTargetSURL().toString());
        UnsignedLong knownSize = fileRequest.getExpectedFileSize();
        if (knownSize != null) {
            sizes[i] = knownSize.longValue();
            if (sizes[i] < 0) {
                throw new SRMInvalidRequestException("Negative file size is not allowed.");
            }
        }
        // for now, extract type info from space token in the future
        wantPermanent[i] = true;
        /*                nextRequest.getFileStorageType()==
                TFileStorageType.PERMANENT;*/
        surls[i] = surl;
    }
    PutRequest r = new PutRequest(srm.getSrmId(), user, surls, sizes, wantPermanent, protocols, lifetime, configuration.getPutMaxPollPeriod(), clientHost, spaceToken, retentionPolicy, accessLatency, request.getUserRequestDescription());
    try (JDC ignored = r.applyJdc()) {
        if (overwriteMode != null) {
            r.setOverwriteMode(overwriteMode);
        }
        srm.acceptNewJob(r);
        // Return the request status
        return r.getSrmPrepareToPutResponse(configuration.getPutSwitchToAsynchronousModeDelay());
    }
}
Also used : SRMNotSupportedException(org.dcache.srm.SRMNotSupportedException) UnsignedLong(org.apache.axis.types.UnsignedLong) TRetentionPolicy(org.dcache.srm.v2_2.TRetentionPolicy) JDC(org.dcache.srm.util.JDC) PutRequest(org.dcache.srm.request.PutRequest) SrmPrepareToPutRequest(org.dcache.srm.v2_2.SrmPrepareToPutRequest) TOverwriteMode(org.dcache.srm.v2_2.TOverwriteMode) TPutFileRequest(org.dcache.srm.v2_2.TPutFileRequest) URI(java.net.URI) UnsignedLong(org.apache.axis.types.UnsignedLong) TAccessLatency(org.dcache.srm.v2_2.TAccessLatency) SRMInvalidRequestException(org.dcache.srm.SRMInvalidRequestException)

Example 3 with SrmPrepareToPutResponse

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

the class SrmPrepareToPut method getFailedResponse.

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

Example 4 with SrmPrepareToPutResponse

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

the class RemoteTurlPutterV2 method getInitialRequest.

@Override
public void getInitialRequest() throws SRMException {
    if (number_of_file_reqs == 0) {
        LOGGER.debug("number_of_file_reqs is 0, nothing to do");
        return;
    }
    try {
        java.net.URI srmUrl = URIs.createWithDefaultPort(SURLs[0]);
        srmv2 = new SRMClientV2(srmUrl, Optional.of(credential.getDelegatedCredential()), Optional.empty(), retry_timout, retry_num, false, false, caCertificatePath, transport);
        int len = SURLs.length;
        TPutFileRequest[] fileRequests = new TPutFileRequest[len];
        for (int i = 0; i < len; ++i) {
            URI uri = new URI(SURLs[i]);
            fileRequests[i] = new TPutFileRequest();
            fileRequests[i].setTargetSURL(uri);
            pendingSurlsToIndex.put(SURLs[i], i);
        }
        SrmPrepareToPutRequest srmPrepareToPutRequest = new SrmPrepareToPutRequest();
        if (retentionPolicy != null || accessLatency != null) {
            TRetentionPolicyInfo retentionPolicyInfo = new TRetentionPolicyInfo();
            retentionPolicyInfo.setRetentionPolicy(retentionPolicy);
            retentionPolicyInfo.setAccessLatency(accessLatency);
            srmPrepareToPutRequest.setTargetFileRetentionPolicyInfo(retentionPolicyInfo);
        }
        TTransferParameters transferParameters = new TTransferParameters();
        transferParameters.setAccessPattern(TAccessPattern.TRANSFER_MODE);
        transferParameters.setConnectionType(TConnectionType.WAN);
        transferParameters.setArrayOfTransferProtocols(new ArrayOfString(protocols));
        srmPrepareToPutRequest.setTransferParameters(transferParameters);
        srmPrepareToPutRequest.setArrayOfFileRequests(new ArrayOfTPutFileRequest(fileRequests));
        srmPrepareToPutRequest.setDesiredFileStorageType(storageType);
        srmPrepareToPutRequest.setDesiredTotalRequestTime((int) requestLifetime);
        srmPrepareToPutRequest.setOverwriteOption(overwriteMode);
        srmPrepareToPutRequest.setTargetSpaceToken(targetSpaceToken);
        srmPrepareToPutResponse = srmv2.srmPrepareToPut(srmPrepareToPutRequest);
    } catch (URISyntaxException | IOException | InterruptedException | ServiceException e) {
        LOGGER.error("failed to connect to {} {}", SURLs[0], e.getMessage());
        throw new SRMException("failed to connect to " + SURLs[0], e);
    }
}
Also used : URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) ArrayOfTPutFileRequest(org.dcache.srm.v2_2.ArrayOfTPutFileRequest) TPutFileRequest(org.dcache.srm.v2_2.TPutFileRequest) TTransferParameters(org.dcache.srm.v2_2.TTransferParameters) ArrayOfTPutFileRequest(org.dcache.srm.v2_2.ArrayOfTPutFileRequest) ArrayOfAnyURI(org.dcache.srm.v2_2.ArrayOfAnyURI) URI(org.apache.axis.types.URI) TRetentionPolicyInfo(org.dcache.srm.v2_2.TRetentionPolicyInfo) SRMException(org.dcache.srm.SRMException) ServiceException(javax.xml.rpc.ServiceException) SrmPrepareToPutRequest(org.dcache.srm.v2_2.SrmPrepareToPutRequest) ArrayOfString(org.dcache.srm.v2_2.ArrayOfString)

Example 5 with SrmPrepareToPutResponse

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

Aggregations

SrmPrepareToPutResponse (org.dcache.srm.v2_2.SrmPrepareToPutResponse)3 TReturnStatus (org.dcache.srm.v2_2.TReturnStatus)3 IOException (java.io.IOException)2 URI (org.apache.axis.types.URI)2 ArrayOfAnyURI (org.dcache.srm.v2_2.ArrayOfAnyURI)2 ArrayOfString (org.dcache.srm.v2_2.ArrayOfString)2 ArrayOfTPutRequestFileStatus (org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus)2 SrmPrepareToPutRequest (org.dcache.srm.v2_2.SrmPrepareToPutRequest)2 SrmStatusOfPutRequestResponse (org.dcache.srm.v2_2.SrmStatusOfPutRequestResponse)2 TPutFileRequest (org.dcache.srm.v2_2.TPutFileRequest)2 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Date (java.util.Date)1 ServiceException (javax.xml.rpc.ServiceException)1 UnsignedLong (org.apache.axis.types.UnsignedLong)1 SRMException (org.dcache.srm.SRMException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)1 PutRequest (org.dcache.srm.request.PutRequest)1 JDC (org.dcache.srm.util.JDC)1