use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.
the class GetFileRequest method processStateChange.
@Override
protected void processStateChange(State newState, String description) {
State oldState = getState();
LOGGER.debug("State changed from {} to {}", oldState, newState);
switch(newState) {
case READY:
try {
getContainerRequest().resetRetryDeltaTime();
} catch (SRMInvalidRequestException ire) {
LOGGER.error(ire.toString());
}
break;
case DONE:
case FAILED:
case CANCELED:
AbstractStorageElement storage = getStorage();
try {
SRMUser user = getUser();
String fileId = getFileId();
String pinId = getPinId();
if (fileId != null && pinId != null) {
LOGGER.info("State changed to final state, unpinning fileId = {} pinId = {}.", fileId, pinId);
CheckedFuture<String, ? extends SRMException> future = storage.unPinFile(null, fileId, pinId);
future.addListener(() -> {
try {
LOGGER.debug("Unpinned (pinId={}).", future.checkedGet());
} catch (SRMException e) {
LOGGER.error("Unpinning failed: {}", e.getMessage());
}
}, MoreExecutors.directExecutor());
} else {
BringOnlineFileRequest.unpinBySURLandRequestToken(storage, user, String.valueOf(getRequestId()), getSurl());
}
} catch (SRMInternalErrorException | SRMInvalidRequestException e) {
LOGGER.error(e.toString());
}
}
super.processStateChange(newState, description);
}
use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.
the class BringOnlineFileRequest method release.
public TReturnStatus release(SRMUser user) throws SRMInternalErrorException {
String fileId;
String pinId;
wlock();
try {
State state = getState();
switch(state) {
case DONE:
fileId = getFileId();
pinId = getPinId();
if (fileId == null || pinId == null) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, "SURL is not pinned");
}
// Unpinning is done below, outside the lock
break;
case CANCELED:
return new TReturnStatus(TStatusCode.SRM_ABORTED, "SURL has been aborted and cannot be released");
case FAILED:
return new TReturnStatus(TStatusCode.SRM_FAILURE, "Pinning failed");
default:
setState(State.CANCELED, "Aborted by srmReleaseFile request.");
return new TReturnStatus(TStatusCode.SRM_ABORTED, "SURL is not yet pinned, pinning aborted");
}
} catch (IllegalStateTransition e) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage());
} finally {
wunlock();
}
LOGGER.debug("srmReleaseFile, unpinning fileId={} pinId={}", fileId, pinId);
CheckedFuture<String, ? extends SRMException> future = getStorage().unPinFile(user, fileId, pinId);
try {
future.checkedGet(60, TimeUnit.SECONDS);
setPinId(null);
saveJob(true);
return new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
} catch (TimeoutException e) {
throw new SRMInternalErrorException("Operation timed out.");
} catch (SRMException e) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, "Failed to unpin SURL: " + e.getMessage());
}
}
use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.
the class BringOnlineFileRequest method unpinBySURLandRequestToken.
public static TReturnStatus unpinBySURLandRequestToken(AbstractStorageElement storage, SRMUser user, String requestToken, URI surl) throws SRMInternalErrorException {
String fileId;
try {
fileId = storage.getFileMetaData(user, surl, true).fileId;
} catch (SRMInternalErrorException e) {
throw e;
} catch (SRMAuthorizationException e) {
return new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
} catch (SRMInvalidPathException e) {
return new TReturnStatus(TStatusCode.SRM_INVALID_PATH, e.getMessage());
} catch (SRMException e) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage());
}
CheckedFuture<String, ? extends SRMException> future = storage.unPinFileBySrmRequestId(user, fileId, requestToken);
try {
future.checkedGet(60, TimeUnit.SECONDS);
} catch (TimeoutException e) {
throw new SRMInternalErrorException("Operation timed out");
} catch (SRMException e) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, "Failed to unpin: " + e.getMessage());
}
return new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
}
use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.
the class BringOnlineFileRequest method unpinBySURL.
public static TReturnStatus unpinBySURL(AbstractStorageElement storage, SRMUser user, URI surl) throws SRMInternalErrorException {
String fileId;
try {
fileId = storage.getFileMetaData(user, surl, true).fileId;
} catch (SRMInternalErrorException e) {
throw e;
} catch (SRMAuthorizationException e) {
return new TReturnStatus(TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
} catch (SRMInvalidPathException e) {
return new TReturnStatus(TStatusCode.SRM_INVALID_PATH, e.getMessage());
} catch (SRMException e) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, e.getMessage());
}
CheckedFuture<String, ? extends SRMException> future = storage.unPinFile(user, fileId);
try {
future.checkedGet(60, TimeUnit.SECONDS);
} catch (TimeoutException e) {
throw new SRMInternalErrorException("Operation timed out");
} catch (SRMException e) {
return new TReturnStatus(TStatusCode.SRM_FAILURE, "Failed to unpin: " + e.getMessage());
}
return new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
}
use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.
the class TStatusCodes method checkSuccess.
public static void checkSuccess(TReturnStatus returnStatus, TStatusCode... success) throws SRMException {
TStatusCode statusCode = returnStatus.getStatusCode();
String explanation = returnStatus.getExplanation();
if (asList(success).contains(statusCode)) {
return;
}
if (explanation == null) {
explanation = "Operation failed with " + returnStatus.getStatusCode();
}
if (statusCode == TStatusCode.SRM_FAILURE) {
throw new SRMException(explanation);
} else if (statusCode == TStatusCode.SRM_PARTIAL_SUCCESS) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_AUTHENTICATION_FAILURE) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_AUTHORIZATION_FAILURE) {
throw new SRMAuthorizationException(explanation);
} else if (statusCode == TStatusCode.SRM_INVALID_REQUEST) {
throw new SRMInvalidRequestException(explanation);
} else if (statusCode == TStatusCode.SRM_INVALID_PATH) {
throw new SRMInvalidPathException(explanation);
} else if (statusCode == TStatusCode.SRM_FILE_LIFETIME_EXPIRED) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_SPACE_LIFETIME_EXPIRED) {
throw new SRMSpaceLifetimeExpiredException(explanation);
} else if (statusCode == TStatusCode.SRM_EXCEED_ALLOCATION) {
throw new SRMExceedAllocationException(explanation);
} else if (statusCode == TStatusCode.SRM_NO_USER_SPACE) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_NO_FREE_SPACE) {
throw new SRMNoFreeSpaceException(explanation);
} else if (statusCode == TStatusCode.SRM_DUPLICATION_ERROR) {
throw new SRMDuplicationException(explanation);
} else if (statusCode == TStatusCode.SRM_NON_EMPTY_DIRECTORY) {
throw new SRMNonEmptyDirectoryException(explanation);
} else if (statusCode == TStatusCode.SRM_TOO_MANY_RESULTS) {
throw new SRMTooManyResultsException(explanation);
} else if (statusCode == TStatusCode.SRM_INTERNAL_ERROR) {
throw new SRMInternalErrorException(explanation);
} else if (statusCode == TStatusCode.SRM_FATAL_INTERNAL_ERROR) {
throw new SRMInternalErrorException(explanation);
} else if (statusCode == TStatusCode.SRM_NOT_SUPPORTED) {
throw new SRMNotSupportedException(explanation);
} else if (statusCode == TStatusCode.SRM_REQUEST_QUEUED) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_REQUEST_INPROGRESS) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_ABORTED) {
throw new SRMAbortedException(explanation);
} else if (statusCode == TStatusCode.SRM_RELEASED) {
throw new SRMReleasedException(explanation);
} else if (statusCode == TStatusCode.SRM_FILE_PINNED) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_FILE_IN_CACHE) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_SPACE_AVAILABLE) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_LOWER_SPACE_GRANTED) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_REQUEST_TIMED_OUT) {
throw new SRMRequestTimedOutException(explanation);
} else if (statusCode == TStatusCode.SRM_LAST_COPY) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_FILE_BUSY) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_FILE_LOST) {
throw new SRMOtherException(statusCode, explanation);
} else if (statusCode == TStatusCode.SRM_FILE_UNAVAILABLE) {
throw new SRMFileUnvailableException(explanation);
} else if (statusCode == TStatusCode.SRM_CUSTOM_STATUS) {
throw new SRMOtherException(statusCode, explanation);
} else {
throw new SRMOtherException(statusCode, explanation);
}
}
Aggregations