use of org.dcache.srm.util.JDC in project dcache by dCache.
the class Job method applyJdc.
public JDC applyJdc() {
JDC current = jdc.apply();
JDC.appendToSession(String.valueOf(id));
return current;
}
use of org.dcache.srm.util.JDC in project dcache by dCache.
the class SrmStatusOfGetRequest method srmGetStatus.
private SrmStatusOfGetRequestResponse srmGetStatus() throws SRMInvalidRequestException {
String requestToken = request.getRequestToken();
GetRequest getRequest = Request.getRequest(requestToken, GetRequest.class);
try (JDC ignored = getRequest.applyJdc()) {
getRequest.tryToReady();
if (request.getArrayOfSourceSURLs() == null) {
return getRequest.getSrmStatusOfGetRequestResponse();
}
URI[] surls = request.getArrayOfSourceSURLs().getUrlArray();
if (surls.length == 0) {
return getRequest.getSrmStatusOfGetRequestResponse();
}
return getRequest.getSrmStatusOfGetRequestResponse(surls);
}
}
use of org.dcache.srm.util.JDC in project dcache by dCache.
the class SrmStatusOfPutRequest method srmPutStatus.
private SrmStatusOfPutRequestResponse srmPutStatus() throws SRMException {
String requestToken = statusOfPutRequestRequest.getRequestToken();
PutRequest putRequest = Request.getRequest(requestToken, PutRequest.class);
try (JDC ignored = putRequest.applyJdc()) {
putRequest.tryToReady();
if (statusOfPutRequestRequest.getArrayOfTargetSURLs() == null) {
return putRequest.getSrmStatusOfPutRequestResponse();
}
URI[] surls = statusOfPutRequestRequest.getArrayOfTargetSURLs().getUrlArray();
if (surls.length == 0) {
return putRequest.getSrmStatusOfPutRequestResponse();
}
return putRequest.getSrmStatusOfPutRequestResponse(surls);
}
}
use of org.dcache.srm.util.JDC 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();
}
}
}
use of org.dcache.srm.util.JDC in project dcache by dCache.
the class SrmReleaseFiles method srmReleaseFiles.
private SrmReleaseFilesResponse srmReleaseFiles() throws DataAccessException, SRMInvalidRequestException, SRMInternalErrorException {
ArrayOfAnyURI arrayOfSURLs = srmReleaseFilesRequest.getArrayOfSURLs();
org.apache.axis.types.URI[] surls;
if (arrayOfSURLs != null) {
surls = arrayOfSURLs.getUrlArray();
} else {
surls = null;
}
if (surls != null && surls.length == 0) {
throw new SRMInvalidRequestException("Request contains no SURL");
}
String requestToken = srmReleaseFilesRequest.getRequestToken();
if (requestToken == null) {
if (surls == null) {
throw new SRMInvalidRequestException("Request contains no SURL");
}
return releaseBySURLs(surls);
}
ContainerRequest<?> requestToRelease;
try {
requestToRelease = Request.getRequest(requestToken, ContainerRequest.class);
} catch (SRMInvalidRequestException e) {
return unpinBySURLAndRequestToken(requestToken, surls);
}
try (JDC ignored = requestToRelease.applyJdc()) {
TSURLReturnStatus[] surlReturnStatuses;
if (requestToRelease instanceof GetRequest) {
GetRequest getRequest = (GetRequest) requestToRelease;
if (surls == null) {
surlReturnStatuses = getRequest.release();
} else {
surlReturnStatuses = getRequest.releaseFiles(surls);
}
getRequest.updateStatus();
} else if (requestToRelease instanceof BringOnlineRequest) {
BringOnlineRequest bringOnlineRequest = (BringOnlineRequest) requestToRelease;
if (surls == null) {
surlReturnStatuses = bringOnlineRequest.release();
} else {
surlReturnStatuses = bringOnlineRequest.releaseFiles(surls);
}
bringOnlineRequest.updateStatus();
} else {
throw new SRMInvalidRequestException("No such get or bring online request: " + requestToken);
}
return new SrmReleaseFilesResponse(getSummaryReturnStatus(surlReturnStatuses), new ArrayOfTSURLReturnStatus(surlReturnStatuses));
}
}
Aggregations