Skip to content

Commit

Permalink
minor fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Petar Dzepina <petar.dzepina@gmail.com>
  • Loading branch information
petardz committed Nov 1, 2022
1 parent 7e5139c commit b7f19be
Showing 1 changed file with 27 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<HistoryIndexInfo> alertHistoryIndices = new ArrayList<>();
List<HistoryIndexInfo> findingHistoryIndices = new ArrayList<>();
Expand Down Expand Up @@ -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
Expand All @@ -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();
}
}

Expand Down Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b7f19be

Please sign in to comment.