This repository has been archived by the owner on Dec 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for task resiliency on persistence features, and tests to ver…
…ify the same using AOP based failure injection. Added the configuration to control WorkflowRepairService from the sweeper service.
- Loading branch information
1 parent
289ca1c
commit 114a91d
Showing
21 changed files
with
551 additions
and
57 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
common/src/main/java/com/netflix/conductor/common/constraints/FaultInjectionInterceptor.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,14 @@ | ||
package com.netflix.conductor.common.constraints; | ||
|
||
|
||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
|
||
/** | ||
* Interceptor intended for failure injection during unit / integration testing. | ||
*/ | ||
@Retention(RetentionPolicy.RUNTIME) @Target(ElementType.METHOD) | ||
public @interface FaultInjectionInterceptor { | ||
} |
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
112 changes: 112 additions & 0 deletions
112
core/src/main/java/com/netflix/conductor/core/execution/WorkflowRepairService.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,112 @@ | ||
package com.netflix.conductor.core.execution; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.netflix.conductor.common.metadata.tasks.Task; | ||
import com.netflix.conductor.common.run.Workflow; | ||
import com.netflix.conductor.core.config.Configuration; | ||
import com.netflix.conductor.core.execution.tasks.WorkflowSystemTask; | ||
import com.netflix.conductor.dao.ExecutionDAO; | ||
import com.netflix.conductor.dao.QueueDAO; | ||
import com.netflix.conductor.metrics.Monitors; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Inject; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.function.Predicate; | ||
|
||
/** | ||
* A helper service that tries to keep ExecutionDAO and QueueDAO in sync, based on the | ||
* task or workflow state. | ||
* | ||
* This service expects that the underlying Queueing layer implements QueueDAO.containsMessage method. This can be controlled | ||
* with Configuration.isWorkflowRepairServiceEnabled() property. | ||
*/ | ||
public class WorkflowRepairService { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(WorkflowRepairService.class); | ||
|
||
private final ExecutionDAO executionDAO; | ||
private final QueueDAO queueDAO; | ||
private final Configuration configuration; | ||
|
||
private final Predicate<Task> isSystemTask = task -> WorkflowSystemTask.is(task.getTaskType()); | ||
|
||
@Inject | ||
public WorkflowRepairService( | ||
ExecutionDAO executionDAO, | ||
QueueDAO queueDAO, | ||
Configuration configuration | ||
) { | ||
this.executionDAO = executionDAO; | ||
this.queueDAO = queueDAO; | ||
this.configuration = configuration; | ||
} | ||
|
||
/** | ||
* Verify and repair if the workflowId exists in deciderQueue, and then if each scheduled task has relevant message | ||
* in the queue. | ||
* @param workflowId | ||
* @param includeTasks | ||
* @return | ||
*/ | ||
public boolean verifyAndRepairWorkflow(String workflowId, boolean includeTasks) { | ||
Workflow workflow = executionDAO.getWorkflow(workflowId, includeTasks); | ||
AtomicBoolean repaired = new AtomicBoolean(false); | ||
repaired.set(verifyAndRepairDeciderQueue(workflow)); | ||
if (includeTasks) { | ||
workflow.getTasks().forEach(task -> { | ||
repaired.set(verifyAndRepairTask(task)); | ||
}); | ||
} | ||
return repaired.get(); | ||
} | ||
|
||
/** | ||
* Verify and repair tasks in a workflow | ||
* @param workflowId | ||
*/ | ||
public void verifyAndRepairWorkflowTasks(String workflowId) { | ||
Workflow workflow = executionDAO.getWorkflow(workflowId, true); | ||
workflow.getTasks().forEach(task -> verifyAndRepairTask(task)); | ||
} | ||
|
||
/** | ||
* Verify and fix if Workflow decider queue contains this workflowId. | ||
* @param workflow | ||
* @return | ||
*/ | ||
private boolean verifyAndRepairDeciderQueue(Workflow workflow) { | ||
if (!workflow.getStatus().isTerminal()) { | ||
String queueName = WorkflowExecutor.DECIDER_QUEUE; | ||
if (!queueDAO.containsMessage(queueName, workflow.getWorkflowId())) { | ||
queueDAO.push(queueName, workflow.getWorkflowId(), configuration.getSweepFrequency()); | ||
Monitors.recordQueueMessageRepushFromRepairService(queueName); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Verify if ExecutionDAO and QueueDAO agree for the provided task. | ||
* @param task | ||
* @return | ||
*/ | ||
@VisibleForTesting | ||
protected boolean verifyAndRepairTask(Task task) { | ||
WorkflowSystemTask workflowSystemTask = WorkflowSystemTask.get(task.getTaskType()); | ||
if (task.getStatus().equals(Task.Status.SCHEDULED)) { | ||
if (isSystemTask.test(task) && !workflowSystemTask.isAsync()) { | ||
return false; | ||
} | ||
// Ensure QueueDAO contains this taskId | ||
if (!queueDAO.containsMessage(task.getTaskDefName(), task.getTaskId())) { | ||
queueDAO.push(task.getTaskDefName(), task.getTaskId(), task.getCallbackAfterSeconds()); | ||
Monitors.recordQueueMessageRepushFromRepairService(task.getTaskDefName()); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
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
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.