Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(notifications/cdEvents): Fixed CDEvents notification for ManualJu… #1451

Merged
merged 3 commits into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public abstract class AbstractEventNotificationAgent implements EventListener {
.put(STAGE, ImmutableMap.of("type", STAGE, "link", "stage"))
.build();

private static final Map<String, String> MANUAL_JUDGMENT_CONDITIONS =
ImmutableMap.<String, String>builder()
.put(ManualJudgmentCondition.MANUAL_JUDGMENT.getName(), StageStatus.STARTING.getName())
.put(ManualJudgmentCondition.CONTINUE.getName(), StageStatus.COMPLETE.getName())
.put(ManualJudgmentCondition.STOP.getName(), StageStatus.FAILED.getName())
.build();

private final Logger log = LoggerFactory.getLogger(getClass());

protected ObjectMapper mapper = EchoObjectMapper.getInstance();
Expand Down Expand Up @@ -182,9 +189,11 @@ private boolean shouldSendRequestForNotification(
if (when != null) {
String requiredWhen = format("%s.%s", configType, status);
if (when instanceof String) {
return ((String) when).contains(requiredWhen);
return isManualJudgmentMatchStringCase((String) when, status)
|| ((String) when).contains(requiredWhen);
} else if (when instanceof Collection) {
return ((Collection<String>) when).contains(requiredWhen);
return isManualJudgmentMatchCollectionCase((Collection<String>) when, status)
|| ((Collection<String>) when).contains(requiredWhen);
}
}
}
Expand All @@ -199,6 +208,52 @@ private boolean contentKeyAsBoolean(Event event, String key) {
return Boolean.parseBoolean(value.toString());
}

enum StageStatus {
COMPLETE("complete"),
STARTING("starting"),
FAILED("failed");

final String name;

StageStatus(String name) {
this.name = name;
}

String getName() {
return this.name;
}
}

enum ManualJudgmentCondition {
CONTINUE("manualJudgmentContinue"),
STOP("manualJudgmentStop"),
MANUAL_JUDGMENT("manualJudgment");

final String name;

ManualJudgmentCondition(String name) {
this.name = name;
}

String getName() {
return this.name;
}
}

private static boolean isManualJudgmentMatchStringCase(String when, String status) {
return status.equals(MANUAL_JUDGMENT_CONDITIONS.get(when));
}

private static boolean isManualJudgmentMatchCollectionCase(
Collection<String> when, String status) {
for (String condition : when) {
if (status.equals(MANUAL_JUDGMENT_CONDITIONS.get(condition))) {
return true;
}
}
return false;
}

private static boolean isExecution(String type) {
return "pipeline".equals(type) || "orchestration".equals(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,24 @@ class AbstractEventNotificationAgentSpec extends Specification {
fakeStageEvent("orca:stage:complete", "stage.complete", false, true) || 0
}

@Unroll
def "sends notifications for ManualJudgment stage based on status and configuration"() {
given:
subclassMock.sendNotifications(*_) >> { notification, application, event_local, config, status -> }

when:
agent.processEvent(event)

then:
expectedNotifications * subclassMock.sendNotifications(*_)

where:
event || expectedNotifications
fakeStageEvent("orca:stage:complete", "manualJudgmentContinue") || 1
fakeStageEvent("orca:stage:starting", "manualJudgment") || 1
fakeStageEvent("orca:stage:failed", "manualJudgmentStop") || 1
}

private def fakePipelineEvent(String type, String status, String notifyWhen, Map extraExecutionProps = [:]) {
def eventProps = [
details: [type: type],
Expand Down