diff --git a/src/main/java/org/opensearch/timeseries/indices/IndexManagement.java b/src/main/java/org/opensearch/timeseries/indices/IndexManagement.java index c6357cf24..1c3f30c77 100644 --- a/src/main/java/org/opensearch/timeseries/indices/IndexManagement.java +++ b/src/main/java/org/opensearch/timeseries/indices/IndexManagement.java @@ -1240,29 +1240,22 @@ protected void rolloverAndDeleteHistoryIndex( String rolloverIndexPattern, IndexType resultIndex ) { - // rollover and delete default result index + // perform rollover and delete on default result index if (doesDefaultResultIndexExist()) { RolloverRequest defaultResultIndexRolloverRequest = buildRolloverRequest(resultIndexAlias, rolloverIndexPattern); defaultResultIndexRolloverRequest.addMaxIndexDocsCondition(historyMaxDocs * getNumberOfPrimaryShards()); - proceedWithDefaultRolloverAndDelete( - resultIndexAlias, - defaultResultIndexRolloverRequest, - allResultIndicesPattern, - resultIndex - ); + proceedWithDefaultRolloverAndDelete(resultIndexAlias, defaultResultIndexRolloverRequest, allResultIndicesPattern, resultIndex); } - - // rollover and delete custom result index + // get config files that have custom result index alias to perform rollover on getConfigsWithCustomResultIndexAlias(ActionListener.wrap(candidateResultAliases -> { if (candidateResultAliases == null || candidateResultAliases.isEmpty()) { logger.info("Candidate custom result indices are empty."); return; } + // perform rollover and delete on found custom result index alias candidateResultAliases.forEach(config -> handleCustomResultIndex(config, resultIndex)); - }, e -> { - logger.error("Failed to get configs with custom result index alias.", e); - })); + }, e -> { logger.error("Failed to get configs with custom result index alias.", e); })); } private void handleCustomResultIndex(Config config, IndexType resultIndex) { diff --git a/src/test/java/org/opensearch/ad/indices/RolloverTests.java b/src/test/java/org/opensearch/ad/indices/RolloverTests.java index 561170c74..2d847d266 100644 --- a/src/test/java/org/opensearch/ad/indices/RolloverTests.java +++ b/src/test/java/org/opensearch/ad/indices/RolloverTests.java @@ -283,7 +283,6 @@ public void testNoCustomResultIndexFound_RolloverDefaultResultIndex_shouldSuccee public void testCustomResultIndexFound_RolloverCustomResultIndex_withConditions_shouldSucceed() throws IOException { setUpGetConfigs_withCustomResultIndexAlias(); - setUpRolloverSuccessForCustomIndex(); adIndices.rolloverAndDeleteHistoryIndex(); @@ -361,7 +360,6 @@ private void setUpGetConfigs_withCustomResultIndexAlias() throws IOException { IndexMetadata defaultResultIndex = IndexMetadata .builder(".opendistro-anomaly-detectors") .settings(settings(Version.CURRENT)) - .putAlias(AliasMetadata.builder(ADCommonName.ANOMALY_RESULT_INDEX_ALIAS).writeIndex(true).build()) .numberOfShards(1) .numberOfReplicas(0) .build(); @@ -396,8 +394,10 @@ private void setUpGetConfigs_withCustomResultIndexAlias() throws IOException { doAnswer(invocation -> { Object[] args = invocation.getArguments(); ActionListener listener = (ActionListener) args[1]; + setUpRolloverSuccessForCustomIndex(); listener.onResponse(createSearchResponse(parsedDetector)); return null; }).when(client).search(any(), any()); + } }