use of org.dcache.srm.SRMNotSupportedException in project dcache by dCache.
the class SrmService method messageArrived.
public SrmResponse messageArrived(SrmRequest request) throws SRMException {
try {
CertPath certPath = getFirst(request.getSubject().getPublicCredentials(CertPath.class), null);
LoginReply login = new LoginReply(request.getSubject(), request.getLoginAttributes());
SRMUser user = userManager.persist(certPath, login);
String requestName = request.getRequestName();
Class<?> requestClass = request.getRequest().getClass();
String capitalizedRequestName = Character.toUpperCase(requestName.charAt(0)) + requestName.substring(1);
LOGGER.debug("About to call {} handler", requestName);
Constructor<?> handlerConstructor;
Object handler;
Method handleGetResponseMethod;
try {
Class<?> handlerClass = Class.forName("org.dcache.srm.handler." + capitalizedRequestName);
handlerConstructor = handlerClass.getConstructor(SRMUser.class, requestClass, AbstractStorageElement.class, SRM.class, String.class);
handler = handlerConstructor.newInstance(user, request.getRequest(), storage, srm, request.getRemoteHost());
if (handler instanceof CredentialAwareHandler) {
CredentialAwareHandler credentialAware = (CredentialAwareHandler) handler;
RequestCredential requestCredential = saveRequestCredential(request.getSubject(), request.getCredential());
credentialAware.setCredential(requestCredential);
}
handleGetResponseMethod = handlerClass.getMethod("getResponse");
} catch (ClassNotFoundException e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.info("handler discovery and dynamic loading failed", e);
} else {
LOGGER.info("handler discovery and dynamic loading failed");
}
throw new SRMNotSupportedException(requestName + " is unsupported");
}
Object result = handleGetResponseMethod.invoke(handler);
return new SrmResponse(id, result);
} catch (CertificateEncodingException | KeyStoreException e) {
throw new SRMInternalErrorException("Failed to process certificate chain.", e);
} catch (InvocationTargetException | NoSuchMethodException | InstantiationException | IllegalAccessException | RuntimeException e) {
LOGGER.error("Please report this failure to support@dcache.org", e);
throw new SRMInternalErrorException("Internal error (server log contains additional information)");
}
}
use of org.dcache.srm.SRMNotSupportedException in project dcache by dCache.
the class SrmShell method cd.
@SuppressWarnings("fallthrough")
private void cd(String path) throws URI.MalformedURIException, RemoteException, SRMException, InterruptedException {
if (!path.endsWith("/")) {
path = path + "/";
}
URI uri = new URI(pwd, path);
checkValidPath(fs.stat(uri).getType() == TFileType.DIRECTORY, "Not a directory");
switch(checkCdPermission) {
case SRM_CHECK_PERMISSION:
try {
TPermissionMode permission = fs.checkPermission(uri);
if (permission != TPermissionMode.RWX && permission != TPermissionMode.RX && permission != TPermissionMode.WX && permission != TPermissionMode.X) {
throw new SRMAuthorizationException("Access denied");
}
break;
} catch (SRMNotSupportedException e) {
/* StoRM does not support checkPermission:
*
* https://ggus.eu/index.php?mode=ticket_info&ticket_id=124634
*/
notifications.add("The CheckPermission operation is not supported, using directory listing instead.");
checkCdPermission = PermissionOperation.SRM_LS;
// fall-through: use srmLs
}
case SRM_LS:
fs.list(uri, false);
}
pwd = uri;
}
use of org.dcache.srm.SRMNotSupportedException in project dcache by dCache.
the class Storage method srmGetSpaceMetaData.
/**
* @param spaceTokens
* @return
* @throws SRMException
*/
@Override
public TMetaDataSpace[] srmGetSpaceMetaData(SRMUser user, String[] spaceTokens) throws SRMException {
guardSpaceManagerEnabled();
GetSpaceMetaData getSpaces = new GetSpaceMetaData(spaceTokens);
try {
getSpaces = _spaceManagerStub.sendAndWait(getSpaces);
} catch (TimeoutCacheException e) {
throw new SRMInternalErrorException("Space manager timeout", e);
} catch (NoRouteToCellException e) {
throw new SRMNotSupportedException("Space manager is unavailable", e);
} catch (InterruptedException e) {
throw new SRMInternalErrorException("Operation interrupted", e);
} catch (CacheException e) {
_log.warn("GetSpaceMetaData failed with rc={} error={}", e.getRc(), e.getMessage());
throw new SRMException("Space manager failure: " + e.getMessage(), e);
}
Space[] spaces = getSpaces.getSpaces();
TMetaDataSpace[] spaceMetaDatas = new TMetaDataSpace[spaces.length];
for (int i = 0; i < spaceMetaDatas.length; ++i) {
Space space = spaces[i];
TMetaDataSpace metaDataSpace = new TMetaDataSpace();
TReturnStatus status;
if (space != null) {
Long expirationTime = space.getExpirationTime();
if (expirationTime == null) {
metaDataSpace.setLifetimeAssigned(-1);
metaDataSpace.setLifetimeLeft(-1);
} else {
long lifetimeleft = Math.max(0, MILLISECONDS.toSeconds(expirationTime - System.currentTimeMillis()));
metaDataSpace.setLifetimeAssigned((int) MILLISECONDS.toSeconds(expirationTime - space.getCreationTime()));
metaDataSpace.setLifetimeLeft((int) lifetimeleft);
}
RetentionPolicy retentionPolicy = space.getRetentionPolicy();
TRetentionPolicy policy = retentionPolicy.equals(RetentionPolicy.CUSTODIAL) ? TRetentionPolicy.CUSTODIAL : retentionPolicy.equals(RetentionPolicy.OUTPUT) ? TRetentionPolicy.OUTPUT : TRetentionPolicy.REPLICA;
AccessLatency accessLatency = space.getAccessLatency();
TAccessLatency latency = accessLatency.equals(AccessLatency.ONLINE) ? TAccessLatency.ONLINE : TAccessLatency.NEARLINE;
UnsignedLong totalSize = new UnsignedLong(space.getSizeInBytes());
UnsignedLong unusedSize = new UnsignedLong(space.getSizeInBytes() - space.getUsedSizeInBytes());
metaDataSpace.setRetentionPolicyInfo(new TRetentionPolicyInfo(policy, latency));
metaDataSpace.setTotalSize(totalSize);
metaDataSpace.setGuaranteedSize(totalSize);
metaDataSpace.setUnusedSize(unusedSize);
SpaceState spaceState = space.getState();
switch(spaceState) {
case RESERVED:
status = new TReturnStatus(TStatusCode.SRM_SUCCESS, null);
break;
case EXPIRED:
status = new TReturnStatus(TStatusCode.SRM_SPACE_LIFETIME_EXPIRED, "The lifetime on the space that is associated with the spaceToken has expired already");
break;
default:
status = new TReturnStatus(TStatusCode.SRM_FAILURE, "Space has been released");
break;
}
metaDataSpace.setOwner("VoGroup=" + space.getVoGroup() + " VoRole=" + space.getVoRole());
} else {
status = new TReturnStatus(TStatusCode.SRM_INVALID_REQUEST, "No such space");
}
metaDataSpace.setStatus(status);
metaDataSpace.setSpaceToken(spaceTokens[i]);
spaceMetaDatas[i] = metaDataSpace;
}
return spaceMetaDatas;
}
use of org.dcache.srm.SRMNotSupportedException 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.SRMNotSupportedException in project dcache by dCache.
the class SrmPrepareToGet method srmPrepareToGet.
private SrmPrepareToGetResponse srmPrepareToGet() throws IllegalStateTransition, InterruptedException, SRMInvalidRequestException, SRMNotSupportedException, SRMInternalErrorException {
String[] protocols = getTransferProtocols(request);
String clientHost = getClientHost(request).orElse(this.clientHost);
long lifetime = Lifetimes.calculateLifetime(request.getDesiredTotalRequestTime(), configuration.getGetLifetime());
String[] supportedProtocols = storage.supportedGetProtocols();
URI[] surls = getSurls(request);
if (protocols != null && protocols.length > 0) {
boolean isAnyProtocolSupported = any(asList(protocols), in(asList(supportedProtocols)));
if (!isAnyProtocolSupported) {
throw new SRMNotSupportedException("Protocol(s) not supported: " + Arrays.toString(protocols));
}
}
GetRequest r = new GetRequest(srm.getSrmId(), user, surls, protocols, lifetime, configuration.getGetMaxPollPeriod(), request.getUserRequestDescription(), clientHost, isStagingAllowed());
try (JDC ignored = r.applyJdc()) {
srm.acceptNewJob(r);
return r.getSrmPrepareToGetResponse(configuration.getGetSwitchToAsynchronousModeDelay());
}
}
Aggregations