use of org.dcache.srm.v2_2.TSURLReturnStatus 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.TSURLReturnStatus in project dcache by dCache.
the class SRMRmClientV2 method start.
@Override
public void start() throws Exception {
checkCredentialValid();
SrmRmRequest req = new SrmRmRequest();
URI[] uris = new URI[surls.length];
for (int i = 0; i < surls.length; ++i) {
uris[i] = new URI(surl_strings[i]);
}
req.setArrayOfSURLs(new ArrayOfAnyURI(uris));
configuration.getStorageSystemInfo().ifPresent(req::setStorageSystemInfo);
SrmRmResponse resp = srm.srmRm(req);
TReturnStatus rs = resp.getReturnStatus();
if (rs.getStatusCode() != TStatusCode.SRM_SUCCESS) {
TStatusCode rc = rs.getStatusCode();
StringBuilder sb = new StringBuilder();
sb.append("Return code: ").append(rc.toString()).append("\n");
sb.append("Explanation: ").append(rs.getExplanation()).append("\n");
if (resp.getArrayOfFileStatuses() != null) {
TSURLReturnStatus[] arrayOfStatuses = resp.getArrayOfFileStatuses().getStatusArray();
if (arrayOfStatuses != null) {
for (int i = 0; i < arrayOfStatuses.length; i++) {
if (arrayOfStatuses[i] != null) {
sb.append("file#").append(i).append(" : ");
if (arrayOfStatuses[i].getSurl() != null) {
sb.append(arrayOfStatuses[i].getSurl());
}
if (arrayOfStatuses[i].getStatus() != null) {
sb.append(", ");
sb.append(arrayOfStatuses[i].getStatus().getStatusCode());
sb.append(", \"");
sb.append(arrayOfStatuses[i].getStatus().getExplanation());
sb.append("\"");
}
sb.append('\n');
}
}
}
}
System.out.println(sb.toString());
System.exit(1);
}
}
use of org.dcache.srm.v2_2.TSURLReturnStatus 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.TSURLReturnStatus 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.TSURLReturnStatus in project dcache by dCache.
the class BringOnlineRequest method release.
public TSURLReturnStatus[] release() throws SRMInternalErrorException {
SRMUser user = getUser();
int len = getNumOfFileRequest();
TSURLReturnStatus[] surlReturnStatuses = new TSURLReturnStatus[len];
LOGGER.debug("releaseFiles, releasing all {} files", len);
List<BringOnlineFileRequest> requests = getFileRequests();
for (int i = 0; i < len; i++) {
BringOnlineFileRequest request = requests.get(i);
org.apache.axis.types.URI surl;
try {
surl = new org.apache.axis.types.URI(request.getSurlString());
} catch (org.apache.axis.types.URI.MalformedURIException e) {
throw new RuntimeException("Failed to convert Java URI to Axis URI. " + "Please report this to support@dcache.org: " + e.getMessage(), e);
}
surlReturnStatuses[i] = new TSURLReturnStatus(surl, request.release(user));
}
return surlReturnStatuses;
}
Aggregations