Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Jackie Han <[email protected]>
  • Loading branch information
jackiehanyang committed Jun 10, 2024
1 parent 3a07ec8 commit f3111c5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/opensearch/ad/indices/RolloverTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ public void testNoCustomResultIndexFound_RolloverDefaultResultIndex_shouldSuccee

public void testCustomResultIndexFound_RolloverCustomResultIndex_withConditions_shouldSucceed() throws IOException {
setUpGetConfigs_withCustomResultIndexAlias();
setUpRolloverSuccessForCustomIndex();

adIndices.rolloverAndDeleteHistoryIndex();

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -396,8 +394,10 @@ private void setUpGetConfigs_withCustomResultIndexAlias() throws IOException {
doAnswer(invocation -> {
Object[] args = invocation.getArguments();
ActionListener<SearchResponse> listener = (ActionListener<SearchResponse>) args[1];
setUpRolloverSuccessForCustomIndex();
listener.onResponse(createSearchResponse(parsedDetector));
return null;
}).when(client).search(any(), any());

}
}

0 comments on commit f3111c5

Please sign in to comment.