in src/main/java/org/opensearch/search/asynchronous/service/AsynchronousSearchPersistenceService.java [116:150]
public void getResponse(String id, User user, ActionListener<AsynchronousSearchPersistenceModel> listener) {
if (indexExists() == false) {
listener.onFailure(new ResourceNotFoundException(id));
return;
}
GetRequest request = new GetRequest(ASYNC_SEARCH_RESPONSE_INDEX, id);
client.get(request, ActionListener.wrap(getResponse ->
{
if (getResponse.isExists()) {
Map<String, Object> source = getResponse.getSource();
AsynchronousSearchPersistenceModel asynchronousSearchPersistenceModel = new AsynchronousSearchPersistenceModel(
(long) source.get(START_TIME_MILLIS),
(long) source.get(EXPIRATION_TIME_MILLIS),
source.containsKey(RESPONSE) ? (String) source.get(RESPONSE) : null,
source.containsKey(ERROR) ? (String) source.get(ERROR) : null,
parseUser((Map<String, Object>) source.get(USER)));
if (isUserValid(user, asynchronousSearchPersistenceModel.getUser())) {
listener.onResponse(asynchronousSearchPersistenceModel);
} else {
logger.debug("Invalid user requesting GET persisted context for asynchronous search [{}]", id);
listener.onFailure(new OpenSearchSecurityException(
"User doesn't have necessary roles to access the asynchronous search [" + id + "]",
RestStatus.FORBIDDEN));
}
} else {
listener.onFailure(new ResourceNotFoundException(id));
}
},
exception -> {
logger.error(() -> new ParameterizedMessage("Failed to get response for asynchronous search [{}]", id),
exception);
final Throwable cause = ExceptionsHelper.unwrapCause(exception);
listener.onFailure(cause instanceof Exception ? (Exception) cause : new NotSerializableExceptionWrapper(cause));
}));
}