Skip to content

Commit 914cc88

Browse files
author
Artur Ciocanu
committed
Removing Saga from Dapr Workflows
Signed-off-by: Artur Ciocanu <[email protected]>
1 parent 22d9874 commit 914cc88

17 files changed

+12
-1570
lines changed

sdk-workflows/src/main/java/io/dapr/workflows/Workflow.java

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@
1313

1414
package io.dapr.workflows;
1515

16-
import com.microsoft.durabletask.interruption.ContinueAsNewInterruption;
17-
import com.microsoft.durabletask.interruption.OrchestratorBlockedException;
18-
import io.dapr.workflows.saga.SagaCompensationException;
19-
import io.dapr.workflows.saga.SagaOptions;
20-
2116
/**
2217
* Common interface for workflow implementations.
2318
*/
@@ -39,43 +34,6 @@ public interface Workflow {
3934
default void run(WorkflowContext ctx) {
4035
WorkflowStub stub = this.create();
4136

42-
if (!this.isSagaEnabled()) {
43-
// saga disabled
44-
stub.run(ctx);
45-
} else {
46-
// saga enabled
47-
try {
48-
stub.run(ctx);
49-
} catch (OrchestratorBlockedException | ContinueAsNewInterruption e) {
50-
throw e;
51-
} catch (SagaCompensationException e) {
52-
// Saga compensation is triggered gracefully but failed in exception
53-
// don't need to trigger compensation again
54-
throw e;
55-
} catch (Exception e) {
56-
try {
57-
ctx.getSagaContext().compensate();
58-
} catch (Exception se) {
59-
se.addSuppressed(e);
60-
throw se;
61-
}
62-
63-
throw e;
64-
}
65-
}
66-
}
67-
68-
default boolean isSagaEnabled() {
69-
return this.getSagaOption() != null;
70-
}
71-
72-
/**
73-
* get saga configuration.
74-
*
75-
* @return saga configuration
76-
*/
77-
default SagaOptions getSagaOption() {
78-
// by default, saga is disabled
79-
return null;
37+
stub.run(ctx);
8038
}
8139
}

sdk-workflows/src/main/java/io/dapr/workflows/WorkflowContext.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import com.microsoft.durabletask.Task;
1818
import com.microsoft.durabletask.TaskCanceledException;
1919
import com.microsoft.durabletask.TaskFailedException;
20-
import io.dapr.workflows.saga.SagaContext;
2120
import org.slf4j.Logger;
2221

2322
import javax.annotation.Nullable;
@@ -530,12 +529,4 @@ default void continueAsNew(Object input) {
530529
default UUID newUuid() {
531530
throw new RuntimeException("No implementation found.");
532531
}
533-
534-
/**
535-
* get saga context.
536-
*
537-
* @return saga context
538-
* @throws UnsupportedOperationException if saga is not enabled.
539-
*/
540-
SagaContext getSagaContext();
541532
}

