use of org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus in project dcache by dCache.
the class PutRequest method getSrmStatusOfPutRequestResponse.
public final SrmStatusOfPutRequestResponse getSrmStatusOfPutRequestResponse(org.apache.axis.types.URI[] surls) throws SRMFileRequestNotFoundException, SRMInvalidRequestException {
SrmStatusOfPutRequestResponse response = new SrmStatusOfPutRequestResponse();
response.setReturnStatus(getTReturnStatus());
TPutRequestFileStatus[] statusArray = getArrayOfTPutRequestFileStatus(surls);
if (LOGGER.isDebugEnabled()) {
StringBuilder s = new StringBuilder("getSrmStatusOfPutRequestResponse:");
s.append(" StatusCode = ").append(response.getReturnStatus().getStatusCode());
for (TPutRequestFileStatus fs : statusArray) {
s.append(" FileStatusCode = ").append(fs.getStatus().getStatusCode());
}
LOGGER.debug(s.toString());
}
response.setArrayOfFileStatuses(new ArrayOfTPutRequestFileStatus(statusArray));
response.setRemainingTotalRequestTime(getRemainingLifetimeIn(TimeUnit.SECONDS));
return response;
}
use of org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus 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);
}
}
use of org.dcache.srm.v2_2.ArrayOfTPutRequestFileStatus in project dcache by dCache.
the class PutRequest method getSrmPrepareToPutResponse.
private final SrmPrepareToPutResponse getSrmPrepareToPutResponse() throws SRMInvalidRequestException {
SrmPrepareToPutResponse response = new SrmPrepareToPutResponse();
response.setReturnStatus(getTReturnStatus());
response.setRequestToken(getTRequestToken());
response.setArrayOfFileStatuses(new ArrayOfTPutRequestFileStatus(getArrayOfTPutRequestFileStatus()));
response.setRemainingTotalRequestTime(getRemainingLifetimeIn(TimeUnit.SECONDS));
return response;
}
Aggregations