-
Notifications
You must be signed in to change notification settings - Fork 223
Workflows alignment with Spring Boot (Dependency Injection for Workflows and Activities) #1170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
5454194
evaluating annotations
salaboy d75d35b
adding workflows autoconfig
salaboy 6c7389d
initial @EnableDaprWorkflows implementation
salaboy 947d5b7
validating managed beans for workflows and activities
salaboy 0521e1a
[docs] remove 'beta' for Java SDK workflow docs (#1169)
hhunter-ms 7c20bb2
Fix create release to run with right JDK (#1171)
artursouza 451938b
Remove test from create release script. (#1172)
artursouza 57e97b8
Fix typo crashing release script. (#1173)
artursouza 678bd30
Update master version to 1.14.0-SNAPSHOT (#1174)
dapr-bot bcc361f
Generate updated javadocs for 1.13.1 (#1179)
artursouza 7d6664c
upgrading snap
salaboy 6aee76c
fix checkstyle
salaboy c89eee0
Fix conflict and build trigger on right branch for SNAPSHOT. (#1180)
artursouza da8049f
private internals
salaboy 2ec6baf
Merge branch 'master' into workflows-1164
salaboy 0cbbdba
Merge branch 'master' into workflows-1164
artursouza File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
44 changes: 44 additions & 0 deletions
44
...rc/test/java/io/dapr/spring/boot/autoconfigure/client/DaprWorkflowsRegistrationTests.java
This file contains hidden or 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,44 @@ | ||
| package io.dapr.spring.boot.autoconfigure.client; | ||
|
|
||
| import io.dapr.spring.boot.autoconfigure.client.workflows.TestActivity; | ||
| import io.dapr.spring.boot.autoconfigure.client.workflows.TestWorkflow; | ||
| import io.dapr.workflows.client.DaprWorkflowClient; | ||
| import io.dapr.workflows.runtime.WorkflowRuntimeBuilder; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.test.context.SpringBootTest; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| @SpringBootTest(classes = {WorkflowTestApplication.class, DaprClientAutoConfiguration.class, TestActivity.class, TestWorkflow.class}) | ||
| public class DaprWorkflowsRegistrationTests { | ||
|
|
||
| @Autowired | ||
| private DaprWorkflowClient daprWorkflowClient; | ||
|
|
||
| @Autowired | ||
| private WorkflowRuntimeBuilder workflowRuntimeBuilder; | ||
|
|
||
| @Autowired | ||
| private TestActivity testActivity; | ||
|
|
||
| @Autowired | ||
| private TestWorkflow testWorkflow; | ||
|
|
||
| @Test | ||
| public void testWorkflowInjection(){ | ||
|
|
||
| //I cannot test here if the client works, as it needs the runtime | ||
| assertNotNull(daprWorkflowClient); | ||
salaboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| //@TODO: there is no way to assert the runtime and its registered workflows and activities | ||
| assertNotNull(workflowRuntimeBuilder); | ||
|
|
||
| //Check that both Activities and Workflows are managed beans | ||
| assertNotNull(testActivity); | ||
| assertNotNull(testWorkflow); | ||
| assertNotNull(testActivity.getRestTemplate()); | ||
| assertNotNull(testWorkflow.getRestTemplate()); | ||
|
|
||
| } | ||
| } | ||
24 changes: 24 additions & 0 deletions
24
...igure/src/test/java/io/dapr/spring/boot/autoconfigure/client/WorkflowTestApplication.java
This file contains hidden or 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,24 @@ | ||
| package io.dapr.spring.boot.autoconfigure.client; | ||
|
|
||
| import io.dapr.spring.workflows.config.EnableDaprWorkflows; | ||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.web.client.RestTemplate; | ||
|
|
||
| @SpringBootApplication | ||
| @EnableDaprWorkflows | ||
| public class WorkflowTestApplication { | ||
| public static void main(String[] args) { | ||
| SpringApplication.run(WorkflowTestApplication.class, args); | ||
salaboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| @Configuration | ||
| static class Config { | ||
| @Bean | ||
| RestTemplate restTemplate(){ | ||
| return new RestTemplate(); | ||
| } | ||
| } | ||
| } | ||
21 changes: 21 additions & 0 deletions
21
...figure/src/test/java/io/dapr/spring/boot/autoconfigure/client/workflows/TestActivity.java
This file contains hidden or 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,21 @@ | ||
| package io.dapr.spring.boot.autoconfigure.client.workflows; | ||
|
|
||
| import io.dapr.workflows.runtime.WorkflowActivity; | ||
| import io.dapr.workflows.runtime.WorkflowActivityContext; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.web.client.RestTemplate; | ||
|
|
||
| public class TestActivity implements WorkflowActivity { | ||
|
|
||
| @Autowired | ||
| private RestTemplate restTemplate; | ||
|
|
||
| @Override | ||
| public Object run(WorkflowActivityContext ctx) { | ||
| return "OK"; | ||
| } | ||
|
|
||
| public RestTemplate getRestTemplate() { | ||
| return restTemplate; | ||
| } | ||
| } |
23 changes: 23 additions & 0 deletions
23
...figure/src/test/java/io/dapr/spring/boot/autoconfigure/client/workflows/TestWorkflow.java
This file contains hidden or 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,23 @@ | ||
| package io.dapr.spring.boot.autoconfigure.client.workflows; | ||
|
|
||
| import io.dapr.workflows.Workflow; | ||
| import io.dapr.workflows.WorkflowStub; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.web.client.RestTemplate; | ||
|
|
||
| public class TestWorkflow extends Workflow { | ||
|
|
||
| @Autowired | ||
| private RestTemplate restTemplate; | ||
|
|
||
| @Override | ||
| public WorkflowStub create() { | ||
| return ctx -> { | ||
| ctx.callActivity(TestActivity.class.getName(), null).await(); | ||
| }; | ||
| } | ||
|
|
||
| public RestTemplate getRestTemplate() { | ||
| return restTemplate; | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <parent> | ||
| <groupId>io.dapr.spring</groupId> | ||
| <artifactId>dapr-spring-parent</artifactId> | ||
| <version>0.14.0-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
salaboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| <artifactId>dapr-spring-workflows</artifactId> | ||
| <name>dapr-spring-workflows</name> | ||
| <description>Dapr Spring Workflows</description> | ||
| <packaging>jar</packaging> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.dapr</groupId> | ||
| <artifactId>dapr-sdk-workflows</artifactId> | ||
| <version>${project.version}</version> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> | ||
55 changes: 55 additions & 0 deletions
55
...g-workflows/src/main/java/io/dapr/spring/workflows/config/DaprWorkflowsConfiguration.java
This file contains hidden or 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,55 @@ | ||
| package io.dapr.spring.workflows.config; | ||
|
|
||
| import io.dapr.workflows.Workflow; | ||
| import io.dapr.workflows.runtime.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; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| @Configuration | ||
| public class DaprWorkflowsConfiguration implements ApplicationContextAware { | ||
| private static final Logger LOGGER = LoggerFactory.getLogger(DaprWorkflowsConfiguration.class); | ||
|
|
||
| private WorkflowRuntimeBuilder workflowRuntimeBuilder; | ||
|
|
||
| public DaprWorkflowsConfiguration(WorkflowRuntimeBuilder workflowRuntimeBuilder) { | ||
| this.workflowRuntimeBuilder = workflowRuntimeBuilder; | ||
| } | ||
|
|
||
| /** | ||
| * Register workflows and activities to the workflowRuntimeBuilder. | ||
| * @param applicationContext Spring Application Context | ||
| */ | ||
salaboy marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| private void registerWorkflowsAndActivities(ApplicationContext applicationContext) { | ||
| LOGGER.info("Registering Dapr Workflows and Activities"); | ||
| Map<String, Workflow> workflowBeans = applicationContext.getBeansOfType(Workflow.class); | ||
| for (Workflow w : workflowBeans.values()) { | ||
| LOGGER.info("Dapr Workflow: '{}' registered", w.getClass().getName()); | ||
| workflowRuntimeBuilder.registerWorkflow(w.getClass()); | ||
| } | ||
|
|
||
| Map<String, WorkflowActivity> workflowActivitiesBeans = applicationContext.getBeansOfType(WorkflowActivity.class); | ||
| for (WorkflowActivity a : workflowActivitiesBeans.values()) { | ||
| LOGGER.info("Dapr Workflow Activity: '{}' registered", a.getClass().getName()); | ||
| workflowRuntimeBuilder.registerActivity(a.getClass()); | ||
| } | ||
|
|
||
| try (WorkflowRuntime runtime = workflowRuntimeBuilder.build()) { | ||
| LOGGER.info("Starting workflow runtime ... "); | ||
| runtime.start(false); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { | ||
| registerWorkflowsAndActivities(applicationContext); | ||
| } | ||
| } | ||
16 changes: 16 additions & 0 deletions
16
...r-spring-workflows/src/main/java/io/dapr/spring/workflows/config/EnableDaprWorkflows.java
This file contains hidden or 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,16 @@ | ||
| package io.dapr.spring.workflows.config; | ||
|
|
||
|
|
||
| import org.springframework.context.annotation.Import; | ||
|
|
||
| import java.lang.annotation.Retention; | ||
| import java.lang.annotation.Target; | ||
|
|
||
| import static java.lang.annotation.ElementType.TYPE; | ||
| import static java.lang.annotation.RetentionPolicy.RUNTIME; | ||
|
|
||
| @Retention(RUNTIME) | ||
| @Target(TYPE) | ||
| @Import(DaprWorkflowsConfiguration.class) | ||
| public @interface EnableDaprWorkflows { | ||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.