Search in sources :

Example 1 with TOverwriteMode

use of org.dcache.srm.v2_2.TOverwriteMode 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 2 with TOverwriteMode

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

URI (java.net.URI)2 JDC (org.dcache.srm.util.JDC)2 TAccessLatency (org.dcache.srm.v2_2.TAccessLatency)2 TOverwriteMode (org.dcache.srm.v2_2.TOverwriteMode)2 TRetentionPolicy (org.dcache.srm.v2_2.TRetentionPolicy)2 UnsignedLong (org.apache.axis.types.UnsignedLong)1 SRMInternalErrorException (org.dcache.srm.SRMInternalErrorException)1 SRMInvalidRequestException (org.dcache.srm.SRMInvalidRequestException)1 SRMNotSupportedException (org.dcache.srm.SRMNotSupportedException)1 CopyRequest (org.dcache.srm.request.CopyRequest)1 PutRequest (org.dcache.srm.request.PutRequest)1 IllegalStateTransition (org.dcache.srm.scheduler.IllegalStateTransition)1 SrmCopyRequest (org.dcache.srm.v2_2.SrmCopyRequest)1 SrmPrepareToPutRequest (org.dcache.srm.v2_2.SrmPrepareToPutRequest)1 TCopyFileRequest (org.dcache.srm.v2_2.TCopyFileRequest)1 TPutFileRequest (org.dcache.srm.v2_2.TPutFileRequest)1