From b7f19be4dc3d5a05fc3594de889958289520faa9 Mon Sep 17 00:00:00 2001 From: Petar Dzepina Date: Tue, 1 Nov 2022 01:33:14 +0100 Subject: [PATCH] minor fixes Signed-off-by: Petar Dzepina --- .../DetectorIndexManagementService.java | 43 ++++++++++++------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/src/main/java/org/opensearch/securityanalytics/indexmanagment/DetectorIndexManagementService.java b/src/main/java/org/opensearch/securityanalytics/indexmanagment/DetectorIndexManagementService.java index 1e08e20ea..ad6bbd240 100644 --- a/src/main/java/org/opensearch/securityanalytics/indexmanagment/DetectorIndexManagementService.java +++ b/src/main/java/org/opensearch/securityanalytics/indexmanagment/DetectorIndexManagementService.java @@ -80,7 +80,8 @@ public class DetectorIndexManagementService extends AbstractLifecycleComponent i private volatile boolean isClusterManager = false; - private Scheduler.Cancellable scheduledRollover = null; + private Scheduler.Cancellable scheduledAlertsRollover = null; + private Scheduler.Cancellable scheduledFindingsRollover = null; List alertHistoryIndices = new ArrayList<>(); List findingHistoryIndices = new ArrayList<>(); @@ -201,16 +202,15 @@ public void clusterChanged(ClusterChangedEvent event) { } } - private void onMaster() { try { // try to rollover immediately as we might be restarting the cluster rolloverAlertHistoryIndices(); rolloverFindingHistoryIndices(); // schedule the next rollover for approx MAX_AGE later - scheduledRollover = threadPool + scheduledAlertsRollover = threadPool .scheduleWithFixedDelay(() -> rolloverAndDeleteAlertHistoryIndices(), alertHistoryRolloverPeriod, executorName()); - scheduledRollover = threadPool + scheduledFindingsRollover = threadPool .scheduleWithFixedDelay(() -> rolloverAndDeleteFindingHistoryIndices(), findingHistoryRolloverPeriod, executorName()); } catch (Exception e) { // This should be run on cluster startup @@ -223,8 +223,11 @@ private void onMaster() { } private void offMaster() { - if (scheduledRollover != null) { - scheduledRollover.cancel(); + if (scheduledAlertsRollover != null) { + scheduledAlertsRollover.cancel(); + } + if (scheduledFindingsRollover != null) { + scheduledFindingsRollover.cancel(); } } @@ -423,26 +426,24 @@ private void rolloverFindingHistoryIndices() { private void rescheduleAlertRollover() { if (clusterService.state().getNodes().isLocalNodeElectedMaster()) { - if (scheduledRollover != null) { - scheduledRollover.cancel(); + if (scheduledAlertsRollover != null) { + scheduledAlertsRollover.cancel(); } - scheduledRollover = threadPool + scheduledAlertsRollover = threadPool .scheduleWithFixedDelay(() -> rolloverAndDeleteAlertHistoryIndices(), alertHistoryRolloverPeriod, executorName()); } } private void rescheduleFindingRollover() { if (clusterService.state().getNodes().isLocalNodeElectedMaster()) { - if (scheduledRollover != null) { - scheduledRollover.cancel(); + if (scheduledFindingsRollover != null) { + scheduledFindingsRollover.cancel(); } - scheduledRollover = threadPool + scheduledFindingsRollover = threadPool .scheduleWithFixedDelay(() -> rolloverAndDeleteFindingHistoryIndices(), findingHistoryRolloverPeriod, executorName()); } } - - private String alertMapping() { String alertMapping = null; try ( @@ -520,12 +521,22 @@ protected void doStart() { @Override protected void doStop() { - scheduledRollover.cancel(); + if (scheduledAlertsRollover != null) { + scheduledAlertsRollover.cancel(); + } + if (scheduledFindingsRollover != null) { + scheduledFindingsRollover.cancel(); + } } @Override protected void doClose() { - scheduledRollover.cancel(); + if (scheduledAlertsRollover != null) { + scheduledAlertsRollover.cancel(); + } + if (scheduledFindingsRollover != null) { + scheduledFindingsRollover.cancel(); + } } private static class HistoryIndexInfo {