Skip to content

Commit 510679e

Browse files
Removing Saga from Dapr Workflows (#1216)
1 parent bd3a54d commit 510679e

24 files changed

+29
-1582
lines changed

sdk-tests/src/test/java/io/dapr/it/spring/data/DaprKeyValueRepositoryIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@
2929
import org.testcontainers.junit.jupiter.Container;
3030
import org.testcontainers.junit.jupiter.Testcontainers;
3131

32-
import java.util.Collections;
3332
import java.util.HashMap;
3433
import java.util.List;
3534
import java.util.Map;
3635

3736
import static io.dapr.it.spring.data.DaprSpringDataConstants.BINDING_NAME;
3837
import static io.dapr.it.spring.data.DaprSpringDataConstants.STATE_STORE_NAME;
38+
import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
3939
import static org.junit.jupiter.api.Assertions.*;
4040

4141
/**
@@ -65,7 +65,7 @@ public class DaprKeyValueRepositoryIT {
6565

6666
@Container
6767
@ServiceConnection
68-
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
68+
private static final DaprContainer DAPR_CONTAINER = new DaprContainer(IMAGE_TAG)
6969
.withAppName("postgresql-repository-dapr-app")
7070
.withNetwork(DAPR_NETWORK)
7171
.withComponent(new Component(STATE_STORE_NAME, "state.postgresql", "v1", STATE_STORE_PROPERTIES))

sdk-tests/src/test/java/io/dapr/it/spring/data/MySQLDaprKeyValueTemplateIT.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
2727
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
2828
import org.springframework.test.context.ContextConfiguration;
29-
import org.springframework.test.context.DynamicPropertyRegistry;
30-
import org.springframework.test.context.DynamicPropertySource;
3129
import org.springframework.test.context.junit.jupiter.SpringExtension;
3230
import org.testcontainers.containers.MySQLContainer;
3331
import org.testcontainers.containers.Network;
@@ -39,14 +37,14 @@
3937
import java.time.Duration;
4038
import java.time.temporal.ChronoUnit;
4139
import java.util.ArrayList;
42-
import java.util.Collections;
4340
import java.util.HashMap;
4441
import java.util.List;
4542
import java.util.Map;
4643
import java.util.Optional;
4744

4845
import static io.dapr.it.spring.data.DaprSpringDataConstants.STATE_STORE_NAME;
4946
import static io.dapr.it.spring.data.DaprSpringDataConstants.BINDING_NAME;
47+
import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
5048
import static org.assertj.core.api.Assertions.assertThat;
5149
import static org.junit.jupiter.api.Assertions.assertEquals;
5250

@@ -82,7 +80,7 @@ public class MySQLDaprKeyValueTemplateIT {
8280

8381
@Container
8482
@ServiceConnection
85-
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
83+
private static final DaprContainer DAPR_CONTAINER = new DaprContainer(IMAGE_TAG)
8684
.withAppName("mysql-dapr-app")
8785
.withNetwork(DAPR_NETWORK)
8886
.withComponent(new Component(STATE_STORE_NAME, "state.mysql", "v1", STATE_STORE_PROPERTIES))

sdk-tests/src/test/java/io/dapr/it/spring/data/PostgreSQLDaprKeyValueTemplateIT.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
2727
import org.springframework.data.keyvalue.core.query.KeyValueQuery;
2828
import org.springframework.test.context.ContextConfiguration;
29-
import org.springframework.test.context.DynamicPropertyRegistry;
30-
import org.springframework.test.context.DynamicPropertySource;
3129
import org.springframework.test.context.junit.jupiter.SpringExtension;
3230
import org.testcontainers.containers.Network;
3331
import org.testcontainers.containers.PostgreSQLContainer;
@@ -38,6 +36,7 @@
3836

3937
import static io.dapr.it.spring.data.DaprSpringDataConstants.BINDING_NAME;
4038
import static io.dapr.it.spring.data.DaprSpringDataConstants.STATE_STORE_NAME;
39+
import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
4140
import static org.assertj.core.api.Assertions.assertThat;
4241
import static org.junit.jupiter.api.Assertions.assertEquals;
4342

@@ -68,7 +67,7 @@ public class PostgreSQLDaprKeyValueTemplateIT {
6867

6968
@Container
7069
@ServiceConnection
71-
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
70+
private static final DaprContainer DAPR_CONTAINER = new DaprContainer(IMAGE_TAG)
7271
.withAppName("postgresql-dapr-app")
7372
.withNetwork(DAPR_NETWORK)
7473
.withComponent(new Component(STATE_STORE_NAME, "state.postgresql", "v1", STATE_STORE_PROPERTIES))

sdk-tests/src/test/java/io/dapr/it/spring/messaging/DaprSpringMessagingIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.Collections;
3838
import java.util.List;
3939

40+
import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
4041
import static org.assertj.core.api.Assertions.assertThat;
4142

4243
@SpringBootTest(
@@ -60,7 +61,7 @@ public class DaprSpringMessagingIT {
6061

6162
@Container
6263
@ServiceConnection
63-
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
64+
private static final DaprContainer DAPR_CONTAINER = new DaprContainer(IMAGE_TAG)
6465
.withAppName("messaging-dapr-app")
6566
.withNetwork(DAPR_NETWORK)
6667
.withComponent(new Component("pubsub", "pubsub.in-memory", "v1", Collections.emptyMap()))
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package io.dapr.it.testcontainers;
2+
3+
public interface DaprContainerConstants {
4+
String IMAGE_TAG = "daprio/daprd:1.14.1";
5+
}

sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprContainerIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo;
4545
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
4646
import static com.github.tomakehurst.wiremock.client.WireMock.verify;
47+
import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
4748
import static org.junit.jupiter.api.Assertions.assertEquals;
4849
import static org.junit.jupiter.api.Assertions.assertNotNull;
4950
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -61,7 +62,7 @@ public class DaprContainerIT {
6162
private static final String PUBSUB_TOPIC_NAME = "topic";
6263

6364
@Container
64-
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd")
65+
private static final DaprContainer DAPR_CONTAINER = new DaprContainer(IMAGE_TAG)
6566
.withAppName("dapr-app")
6667
.withAppPort(8081)
6768
.withAppChannelAddress("host.testcontainers.internal");

sdk-tests/src/test/java/io/dapr/it/testcontainers/DaprWorkflowsIT.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import java.util.Collections;
4040
import java.util.Map;
4141

42+
import static io.dapr.it.testcontainers.DaprContainerConstants.IMAGE_TAG;
4243
import static org.junit.jupiter.api.Assertions.assertEquals;
4344
import static org.junit.jupiter.api.Assertions.assertNotNull;
4445

@@ -56,7 +57,7 @@ public class DaprWorkflowsIT {
5657
private static final Network DAPR_NETWORK = Network.newNetwork();
5758

5859
@Container
59-
private static final DaprContainer DAPR_CONTAINER = new DaprContainer("daprio/daprd:1.13.2")
60+
private static final DaprContainer DAPR_CONTAINER = new DaprContainer(IMAGE_TAG)
6061
.withAppName("workflow-dapr-app")
6162
.withNetwork(DAPR_NETWORK)
6263
.withComponent(new Component("kvstore", "state.in-memory", "v1",

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
}

0 commit comments

Comments
 (0)