Skip to content

Commit

Permalink
Ensure Dapr workflows classes and interfaces have proper packages and…
Browse files Browse the repository at this point in the history
… visibility (#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]>
  • Loading branch information
artur-ciocanu and Artur Ciocanu authored Jan 4, 2025
1 parent 69f2407 commit 380cda6
Show file tree
Hide file tree
Showing 41 changed files with 154 additions and 138 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.dapr.spring.boot.autoconfigure.client.workflows;

import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.WorkflowActivityContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.client.RestTemplate;

public class TestWorkflow extends Workflow {
public class TestWorkflow implements Workflow {

@Autowired
private RestTemplate restTemplate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package io.dapr.spring.workflows.config;

import io.dapr.workflows.Workflow;
import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowRuntime;
import io.dapr.workflows.runtime.WorkflowRuntimeBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class DaprWorkflowExampleTest {
private static final String noTimeoutWorkflow = "DemoWorkflowNoTimeout";
private static final String workflowDefaultId = "demo-workflow-123";

private class DemoWorkflow extends Workflow {
private class DemoWorkflow implements Workflow {

@Override
public WorkflowStub create() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;

public class DemoChainWorkflow extends Workflow {
public class DemoChainWorkflow implements Workflow {
@Override
public WorkflowStub create() {
return ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package io.dapr.examples.workflows.chain;

import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.WorkflowActivityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;

public class DemoChildWorkflow extends Workflow {
public class DemoChildWorkflow implements Workflow {
@Override
public WorkflowStub create() {
return ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;

public class DemoWorkflow extends Workflow {
public class DemoWorkflow implements Workflow {
@Override
public WorkflowStub create() {
return ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package io.dapr.examples.workflows.childworkflow;

import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.WorkflowActivityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package io.dapr.examples.workflows.continueasnew;

import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.WorkflowActivityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

import java.time.Duration;

public class DemoContinueAsNewWorkflow extends Workflow {
public class DemoContinueAsNewWorkflow implements Workflow {
/*
Compared with a CRON schedule, this periodic workflow example will never overlap.
For example, a CRON schedule that executes a cleanup every hour will execute it at 1:00, 2:00, 3:00 etc.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package io.dapr.examples.workflows.externalevent;

import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.WorkflowActivityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;

public class DemoExternalEventWorkflow extends Workflow {
public class DemoExternalEventWorkflow implements Workflow {
@Override
public WorkflowStub create() {
return ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package io.dapr.examples.workflows.externalevent;

import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.WorkflowActivityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package io.dapr.examples.workflows.faninout;

import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.WorkflowActivityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.List;
import java.util.stream.Collectors;

public class DemoFanInOutWorkflow extends Workflow {
public class DemoFanInOutWorkflow implements Workflow {
@Override
public WorkflowStub create() {
return ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package io.dapr.it.testcontainers;

import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.WorkflowActivityContext;

public class FirstActivity implements WorkflowActivity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

package io.dapr.it.testcontainers;

import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import io.dapr.workflows.WorkflowActivity;
import io.dapr.workflows.WorkflowActivityContext;

public class SecondActivity implements WorkflowActivity {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.time.Duration;

public class TestWorkflow extends Workflow {
public class TestWorkflow implements Workflow {

@Override
public WorkflowStub create() {
Expand Down
13 changes: 5 additions & 8 deletions sdk-workflows/src/main/java/io/dapr/workflows/Workflow.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,13 @@
/**
* Common interface for workflow implementations.
*/
public abstract class Workflow {
public Workflow() {
}

public interface Workflow {
/**
* Executes the workflow logic.
*
* @return A WorkflowStub.
*/
public abstract WorkflowStub create();
WorkflowStub create();

/**
* Executes the workflow logic.
Expand All @@ -39,7 +36,7 @@ public Workflow() {
* getting information about the current
* workflow instance.
*/
public void run(WorkflowContext ctx) {
default void run(WorkflowContext ctx) {
WorkflowStub stub = this.create();

if (!this.isSagaEnabled()) {
Expand Down Expand Up @@ -68,7 +65,7 @@ public void run(WorkflowContext ctx) {
}
}

public boolean isSagaEnabled() {
default boolean isSagaEnabled() {
return this.getSagaOption() != null;
}

Expand All @@ -77,7 +74,7 @@ public boolean isSagaEnabled() {
*
* @return saga configuration
*/
public SagaOption getSagaOption() {
default SagaOption getSagaOption() {
// by default, saga is disabled
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
limitations under the License.
*/

package io.dapr.workflows.runtime;
package io.dapr.workflows;

/**
* Common interface for task activity implementations.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2023 The Dapr Authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
limitations under the License.
*/

package io.dapr.workflows;

public interface WorkflowActivityContext {
String getName();

<T> T getInput(Class<T> targetType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
package io.dapr.workflows.runtime;

import com.microsoft.durabletask.TaskActivityContext;
import io.dapr.workflows.WorkflowActivityContext;

/**
* Wrapper for Durable Task Framework {@link TaskActivityContext}.
*/
public class WorkflowActivityContext implements TaskActivityContext {
class DefaultWorkflowActivityContext implements WorkflowActivityContext {
private final TaskActivityContext innerContext;

/**
Expand All @@ -27,7 +28,7 @@ public class WorkflowActivityContext implements TaskActivityContext {
* @param context TaskActivityContext
* @throws IllegalArgumentException if context is null
*/
public WorkflowActivityContext(TaskActivityContext context) throws IllegalArgumentException {
public DefaultWorkflowActivityContext(TaskActivityContext context) throws IllegalArgumentException {
if (context == null) {
throw new IllegalArgumentException("Context cannot be null");
}
Expand All @@ -39,6 +40,7 @@ public WorkflowActivityContext(TaskActivityContext context) throws IllegalArgume
*
* @return the name of the current activity
*/
@Override
public String getName() {
return this.innerContext.getName();
}
Expand All @@ -50,6 +52,7 @@ public String getName() {
* @param targetType targetType of the input
* @return the input of the current activity
*/
@Override
public <T> T getInput(Class<T> targetType) {
return this.innerContext.getInput(targetType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@
limitations under the License.
*/

package io.dapr.workflows;
package io.dapr.workflows.runtime;

import com.microsoft.durabletask.CompositeTaskFailedException;
import com.microsoft.durabletask.Task;
import com.microsoft.durabletask.TaskCanceledException;
import com.microsoft.durabletask.TaskOptions;
import com.microsoft.durabletask.TaskOrchestrationContext;
import io.dapr.workflows.saga.DaprSagaContextImpl;
import io.dapr.workflows.WorkflowContext;
import io.dapr.workflows.runtime.saga.DefaultSagaContext;
import io.dapr.workflows.saga.Saga;
import io.dapr.workflows.saga.SagaContext;
import org.slf4j.Logger;
Expand All @@ -32,7 +33,7 @@
import java.util.List;
import java.util.UUID;

public class DaprWorkflowContextImpl implements WorkflowContext {
public class DefaultWorkflowContext implements WorkflowContext {
private final TaskOrchestrationContext innerContext;
private final Logger logger;
private final Saga saga;
Expand All @@ -43,7 +44,7 @@ public class DaprWorkflowContextImpl implements WorkflowContext {
* @param context TaskOrchestrationContext
* @throws IllegalArgumentException if context is null
*/
public DaprWorkflowContextImpl(TaskOrchestrationContext context) throws IllegalArgumentException {
public DefaultWorkflowContext(TaskOrchestrationContext context) throws IllegalArgumentException {
this(context, LoggerFactory.getLogger(WorkflowContext.class));
}

Expand All @@ -54,11 +55,11 @@ public DaprWorkflowContextImpl(TaskOrchestrationContext context) throws IllegalA
* @param logger Logger
* @throws IllegalArgumentException if context or logger is null
*/
public DaprWorkflowContextImpl(TaskOrchestrationContext context, Logger logger) throws IllegalArgumentException {
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger) throws IllegalArgumentException {
this(context, logger, null);
}

public DaprWorkflowContextImpl(TaskOrchestrationContext context, Saga saga) throws IllegalArgumentException {
public DefaultWorkflowContext(TaskOrchestrationContext context, Saga saga) throws IllegalArgumentException {
this(context, LoggerFactory.getLogger(WorkflowContext.class), saga);
}

Expand All @@ -70,7 +71,7 @@ public DaprWorkflowContextImpl(TaskOrchestrationContext context, Saga saga) thro
* @param saga saga object, if null, saga is disabled
* @throws IllegalArgumentException if context or logger is null
*/
public DaprWorkflowContextImpl(TaskOrchestrationContext context, Logger logger, Saga saga)
public DefaultWorkflowContext(TaskOrchestrationContext context, Logger logger, Saga saga)
throws IllegalArgumentException {
if (context == null) {
throw new IllegalArgumentException("Context cannot be null");
Expand Down Expand Up @@ -248,6 +249,6 @@ public SagaContext getSagaContext() {
throw new UnsupportedOperationException("Saga is not enabled");
}

return new DaprSagaContextImpl(this.saga, this);
return new DefaultSagaContext(this.saga, this);
}
}
Loading

0 comments on commit 380cda6

Please sign in to comment.