Skip to content

Commit 380cda6

Browse files
artur-ciocanuArtur Ciocanu
and
Artur Ciocanu
authored
Ensure Dapr workflows classes and interfaces have proper packages and visibility (dapr#1176)
* Rename orchestrator and activity wrapper Signed-off-by: Artur Ciocanu <[email protected]> * Move workflow activity to root package Signed-off-by: Artur Ciocanu <[email protected]> * Move workflow context implementation to runtime Signed-off-by: Artur Ciocanu <[email protected]> * Rename workflow activity context and add an interface Signed-off-by: Artur Ciocanu <[email protected]> * Convert workflow abstract class to interface Signed-off-by: Artur Ciocanu <[email protected]> * Move saga internals to runtime.saga package Signed-off-by: Artur Ciocanu <[email protected]> * Tiny typo fix Signed-off-by: Artur Ciocanu <[email protected]> * Adjusting the class names based on feedback Signed-off-by: Artur Ciocanu <[email protected]> * Revert accidental JavaDocs commits Signed-off-by: Artur Ciocanu <[email protected]> * Fixing some compilation errors Signed-off-by: Artur Ciocanu <[email protected]> --------- Signed-off-by: Artur Ciocanu <[email protected]> Co-authored-by: Artur Ciocanu <[email protected]>
1 parent 69f2407 commit 380cda6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+154
-138
lines changed

dapr-spring/dapr-spring-boot-autoconfigure/src/test/java/io/dapr/spring/boot/autoconfigure/client/workflows/TestActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package io.dapr.spring.boot.autoconfigure.client.workflows;
22

3-
import io.dapr.workflows.runtime.WorkflowActivity;
4-
import io.dapr.workflows.runtime.WorkflowActivityContext;
3+
import io.dapr.workflows.WorkflowActivity;
4+
import io.dapr.workflows.WorkflowActivityContext;
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.web.client.RestTemplate;
77

dapr-spring/dapr-spring-boot-autoconfigure/src/test/java/io/dapr/spring/boot/autoconfigure/client/workflows/TestWorkflow.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.springframework.beans.factory.annotation.Autowired;
66
import org.springframework.web.client.RestTemplate;
77

8-
public class TestWorkflow extends Workflow {
8+
public class TestWorkflow implements Workflow {
99

1010
@Autowired
1111
private RestTemplate restTemplate;

dapr-spring/dapr-spring-workflows/src/main/java/io/dapr/spring/workflows/config/DaprWorkflowsConfiguration.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
package io.dapr.spring.workflows.config;
22

33
import io.dapr.workflows.Workflow;
4-
import io.dapr.workflows.runtime.WorkflowActivity;
4+
import io.dapr.workflows.WorkflowActivity;
55
import io.dapr.workflows.runtime.WorkflowRuntime;
66
import io.dapr.workflows.runtime.WorkflowRuntimeBuilder;
77
import org.slf4j.Logger;
88
import org.slf4j.LoggerFactory;
99
import org.springframework.beans.BeansException;
10-
import org.springframework.beans.factory.annotation.Autowired;
1110
import org.springframework.context.ApplicationContext;
1211
import org.springframework.context.ApplicationContextAware;
1312
import org.springframework.context.annotation.Configuration;

examples/src/main/java/io/dapr/examples/unittesting/DaprWorkflowExampleTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public class DaprWorkflowExampleTest {
4242
private static final String noTimeoutWorkflow = "DemoWorkflowNoTimeout";
4343
private static final String workflowDefaultId = "demo-workflow-123";
4444

45-
private class DemoWorkflow extends Workflow {
45+
private class DemoWorkflow implements Workflow {
4646

4747
@Override
4848
public WorkflowStub create() {

examples/src/main/java/io/dapr/examples/workflows/chain/DemoChainWorkflow.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.dapr.workflows.Workflow;
1717
import io.dapr.workflows.WorkflowStub;
1818

19-
public class DemoChainWorkflow extends Workflow {
19+
public class DemoChainWorkflow implements Workflow {
2020
@Override
2121
public WorkflowStub create() {
2222
return ctx -> {

examples/src/main/java/io/dapr/examples/workflows/chain/ToUpperCaseActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
package io.dapr.examples.workflows.chain;
1515

16-
import io.dapr.workflows.runtime.WorkflowActivity;
17-
import io.dapr.workflows.runtime.WorkflowActivityContext;
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflow.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.dapr.workflows.Workflow;
1717
import io.dapr.workflows.WorkflowStub;
1818

19-
public class DemoChildWorkflow extends Workflow {
19+
public class DemoChildWorkflow implements Workflow {
2020
@Override
2121
public WorkflowStub create() {
2222
return ctx -> {

examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoWorkflow.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.dapr.workflows.Workflow;
1717
import io.dapr.workflows.WorkflowStub;
1818

19-
public class DemoWorkflow extends Workflow {
19+
public class DemoWorkflow implements Workflow {
2020
@Override
2121
public WorkflowStub create() {
2222
return ctx -> {

examples/src/main/java/io/dapr/examples/workflows/childworkflow/ReverseActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
package io.dapr.examples.workflows.childworkflow;
1515

16-
import io.dapr.workflows.runtime.WorkflowActivity;
17-
import io.dapr.workflows.runtime.WorkflowActivityContext;
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

examples/src/main/java/io/dapr/examples/workflows/continueasnew/CleanUpActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
package io.dapr.examples.workflows.continueasnew;
1515

16-
import io.dapr.workflows.runtime.WorkflowActivity;
17-
import io.dapr.workflows.runtime.WorkflowActivityContext;
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

examples/src/main/java/io/dapr/examples/workflows/continueasnew/DemoContinueAsNewWorkflow.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import java.time.Duration;
2020

21-
public class DemoContinueAsNewWorkflow extends Workflow {
21+
public class DemoContinueAsNewWorkflow implements Workflow {
2222
/*
2323
Compared with a CRON schedule, this periodic workflow example will never overlap.
2424
For example, a CRON schedule that executes a cleanup every hour will execute it at 1:00, 2:00, 3:00 etc.

examples/src/main/java/io/dapr/examples/workflows/externalevent/ApproveActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
package io.dapr.examples.workflows.externalevent;
1515

16-
import io.dapr.workflows.runtime.WorkflowActivity;
17-
import io.dapr.workflows.runtime.WorkflowActivityContext;
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

examples/src/main/java/io/dapr/examples/workflows/externalevent/DemoExternalEventWorkflow.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import io.dapr.workflows.Workflow;
1717
import io.dapr.workflows.WorkflowStub;
1818

19-
public class DemoExternalEventWorkflow extends Workflow {
19+
public class DemoExternalEventWorkflow implements Workflow {
2020
@Override
2121
public WorkflowStub create() {
2222
return ctx -> {

examples/src/main/java/io/dapr/examples/workflows/externalevent/DenyActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
package io.dapr.examples.workflows.externalevent;
1515

16-
import io.dapr.workflows.runtime.WorkflowActivity;
17-
import io.dapr.workflows.runtime.WorkflowActivityContext;
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

examples/src/main/java/io/dapr/examples/workflows/faninout/CountWordsActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
package io.dapr.examples.workflows.faninout;
1515

16-
import io.dapr.workflows.runtime.WorkflowActivity;
17-
import io.dapr.workflows.runtime.WorkflowActivityContext;
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
1818
import org.slf4j.Logger;
1919
import org.slf4j.LoggerFactory;
2020

examples/src/main/java/io/dapr/examples/workflows/faninout/DemoFanInOutWorkflow.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.List;
2121
import java.util.stream.Collectors;
2222

23-
public class DemoFanInOutWorkflow extends Workflow {
23+
public class DemoFanInOutWorkflow implements Workflow {
2424
@Override
2525
public WorkflowStub create() {
2626
return ctx -> {

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
package io.dapr.it.testcontainers;
1515

16-
import io.dapr.workflows.runtime.WorkflowActivity;
17-
import io.dapr.workflows.runtime.WorkflowActivityContext;
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
1818

1919
public class FirstActivity implements WorkflowActivity {
2020

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
package io.dapr.it.testcontainers;
1515

16-
import io.dapr.workflows.runtime.WorkflowActivity;
17-
import io.dapr.workflows.runtime.WorkflowActivityContext;
16+
import io.dapr.workflows.WorkflowActivity;
17+
import io.dapr.workflows.WorkflowActivityContext;
1818

1919
public class SecondActivity implements WorkflowActivity {
2020

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import java.time.Duration;
2121

22-
public class TestWorkflow extends Workflow {
22+
public class TestWorkflow implements Workflow {
2323

2424
@Override
2525
public WorkflowStub create() {

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

+5-8
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,13 @@
2121
/**
2222
* Common interface for workflow implementations.
2323
*/
24-
public abstract class Workflow {
25-
public Workflow() {
26-
}
27-
24+
public interface Workflow {
2825
/**
2926
* Executes the workflow logic.
3027
*
3128
* @return A WorkflowStub.
3229
*/
33-
public abstract WorkflowStub create();
30+
WorkflowStub create();
3431

3532
/**
3633
* Executes the workflow logic.
@@ -39,7 +36,7 @@ public Workflow() {
3936
* getting information about the current
4037
* workflow instance.
4138
*/
42-
public void run(WorkflowContext ctx) {
39+
default void run(WorkflowContext ctx) {
4340
WorkflowStub stub = this.create();
4441

4542
if (!this.isSagaEnabled()) {
@@ -68,7 +65,7 @@ public void run(WorkflowContext ctx) {
6865
}
6966
}
7067

71-
public boolean isSagaEnabled() {
68+
default boolean isSagaEnabled() {
7269
return this.getSagaOption() != null;
7370
}
7471

@@ -77,7 +74,7 @@ public boolean isSagaEnabled() {
7774
*
7875
* @return saga configuration
7976
*/
80-
public SagaOption getSagaOption() {
77+
default SagaOption getSagaOption() {
8178
// by default, saga is disabled
8279
return null;
8380
}

sdk-workflows/src/main/java/io/dapr/workflows/runtime/WorkflowActivity.java renamed to sdk-workflows/src/main/java/io/dapr/workflows/WorkflowActivity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
limitations under the License.
1212
*/
1313

14-
package io.dapr.workflows.runtime;
14+
package io.dapr.workflows;
1515

1616
/**
1717
* Common interface for task activity implementations.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2023 The Dapr Authors
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
* Unless required by applicable law or agreed to in writing, software
8+
* distributed under the License is distributed on an "AS IS" BASIS,
9+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
* See the License for the specific language governing permissions and
11+
limitations under the License.
12+
*/
13+
14+
package io.dapr.workflows;
15+
16+
public interface WorkflowActivityContext {
17+
String getName();
18+
19+
<T> T getInput(Class<T> targetType);
20+
}

sdk-workflows/src/main/java/io/dapr/workflows/runtime/WorkflowActivityContext.java renamed to sdk-workflows/src/main/java/io/dapr/workflows/runtime/DefaultWorkflowActivityContext.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@
1414
package io.dapr.workflows.runtime;
1515

1616
import com.microsoft.durabletask.TaskActivityContext;
17+
import io.dapr.workflows.WorkflowActivityContext;
1718

1819
/**
1920
* Wrapper for Durable Task Framework {@link TaskActivityContext}.
2021
*/
21-
public class WorkflowActivityContext implements TaskActivityContext {
22+
class DefaultWorkflowActivityContext implements WorkflowActivityContext {
2223
private final TaskActivityContext innerContext;
2324

2425
/**
@@ -27,7 +28,7 @@ public class WorkflowActivityContext implements TaskActivityContext {
2728
* @param context TaskActivityContext
2829
* @throws IllegalArgumentException if context is null
2930
*/
30-
public WorkflowActivityContext(TaskActivityContext context) throws IllegalArgumentException {
31+
public DefaultWorkflowActivityContext(TaskActivityContext context) throws IllegalArgumentException {
3132
if (context == null) {
3233
throw new IllegalArgumentException("Context cannot be null");
3334
}
@@ -39,6 +40,7 @@ public WorkflowActivityContext(TaskActivityContext context) throws IllegalArgume
3940
*
4041
* @return the name of the current activity
4142
*/
43+
@Override
4244
public String getName() {
4345
return this.innerContext.getName();
4446
}
@@ -50,6 +52,7 @@ public String getName() {
5052
* @param targetType targetType of the input
5153
* @return the input of the current activity
5254
*/
55+
@Override
5356
public <T> T getInput(Class<T> targetType) {
5457
return this.innerContext.getInput(targetType);
5558
}

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

+9-8
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
limitations under the License.
1212
*/
1313

14-
package io.dapr.workflows;
14+
package io.dapr.workflows.runtime;
1515

1616
import com.microsoft.durabletask.CompositeTaskFailedException;
1717
import com.microsoft.durabletask.Task;
1818
import com.microsoft.durabletask.TaskCanceledException;
1919
import com.microsoft.durabletask.TaskOptions;
2020
import com.microsoft.durabletask.TaskOrchestrationContext;
21-
import io.dapr.workflows.saga.DaprSagaContextImpl;
21+
import io.dapr.workflows.WorkflowContext;
22+
import io.dapr.workflows.runtime.saga.DefaultSagaContext;
2223
import io.dapr.workflows.saga.Saga;
2324
import io.dapr.workflows.saga.SagaContext;
2425
import org.slf4j.Logger;
@@ -32,7 +33,7 @@
3233
import java.util.List;
3334
import java.util.UUID;
3435

35-
public class DaprWorkflowContextImpl implements WorkflowContext {
36+
public class DefaultWorkflowContext implements WorkflowContext {
3637
private final TaskOrchestrationContext innerContext;
3738
private final Logger logger;
3839
private final Saga saga;
@@ -43,7 +44,7 @@ public class DaprWorkflowContextImpl implements WorkflowContext {
4344
* @param context TaskOrchestrationContext
4445
* @throws IllegalArgumentException if context is null
4546
*/
46-
public DaprWorkflowContextImpl(TaskOrchestrationContext context) throws IllegalArgumentException {
47+
public DefaultWorkflowContext(TaskOrchestrationContext context) throws IllegalArgumentException {
4748
this(context, LoggerFactory.getLogger(WorkflowContext.class));
4849
}
4950

@@ -54,11 +55,11 @@ public DaprWorkflowContextImpl(TaskOrchestrationContext context) throws IllegalA
5455
* @param logger Logger
5556
* @throws IllegalArgumentException if context or logger is null
5657
*/
57-
public DaprWorkflowContextImpl(TaskOrchestrationContext context, Logger logger) throws IllegalArgumentException {
58+
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger) throws IllegalArgumentException {
5859
this(context, logger, null);
5960
}
6061

61-
public DaprWorkflowContextImpl(TaskOrchestrationContext context, Saga saga) throws IllegalArgumentException {
62+
public DefaultWorkflowContext(TaskOrchestrationContext context, Saga saga) throws IllegalArgumentException {
6263
this(context, LoggerFactory.getLogger(WorkflowContext.class), saga);
6364
}
6465

@@ -70,7 +71,7 @@ public DaprWorkflowContextImpl(TaskOrchestrationContext context, Saga saga) thro
7071
* @param saga saga object, if null, saga is disabled
7172
* @throws IllegalArgumentException if context or logger is null
7273
*/
73-
public DaprWorkflowContextImpl(TaskOrchestrationContext context, Logger logger, Saga saga)
74+
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger, Saga saga)
7475
throws IllegalArgumentException {
7576
if (context == null) {
7677
throw new IllegalArgumentException("Context cannot be null");
@@ -248,6 +249,6 @@ public SagaContext getSagaContext() {
248249
throw new UnsupportedOperationException("Saga is not enabled");
249250
}
250251

251-
return new DaprSagaContextImpl(this.saga, this);
252+
return new DefaultSagaContext(this.saga, this);
252253
}
253254
}

0 commit comments

Comments
 (0)