From bb56b8d8a815699b1750d1fc116ab6b68dbe1ac6 Mon Sep 17 00:00:00 2001 From: Siri Varma Vegiraju Date: Tue, 29 Apr 2025 06:27:02 -0700 Subject: [PATCH 01/11] Update CONTRIBUTING.md Signed-off-by: Siri Varma Vegiraju --- CONTRIBUTING.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4009213b11..c094f92fa1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -51,6 +51,11 @@ Before you file an issue, make sure you've checked the following: This section describes the guidelines for contributing code / docs to Dapr. +### Things to consider when adding new API to SDK + +1. All the new API's go under [dapr-sdk maven package](https://github.com/dapr/java-sdk/tree/master/sdk) +2. Make sure there is an example talking about how to use the API along with a README. [Example](https://github.com/dapr/java-sdk/pull/1235/files#diff-69ed756c4c01fd5fa884aac030dccb8f3f4d4fefa0dc330862d55a6f87b34a14) + ### Pull Requests All contributions come through pull requests. To submit a proposed change, we recommend following this workflow: @@ -64,6 +69,7 @@ All contributions come through pull requests. To submit a proposed change, we re 6. Commit and open a PR 7. Wait for the CI process to finish and make sure all checks are green 8. A maintainer of the project will be assigned, and you can expect a review within a few days +9. All the files have the Copyright header. ### Configure the code style with checkstyle From dae3eaa623795061db14fa24bab0649683b5de20 Mon Sep 17 00:00:00 2001 From: siri-varma Date: Mon, 12 May 2025 19:54:47 -0700 Subject: [PATCH 02/11] Fix NPE Signed-off-by: siri-varma --- .../DemoChildWorkerflowClient.java | 17 +++++++++----- .../childworkflow/DemoChildWorkflow.java | 23 ++++++++++++++++++- .../DemoChildWorkflowWorker.java | 6 +++++ .../childworkflow/ReverseActivity.java | 9 +++++++- sdk-workflows/pom.xml | 2 +- .../workflows/WorkflowTaskRetryPolicy.java | 5 ++-- .../runtime/DefaultWorkflowContext.java | 4 +++- 7 files changed, 54 insertions(+), 12 deletions(-) diff --git a/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkerflowClient.java b/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkerflowClient.java index 139f93e414..93c57278b3 100644 --- a/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkerflowClient.java +++ b/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkerflowClient.java @@ -16,6 +16,7 @@ import io.dapr.workflows.client.DaprWorkflowClient; import io.dapr.workflows.client.WorkflowInstanceStatus; +import java.time.Duration; import java.util.concurrent.TimeoutException; public class DemoChildWorkerflowClient { @@ -27,15 +28,19 @@ public class DemoChildWorkerflowClient { */ public static void main(String[] args) { try (DaprWorkflowClient client = new DaprWorkflowClient()) { - String instanceId = client.scheduleNewWorkflow(DemoWorkflow.class); + String instanceId = client.scheduleNewWorkflow(DemoChildWorkflow.class, "Hello Word"); System.out.printf("Started a new child-workflow model workflow with instance ID: %s%n", instanceId); - WorkflowInstanceStatus workflowInstanceStatus = - client.waitForInstanceCompletion(instanceId, null, true); - String result = workflowInstanceStatus.readOutputAs(String.class); - System.out.printf("workflow instance with ID: %s completed with result: %s%n", instanceId, result); + while (true) { + try { + Thread.sleep(10000); + System.out.println(client.getInstanceState(instanceId, true).getRuntimeStatus()); + } catch (Exception ex) { + System.out.println("exception"); + } + } - } catch (TimeoutException | InterruptedException e) { + } catch (InterruptedException e) { throw new RuntimeException(e); } } diff --git a/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflow.java b/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflow.java index c9a9af4557..8c5ac63dff 100644 --- a/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflow.java +++ b/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflow.java @@ -13,8 +13,13 @@ package io.dapr.examples.workflows.childworkflow; +import io.dapr.durabletask.interruption.OrchestratorBlockedException; import io.dapr.workflows.Workflow; import io.dapr.workflows.WorkflowStub; +import io.dapr.workflows.WorkflowTaskOptions; +import io.dapr.workflows.WorkflowTaskRetryPolicy; + +import java.time.Duration; public class DemoChildWorkflow implements Workflow { @Override @@ -22,11 +27,27 @@ public WorkflowStub create() { return ctx -> { ctx.getLogger().info("Starting ChildWorkflow: " + ctx.getName()); + WorkflowTaskRetryPolicy policy = WorkflowTaskRetryPolicy.newBuilder() + .setFirstRetryInterval(Duration.ofSeconds(1)) + .setMaxNumberOfAttempts(10) + .build(); + + WorkflowTaskOptions options = new WorkflowTaskOptions(policy); + var childWorkflowInput = ctx.getInput(String.class); ctx.getLogger().info("ChildWorkflow received input: " + childWorkflowInput); ctx.getLogger().info("ChildWorkflow is calling Activity: " + ReverseActivity.class.getName()); - String result = ctx.callActivity(ReverseActivity.class.getName(), childWorkflowInput, String.class).await(); + String result = new String(""); + + try { + result = ctx.callActivity(ReverseActivity.class.getName(), childWorkflowInput, options, String.class).await(); + } catch (OrchestratorBlockedException ex) { + throw ex; + } catch (Exception ex) { + System.out.println("EX:" + ex.getMessage()); + ctx.getLogger().warn("Ex is what instance of " + (ex.getMessage())); + } ctx.getLogger().info("ChildWorkflow finished with: " + result); ctx.complete(result); diff --git a/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflowWorker.java b/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflowWorker.java index 0e692551e5..2ee3f4d584 100644 --- a/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflowWorker.java +++ b/examples/src/main/java/io/dapr/examples/workflows/childworkflow/DemoChildWorkflowWorker.java @@ -13,9 +13,13 @@ package io.dapr.examples.workflows.childworkflow; +import io.dapr.workflows.WorkflowTaskRetryPolicy; import io.dapr.workflows.runtime.WorkflowRuntime; import io.dapr.workflows.runtime.WorkflowRuntimeBuilder; +import java.time.Duration; +import java.time.temporal.ChronoUnit; + public class DemoChildWorkflowWorker { /** * The main method of this app. @@ -25,6 +29,7 @@ public class DemoChildWorkflowWorker { */ public static void main(String[] args) throws Exception { // Register the Workflow with the builder. + WorkflowRuntimeBuilder builder = new WorkflowRuntimeBuilder() .registerWorkflow(DemoWorkflow.class) .registerWorkflow(DemoChildWorkflow.class); @@ -32,6 +37,7 @@ public static void main(String[] args) throws Exception { // Build and then start the workflow runtime pulling and executing tasks WorkflowRuntime runtime = builder.build(); + runtime.start(); System.out.println("Start workflow runtime"); } } diff --git a/examples/src/main/java/io/dapr/examples/workflows/childworkflow/ReverseActivity.java b/examples/src/main/java/io/dapr/examples/workflows/childworkflow/ReverseActivity.java index 544b29ea05..3689890ed9 100644 --- a/examples/src/main/java/io/dapr/examples/workflows/childworkflow/ReverseActivity.java +++ b/examples/src/main/java/io/dapr/examples/workflows/childworkflow/ReverseActivity.java @@ -30,6 +30,13 @@ public Object run(WorkflowActivityContext ctx) { logger.info("Message Received from input: " + message); logger.info("Sending message to output: " + newMessage); - return newMessage; + throw new RuntimeException("abcdef"); } } + +class MyCustomException extends RuntimeException { + + public MyCustomException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/sdk-workflows/pom.xml b/sdk-workflows/pom.xml index 0a5289daf6..e763e7630d 100644 --- a/sdk-workflows/pom.xml +++ b/sdk-workflows/pom.xml @@ -47,7 +47,7 @@ io.dapr durabletask-client - 1.5.2 + 1.5.3