use of org.dcache.srm.v2_2.TStatusCode.SRM_SUCCESS in project dcache by dCache.
the class PutRequest method abort.
/**
* this callbacks are given to storage.prepareToPut storage.prepareToPut calls methods of
* callbacks to indicate progress
*/
@Override
public TReturnStatus abort(String reason) {
wlock();
try {
/* [ SRM 2.2, 5.11.2 ]
*
* a) srmAbortRequest terminates all files in the request regardless of the file
* state. Remove files from the queue, and release cached files if a limited
* lifetime is associated with the file.
* c) Abort must be allowed to all requests with requestToken.
* f) When aborting srmPrepareToPut request before srmPutDone and before the file
* transfer, the SURL must not exist as the result of the successful abort on
* the SURL. Any srmRm request on the SURL must fail.
* g) When aborting srmPrepareToPut request before srmPutDone and after the file
* transfer, the SURL may exist, and a srmRm request on the SURL may remove
* the requested SURL.
* h) When aborting srmPrepareToPut request after srmPutDone, it must be failed
* for those files. An explicit srmRm is required to remove those successfully
* completed files for srmPrepareToPut.
* i) When duplicate abort request is issued on the same request, SRM_SUCCESS
* may be returned to all duplicate abort requests and no operations on
* duplicate abort requests are performed.
*/
boolean hasSuccess = false;
boolean hasFailure = false;
boolean hasCompleted = false;
updateStatus();
State state = getState();
if (!state.isFinal()) {
for (PutFileRequest file : getFileRequests()) {
try {
file.abort(reason);
hasSuccess = true;
} catch (SRMException e) {
hasFailure = true;
} catch (IllegalStateTransition e) {
if (e.getFromState() == State.DONE) {
hasCompleted = true;
}
hasFailure = true;
}
}
try {
setStateAndStatusCode(State.CANCELED, "Request aborted", TStatusCode.SRM_ABORTED);
} catch (IllegalStateTransition e) {
hasFailure = true;
}
} else if (state == State.DONE) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, "Put request completed successfully and cannot be aborted");
}
TReturnStatus returnStatus = getSummaryReturnStatus(hasFailure, hasSuccess);
if (hasCompleted) {
returnStatus = new TReturnStatus(returnStatus.getStatusCode(), "Some SURLs have completed successfully and cannot be aborted");
}
return returnStatus;
} finally {
wunlock();
}
}
use of org.dcache.srm.v2_2.TStatusCode.SRM_SUCCESS in project dcache by dCache.
the class SrmHandler method mapGetRequestTokensResponse.
private SrmGetRequestTokensResponse mapGetRequestTokensResponse(List<SrmResponse> responses) {
List<TRequestTokenReturn> tokens = new ArrayList<>();
for (SrmResponse srmResponse : responses) {
SrmGetRequestTokensResponse response = (SrmGetRequestTokensResponse) srmResponse.getResponse();
if (response.getReturnStatus().getStatusCode() != SRM_SUCCESS) {
return response;
}
for (TRequestTokenReturn token : response.getArrayOfRequestTokens().getTokenArray()) {
tokens.add(new TRequestTokenReturn(prefix(srmResponse.getId(), token.getRequestToken()), token.getCreatedAtTime()));
}
}
ArrayOfTRequestTokenReturn arrayOfRequestTokens = new ArrayOfTRequestTokenReturn(tokens.toArray(TRequestTokenReturn[]::new));
return new SrmGetRequestTokensResponse(new TReturnStatus(SRM_SUCCESS, "Request processed successfully."), arrayOfRequestTokens);
}
use of org.dcache.srm.v2_2.TStatusCode.SRM_SUCCESS 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.TStatusCode.SRM_SUCCESS in project dcache by dCache.
the class SrmHandler method toGetRequestSummaryResponse.
private SrmGetRequestSummaryResponse toGetRequestSummaryResponse(Map<String, ListenableFuture<TRequestSummary>> futureMap) throws InterruptedException, CacheException, NoRouteToCellException {
boolean hasFailure = false;
boolean hasSuccess = false;
List<TRequestSummary> summaries = new ArrayList<>();
for (Map.Entry<String, ListenableFuture<TRequestSummary>> entry : futureMap.entrySet()) {
try {
summaries.add(entry.getValue().get());
hasSuccess = true;
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof SRMException) {
summaries.add(createRequestSummaryFailure(entry.getKey(), ((SRMException) cause).getStatusCode(), cause.getMessage()));
hasFailure = true;
} else {
Throwables.throwIfInstanceOf(cause, CacheException.class);
Throwables.throwIfInstanceOf(cause, NoRouteToCellException.class);
Throwables.throwIfUnchecked(e);
throw new RuntimeException(e);
}
}
}
TReturnStatus status;
if (!hasFailure) {
status = new TReturnStatus(SRM_SUCCESS, "All request statuses have been retrieved.");
} else if (hasSuccess) {
status = new TReturnStatus(SRM_PARTIAL_SUCCESS, "Some request statuses have been retrieved.");
} else {
status = new TReturnStatus(SRM_FAILURE, "No request statuses have been retrieved.");
}
return new SrmGetRequestSummaryResponse(status, new ArrayOfTRequestSummary(summaries.toArray(TRequestSummary[]::new)));
}
Aggregations