Ensure workflow is only restarted on events that match the activation condition

Closes #44399

Signed-off-by: Stefan Guilhen <sguilhen@redhat.com>
This commit is contained in:
Stefan Guilhen
2025-11-21 23:26:38 -03:00
committed by Pedro Igor
parent 6653b72f88
commit cd350082f7
3 changed files with 91 additions and 3 deletions

View File

@@ -261,7 +261,7 @@ public class DefaultWorkflowProvider implements WorkflowProvider {
// workflow is active for the resource, check if the provider wants to reset or deactivate it based on the event
String executionId = scheduledStep.executionId();
String resourceId = scheduledStep.resourceId();
if (provider.reset(context)) {
if (provider.restart(context)) {
new DefaultWorkflowExecutionContext(session, workflow, event, scheduledStep).restart();
} else if (provider.deactivate(context)) {
log.debugf("Workflow '%s' cancelled for resource %s (execution id: %s)", workflow.getName(), resourceId, executionId);

View File

@@ -47,12 +47,12 @@ final class EventBasedWorkflow {
return false;
}
boolean reset(WorkflowExecutionContext executionContext) throws WorkflowInvalidStateException {
boolean restart(WorkflowExecutionContext executionContext) throws WorkflowInvalidStateException {
WorkflowEvent event = executionContext.getEvent();
if (event == null) {
return false;
}
return supports(event.getResourceType()) && isCancelIfRunning() && validateResourceConditions(executionContext);
return isCancelIfRunning() && activate(executionContext);
}
public boolean validateResourceConditions(WorkflowExecutionContext context) {