use of org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus in project dcache by dCache.
the class SrmHandler method mapReleaseFilesResponse.
private SrmReleaseFilesResponse mapReleaseFilesResponse(SrmReleaseFilesRequest request, List<SrmResponse> responses) {
Map<URI, TSURLReturnStatus> map = new HashMap<>();
for (SrmResponse srmResponse : responses) {
SrmReleaseFilesResponse response = (SrmReleaseFilesResponse) srmResponse.getResponse();
for (TSURLReturnStatus status : response.getArrayOfFileStatuses().getStatusArray()) {
if (status.getStatus().getStatusCode() == SRM_SUCCESS) {
map.put(status.getSurl(), status);
} else if (status.getStatus().getStatusCode() == SRM_INVALID_PATH) {
// no entry
} else if (status.getStatus().getStatusCode() == SRM_AUTHORIZATION_FAILURE) {
map.putIfAbsent(status.getSurl(), status);
} else if (status.getStatus().getStatusCode() == SRM_FILE_LIFETIME_EXPIRED) {
map.putIfAbsent(status.getSurl(), status);
} else if (status.getStatus().getStatusCode() == SRM_FAILURE) {
map.putIfAbsent(status.getSurl(), status);
}
}
}
TSURLReturnStatus[] statuses = Stream.of(request.getArrayOfSURLs().getUrlArray()).map(surl -> {
TSURLReturnStatus status = map.get(surl);
return (status != null) ? status : new TSURLReturnStatus(surl, new TReturnStatus(SRM_INVALID_PATH, "File not found"));
}).toArray(TSURLReturnStatus[]::new);
return new SrmReleaseFilesResponse(getSummaryReturnStatus(statuses), new ArrayOfTSURLReturnStatus(statuses));
}
use of org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus in project dcache by dCache.
the class SRMV2CopyJob method done.
@Override
public void done(boolean success, String error) {
synchronized (this) {
if (isDone) {
return;
}
isDone = true;
}
try {
URI[] surlArray = new URI[] { new URI(surl.toASCIIString()) };
if (!success) {
SrmAbortFilesRequest srmAbortFilesRequest = new SrmAbortFilesRequest();
srmAbortFilesRequest.setRequestToken(requestToken);
srmAbortFilesRequest.setArrayOfSURLs(new ArrayOfAnyURI(surlArray));
SrmAbortFilesResponse srmAbortFilesResponse = srm.srmAbortFiles(srmAbortFilesRequest);
if (srmAbortFilesResponse == null) {
logger.elog("srmAbortFilesResponse is null");
} else {
TReturnStatus returnStatus = srmAbortFilesResponse.getReturnStatus();
if (returnStatus == null) {
logger.elog("srmAbortFiles return status is null");
} else {
logger.log("srmAbortFiles status code=" + returnStatus.getStatusCode());
}
}
} else if (isSrmPrepareToGet) {
SrmReleaseFilesRequest srmReleaseFilesRequest = new SrmReleaseFilesRequest();
srmReleaseFilesRequest.setRequestToken(requestToken);
srmReleaseFilesRequest.setArrayOfSURLs(new ArrayOfAnyURI(surlArray));
SrmReleaseFilesResponse srmReleaseFilesResponse = srm.srmReleaseFiles(srmReleaseFilesRequest);
TReturnStatus returnStatus = srmReleaseFilesResponse.getReturnStatus();
if (returnStatus == null) {
success = false;
error = "srmReleaseFilesResponse return status is null";
} else {
logger.log("srmReleaseFilesResponse status code=" + returnStatus.getStatusCode());
}
} else {
SrmPutDoneRequest srmPutDoneRequest = new SrmPutDoneRequest();
srmPutDoneRequest.setRequestToken(requestToken);
srmPutDoneRequest.setArrayOfSURLs(new ArrayOfAnyURI(surlArray));
SrmPutDoneResponse srmPutDoneResponse = srm.srmPutDone(srmPutDoneRequest);
TReturnStatus returnStatus = srmPutDoneResponse.getReturnStatus();
if (returnStatus == null) {
success = false;
error = "srmPutDone return status is null";
} else if (returnStatus.getStatusCode() != TStatusCode.SRM_SUCCESS) {
success = false;
ArrayOfTSURLReturnStatus arrayOfFileStatuses = srmPutDoneResponse.getArrayOfFileStatuses();
if (arrayOfFileStatuses != null && arrayOfFileStatuses.getStatusArray() != null && arrayOfFileStatuses.getStatusArray().length > 0 && arrayOfFileStatuses.getStatusArray()[0].getStatus().getStatusCode() != TStatusCode.SRM_SUCCESS && !Strings.isNullOrEmpty(arrayOfFileStatuses.getStatusArray()[0].getStatus().getExplanation())) {
error = arrayOfFileStatuses.getStatusArray()[0].getStatus().getExplanation();
} else {
error = returnStatus.getExplanation();
}
}
}
} catch (URI.MalformedURIException | RemoteException e) {
if (success) {
success = false;
error = e.toString();
} else {
logger.elog(e.toString());
}
} finally {
if (success) {
if (isSrmPrepareToGet) {
client.setReportSucceeded(surl, null);
} else {
client.setReportSucceeded(null, surl);
}
} else {
error = "received TURL but failed to copy: " + error;
if (isSrmPrepareToGet) {
client.setReportFailed(surl, null, error);
} else {
client.setReportFailed(null, surl, error);
}
}
}
}
use of org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus in project dcache by dCache.
the class SrmReleaseFiles method unpinBySURLAndRequestToken.
private SrmReleaseFilesResponse unpinBySURLAndRequestToken(String requestToken, org.apache.axis.types.URI[] surls) throws SRMInternalErrorException {
TSURLReturnStatus[] surlReturnStatusArray = new TSURLReturnStatus[surls.length];
for (int i = 0; i < surls.length; ++i) {
org.apache.axis.types.URI surl = surls[i];
TReturnStatus returnStatus = BringOnlineFileRequest.unpinBySURLandRequestToken(storage, user, requestToken, URI.create(surl.toString()));
surlReturnStatusArray[i] = new TSURLReturnStatus(surl, returnStatus);
}
return new SrmReleaseFilesResponse(getSummaryReturnStatus(surlReturnStatusArray), new ArrayOfTSURLReturnStatus(surlReturnStatusArray));
}
use of org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus in project dcache by dCache.
the class SrmRm method srmRm.
private SrmRmResponse srmRm() throws DataAccessException, InterruptedException, SRMInternalErrorException, SRMInvalidRequestException {
if (request.getArrayOfSURLs() == null) {
throw new SRMInvalidRequestException("arrayOfSURLs is empty");
}
org.apache.axis.types.URI[] surls = request.getArrayOfSURLs().getUrlArray();
if (surls == null || surls.length == 0) {
throw new SRMInvalidRequestException("arrayOfSURLs is empty");
}
TSURLReturnStatus[] returnStatuses = new TSURLReturnStatus[surls.length];
Semaphore semaphore = new Semaphore(sizeOfSingleRemoveBatch);
for (int i = 0; i < surls.length; i++) {
semaphore.acquire();
returnStatuses[i] = new TSURLReturnStatus(surls[i], null);
URI surl = URI.create(surls[i].toString());
storage.removeFile(user, surl, new Callback(semaphore, returnStatuses[i]));
}
semaphore.acquire(sizeOfSingleRemoveBatch);
for (int i = 0; i < surls.length; i++) {
TSURLReturnStatus returnStatus = returnStatuses[i];
if (returnStatus.getStatus().getStatusCode() == TStatusCode.SRM_INTERNAL_ERROR) {
throw new SRMInternalErrorException(returnStatus.getStatus().getExplanation());
}
if (returnStatus.getStatus().getStatusCode() == TStatusCode.SRM_SUCCESS || returnStatus.getStatus().getStatusCode() == TStatusCode.SRM_INVALID_PATH) {
// [SRM 2.2, 4.3.2, e)] srmRm aborts the SURLs from srmPrepareToPut requests not yet
// in SRM_PUT_DONE state, and must set its file status as SRM_ABORTED.
//
// [SRM 2.2, 4.3.2, f)] srmRm must remove SURLs even if the statuses of the SURLs
// are SRM_FILE_BUSY. In this case, operations such as srmPrepareToPut or srmCopy
// that holds the SURL status as SRM_FILE_BUSY must return SRM_INVALID_PATH upon
// status request or srmPutDone.
//
// It seems the SRM specs is undecided about whether to move put requests to
// SRM_ABORTED or SRM_INVALID_PATH. We choose SRM_ABORTED as it seems like the saner
// of the two options.
// [SRM 2.2, 4.3.2, d)] srmLs,srmPrepareToGet or srmBringOnline must not find these
// removed files any more. It must set file requests on SURL from srmPrepareToGet
// as SRM_ABORTED.
URI surl = URI.create(surls[i].toString());
try {
if (srm.abortTransfers(surl, "File was deleted by request " + JDC.getSession() + ".")) {
returnStatus.setStatus(new TReturnStatus(TStatusCode.SRM_SUCCESS, "Upload was aborted."));
}
} catch (SRMException e) {
returnStatus.setStatus(new TReturnStatus(e.getStatusCode(), e.getMessage()));
}
}
}
return new SrmRmResponse(ReturnStatuses.getSummaryReturnStatus(returnStatuses), new ArrayOfTSURLReturnStatus(returnStatuses));
}
use of org.dcache.srm.v2_2.ArrayOfTSURLReturnStatus in project dcache by dCache.
the class SrmPutDone method srmPutDone.
private SrmPutDoneResponse srmPutDone() throws SRMInvalidRequestException, SRMRequestTimedOutException, SRMAbortedException, SRMInternalErrorException, SRMAuthorizationException {
URI[] surls = getSurls(request);
PutRequest putRequest = Request.getRequest(request.getRequestToken(), PutRequest.class);
try (JDC ignored = putRequest.applyJdc()) {
putRequest.wlock();
try {
if (!user.hasAccessTo(putRequest)) {
throw new SRMAuthorizationException("User is not the owner of request " + request.getRequestToken() + ".");
}
switch(putRequest.getState()) {
case FAILED:
if (putRequest.getStatusCode() == TStatusCode.SRM_REQUEST_TIMED_OUT) {
throw new SRMRequestTimedOutException("Total request time exceeded");
}
break;
case CANCELED:
throw new SRMAbortedException("Request has been aborted.");
}
TSURLReturnStatus[] returnStatuses = new TSURLReturnStatus[surls.length];
for (int i = 0; i < surls.length; ++i) {
if (surls[i] == null) {
throw new SRMInvalidRequestException("SiteURLs[" + (i + 1) + "] is null.");
}
TReturnStatus returnStatus;
try {
PutFileRequest fileRequest = putRequest.getFileRequestBySurl(java.net.URI.create(surls[i].toString()));
try (JDC ignore = fileRequest.applyJdc()) {
returnStatus = fileRequest.done(this.user);
}
} catch (SRMFileRequestNotFoundException e) {
returnStatus = new TReturnStatus(TStatusCode.SRM_INVALID_PATH, "File does not exist.");
}
returnStatuses[i] = new TSURLReturnStatus(surls[i], returnStatus);
}
putRequest.updateStatus();
return new SrmPutDoneResponse(ReturnStatuses.getSummaryReturnStatus(returnStatuses), new ArrayOfTSURLReturnStatus(returnStatuses));
} finally {
putRequest.wunlock();
}
}
}
Aggregations