use of org.dcache.srm.SrmResponse 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.SrmResponse in project dcache by dCache.
the class SrmHandler method mapGetRequestTokensResponse.
private SrmGetRequestTokensResponse mapGetRequestTokensResponse(List<SrmResponse> responses) {
List<TRequestTokenReturn> tokens = new ArrayList<>();
for (SrmResponse srmResponse : responses) {
SrmGetRequestTokensResponse response = (SrmGetRequestTokensResponse) srmResponse.getResponse();
if (response.getReturnStatus().getStatusCode() != SRM_SUCCESS) {
return response;
}
for (TRequestTokenReturn token : response.getArrayOfRequestTokens().getTokenArray()) {
tokens.add(new TRequestTokenReturn(prefix(srmResponse.getId(), token.getRequestToken()), token.getCreatedAtTime()));
}
}
ArrayOfTRequestTokenReturn arrayOfRequestTokens = new ArrayOfTRequestTokenReturn(tokens.toArray(TRequestTokenReturn[]::new));
return new SrmGetRequestTokensResponse(new TReturnStatus(SRM_SUCCESS, "Request processed successfully."), arrayOfRequestTokens);
}
use of org.dcache.srm.SrmResponse in project dcache by dCache.
the class SrmHandler method mapReleaseFilesResponse.
private SrmReleaseFilesResponse mapReleaseFilesResponse(SrmReleaseFilesRequest request, List<SrmResponse> responses) {
Map<URI, TSURLReturnStatus> map = new HashMap<>();
for (SrmResponse srmResponse : responses) {
SrmReleaseFilesResponse response = (SrmReleaseFilesResponse) srmResponse.getResponse();
for (TSURLReturnStatus status : response.getArrayOfFileStatuses().getStatusArray()) {
if (status.getStatus().getStatusCode() == SRM_SUCCESS) {
map.put(status.getSurl(), status);
} else if (status.getStatus().getStatusCode() == SRM_INVALID_PATH) {
// no entry
} else if (status.getStatus().getStatusCode() == SRM_AUTHORIZATION_FAILURE) {
map.putIfAbsent(status.getSurl(), status);
} else if (status.getStatus().getStatusCode() == SRM_FILE_LIFETIME_EXPIRED) {
map.putIfAbsent(status.getSurl(), status);
} else if (status.getStatus().getStatusCode() == SRM_FAILURE) {
map.putIfAbsent(status.getSurl(), status);
}
}
}
TSURLReturnStatus[] statuses = Stream.of(request.getArrayOfSURLs().getUrlArray()).map(surl -> {
TSURLReturnStatus status = map.get(surl);
return (status != null) ? status : new TSURLReturnStatus(surl, new TReturnStatus(SRM_INVALID_PATH, "File not found"));
}).toArray(TSURLReturnStatus[]::new);
return new SrmReleaseFilesResponse(getSummaryReturnStatus(statuses), new ArrayOfTSURLReturnStatus(statuses));
}
use of org.dcache.srm.SrmResponse in project dcache by dCache.
the class SrmHandler method provideRequestSummaryForTokenWithBackend.
/**
* Returns a map of summaries from backends for a list of tokens.
*/
private Map<String, ? extends ListenableFuture<TRequestSummary>> provideRequestSummaryForTokenWithBackend(Function<Object, SrmRequest> toMessage, String authorizationId, Collection<String> tokens, CellPath backend) {
SrmRequest msg = toMessage.apply(createRequestSummaryRequest(authorizationId, tokens));
ListenableFuture<SrmResponse> futureResponse = srmManagerStub.send(backend, msg, SrmResponse.class);
return transformToMap(tokens, futureResponse, r -> toRequestSummaries(tokens, r), this::translateBackendError);
}
Aggregations