-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow detectors to be stopped if underlying workflow is deleted. Don'…
…t allow them to then be started/editted (#810) (#958) * Allow detectors to be stopped if underlying workflow is deleted. Don't allow them to then be started * Add copyright headers --------- Signed-off-by: Chase Engelbrecht <[email protected]>
- Loading branch information
Showing
8 changed files
with
286 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/org/opensearch/securityanalytics/util/ExceptionChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.util; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Stream; | ||
|
||
public class ExceptionChecker { | ||
|
||
public boolean doesGroupedActionListenerExceptionMatch(final Exception ex, final List<ThrowableCheckingPredicates> exceptionMatchers) { | ||
// grouped action listener listens on multiple listeners but throws only one exception. If multiple | ||
// listeners fail the other exceptions are added as suppressed exceptions to the first failure. | ||
return Stream.concat(Arrays.stream(ex.getSuppressed()), Stream.of(ex)) | ||
.allMatch(throwable -> doesExceptionMatch(throwable, exceptionMatchers)); | ||
} | ||
|
||
private boolean doesExceptionMatch(final Throwable throwable, final List<ThrowableCheckingPredicates> exceptionMatchers) { | ||
return exceptionMatchers.stream() | ||
.map(ThrowableCheckingPredicates::getMatcherPredicate) | ||
.anyMatch(matcher -> matcher.test(throwable)); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/opensearch/securityanalytics/util/ThrowableCheckingPredicates.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
package org.opensearch.securityanalytics.util; | ||
|
||
import java.util.function.Predicate; | ||
|
||
public enum ThrowableCheckingPredicates { | ||
MONITOR_NOT_FOUND(ThrowableCheckingPredicates::isMonitorNotFoundException), | ||
WORKFLOW_NOT_FOUND(ThrowableCheckingPredicates::isWorkflowNotFoundException), | ||
ALERTING_CONFIG_INDEX_NOT_FOUND(ThrowableCheckingPredicates::isAlertingConfigIndexNotFoundException); | ||
|
||
private final Predicate<Throwable> matcherPredicate; | ||
ThrowableCheckingPredicates(final Predicate<Throwable> matcherPredicate) { | ||
this.matcherPredicate = matcherPredicate; | ||
} | ||
|
||
public Predicate<Throwable> getMatcherPredicate() { | ||
return this.matcherPredicate; | ||
} | ||
|
||
private static boolean isMonitorNotFoundException(final Throwable e) { | ||
return e.getMessage().matches("(.*)Monitor(.*) is not found(.*)"); | ||
} | ||
|
||
public static boolean isWorkflowNotFoundException(final Throwable e) { | ||
return e.getMessage().matches("(.*)Workflow(.*) not found(.*)"); | ||
} | ||
|
||
public static boolean isAlertingConfigIndexNotFoundException(final Throwable e) { | ||
return e.getMessage().contains("Configured indices are not found: [.opendistro-alerting-config]"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.