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());
}
}
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);
}
}
Aggregations