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