sdk-workflows/src/main/java/io/dapr/workflows/runtime/DefaultWorkflowContext.java

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
import io.dapr.workflows.WorkflowContext;
2323
import io.dapr.workflows.WorkflowTaskOptions;
2424
import io.dapr.workflows.WorkflowTaskRetryPolicy;
25-
import io.dapr.workflows.runtime.saga.DefaultSagaContext;
26-
import io.dapr.workflows.saga.Saga;
27-
import io.dapr.workflows.saga.SagaContext;
2825
import org.slf4j.Logger;
2926
import org.slf4j.LoggerFactory;
3027
import org.slf4j.helpers.NOPLogger;
@@ -39,7 +36,6 @@
3936
public class DefaultWorkflowContext implements WorkflowContext {
4037
private final TaskOrchestrationContext innerContext;
4138
private final Logger logger;
42-
private final Saga saga;
4339

4440
/**
4541
* Constructor for DaprWorkflowContextImpl.
@@ -58,23 +54,7 @@ public DefaultWorkflowContext(TaskOrchestrationContext context) throws IllegalAr
5854
* @param logger Logger
5955
* @throws IllegalArgumentException if context or logger is null
6056
*/
61-
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger) throws IllegalArgumentException {
62-
this(context, logger, null);
63-
}
64-
65-
public DefaultWorkflowContext(TaskOrchestrationContext context, Saga saga) throws IllegalArgumentException {
66-
this(context, LoggerFactory.getLogger(WorkflowContext.class), saga);
67-
}
68-
69-
/**
70-
* Constructor for DaprWorkflowContextImpl.
71-
*
72-
* @param context TaskOrchestrationContext
73-
* @param logger Logger
74-
* @param saga saga object, if null, saga is disabled
75-
* @throws IllegalArgumentException if context or logger is null
76-
*/
77-
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger, Saga saga)
57+
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger)
7858
throws IllegalArgumentException {
7959
if (context == null) {
8060
throw new IllegalArgumentException("Context cannot be null");
@@ -85,7 +65,6 @@ public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger, S
8565

8666
this.innerContext = context;
8767
this.logger = logger;
88-
this.saga = saga;
8968
}
9069

9170
/**
@@ -249,15 +228,6 @@ public UUID newUuid() {
249228
return this.innerContext.newUUID();
250229
}
251230

252-
@Override
253-
public SagaContext getSagaContext() {
254-
if (this.saga == null) {
255-
throw new UnsupportedOperationException("Saga is not enabled");
256-
}
257-
258-
return new DefaultSagaContext(this.saga, this);
259-
}
260-
261231
private static TaskOptions toTaskOptions(WorkflowTaskOptions options) {
262232
if (options == null) {
263233
return null;

sdk-workflows/src/main/java/io/dapr/workflows/runtime/WorkflowClassWrapper.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.microsoft.durabletask.TaskOrchestration;
1717
import com.microsoft.durabletask.TaskOrchestrationFactory;
1818
import io.dapr.workflows.Workflow;
19-
import io.dapr.workflows.saga.Saga;
2019

2120
import java.lang.reflect.Constructor;
2221
import java.lang.reflect.InvocationTargetException;
@@ -30,6 +29,7 @@ class WorkflowClassWrapper<T extends Workflow> implements TaskOrchestrationFacto
3029

3130
public WorkflowClassWrapper(Class<T> clazz) {
3231
this.name = clazz.getCanonicalName();
32+
3333
try {
3434
this.workflowConstructor = clazz.getDeclaredConstructor();
3535
} catch (NoSuchMethodException e) {
@@ -48,6 +48,7 @@ public String getName() {
4848
public TaskOrchestration create() {
4949
return ctx -> {
5050
T workflow;
51+
5152
try {
5253
workflow = this.workflowConstructor.newInstance();
5354
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
@@ -56,13 +57,7 @@ public TaskOrchestration create() {
5657
);
5758
}
5859

59-
if (workflow.getSagaOption() != null) {
60-
Saga saga = new Saga(workflow.getSagaOption());
61-
workflow.run(new DefaultWorkflowContext(ctx, saga));
62-
} else {
63-
workflow.run(new DefaultWorkflowContext(ctx));
64-
}
60+
workflow.run(new DefaultWorkflowContext(ctx));
6561
};
66-
6762
}
6863
}

sdk-workflows/src/main/java/io/dapr/workflows/runtime/WorkflowInstanceWrapper.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import com.microsoft.durabletask.TaskOrchestration;
1717
import com.microsoft.durabletask.TaskOrchestrationFactory;
1818
import io.dapr.workflows.Workflow;
19-
import io.dapr.workflows.saga.Saga;
2019

2120
/**
2221
* Wrapper for Durable Task Framework orchestration factory.
@@ -37,13 +36,6 @@ public String getName() {
3736

3837
@Override
3938
public TaskOrchestration create() {
40-
return ctx -> {
41-
if (workflow.getSagaOption() != null) {
42-
Saga saga = new Saga(workflow.getSagaOption());
43-
workflow.run(new DefaultWorkflowContext(ctx, saga));
44-
} else {
45-
workflow.run(new DefaultWorkflowContext(ctx));
46-
}
47-
};
39+
return ctx -> workflow.run(new DefaultWorkflowContext(ctx));
4840
}
4941
}

sdk-workflows/src/main/java/io/dapr/workflows/runtime/saga/DefaultSagaContext.java

Lines changed: 0 additions & 56 deletions
This file was deleted.

sdk-workflows/src/main/java/io/dapr/workflows/saga/CompensationInformation.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

0 commit comments

Comments
 (0)