Search in sources :

Example 1 with AsynchronousSearchStateMachineClosedException

use of org.opensearch.search.asynchronous.context.state.AsynchronousSearchStateMachineClosedException in project asynchronous-search by opensearch-project.

the class AsynchronousSearchPostProcessor method processSearchFailure.

public AsynchronousSearchResponse processSearchFailure(Exception exception, AsynchronousSearchContextId asynchronousSearchContextId) {
    final Optional<AsynchronousSearchActiveContext> asynchronousSearchContextOptional = asynchronousSearchActiveStore.getContext(asynchronousSearchContextId);
    try {
        if (asynchronousSearchContextOptional.isPresent()) {
            AsynchronousSearchActiveContext asynchronousSearchContext = asynchronousSearchContextOptional.get();
            asynchronousSearchStateMachine.trigger(new SearchFailureEvent(asynchronousSearchContext, exception));
            handlePersist(asynchronousSearchContext);
            return asynchronousSearchContext.getAsynchronousSearchResponse();
        }
        // Best effort to return the response.
        return new AsynchronousSearchResponse(AsynchronousSearchState.FAILED, -1L, -1L, null, ExceptionsHelper.convertToOpenSearchException(exception));
    } catch (AsynchronousSearchStateMachineClosedException ex) {
        // Best effort to return the response.
        return new AsynchronousSearchResponse(AsynchronousSearchState.FAILED, -1L, -1L, null, ExceptionsHelper.convertToOpenSearchException(exception));
    }
}
Also used : AsynchronousSearchResponse(org.opensearch.search.asynchronous.response.AsynchronousSearchResponse) SearchFailureEvent(org.opensearch.search.asynchronous.context.state.event.SearchFailureEvent) AsynchronousSearchActiveContext(org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveContext) AsynchronousSearchStateMachineClosedException(org.opensearch.search.asynchronous.context.state.AsynchronousSearchStateMachineClosedException)

Example 2 with AsynchronousSearchStateMachineClosedException

use of org.opensearch.search.asynchronous.context.state.AsynchronousSearchStateMachineClosedException in project asynchronous-search by opensearch-project.

the class AsynchronousSearchPostProcessor method processSearchResponse.

public AsynchronousSearchResponse processSearchResponse(SearchResponse searchResponse, AsynchronousSearchContextId asynchronousSearchContextId) {
    final Optional<AsynchronousSearchActiveContext> asynchronousSearchContextOptional = asynchronousSearchActiveStore.getContext(asynchronousSearchContextId);
    try {
        if (asynchronousSearchContextOptional.isPresent()) {
            AsynchronousSearchActiveContext asynchronousSearchContext = asynchronousSearchContextOptional.get();
            asynchronousSearchStateMachine.trigger(new SearchSuccessfulEvent(asynchronousSearchContext, searchResponse));
            handlePersist(asynchronousSearchContext);
            return asynchronousSearchContext.getAsynchronousSearchResponse();
        }
        // Best effort to return the response.
        return new AsynchronousSearchResponse(AsynchronousSearchState.SUCCEEDED, -1L, -1L, searchResponse, null);
    } catch (AsynchronousSearchStateMachineClosedException ex) {
        // Best effort to return the response.
        return new AsynchronousSearchResponse(AsynchronousSearchState.SUCCEEDED, -1L, -1L, searchResponse, null);
    }
}
Also used : AsynchronousSearchResponse(org.opensearch.search.asynchronous.response.AsynchronousSearchResponse) SearchSuccessfulEvent(org.opensearch.search.asynchronous.context.state.event.SearchSuccessfulEvent) AsynchronousSearchActiveContext(org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveContext) AsynchronousSearchStateMachineClosedException(org.opensearch.search.asynchronous.context.state.AsynchronousSearchStateMachineClosedException)

Aggregations

AsynchronousSearchActiveContext (org.opensearch.search.asynchronous.context.active.AsynchronousSearchActiveContext)2 AsynchronousSearchStateMachineClosedException (org.opensearch.search.asynchronous.context.state.AsynchronousSearchStateMachineClosedException)2 AsynchronousSearchResponse (org.opensearch.search.asynchronous.response.AsynchronousSearchResponse)2 SearchFailureEvent (org.opensearch.search.asynchronous.context.state.event.SearchFailureEvent)1 SearchSuccessfulEvent (org.opensearch.search.asynchronous.context.state.event.SearchSuccessfulEvent)1