use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.
the class SrmHandler method handleRequest.
public Object handleRequest(String requestName, Object request) throws RemoteException {
long startTimeStamp = System.currentTimeMillis();
// requestName values all start "srm". This is redundant, so may
// be removed when creating the session id. The initial character is
// converted to lowercase, so "srmPrepareToPut" becomes "prepareToPut".
String session = "srm2:" + Character.toLowerCase(requestName.charAt(3)) + requestName.substring(4);
try (JDC ignored = JDC.createSession(session)) {
for (RequestLogger logger : loggers) {
logger.request(requestName, request);
}
Subject user = Subject.getSubject(AccessController.getContext());
Object response;
if (requestName.equals("srmPing")) {
// Ping is special as it isn't authenticated and unable to return a failure
response = new SrmPingResponse("v2.2", pingExtraInfo);
} else {
try {
response = dispatch(user, requestName, request);
} catch (SRMInternalErrorException e) {
LOGGER.error(e.getMessage());
response = getFailedResponse(requestName, e.getStatusCode(), "Authentication failed (server log contains additional information).");
} catch (SRMAuthorizationException e) {
LOGGER.info(e.getMessage());
response = getFailedResponse(requestName, e.getStatusCode(), "Permission denied.");
} catch (SRMAuthenticationException e) {
LOGGER.warn(e.getMessage());
response = getFailedResponse(requestName, e.getStatusCode(), "Authentication failed (server log contains additional information).");
} catch (SRMException e) {
response = getFailedResponse(requestName, e.getStatusCode(), e.getMessage());
} catch (PermissionDeniedCacheException e) {
response = getFailedResponse(requestName, TStatusCode.SRM_AUTHORIZATION_FAILURE, e.getMessage());
} catch (CacheException e) {
response = getFailedResponse(requestName, TStatusCode.SRM_INTERNAL_ERROR, e.getMessage());
} catch (InterruptedException e) {
response = getFailedResponse(requestName, TStatusCode.SRM_FATAL_INTERNAL_ERROR, "Server shutdown.");
} catch (NoRouteToCellException e) {
LOGGER.error(e.getMessage());
response = getFailedResponse(requestName, TStatusCode.SRM_INTERNAL_ERROR, "SRM backend serving this request is currently offline.");
}
}
long time = System.currentTimeMillis() - startTimeStamp;
for (RequestLogger logger : loggers) {
logger.response(requestName, request, response, user, time);
}
return response;
}
}
use of org.dcache.srm.SRMInternalErrorException 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.SRMInternalErrorException in project dcache by dCache.
the class PinCompanion method fail.
private void fail(int rc, String error) {
switch(rc) {
case FILE_NOT_FOUND:
setException(new SRMInvalidPathException("No such file."));
break;
case FILE_NOT_IN_REPOSITORY:
_log.warn("Pinning failed for {} ({})", _path, error);
setException(new SRMFileUnvailableException(error));
break;
case PERMISSION_DENIED:
_log.warn("Pinning failed for {} ({})", _path, error);
setException(new SRMAuthorizationException(error));
break;
case TIMEOUT:
_log.info("Pinning failed: {}", error);
setException(new SRMInternalErrorException("Pin operation timed out"));
break;
default:
_log.error("Pinning failed for {} [rc={},msg={}].", _path, rc, error);
String reason = String.format("Failed to pin file [rc=%d,msg=%s].", rc, error);
setException(new SRMException(reason));
break;
}
_state = new FailedState();
}
use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.
the class Storage method putDone.
@Override
public void putDone(SRMUser user, String localTransferPath, URI surl, boolean overwrite) throws SRMException {
try {
Subject subject = asDcacheUser(user).getSubject();
Restriction restriction = asDcacheUser(user).getRestriction();
FsPath fullPath = getPath(surl);
checkNonBrokenUpload(localTransferPath);
EnumSet<CreateOption> options = EnumSet.noneOf(CreateOption.class);
if (overwrite) {
options.add(CreateOption.OVERWRITE_EXISTING);
}
PnfsCommitUpload msg = new PnfsCommitUpload(subject, restriction, FsPath.create(localTransferPath), fullPath, options, EnumSet.of(PNFSID, SIZE, STORAGEINFO));
msg = _pnfsStub.sendAndWait(msg);
DoorRequestInfoMessage infoMsg = new DoorRequestInfoMessage(getCellAddress());
infoMsg.setSubject(subject);
infoMsg.setBillingPath(fullPath.toString());
infoMsg.setTransferPath(localTransferPath);
infoMsg.setTransaction(CDC.getSession());
infoMsg.setPnfsId(msg.getFileAttributes().getPnfsId());
infoMsg.setResult(0, "");
infoMsg.setFileSize(msg.getFileAttributes().getSizeIfPresent().orElse(0L));
infoMsg.setStorageInfo(msg.getFileAttributes().getStorageInfo());
Origin origin = Subjects.getOrigin(subject);
if (origin != null) {
infoMsg.setClient(origin.getAddress().getHostAddress());
}
_billingStub.notify(infoMsg);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException(e.getMessage(), e);
} catch (FileIsNewCacheException | FileCorruptedCacheException e) {
throw new SRMException(e.getMessage(), e);
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied.", e);
} catch (FileExistsCacheException e) {
throw new SRMDuplicationException(surl + " exists.", e);
} catch (CacheException e) {
throw new SRMInternalErrorException(e.getMessage(), e);
} catch (InterruptedException e) {
throw new SRMInternalErrorException("Operation interrupted", e);
} catch (NoRouteToCellException e) {
throw new SRMInternalErrorException("Internal communication failure", e);
}
}
use of org.dcache.srm.SRMInternalErrorException in project dcache by dCache.
the class Storage method moveEntry.
@Override
public void moveEntry(SRMUser abstractUser, URI from, URI to) throws SRMException {
DcacheUser user = asDcacheUser(abstractUser);
PnfsHandler handler = new PnfsHandler(_pnfs, user.getSubject(), user.getRestriction());
FsPath fromPath = getPath(from);
FsPath toPath = getPath(to);
try {
try {
FileAttributes attr = handler.getFileAttributes(toPath.toString(), EnumSet.of(TYPE));
/* We now know the destination exists. In case the
* source and destination names are identical, we
* silently ignore the request.
*/
if (fromPath.equals(toPath)) {
return;
}
if (attr.getFileType() != FileType.DIR) {
throw new SRMDuplicationException("Destination exists");
}
toPath = toPath.child(fromPath.name());
} catch (FileNotFoundCacheException e) {
/* Destination name does not exist; not a problem.
*/
}
handler.renameEntry(fromPath.toString(), toPath.toString(), false);
} catch (FileNotFoundCacheException e) {
throw new SRMInvalidPathException("No such file or directory", e);
} catch (FileExistsCacheException e) {
throw new SRMDuplicationException("Destination exists", e);
} catch (NotDirCacheException e) {
/* The parent of the target name did not exist or was not
* a directory.
*/
FsPath parent = toPath.parent();
throw new SRMInvalidPathException("No such directory: " + parent, e);
} catch (PermissionDeniedCacheException e) {
throw new SRMAuthorizationException("Permission denied");
} catch (TimeoutCacheException e) {
_log.error("Failed to rename {} due to timeout", fromPath);
throw new SRMInternalErrorException("Internal name space timeout");
} catch (CacheException e) {
_log.error("Failed to rename {}: {}", fromPath, e.getMessage());
throw new SRMException(String.format("Rename failed [rc=%d,msg=%s]", e.getRc(), e.getMessage()));
}
}
Aggregations