forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support dynamically adding SearchRequestOperationsListener (opensearc…
…h-project#11526) Along the way, also refactored TransportSearchAction.TimeProvider, so that it's no longer a (redundant) listener. --------- Signed-off-by: Chenyang Ji <[email protected]> Signed-off-by: Shivansh Arora <[email protected]>
- Loading branch information
Showing
28 changed files
with
577 additions
and
246 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
...in/java/org/opensearch/action/search/SearchRequestOperationsCompositeListenerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
*/ | ||
|
||
package org.opensearch.action.search; | ||
|
||
import org.apache.logging.log4j.Logger; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
/** | ||
* SearchRequestOperationsCompositeListenerFactory contains listeners registered to search requests, | ||
* and is responsible for creating the {@link SearchRequestOperationsListener.CompositeListener} | ||
* with the all listeners enabled at cluster-level and request-level. | ||
* | ||
* | ||
* @opensearch.internal | ||
*/ | ||
public final class SearchRequestOperationsCompositeListenerFactory { | ||
private final List<SearchRequestOperationsListener> searchRequestListenersList; | ||
|
||
/** | ||
* Create the SearchRequestOperationsCompositeListenerFactory and add multiple {@link SearchRequestOperationsListener} | ||
* to the searchRequestListenersList. | ||
* Those enabled listeners will be executed during each search request. | ||
* | ||
* @param listeners Multiple SearchRequestOperationsListener object to add. | ||
* @throws IllegalArgumentException if any input listener is null. | ||
*/ | ||
public SearchRequestOperationsCompositeListenerFactory(final SearchRequestOperationsListener... listeners) { | ||
searchRequestListenersList = new ArrayList<>(); | ||
for (SearchRequestOperationsListener listener : listeners) { | ||
if (listener == null) { | ||
throw new IllegalArgumentException("listener must not be null"); | ||
} | ||
searchRequestListenersList.add(listener); | ||
} | ||
} | ||
|
||
/** | ||
* Get searchRequestListenersList, | ||
* | ||
* @return List of SearchRequestOperationsListener | ||
*/ | ||
public List<SearchRequestOperationsListener> getListeners() { | ||
return searchRequestListenersList; | ||
} | ||
|
||
/** | ||
* Create the {@link SearchRequestOperationsListener.CompositeListener} | ||
* with the all listeners enabled at cluster-level and request-level. | ||
* | ||
* @param searchRequest The SearchRequest object used to decide which request-level listeners to add based on states/flags | ||
* @param logger Logger to be attached to the {@link SearchRequestOperationsListener.CompositeListener} | ||
* @param perRequestListeners the per-request listeners that can be optionally added to the returned CompositeListener list. | ||
* @return SearchRequestOperationsListener.CompositeListener | ||
*/ | ||
public SearchRequestOperationsListener.CompositeListener buildCompositeListener( | ||
final SearchRequest searchRequest, | ||
final Logger logger, | ||
final SearchRequestOperationsListener... perRequestListeners | ||
) { | ||
final List<SearchRequestOperationsListener> searchListenersList = Stream.concat( | ||
searchRequestListenersList.stream(), | ||
Arrays.stream(perRequestListeners) | ||
) | ||
.filter((searchRequestOperationsListener -> searchRequestOperationsListener.isEnabled(searchRequest))) | ||
.collect(Collectors.toList()); | ||
|
||
return new SearchRequestOperationsListener.CompositeListener(searchListenersList, logger); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.