use of org.dcache.srm.v2_2.TGetFileRequest in project dcache by dCache.
the class SRMBringOnlineClientV2 method start.
@Override
public void start() throws Exception {
try {
int len = from.length;
String[] SURLS = new String[len];
TGetFileRequest[] fileRequests = new TGetFileRequest[len];
for (int i = 0; i < len; ++i) {
SURLS[i] = from[i].toASCIIString();
URI uri = new URI(SURLS[i]);
fileRequests[i] = new TGetFileRequest();
fileRequests[i].setSourceSURL(uri);
pendingSurlsToIndex.put(SURLS[i], i);
}
hook = new Thread(this);
Runtime.getRuntime().addShutdownHook(hook);
SrmBringOnlineRequest srmBringOnlineRequest = new SrmBringOnlineRequest();
srmBringOnlineRequest.setUserRequestDescription(configuration.getUserRequestDescription());
srmBringOnlineRequest.setDesiredTotalRequestTime((int) configuration.getRequestLifetime());
if (configuration.getDesiredLifetime() != null) {
srmBringOnlineRequest.setDesiredLifeTime(configuration.getDesiredLifetime().intValue());
}
TRetentionPolicy rp = configuration.getRetentionPolicy() != null ? RetentionPolicy.fromString(configuration.getRetentionPolicy()).toTRetentionPolicy() : null;
TAccessLatency al = configuration.getAccessLatency() != null ? AccessLatency.fromString(configuration.getAccessLatency()).toTAccessLatency() : null;
if ((al != null) && (rp == null)) {
throw new IllegalArgumentException("if access latency is specified, " + "then retention policy has to be specified as well");
} else if (rp != null) {
srmBringOnlineRequest.setTargetFileRetentionPolicyInfo(new TRetentionPolicyInfo(rp, al));
}
srmBringOnlineRequest.setArrayOfFileRequests(new ArrayOfTGetFileRequest(fileRequests));
TAccessPattern ap = null;
if (configuration.getAccessPattern() != null) {
ap = TAccessPattern.fromString(configuration.getAccessPattern());
}
TConnectionType ct = null;
if (configuration.getConnectionType() != null) {
ct = TConnectionType.fromString(configuration.getConnectionType());
}
ArrayOfString protocolArray = null;
if (configuration.getProtocols() != null) {
protocolArray = new ArrayOfString(configuration.getProtocols());
}
ArrayOfString arrayOfClientNetworks = null;
if (configuration.getArrayOfClientNetworks() != null) {
arrayOfClientNetworks = new ArrayOfString(configuration.getArrayOfClientNetworks());
}
if (ap != null || ct != null || arrayOfClientNetworks != null || protocolArray != null) {
srmBringOnlineRequest.setTransferParameters(new TTransferParameters(ap, ct, arrayOfClientNetworks, protocolArray));
}
configuration.getStorageSystemInfo().ifPresent(srmBringOnlineRequest::setStorageSystemInfo);
say("calling srmBringOnline");
SrmBringOnlineResponse response = srm.srmBringOnline(srmBringOnlineRequest);
say("received response");
if (response == null) {
throw new IOException(" null response");
}
TReturnStatus status = response.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("srmBringOnline submission failed, unexpected or failed status : " + statusCode + " explanation=" + status.getExplanation());
}
requestToken = response.getRequestToken();
dsay(" srm returned requestToken = " + requestToken);
if (response.getArrayOfFileStatuses() == null) {
throw new IOException("returned bringOnlineRequestFileStatuses is an empty array");
}
TBringOnlineRequestFileStatus[] bringOnlineRequestFileStatuses = response.getArrayOfFileStatuses().getStatusArray();
if (bringOnlineRequestFileStatuses.length != len) {
throw new IOException("incorrect number of TBringOnlineRequestFileStatus" + "in RequestStatus expected " + len + " received " + bringOnlineRequestFileStatuses.length);
}
while (!pendingSurlsToIndex.isEmpty()) {
long estimatedWaitInSeconds = 60;
for (TBringOnlineRequestFileStatus bringOnlineRequestFileStatus : bringOnlineRequestFileStatuses) {
URI surl = bringOnlineRequestFileStatus.getSourceSURL();
if (surl == null) {
esay("invalid bringOnlineRequestFileStatus, surl is null");
continue;
}
String surl_string = surl.toString();
if (!pendingSurlsToIndex.containsKey(surl_string)) {
esay("invalid bringOnlineRequestFileStatus, surl = " + surl_string + " not found");
continue;
}
TReturnStatus fileStatus = bringOnlineRequestFileStatus.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 = "retrieval of surl " + surl_string + " failed, status = " + fileStatusCode + " explanation=" + fileStatus.getExplanation();
esay(error);
int indx = pendingSurlsToIndex.remove(surl_string);
setReportFailed(from[indx], from[indx], error);
continue;
}
if (fileStatus.getStatusCode() == TStatusCode.SRM_SUCCESS) {
int indx = pendingSurlsToIndex.remove(surl_string);
setReportSucceeded(from[indx], from[indx]);
System.out.println(from[indx] + " brought online, use request id " + requestToken + " to release");
continue;
}
Integer estimatedWaitTime = bringOnlineRequestFileStatus.getEstimatedWaitTime();
if (estimatedWaitTime != null && estimatedWaitTime < estimatedWaitInSeconds && estimatedWaitTime >= 1) {
estimatedWaitInSeconds = estimatedWaitTime;
}
}
if (pendingSurlsToIndex.isEmpty()) {
dsay("no more pending transfers, breaking the loop");
Runtime.getRuntime().removeShutdownHook(hook);
break;
}
try {
say("sleeping " + estimatedWaitInSeconds + " seconds ...");
Thread.sleep(estimatedWaitInSeconds * 1000);
} catch (InterruptedException ie) {
}
SrmStatusOfBringOnlineRequestRequest srmStatusOfBringOnlineRequestRequest = new SrmStatusOfBringOnlineRequestRequest();
srmStatusOfBringOnlineRequestRequest.setRequestToken(requestToken);
// we do not know what to expect from the server when
// no surls are specified int the status update request
// so we always are sending the list of all pending srm urls
String[] pendingSurlStrings = pendingSurlsToIndex.keySet().toArray(new String[pendingSurlsToIndex.size()]);
// 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 = pendingSurlStrings.length;
URI[] surlArray = new URI[expectedResponseLength];
for (int i = 0; i < expectedResponseLength; ++i) {
surlArray[i] = new URI(pendingSurlStrings[i]);
}
srmStatusOfBringOnlineRequestRequest.setArrayOfSourceSURLs(new ArrayOfAnyURI(surlArray));
SrmStatusOfBringOnlineRequestResponse srmStatusOfBringOnlineRequestResponse = srm.srmStatusOfBringOnlineRequest(srmStatusOfBringOnlineRequestRequest);
if (srmStatusOfBringOnlineRequestResponse == null) {
throw new IOException(" null srmStatusOfBringOnlineRequestResponse");
}
if (srmStatusOfBringOnlineRequestResponse.getArrayOfFileStatuses() == null) {
esay("incorrect number of RequestFileStatuses");
throw new IOException("incorrect number of RequestFileStatuses");
}
bringOnlineRequestFileStatuses = srmStatusOfBringOnlineRequestResponse.getArrayOfFileStatuses().getStatusArray();
if (bringOnlineRequestFileStatuses == null || bringOnlineRequestFileStatuses.length != expectedResponseLength) {
esay("incorrect number of RequestFileStatuses");
throw new IOException("incorrect number of RequestFileStatuses");
}
status = srmStatusOfBringOnlineRequestResponse.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 = "srmBringOnline update failed, status : " + statusCode + " explanation=" + status.getExplanation();
esay(error);
for (int i = 0; i < expectedResponseLength; ++i) {
TReturnStatus frstatus = bringOnlineRequestFileStatuses[i].getStatus();
if (frstatus != null) {
if (!RequestStatusTool.isTransientStateStatus(frstatus)) {
int indx = pendingSurlsToIndex.remove(bringOnlineRequestFileStatuses[i].getSourceSURL().toString());
setReportFailed(from[indx], from[indx], error);
}
esay("BringOnlineFileRequest[" + bringOnlineRequestFileStatuses[i].getSourceSURL() + "] status=" + frstatus.getStatusCode() + " explanation=" + frstatus.getExplanation());
}
}
throw new IOException(error);
}
}
} catch (Exception e) {
esay(e.toString());
} finally {
report.dumpReport();
if (!report.everythingAllRight()) {
report.reportErrors(System.err);
System.exit(1);
}
}
}
use of org.dcache.srm.v2_2.TGetFileRequest in project dcache by dCache.
the class SrmBringOnline method srmBringOnline.
private SrmBringOnlineResponse srmBringOnline() throws SRMInvalidRequestException, SRMInternalErrorException, SRMNotSupportedException {
String[] protocols = getProtocols(request);
String clientHost = getClientNetwork(request).orElse(this.clientHost);
TGetFileRequest[] fileRequests = getFileRequests(request);
URI[] surls = getSurls(fileRequests);
long requestTime = Lifetimes.calculateLifetime(request.getDesiredTotalRequestTime(), configuration.getBringOnlineLifetime());
long desiredLifetimeInSeconds = getDesiredLifetime(request, requestTime);
if (protocols != null && protocols.length > 0) {
String[] supportedProtocols = storage.supportedGetProtocols();
boolean isAnyProtocolSupported = any(asList(protocols), in(asList(supportedProtocols)));
if (!isAnyProtocolSupported) {
throw new SRMNotSupportedException("Protocol(s) not supported: " + Arrays.toString(protocols));
}
}
BringOnlineRequest r = new BringOnlineRequest(srm.getSrmId(), user, surls, protocols, requestTime, desiredLifetimeInSeconds, configuration.getBringOnlineMaxPollPeriod(), request.getUserRequestDescription(), clientHost);
try (JDC ignored = r.applyJdc()) {
srm.acceptNewJob(r);
return r.getSrmBringOnlineResponse(configuration.getBringOnlineSwitchToAsynchronousModeDelay());
} catch (InterruptedException e) {
throw new SRMInternalErrorException("Operation interrupted", e);
} catch (IllegalStateTransition e) {
throw new SRMInternalErrorException("Scheduling failure", e);
}
}
use of org.dcache.srm.v2_2.TGetFileRequest in project dcache by dCache.
the class SrmBringOnline method getSurls.
private static URI[] getSurls(TGetFileRequest[] fileRequests) throws SRMInvalidRequestException {
URI[] surls = new URI[fileRequests.length];
for (int i = 0; i < fileRequests.length; ++i) {
TGetFileRequest fileRequest = fileRequests[i];
if (fileRequest == null) {
throw new SRMInvalidRequestException("file request #" + (i + 1) + " is null");
}
if (fileRequest.getSourceSURL() == null) {
throw new SRMInvalidRequestException("can't get surl of file request #" + (i + 1) + " null");
}
surls[i] = URI.create(fileRequest.getSourceSURL().toString());
}
return surls;
}
use of org.dcache.srm.v2_2.TGetFileRequest in project dcache by dCache.
the class SRMGetClientV2 method start.
@Override
public void start() throws Exception {
try {
copier = new Copier(configuration);
new Thread(copier).start();
int len = from.length;
String[] SURLS = new String[len];
TGetFileRequest[] fileRequests = new TGetFileRequest[len];
for (int i = 0; i < len; ++i) {
SURLS[i] = from[i].toASCIIString();
URI uri = new URI(SURLS[i]);
fileRequests[i] = new TGetFileRequest();
fileRequests[i].setSourceSURL(uri);
pendingSurlsToIndex.put(SURLS[i], i);
}
hook = new Thread(this);
Runtime.getRuntime().addShutdownHook(hook);
SrmPrepareToGetRequest srmPrepareToGetRequest = new SrmPrepareToGetRequest();
srmPrepareToGetRequest.setUserRequestDescription(configuration.getUserRequestDescription());
srmPrepareToGetRequest.setDesiredTotalRequestTime((int) configuration.getRequestLifetime());
TRetentionPolicy rp = configuration.getRetentionPolicy() != null ? RetentionPolicy.fromString(configuration.getRetentionPolicy()).toTRetentionPolicy() : null;
TAccessLatency al = configuration.getAccessLatency() != null ? AccessLatency.fromString(configuration.getAccessLatency()).toTAccessLatency() : null;
if ((al != null) && (rp == null)) {
throw new IllegalArgumentException("if access latency is specified, " + "then retention policy have to be specified as well");
} else if (rp != null) {
srmPrepareToGetRequest.setTargetFileRetentionPolicyInfo(new TRetentionPolicyInfo(rp, al));
}
srmPrepareToGetRequest.setArrayOfFileRequests(new ArrayOfTGetFileRequest(fileRequests));
TAccessPattern ap = null;
if (configuration.getAccessPattern() != null) {
ap = TAccessPattern.fromString(configuration.getAccessPattern());
}
TConnectionType ct = null;
if (configuration.getConnectionType() != null) {
ct = TConnectionType.fromString(configuration.getConnectionType());
}
ArrayOfString protocolArray = null;
if (configuration.getProtocols() != null) {
protocolArray = new ArrayOfString(configuration.getProtocols());
}
ArrayOfString arrayOfClientNetworks = null;
if (configuration.getArrayOfClientNetworks() != null) {
arrayOfClientNetworks = new ArrayOfString(configuration.getArrayOfClientNetworks());
}
if (ap != null || ct != null || arrayOfClientNetworks != null || protocolArray != null) {
srmPrepareToGetRequest.setTransferParameters(new TTransferParameters(ap, ct, arrayOfClientNetworks, protocolArray));
}
configuration.getStorageSystemInfo().ifPresent(srmPrepareToGetRequest::setStorageSystemInfo);
say("calling srmPrepareToGet");
SrmPrepareToGetResponse response = srm.srmPrepareToGet(srmPrepareToGetRequest);
say("received response");
if (response == null) {
throw new IOException(" null response");
}
TReturnStatus status = response.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) && (statusCode != TStatusCode.SRM_FAILURE || response.getArrayOfFileStatuses() == null)) {
String explanation = status.getExplanation();
if (explanation != null) {
throw new IOException("srmPrepareToGet submission failed, unexpected or failed status : " + statusCode + " explanation= " + explanation);
} else {
throw new IOException("srmPrepareToGet submission failed, unexpected or failed status : " + statusCode);
}
}
requestToken = response.getRequestToken();
dsay(" srm returned requestToken = " + requestToken);
if (response.getArrayOfFileStatuses() == null) {
throw new IOException("returned GetRequestFileStatuses is an empty array");
}
TGetRequestFileStatus[] getRequestFileStatuses = response.getArrayOfFileStatuses().getStatusArray();
if (getRequestFileStatuses.length != len) {
throw new IOException("incorrect number of GetRequestFileStatuses" + "in RequestStatus expected " + len + " received " + getRequestFileStatuses.length);
}
while (!pendingSurlsToIndex.isEmpty()) {
long estimatedWaitInSeconds = 5;
for (TGetRequestFileStatus getRequestFileStatus : getRequestFileStatuses) {
URI surl = getRequestFileStatus.getSourceSURL();
if (surl == null) {
esay("invalid getRequestFileStatus, surl is null");
continue;
}
String surl_string = surl.toString();
if (!pendingSurlsToIndex.containsKey(surl_string)) {
esay("invalid getRequestFileStatus, surl = " + surl_string + " not found");
continue;
}
TReturnStatus fileStatus = getRequestFileStatus.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();
esay(error);
int indx = pendingSurlsToIndex.remove(surl_string);
setReportFailed(from[indx], to[indx], error);
continue;
}
if (getRequestFileStatus.getTransferURL() != null) {
java.net.URI globusTURL = new java.net.URI(getRequestFileStatus.getTransferURL().toString());
int indx = pendingSurlsToIndex.remove(surl_string);
setReportFailed(from[indx], to[indx], "received TURL, but did not complete transfer");
CopyJob job = new SRMV2CopyJob(globusTURL, to[indx], srm, requestToken, logger, from[indx], true, this);
copier.addCopyJob(job);
continue;
}
if (getRequestFileStatus.getEstimatedWaitTime() != null && getRequestFileStatus.getEstimatedWaitTime() < estimatedWaitInSeconds && getRequestFileStatus.getEstimatedWaitTime() >= 1) {
estimatedWaitInSeconds = getRequestFileStatus.getEstimatedWaitTime();
}
}
if (pendingSurlsToIndex.isEmpty()) {
dsay("no more pending transfers, breaking the loop");
Runtime.getRuntime().removeShutdownHook(hook);
break;
}
// do not wait longer then 60 seconds
if (estimatedWaitInSeconds > 60) {
estimatedWaitInSeconds = 60;
}
try {
say("sleeping " + estimatedWaitInSeconds + " seconds ...");
Thread.sleep(estimatedWaitInSeconds * 1000);
} catch (InterruptedException ie) {
}
SrmStatusOfGetRequestRequest srmStatusOfGetRequestRequest = new SrmStatusOfGetRequestRequest();
srmStatusOfGetRequestRequest.setRequestToken(requestToken);
// we do not know what to expect from the server when
// no surls are specified int the status update request
// so we always are sending the list of all pending srm urls
String[] pendingSurlStrings = pendingSurlsToIndex.keySet().toArray(new String[pendingSurlsToIndex.size()]);
// 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 = pendingSurlStrings.length;
URI[] surlArray = new URI[expectedResponseLength];
for (int i = 0; i < expectedResponseLength; ++i) {
surlArray[i] = new URI(pendingSurlStrings[i]);
}
srmStatusOfGetRequestRequest.setArrayOfSourceSURLs(new ArrayOfAnyURI(surlArray));
SrmStatusOfGetRequestResponse srmStatusOfGetRequestResponse = srm.srmStatusOfGetRequest(srmStatusOfGetRequestRequest);
if (srmStatusOfGetRequestResponse == null) {
throw new IOException(" null srmStatusOfGetRequestResponse");
}
if (srmStatusOfGetRequestResponse.getArrayOfFileStatuses() == null) {
String error = "array of RequestFileStatuses is null ";
statusCode = status.getStatusCode();
if (statusCode != null) {
error += " status : " + statusCode + " explanation=" + status.getExplanation();
}
esay(error);
throw new IOException(error);
}
getRequestFileStatuses = srmStatusOfGetRequestResponse.getArrayOfFileStatuses().getStatusArray();
if (getRequestFileStatuses == null || getRequestFileStatuses.length != expectedResponseLength) {
String error = "incorrect number of RequestFileStatuses";
statusCode = status.getStatusCode();
if (statusCode != null) {
error += " status : " + statusCode + " explanation=" + status.getExplanation();
}
esay(error);
throw new IOException(error);
}
status = srmStatusOfGetRequestResponse.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 = "srmPrepareToGet update failed, status : " + statusCode + " explanation=" + status.getExplanation();
esay(error);
for (int i = 0; i < expectedResponseLength; ++i) {
TReturnStatus frstatus = getRequestFileStatuses[i].getStatus();
if (frstatus != null) {
esay("GetFileRequest[" + getRequestFileStatuses[i].getSourceSURL() + "] status=" + frstatus.getStatusCode() + " explanation=" + frstatus.getExplanation());
if (!RequestStatusTool.isTransientStateStatus(frstatus)) {
pendingSurlsToIndex.remove(getRequestFileStatuses[i].getSourceSURL().toString());
}
}
}
throw new IOException(error);
}
}
} catch (Exception e) {
try {
if (copier != null) {
dsay("stopping copier");
copier.stop();
abortAllPendingFiles();
}
} catch (Exception e1) {
edsay(e1.toString());
}
throw e;
} finally {
if (copier != null) {
copier.doneAddingJobs();
try {
copier.waitCompletion();
} catch (Exception e1) {
edsay(e1.toString());
}
}
report.dumpReport();
if (!report.everythingAllRight()) {
report.reportErrors(System.err);
}
}
}
use of org.dcache.srm.v2_2.TGetFileRequest in project dcache by dCache.
the class SrmPrepareToGet method getSurls.
private static URI[] getSurls(SrmPrepareToGetRequest request) throws SRMInvalidRequestException {
TGetFileRequest[] fileRequests = getFileRequests(request);
URI[] surls = new URI[fileRequests.length];
for (int i = 0; i < fileRequests.length; ++i) {
TGetFileRequest nextRequest = fileRequests[i];
if (nextRequest == null) {
throw new SRMInvalidRequestException("file request #" + (i + 1) + " is null");
}
if (nextRequest.getSourceSURL() == null) {
throw new SRMInvalidRequestException("can't get surl of file request #" + (i + 1) + " null");
}
surls[i] = URI.create(nextRequest.getSourceSURL().toString());
}
return surls;
}
Aggregations