public void findContext()

in src/main/java/org/opensearch/search/asynchronous/service/AsynchronousSearchService.java [234:264]


    public void findContext(String id, AsynchronousSearchContextId asynchronousSearchContextId, User user,
                            ActionListener<AsynchronousSearchContext> listener) {

        ActionListener<AsynchronousSearchContext> exceptionTranslationListener = getExceptionTranslationWrapper(id, listener);
        Optional<AsynchronousSearchActiveContext> optionalAsynchronousSearchActiveContext = asynchronousSearchActiveStore
                .getContext(asynchronousSearchContextId);
        // If context is CLOSED we can't acquire permits and hence can't update active context
        // so most likely a CLOSED context is stale
        if (optionalAsynchronousSearchActiveContext.isPresent() && optionalAsynchronousSearchActiveContext.get().isAlive()) {
            logger.debug("Active context is present for asynchronous search ID [{}]", id);
            AsynchronousSearchActiveContext asynchronousSearchActiveContext = optionalAsynchronousSearchActiveContext.get();
            if (isUserValid(user, asynchronousSearchActiveContext.getUser()) == false) {
                logger.debug("Invalid user requesting GET active context for asynchronous search id {}", id);
                exceptionTranslationListener.onFailure(new OpenSearchSecurityException(
                        "User doesn't have necessary roles to access the asynchronous search with id " + id, RestStatus.FORBIDDEN));
            } else {
                exceptionTranslationListener.onResponse(asynchronousSearchActiveContext);
            }
        } else {
            logger.debug("Active context is not present for asynchronous search ID [{}]", id);
            persistenceService.getResponse(id, user, wrap(
                    (persistenceModel) ->
                            exceptionTranslationListener.onResponse(new AsynchronousSearchPersistenceContext(id,
                                    asynchronousSearchContextId, persistenceModel, currentTimeSupplier, namedWriteableRegistry)),
                    ex -> {
                        logger.debug(() -> new ParameterizedMessage("Context not found for ID  in the system index {}", id), ex);
                        exceptionTranslationListener.onFailure(ex);
                    }
            ));
        }
    }