use of org.dcache.srm.SRMInvalidRequestException in project dcache by dCache.
the class LsFileRequest method getMetaDataPathDetail.
protected TMetaDataPathDetail getMetaDataPathDetail() throws SRMInvalidRequestException {
rlock();
try {
if (metaDataPathDetail != null) {
return metaDataPathDetail;
}
if (getState() == State.DONE) {
/* If the request has been processed yet metaDataPathDetail
* is null then the information is no longer known. This
* can happen if the information has been delivered to the
* client, this Request has been garbage collected, and the
* request was fetched back from the database to process a
* StatusOfLsRequest request.
*/
throw new SRMInvalidRequestException("Response no longer available.");
}
TMetaDataPathDetail detail = new TMetaDataPathDetail();
detail.setPath(getPath(surl));
detail.setStatus(getReturnStatus());
return detail;
} finally {
runlock();
}
}
use of org.dcache.srm.SRMInvalidRequestException in project dcache by dCache.
the class RequestCredential method acceptAlternative.
/**
* Allow a user to specify an alternative credential to use.
*/
public synchronized void acceptAlternative(String description) throws SRMInvalidRequestException {
if (description == null) {
return;
}
if (!description.startsWith("gridsite:")) {
throw new SRMInvalidRequestException("Unknown credential type: " + description);
}
String idLabel = description.substring(9);
try {
long id = Long.parseLong(idLabel);
RequestCredential credential = storage.getRequestCredential(id);
if (credential == null || !credential.credentialName.equals(this.credentialName)) {
// discovering which other credentials exist.
throw new IllegalArgumentException("Unknown credential: " + credentialName);
}
if (credential.getDelegatedCredentialRemainingLifetime() == 0) {
throw new IllegalArgumentException("Credential " + description + " has expired");
}
updateCredential(credential.delegatedCredential);
} catch (NumberFormatException e) {
throw new SRMInvalidRequestException("Badly formatted credential id: " + idLabel);
}
}
use of org.dcache.srm.SRMInvalidRequestException in project dcache by dCache.
the class Storage method prepareToPut.
@Override
public CheckedFuture<String, ? extends SRMException> prepareToPut(final SRMUser srmUser, URI surl, Long size, String accessLatency, String retentionPolicy, String spaceToken, boolean overwrite) {
try {
DcacheUser user = asDcacheUser(srmUser);
Subject subject = user.getSubject();
Restriction restriction = user.getRestriction();
FsPath fullPath = getPath(surl);
if (spaceToken != null) {
if (!_isSpaceManagerEnabled) {
return immediateFailedCheckedFuture(new SRMNotSupportedException(SPACEMANAGER_DISABLED_MESSAGE));
}
/* This check could and maybe should be done on the SRM side of AbstractStorageElement:
* The targetSpaceToken is the same for all SURLs in an srmPrepareToPut request, and the
* SRM_EXCEED_ALLOCATION should also be returned if the entire srmPrepareToPut request
* is larger than available space in the reservation - that's a check we cannot possibly
* to on an individual SURL.
*/
try {
Optional<Space> optionalSpace = spaces.get(spaceToken);
if (!optionalSpace.isPresent()) {
return immediateFailedCheckedFuture(new SRMInvalidRequestException("The space token " + spaceToken + " does not refer to an existing known space reservation."));
}
Space space = optionalSpace.get();
if (space.getExpirationTime() != null && space.getExpirationTime() < System.currentTimeMillis()) {
return immediateFailedCheckedFuture(new SRMSpaceLifetimeExpiredException("Space reservation associated with the space token " + spaceToken + " is expired."));
}
if (size != null && space.getAvailableSpaceInBytes() < size) {
return immediateFailedCheckedFuture(new SRMExceedAllocationException("Space associated with the space token " + spaceToken + " is not enough to hold SURL."));
}
} catch (ExecutionException e) {
return immediateFailedCheckedFuture(new SRMException("Failure while querying space reservation: " + e.getCause().getMessage()));
}
}
AccessLatency al = (accessLatency != null) ? AccessLatency.valueOf(accessLatency) : null;
RetentionPolicy rp = (retentionPolicy != null) ? RetentionPolicy.valueOf(retentionPolicy) : null;
EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
if (overwrite) {
options.add(CreateOption.OVERWRITE_EXISTING);
}
if (config.isRecursiveDirectoryCreation()) {
options.add(CreateOption.CREATE_PARENTS);
}
PnfsCreateUploadPath msg = new PnfsCreateUploadPath(subject, restriction, fullPath, user.getRoot(), size, al, rp, spaceToken, options);
final SettableFuture<String> future = SettableFuture.create();
CellStub.addCallback(_pnfsStub.send(msg), new AbstractMessageCallback<PnfsCreateUploadPath>() {
int failures = 0;
@Override
public void success(PnfsCreateUploadPath message) {
future.set(message.getUploadPath().toString());
}
@Override
public void failure(int rc, Object error) {
failures++;
String msg = Objects.toString(error, "");
switch(rc) {
case CacheException.PERMISSION_DENIED:
future.setException(new SRMAuthorizationException(msg));
break;
case CacheException.FILE_EXISTS:
future.setException(new SRMDuplicationException(msg));
break;
case CacheException.FILE_NOT_FOUND:
case CacheException.NOT_DIR:
future.setException(new SRMInvalidPathException(msg));
break;
case CacheException.LOCKED:
if (failures < 3) {
/* Usually due to concurrent uploads to the same non-existing target
* directory. Retry a few times.
*/
PnfsCreateUploadPath retry = new PnfsCreateUploadPath(subject, restriction, fullPath, user.getRoot(), size, al, rp, spaceToken, options);
CellStub.addCallback(_pnfsStub.send(retry), this, _executor);
} else {
future.setException(new SRMInternalErrorException(msg));
}
break;
case CacheException.TIMEOUT:
default:
future.setException(new SRMInternalErrorException(msg));
break;
}
}
}, _executor);
return Futures.makeChecked(future, new ToSRMException());
} catch (SRMAuthorizationException | SRMInvalidPathException e) {
return immediateFailedCheckedFuture(e);
}
}
use of org.dcache.srm.SRMInvalidRequestException in project dcache by dCache.
the class SrmPrepareToGet method isStagingAllowed.
private boolean isStagingAllowed() throws SRMInvalidRequestException {
boolean allowed = true;
ArrayOfTExtraInfo info = request.getStorageSystemInfo();
if (info != null) {
TExtraInfo[] array = info.getExtraInfoArray();
if (array != null) {
List<String> stageValues = Arrays.stream(array).filter(i -> Objects.equals(i.getKey(), "stage")).map(i -> i.getValue()).collect(Collectors.toList());
if (!stageValues.isEmpty()) {
if (stageValues.size() > 1) {
throw new SRMInvalidRequestException("Multiple storageSystemInfo 'stage' entries.");
}
String stageValue = stageValues.get(0);
if (stageValue == null) {
throw new SRMInvalidRequestException("Missing value for storageSystemInfo 'stage' entry.");
}
switch(stageValue) {
case "allow":
allowed = true;
break;
case "deny":
allowed = false;
break;
default:
throw new SRMInvalidRequestException("Invalid value \"" + stageValue + "\" for storageSystemInfo 'stage' entry, must be \"allow\" or \"deny\"");
}
}
}
}
return allowed;
}
use of org.dcache.srm.SRMInvalidRequestException in project dcache by dCache.
the class SrmPrepareToPut method getProtocols.
private String[] getProtocols() throws SRMInvalidRequestException {
String[] protocols = null;
TTransferParameters transferParameters = request.getTransferParameters();
if (transferParameters != null && transferParameters.getArrayOfTransferProtocols() != null) {
protocols = transferParameters.getArrayOfTransferProtocols().getStringArray();
}
protocols = Tools.trimStringArray(protocols);
if (protocols == null || protocols.length < 1) {
throw new SRMInvalidRequestException("request contains no transfer protocols.");
}
return protocols;
}
Aggregations