Skip to content
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

Workflow Implementation - Continues... #880

Merged
merged 82 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
6656e4c
Add ElementType.Type to ActorType (#812)
LionTao Jan 25, 2023
869a231
Bump codecov/codecov-action from 3.1.0 to 3.1.1 (#788)
dependabot[bot] Jan 25, 2023
9e30733
Update springboot to latest minor.patch version. (#826)
artursouza Feb 2, 2023
69292a6
Use runtime 1.10.0-rc.X and CLI 1.10.0-rc.X (#827)
artursouza Feb 3, 2023
bffac88
Upgrade the version to 1.9.0-SNAPSHOT (#829)
artursouza Feb 3, 2023
27131ff
Generate updated javadocs for 1.8.0 (#836)
artursouza Feb 16, 2023
6635627
Update Dapr runtime and CLI to 1.10. (#837)
artursouza Feb 16, 2023
113220f
Inject autoconfiguration in the Spring Boot 3 style (#831)
champel Mar 22, 2023
8378bb0
Bump from reactor 2.3.5.RELEASE to 2.7.8 (#830)
champel Mar 22, 2023
7ade730
Test multiple reminder state types + improve timer tests. (#855)
artursouza May 5, 2023
022c0ee
Convert Config API to Stable endpoints. (#846)
mukundansundar May 9, 2023
64b3ad8
Add PubSub subscriber examples over gPRC (#833)
MregXN May 22, 2023
4117801
auto validate actors (#863)
mukundansundar May 24, 2023
d49c87b
Bump codecov/codecov-action from 3.1.1 to 3.1.4 (#862)
dependabot[bot] May 24, 2023
1f33417
Fix 787 (#832)
MatejNedic May 25, 2023
ae2e61c
Upgrade to 1.11 RCs. (#867)
artursouza May 26, 2023
03d5c2e
Init for workflows
bderusha May 10, 2023
fcfade9
Updating some javadocs and Years.
May 26, 2023
e40722d
Add missing Header
May 26, 2023
9270180
respond to PR feedback
bderusha Jun 1, 2023
1420b4c
Update workflow example README
bderusha Jun 1, 2023
95a2757
Address PR feedback
bderusha Jun 2, 2023
d5345cc
fixup deprecated pom.xml variable
bderusha Jun 2, 2023
94f121c
Updates based on PR feedback
bderusha Jun 6, 2023
7df0031
Update pom files per feedback
bderusha Jun 7, 2023
51d5b04
GetInstanceState implementation (#1)
Aymalla Jun 12, 2023
a2c4867
Management API
kusweta Jun 12, 2023
f6bfade
remove try/catch
kusweta Jun 13, 2023
8a0201d
implementing getIsReplaying() method for Authoring API (#7)
julioalex-rezende Jun 13, 2023
4448b62
Implementing getCurrentInstant() authoring method (#5)
julioalex-rezende Jun 13, 2023
03c0602
Activity Implementation (#3)
macromania Jun 14, 2023
84f89fb
fixing issue with getIsReplaying() call (#8)
julioalex-rezende Jun 15, 2023
1ed7192
Generate updated javadocs for 1.9.0 (#878)
artursouza Jun 12, 2023
4e17f3f
Add .sdkmanrc config file and JDK installation instructions (#873)
ejba Jun 13, 2023
06feae6
Add unit testing example
bderusha Jun 13, 2023
f2ee392
implementing getIsReplaying() method for Authoring API (#7)
julioalex-rezende Jun 13, 2023
aa9cea2
fix parent pom
macromania Jun 14, 2023
730d22d
Send Event Implementation (#10)
macromania Jun 15, 2023
4bba4a4
Implementing allOf, anyOf, createTimer methods (#11)
julioalex-rezende Jun 19, 2023
e7f4fbc
Support remote endpoint. (#877)
artursouza Jun 19, 2023
9816093
Add callSubWorkflow Implementation
Aymalla Jun 19, 2023
d1b64ba
rename DemoSubWorkflow
Aymalla Jun 19, 2023
34b8f82
continueAsNew Implementation (#13)
macromania Jun 20, 2023
1b3a3dd
Merge branch 'master' into master
macromania Jun 21, 2023
d3d8a52
Merge branch 'master' into master
macromania Jun 29, 2023
9343ea7
merge PR 857 changes
macromania Aug 15, 2023
5efc786
remove duplicate class
macromania Aug 15, 2023
93d617e
add missing mockito test dependency
macromania Aug 15, 2023
a1c379a
use new workflow client implementation
macromania Aug 15, 2023
af451cb
moved implementations to new workflow and context
macromania Aug 15, 2023
b596268
relocate duplicate implemantation
macromania Aug 15, 2023
7033b00
remove duplicate test and increase test coverage
macromania Aug 15, 2023
e5c6106
Implement retry and timeout policy for gRPC client. (#889)
artursouza Aug 16, 2023
a2cd162
renamed getIsReplaying
macromania Aug 21, 2023
147b237
rollback changes on client
macromania Aug 21, 2023
6fda032
move workflow runtime state package
macromania Aug 21, 2023
c5ead93
rename workflow instance state to status
macromania Aug 21, 2023
7c657cd
remove unnecessary else
macromania Aug 21, 2023
b9d984e
removed unknown state
macromania Aug 21, 2023
0f4b131
updated comment
macromania Aug 21, 2023
1f4c148
updated workflow failure details
macromania Aug 21, 2023
438001b
fix style issues
macromania Aug 21, 2023
7b31e22
Merge remote-tracking branch 'dapr-upstream/master'
macromania Aug 21, 2023
4c673e6
rollback merge change
macromania Aug 25, 2023
53fe882
fixed pom files
macromania Aug 25, 2023
2a9e49e
rollback actors pom changes on autoformat
macromania Aug 25, 2023
5229957
fixe actors pom
macromania Aug 25, 2023
bc35ee0
fix styling on actors pom
macromania Aug 25, 2023
ed640b8
fix pom spacing
macromania Aug 25, 2023
6278b4a
move test to match the package
macromania Aug 25, 2023
20aad31
add missing dependencies
macromania Aug 25, 2023
9d1abb4
increased test coverage
macromania Aug 25, 2023
e1a45e7
moved workflow runtime package
macromania Aug 25, 2023
980862f
add exception for missing case
macromania Aug 25, 2023
12e69d4
add null check for metadata
macromania Aug 25, 2023
319af01
add runtime exception error messages
macromania Aug 25, 2023
c787eee
update try catch scope
macromania Aug 25, 2023
cf0ec89
update activity definition to an interface
macromania Aug 25, 2023
7fb9a37
update comments
macromania Aug 25, 2023
3847626
removed redundant method
macromania Aug 25, 2023
f5dab2a
PR updates
macromania Sep 12, 2023
65b3354
Merge remote-tracking branch 'dapr-upstream/master'
macromania Sep 12, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.examples.workflows;

public class DemoActivityInput {

private String message;

public DemoActivityInput() {
}

public DemoActivityInput(String message) {
this.message = message;
}

public String getMessage() {
return message;
}

public void setMessage(String message) {
this.message = message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.examples.workflows;

public class DemoActivityOutput {

private String originalMessage;
private String newMessage;

public DemoActivityOutput() {
}

public DemoActivityOutput(String originalMessage, String newMessage) {
this.originalMessage = originalMessage;
this.newMessage = newMessage;
}

public String getOriginalMessage() {
return originalMessage;
}

public void setOriginalMessage(String originalMessage) {
this.originalMessage = originalMessage;
}

public String getNewMessage() {
return newMessage;
}

public void setNewMessage(String newMessage) {
this.newMessage = newMessage;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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.examples.workflows;

import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;

/**
* Implementation of the DemoWorkflow for the server side.
*/
public class DemoSubWorkflow extends Workflow {
@Override
public WorkflowStub create() {
return ctx -> {

var logger = ctx.getLogger();
logger.info("Child-Workflow> Started: " + ctx.getName());
logger.info("Child-Workflow> Instance ID: " + ctx.getInstanceId());
logger.info("Child-Workflow> Current Time: " + ctx.getCurrentInstant());

var input = ctx.getInput(String.class);
logger.info("Child-Workflow> Input: " + input);

logger.info("Child-Workflow> Completed");
ctx.complete("result: " + input);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,114 @@

package io.dapr.examples.workflows;

import com.microsoft.durabletask.CompositeTaskFailedException;
import com.microsoft.durabletask.Task;
import com.microsoft.durabletask.TaskCanceledException;
import io.dapr.workflows.Workflow;
import io.dapr.workflows.WorkflowStub;

import java.time.Duration;
import java.util.Arrays;
import java.util.List;

/**
* Implementation of the DemoWorkflow for the server side.
*/
public class DemoWorkflow extends Workflow {

@Override
public WorkflowStub create() {
return ctx -> {
ctx.getLogger().info("Starting Workflow: " + ctx.getName());
ctx.getLogger().info("Instance ID: " + ctx.getInstanceId());
ctx.getLogger().info("Waiting for event: 'myEvent'...");
ctx.getLogger().info("Current Orchestration Time: " + ctx.getCurrentInstant());
ctx.getLogger().info("Waiting for event: 'TimedOutEvent'...");
try {
ctx.waitForExternalEvent("TimedOutEvent", Duration.ofSeconds(10)).await();
} catch (TaskCanceledException e) {
ctx.getLogger().warn("Timed out");
ctx.getLogger().warn(e.getMessage());
}

ctx.getLogger().info("Waiting for event: 'TestEvent'...");
try {
ctx.waitForExternalEvent("TestEvent", Duration.ofSeconds(10)).await();
ctx.getLogger().info("Received TestEvent");
} catch (TaskCanceledException e) {
ctx.getLogger().warn("Timed out");
ctx.getLogger().warn(e.getMessage());
}

ctx.getLogger().info("Parallel Execution - Waiting for all tasks to finish...");
try {
Task<String> t1 = ctx.waitForExternalEvent("event1", Duration.ofSeconds(5), String.class);
Task<String> t2 = ctx.waitForExternalEvent("event2", Duration.ofSeconds(5), String.class);
Task<String> t3 = ctx.waitForExternalEvent("event3", Duration.ofSeconds(5), String.class);

List<String> results = ctx.allOf(Arrays.asList(t1, t2, t3)).await();
results.forEach(t -> ctx.getLogger().info("finished task: " + t));
ctx.getLogger().info("All tasks finished!");

} catch (CompositeTaskFailedException e) {
ctx.getLogger().warn(e.getMessage());
List<Exception> exceptions = e.getExceptions();
exceptions.forEach(ex -> ctx.getLogger().warn(ex.getMessage()));
}

ctx.getLogger().info("Parallel Execution - Waiting for any task to finish...");
try {
ctx.waitForExternalEvent("myEvent", Duration.ofSeconds(10)).await();
ctx.getLogger().info("Received!");
Task<String> e1 = ctx.waitForExternalEvent("e1", Duration.ofSeconds(5), String.class);
Task<String> e2 = ctx.waitForExternalEvent("e2", Duration.ofSeconds(5), String.class);
Task<String> e3 = ctx.waitForExternalEvent("e3", Duration.ofSeconds(5), String.class);
Task<Void> timeoutTask = ctx.createTimer(Duration.ofSeconds(1));

Task<?> winner = ctx.anyOf(Arrays.asList(e1, e2, e3, timeoutTask)).await();
if (winner == timeoutTask) {
ctx.getLogger().info("All tasks timed out!");
} else {
ctx.getLogger().info("One of the tasks finished!");
}
} catch (TaskCanceledException e) {
ctx.getLogger().warn("Timed out");
ctx.getLogger().warn(e.getMessage());
}
ctx.complete("finished");

ctx.getLogger().info("Calling Activity...");
var input = new DemoActivityInput("Hello Activity!");
var output = ctx.callActivity(DemoWorkflowActivity.class.getName(), input, DemoActivityOutput.class).await();

ctx.getLogger().info("Activity returned: " + output);
ctx.getLogger().info("Activity returned: " + output.getNewMessage());
ctx.getLogger().info("Activity returned: " + output.getOriginalMessage());


boolean shouldComplete = true;
ctx.getLogger().info("Waiting for event: 'RestartEvent'...");
try {
ctx.waitForExternalEvent("RestartEvent", Duration.ofSeconds(10)).await();
ctx.getLogger().info("Received RestartEvent");
ctx.getLogger().info("Restarting Workflow by calling continueAsNew...");
ctx.continueAsNew("TestInputRestart", false);
shouldComplete = false;
} catch (TaskCanceledException e) {
ctx.getLogger().warn("Restart Timed out");
ctx.getLogger().warn(e.getMessage());
}

if (shouldComplete) {
ctx.getLogger().info("Child-Workflow> Calling ChildWorkflow...");
var childWorkflowInput = "Hello ChildWorkflow!";
var childWorkflowOutput =
ctx.callSubWorkflow(DemoSubWorkflow.class.getName(), childWorkflowInput, String.class).await();

ctx.getLogger().info("Child-Workflow> returned: " + childWorkflowOutput);

ctx.getLogger().info("Workflow finished");
ctx.complete("finished");

return;
}

ctx.getLogger().info("Workflow restarted");
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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.examples.workflows;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import io.dapr.workflows.runtime.WorkflowActivity;
import io.dapr.workflows.runtime.WorkflowActivityContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.TimeUnit;

@JsonAutoDetect(fieldVisibility = JsonAutoDetect.Visibility.ANY)
public class DemoWorkflowActivity implements WorkflowActivity {

@Override
public DemoActivityOutput run(WorkflowActivityContext ctx) {
Logger logger = LoggerFactory.getLogger(DemoWorkflowActivity.class);
logger.info("Starting Activity: " + ctx.getName());

var message = ctx.getInput(DemoActivityInput.class).getMessage();
var newMessage = message + " World!, from Activity";
logger.info("Message Received from input: " + message);
logger.info("Sending message to output: " + newMessage);

logger.info("Sleeping for 5 seconds to simulate long running operation...");

try {
TimeUnit.SECONDS.sleep(5);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}


logger.info("Activity finished");

var output = new DemoActivityOutput(message, newMessage);
logger.info("Activity returned: " + output);

return output;
}
}
Loading
Loading