Skip to content

Commit

Permalink
Fix Null Pointer Exception and Improve Handling for Missing Config In…
Browse files Browse the repository at this point in the history
…dex (#1234)

This PR addresses two issues to enhance robustness in the IndexManagement class:

* Null Check for Candidate Result Aliases:
 * Added a null check for candidateResultAliases in updateCustomResultIndexMapping to prevent NullPointerExceptions.
* Graceful Handling for Missing Config Index:
  * Modified searchConfigs to return an empty list instead of throwing a ResourceNotFoundException when the config index does not exist.

Testing:
* Verified that NullPointerExceptions are prevented and the system gracefully handles cases where the config index does not exist.

Signed-off-by: Kaituo Li <[email protected]>
(cherry picked from commit 2843d1b)
Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
github-actions[bot] committed Jun 10, 2024
1 parent 71d47e4 commit 19f00e6
Showing 1 changed file with 3 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
import org.opensearch.threadpool.Scheduler;
import org.opensearch.threadpool.ThreadPool;
import org.opensearch.timeseries.common.exception.EndRunException;
import org.opensearch.timeseries.common.exception.ResourceNotFoundException;
import org.opensearch.timeseries.common.exception.TimeSeriesException;
import org.opensearch.timeseries.constant.CommonMessages;
import org.opensearch.timeseries.constant.CommonName;
Expand Down Expand Up @@ -747,7 +746,7 @@ private void updateMappingIfNecessary(GroupedActionListener<Void> delegateListen

private void updateCustomResultIndexMapping(IndexType customIndex, GroupedActionListener<Void> delegateListeneer) {
getConfigsWithCustomResultIndexAlias(ActionListener.wrap(candidateResultAliases -> {
if (candidateResultAliases.size() == 0) {
if (candidateResultAliases == null || candidateResultAliases.size() == 0) {
logger.info("candidate custom result indices are empty.");
markMappingUpdated(customIndex);
delegateListeneer.onResponse(null);
Expand Down Expand Up @@ -784,7 +783,7 @@ private void getConfigsWithCustomResultIndexAlias(ActionListener<List<Config>> l
}
}
if (configIndex == null || configIndex.getIndexName() == null) {
listener.onFailure(new ResourceNotFoundException("fail to find config index"));
listener.onResponse(new ArrayList<Config>());
return;
}
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery();
Expand All @@ -800,7 +799,7 @@ private void getConfigsWithCustomResultIndexAlias(ActionListener<List<Config>> l
client.search(searchRequest, ActionListener.wrap(r -> {
if (r == null || r.getHits().getTotalHits() == null || r.getHits().getTotalHits().value == 0) {
logger.info("no config available.");
listener.onResponse(null);
listener.onResponse(new ArrayList<Config>());
return;
}
Iterator<SearchHit> iterator = r.getHits().iterator();
Expand Down

0 comments on commit 19f00e6

Please sign in to comment.