Skip to content

Commit

Permalink
Workflow Implementation - Continues... (#880)
Browse files Browse the repository at this point in the history
* Add ElementType.Type to ActorType (#812)

Signed-off-by: LionTao <taojiachun980831@163.com>

Signed-off-by: LionTao <taojiachun980831@163.com>
Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Bump codecov/codecov-action from 3.1.0 to 3.1.1 (#788)

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3.1.0 to 3.1.1.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/master/CHANGELOG.md)
- [Commits](codecov/codecov-action@v3.1.0...v3.1.1)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Update springboot to latest minor.patch version. (#826)

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Use runtime 1.10.0-rc.X and CLI 1.10.0-rc.X (#827)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Upgrade the version to 1.9.0-SNAPSHOT (#829)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Generate updated javadocs for 1.8.0 (#836)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Update Dapr runtime and CLI to 1.10. (#837)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Inject autoconfiguration in the Spring Boot 3 style (#831)

* Bump from spring boot 2.3.5.RELEASE to 2.7.8

Signed-off-by: Sergio <champel@gmail.com>
(cherry picked from commit 9152c91)

* Ensure old versions of spring boot are still compatible

Signed-off-by: Sergio <champel@gmail.com>

---------

Signed-off-by: champel <champel@gmail.com>
Signed-off-by: Sergio <champel@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Bump from reactor 2.3.5.RELEASE to 2.7.8 (#830)

* Bump from reactor 2.3.5.RELEASE to 2.7.8

Signed-off-by: Sergio <champel@gmail.com>

* Simplification

Signed-off-by: Sergio <champel@gmail.com>

---------

Signed-off-by: Sergio <champel@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Test multiple reminder state types + improve timer tests. (#855)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Convert Config API to Stable endpoints. (#846)

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Add PubSub subscriber examples over gPRC (#833)

* add grpc subscriber

Signed-off-by: MregXN <mregxn@gmail.com>

* modify README.md

Signed-off-by: MregXN <mregxn@gmail.com>

* modify README.md in examples

Signed-off-by: MregXN <mregxn@gmail.com>

* Modify DaprApplication to support examples where protocol is not specified.

Signed-off-by: MregXN <mregxn@gmail.com>

* modify formatter to pass checkstyle

Signed-off-by: MregXN <mregxn@gmail.com>

* Update springboot to latest minor.patch version. (#826)

Signed-off-by: MregXN <mregxn@gmail.com>

* Use runtime 1.10.0-rc.X and CLI 1.10.0-rc.X (#827)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: MregXN <mregxn@gmail.com>

* Upgrade the version to 1.9.0-SNAPSHOT (#829)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: MregXN <mregxn@gmail.com>

* Generate updated javadocs for 1.8.0 (#836)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: MregXN <mregxn@gmail.com>

* Update Dapr runtime and CLI to 1.10. (#837)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: MregXN <mregxn@gmail.com>

* Inject autoconfiguration in the Spring Boot 3 style (#831)

* Bump from spring boot 2.3.5.RELEASE to 2.7.8

Signed-off-by: Sergio <champel@gmail.com>
(cherry picked from commit 9152c91)

* Ensure old versions of spring boot are still compatible

Signed-off-by: Sergio <champel@gmail.com>

---------

Signed-off-by: champel <champel@gmail.com>
Signed-off-by: Sergio <champel@gmail.com>
Signed-off-by: MregXN <mregxn@gmail.com>

* Bump from reactor 2.3.5.RELEASE to 2.7.8 (#830)

* Bump from reactor 2.3.5.RELEASE to 2.7.8

Signed-off-by: Sergio <champel@gmail.com>

* Simplification

Signed-off-by: Sergio <champel@gmail.com>

---------

Signed-off-by: Sergio <champel@gmail.com>
Signed-off-by: MregXN <mregxn@gmail.com>

* rerun checks

Signed-off-by: MregXN <mregxn@gmail.com>

* modify the way of grpc server starts

Signed-off-by: MregXN <mregxn@gmail.com>

* modify README

Signed-off-by: MregXN <mregxn@gmail.com>

* Update pom.xml

Signed-off-by: MregXN <46479059+MregXN@users.noreply.github.com>

---------

Signed-off-by: MregXN <mregxn@gmail.com>
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: champel <champel@gmail.com>
Signed-off-by: Sergio <champel@gmail.com>
Signed-off-by: MregXN <46479059+MregXN@users.noreply.github.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Co-authored-by: champel <champel@gmail.com>
Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* auto validate actors (#863)

Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Bump codecov/codecov-action from 3.1.1 to 3.1.4 (#862)

Bumps [codecov/codecov-action](https://github.com/codecov/codecov-action) from 3.1.1 to 3.1.4.
- [Release notes](https://github.com/codecov/codecov-action/releases)
- [Changelog](https://github.com/codecov/codecov-action/blob/main/CHANGELOG.md)
- [Commits](codecov/codecov-action@v3.1.1...v3.1.4)

---
updated-dependencies:
- dependency-name: codecov/codecov-action
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Fix 787 (#832)

* prepare before testing

* Update tests

* fix checkstyle

---------

Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Upgrade to 1.11 RCs. (#867)

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Init for workflows

Signed-off-by: Bill DeRusha <billderusha@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Updating some javadocs and Years.

Signed-off-by: Hannah Kennedy <hakenned@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Add missing Header

Signed-off-by: Hannah Kennedy <hakenned@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* respond to PR feedback

Signed-off-by: Bill DeRusha <444835+bderusha@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Update workflow example README

Signed-off-by: Bill DeRusha <444835+bderusha@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Address PR feedback

Signed-off-by: Bill DeRusha <444835+bderusha@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* fixup deprecated pom.xml variable

Signed-off-by: Bill DeRusha <444835+bderusha@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Updates based on PR feedback

Signed-off-by: Bill DeRusha <444835+bderusha@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Update pom files per feedback

Signed-off-by: Bill DeRusha <444835+bderusha@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* GetInstanceState implementation (#1)

* addiny getInstanceMetadata, waitForInstanceStart and waitForInstanceCompletion implementation
---------

Co-authored-by: aymanmahmoud_microsoft <aymanmahmoud@microsoft.com>
Signed-off-by: Aymand Mahmoud <aymanmahmoud@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Management API

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* remove try/catch

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* implementing getIsReplaying() method for Authoring API (#7)

Co-authored-by: Julio Rezende <jsilvarezend@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>
Signed-off-by: Julio Rezende <jsilvarezend@microsoft.com>

* Implementing getCurrentInstant() authoring method (#5)

Co-authored-by: Julio Rezende <jsilvarezend@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>
Signed-off-by: Julio Rezende <jsilvarezend@microsoft.com>

* Activity Implementation (#3)

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* fixing issue with getIsReplaying() call (#8)

Co-authored-by: Julio Rezende <jsilvarezend@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>
Signed-off-by: Julio Rezende <jsilvarezend@microsoft.com>

* Generate updated javadocs for 1.9.0 (#878)

* Generate updated javadocs for 1.9.0

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

* Update _index.md

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

---------

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Add .sdkmanrc config file and JDK installation instructions (#873)

* Add .sdkmanrc file with installation instructions

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>

* Update README.md

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

---------

Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Co-authored-by: Artur Souza <asouza.pro@gmail.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Add unit testing example

Signed-off-by: Bill DeRusha <444835+bderusha@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* implementing getIsReplaying() method for Authoring API (#7)

Co-authored-by: Julio Rezende <jsilvarezend@microsoft.com>

Signed-off-by: Julio Rezende <jsilvarezend@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* fix parent pom

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Send Event Implementation (#10)

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Implementing allOf, anyOf, createTimer methods (#11)

Co-authored-by: Julio Rezende <jsilvarezend@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>
Co-authored-by: Julio Rezende <jsilvarezend@microsoft.com>

* Support remote endpoint. (#877)

* Support remote endpoint.

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

* Use GRPC_ENDPOINT and HTTP_ENDPOINT in integration tests.

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

* Fix happy path for waiting for sidecar test.

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

---------

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Add callSubWorkflow Implementation

Co-authored-by: Aymand Mahmoud <aymanmahmoud@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>
Signed-off-by: Aymand Mahmoud <aymanmahmoud@microsoft.com>

* rename DemoSubWorkflow

Co-authored-by: Aymand Mahmoud <aymanmahmoud@microsoft.com>
Signed-off-by: Aymand Mahmoud <aymanmahmoud@microsoft.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* continueAsNew Implementation (#13)

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* remove duplicate class

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* add missing mockito test dependency

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* use new workflow client implementation

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* moved implementations to new workflow and context

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* relocate duplicate implemantation

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* remove duplicate test and increase test coverage

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* Implement retry and timeout policy for gRPC client. (#889)

* Implement retry and timeout policy for gRPC client.

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

* Fix invoke actor after aborted flow.

Signed-off-by: Artur Souza <asouza.pro@gmail.com>

---------

Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* renamed getIsReplaying

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* rollback changes on client

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* move workflow runtime state package

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* rename workflow instance state to status

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* remove unnecessary else

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* removed unknown state

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* updated comment

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* updated workflow failure details

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* fix style issues

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* rollback merge change

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* fixed pom files

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* rollback actors pom changes on autoformat

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* fixe actors pom

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* fix styling on actors pom

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* fix pom spacing

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* move test to match the package

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* add missing dependencies

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* increased test coverage

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* moved workflow runtime package

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* add exception for missing case

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* add null check for metadata

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* add runtime exception error messages

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* update try catch scope

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* update activity definition to an interface

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* update comments

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* removed redundant method

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

* PR updates

Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>

---------

Signed-off-by: LionTao <taojiachun980831@163.com>
Signed-off-by: Mahmut Canga <cangamahmut@gmail.com>
Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Artur Souza <asouza.pro@gmail.com>
Signed-off-by: champel <champel@gmail.com>
Signed-off-by: Sergio <champel@gmail.com>
Signed-off-by: MregXN <mregxn@gmail.com>
Signed-off-by: MregXN <46479059+MregXN@users.noreply.github.com>
Signed-off-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Signed-off-by: Bill DeRusha <billderusha@microsoft.com>
Signed-off-by: Hannah Kennedy <hakenned@microsoft.com>
Signed-off-by: Bill DeRusha <444835+bderusha@users.noreply.github.com>
Signed-off-by: Aymand Mahmoud <aymanmahmoud@microsoft.com>
Signed-off-by: Julio Rezende <jsilvarezend@microsoft.com>
Signed-off-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>
Signed-off-by: Mahmut Canga <macromania@users.noreply.github.com>
Co-authored-by: LionTao <taojiachun980831@163.com>
Co-authored-by: Mukundan Sundararajan <65565396+mukundansundar@users.noreply.github.com>
Co-authored-by: Artur Souza <artursouza.ms@outlook.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: champel <champel@gmail.com>
Co-authored-by: MregXN <46479059+MregXN@users.noreply.github.com>
Co-authored-by: MatejNedic <matejnedic1@gmail.com>
Co-authored-by: Bill DeRusha <billderusha@microsoft.com>
Co-authored-by: Hannah Kennedy <hakenned@microsoft.com>
Co-authored-by: Bill DeRusha <444835+bderusha@users.noreply.github.com>
Co-authored-by: Aymalla <Aymalla@outlook.com>
Co-authored-by: aymanmahmoud_microsoft <aymanmahmoud@microsoft.com>
Co-authored-by: swetakumari <swetakumari@microsoft.com>
Co-authored-by: julio <107879411+julioalex-rezende@users.noreply.github.com>
Co-authored-by: Julio Rezende <jsilvarezend@microsoft.com>
Co-authored-by: Emanuel Alves <emanuel.j.b.alves@gmail.com>
Co-authored-by: Artur Souza <asouza.pro@gmail.com>
  • Loading branch information
18 people authored Sep 13, 2023
1 parent 85ffe8e commit 056aed4
Show file tree
Hide file tree
Showing 28 changed files with 2,286 additions and 95 deletions.
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

0 comments on commit 056aed4

Please sign in to comment.