This is an automated email from the ASF dual-hosted git repository.
wmedvedeo pushed a commit to branch main
in repository
https://gitbox.apache.org/repos/asf/incubator-kie-kogito-examples.git
The following commit(s) were added to refs/heads/main by this push:
new e59684523 kie-kogito-examples-2119: Create an example showing how to
confugre the Circuit Breaker Pattern (#2120)
e59684523 is described below
commit e59684523bbb8610dc302c7007d746d87a181205
Author: Walter Medvedeo <[email protected]>
AuthorDate: Fri Aug 8 18:29:34 2025 +0200
kie-kogito-examples-2119: Create an example showing how to confugre the
Circuit Breaker Pattern (#2120)
* kie-kogito-examples-2119: Create an example showing how to confugre the
Circuit Breaker Pattern
* Apply suggestions from code review
Co-authored-by: Gonzalo Muñoz <[email protected]>
* Apply suggestions from code review
Co-authored-by: Gonzalo Muñoz <[email protected]>
* Apply suggestions from code review
---------
Co-authored-by: Gonzalo Muñoz <[email protected]>
---
serverless-workflow-examples/pom.xml | 1 +
.../serverless-workflow-fault-tolerance/.gitignore | 38 ++++
.../serverless-workflow-fault-tolerance/Readme.md | 247 +++++++++++++++++++++
.../docs/call-echo-service-circuit-breaker.drawio | 81 +++++++
.../docs/circuit-breaker-call.png | Bin 0 -> 16600 bytes
.../docs/circuit-breaker-class-name.png | Bin 0 -> 87930 bytes
.../docs/circuit-breaker-generated-sources.png | Bin 0 -> 28083 bytes
.../serverless-workflow-fault-tolerance/pom.xml | 181 +++++++++++++++
.../src/main/docker/Dockerfile.jvm | 98 ++++++++
.../src/main/docker/Dockerfile.legacy-jar | 94 ++++++++
.../src/main/docker/Dockerfile.native | 29 +++
.../src/main/docker/Dockerfile.native-micro | 32 +++
.../java/org/kie/kogito/examples/AdminRequest.java | 24 ++
.../java/org/kie/kogito/examples/EchoResponse.java | 31 +++
.../kogito/examples/ExternalServiceResource.java | 62 ++++++
.../src/main/resources/application.properties | 41 ++++
.../src/main/resources/call-echo.sw.yml | 22 ++
.../src/main/resources/specs/external-service.yaml | 79 +++++++
.../java/org/kie/kogito/examples/CallEchoIT.java | 77 +++++++
19 files changed, 1137 insertions(+)
diff --git a/serverless-workflow-examples/pom.xml
b/serverless-workflow-examples/pom.xml
index c9bb9cf6f..a83c8bf9d 100644
--- a/serverless-workflow-examples/pom.xml
+++ b/serverless-workflow-examples/pom.xml
@@ -81,6 +81,7 @@
<module>serverless-workflow-timeouts-showcase-operator-devprofile</module>
<module>serverless-workflow-python-quarkus</module>
<module>sonataflow-fluent</module>
+ <module>serverless-workflow-fault-tolerance</module>
</modules>
</profile>
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/.gitignore
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/.gitignore
new file mode 100644
index 000000000..5ff6309b7
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/.gitignore
@@ -0,0 +1,38 @@
+target/
+!.mvn/wrapper/maven-wrapper.jar
+!**/src/main/**/target/
+!**/src/test/**/target/
+
+### IntelliJ IDEA ###
+.idea/modules.xml
+.idea/jarRepositories.xml
+.idea/compiler.xml
+.idea/libraries/
+*.iws
+*.iml
+*.ipr
+
+### Eclipse ###
+.apt_generated
+.classpath
+.factorypath
+.project
+.settings
+.springBeans
+.sts4-cache
+
+### NetBeans ###
+/nbproject/private/
+/nbbuild/
+/dist/
+/nbdist/
+/.nb-gradle/
+build/
+!**/src/main/**/build/
+!**/src/test/**/build/
+
+### VS Code ###
+.vscode/
+
+### Mac OS ###
+.DS_Store
\ No newline at end of file
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/Readme.md
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/Readme.md
new file mode 100644
index 000000000..f9d52243d
--- /dev/null
+++ b/serverless-workflow-examples/serverless-workflow-fault-tolerance/Readme.md
@@ -0,0 +1,247 @@
+# Kogito Serverless Workflow Fault Tolerance
+
+This example shows how to configure fault tolerance alternatives when you work
with workflows.
+
+## Circuit Breaker Pattern
+
+Every REST call executed by a workflow can be configured to use the Circuit
Breaker Pattern.
+
+
+
+The internals of the pattern configuration and execution are based on the
[MicroProfile Fault
Tolerance](https://github.com/eclipse/microprofile-fault-tolerance/)
specification,
+and the corresponding [Smallrye Fault
Tolerance](https://github.com/smallrye/smallrye-fault-tolerance) implementation
shipped with Quarkus.
+
+The following example shows how to configure the
[call-echo](src/main/resources/call-echo.sw.yml) workflow to use the Circuit
Breaker Pattern to execute the `circuitBreakerEcho` operation provided by the
[external-service](src/main/resources/specs/external-service.yaml).
+
+### Build time configurations
+
+
+To enable and configure the Circuit Breaker you must follow this procedure:
+
+1. Add the following maven dependency to your project:
+````
+<dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-smallrye-fault-tolerance</artifactId>
+</dependency>
+````
+
+2. Enable the Circuit Breaker
+
+When a workflow uses REST calls, behind the scene, a set of classes are
generated to support these invocations.
+In general, the generation is transparent, and you don't need to pay attention
on it.
+
+However, to enable the Circuit Breaker, you must provide some configurations
that are related to that generation, and impacts the generated code.
+
+The first step is to find the generated Java class name that is registered as
the Microprofile Rest Client to access the external service.
+
+The following picture shows how this class name is calculated at code
generation time:
+
+
+
+We recommend that you build the project and inspect the generated sources
under the directory
`target/generated-sources/open-api-stream/org/kie/kogito/openapi`:
+
+
+
+
+By default, when the Circuit Breaker is not enabled, the generated signature
for the Java method corresponding to the `circuitBreakerEcho` operation will
look like this:
+
+````
[email protected](name="",
openApiSpecId="external_service_yaml", operationId="circuitBreakerEcho",
method="POST", path="/external-service/circuit-breaker")
[email protected]
[email protected]("/circuit-breaker")
[email protected]({"text/plain"})
[email protected]({"application/json"})
[email protected]("circuitBreakerEcho")
+public EchoResponse circuitBreakerEcho(
+ String body
+);
+````
+
+Given the class name
`org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi`, and
the method `circuitBreakerEcho`,
+to enable the Circuit Breaker, you must add the following entry in the
`application.properties`:
+
+````
+org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho/CircuitBreaker/enabled=true
+````
+
+In general, for any other operation you must follow this pattern:
+
+`<classname>/<methodname>/CircuitBreaker/enabled=true`
+
+* classname: is the fully qualified name of the generated class.
+* methodname: is the name of the method corresponding to the given operation.
+
+
+> **NOTE:** Every operation must be configured individually, and different
operations might be located in different classes.
+
+After adding the configuration, the next build will generate the following
signature:
+
+````
[email protected](name="",
openApiSpecId="external_service_yaml", operationId="circuitBreakerEcho",
method="POST", path="/external-service/circuit-breaker")
[email protected]
[email protected]("/circuit-breaker")
[email protected]({"text/plain"})
[email protected]({"application/json"})
[email protected]("circuitBreakerEcho")
[email protected]
+public EchoResponse circuitBreakerEcho(
+ String body
+);
+````
+
+If the `@org.eclipse.microprofile.faulttolerance.CircuitBreaker` annotation is
present in the generated method signature,
+it means that the configuration was set correct.
+
+If you don't see the annotation, we recommend that you navigate and look into
the generated sources to find the correct class name, or any potential typo in
the property name, etc.
+
+3. Configure other behavioural properties:
+
+The build time behavioural properties are used to define configurations like
thresholds and delays, for more information
[see](https://quarkus.io/version/3.20/guides/smallrye-fault-tolerance#configuration-reference).
+
+To create these properties you must follow this pattern:
+
+`quarkus.fault-tolerance."<classname>/<methodname>".<property>=<value>`
+* classname: is the fully qualified name of the generated class.
+* methodname: is the name of the method corresponding to the given operation.
+
+Below is the configuration used for the example:
+
+````
+# Build time property to add the Circuit Breaker capability to the
corresponding generated class/method, by annotating
+# it with the eclipse microprofile
@org.eclipse.microprofile.faulttolerance.CircuitBreaker.
+# NOTE: this property doesn't follow the quarkus.fault-tolerance.xxx prefix,
you must use this format instead.
+org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho/CircuitBreaker/enabled=true
+
+# Configuration values for the sake of current example. Produces a quick
circuit Open, and a long delayed transitioning
+# to the Half Closed state. Don't consider this as suggested configurations
for a production system.
+
+# Use a rolling window of 4 consecutive requests
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.request-volume-threshold=4
+# With a ratio of .5, if 2 requests fail, the circuit is Opened.
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.failure-ratio=0.5
+
+# Wait 2 minutes before the Open circuit goes to the Half Open state.
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.delay=2
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.delay-unit=minutes
+````
+
+### Executing the example
+
+#### Prerequisites
+
+You will need:
+- Java 17+ installed
+- Environment variable JAVA_HOME set accordingly
+- Maven 3.9.6+ installed
+
+##### Executing in Quarkus Dev mode
+
+To see the Circuit Breaker behaviour, we recommend that you follow this
procedure:
+
+1. Start the workflow:
+
+````
+mvn quarkus:dev
+````
+
+2. Execute the workflow to verify a regular execution (without errors):
+
+````
+curl -X 'POST' \
+'http://localhost:8080/call-echo' \
+-H 'accept: */*' \
+-H 'Content-Type: application/json' \
+-d '{ "echo" : "Hello!" }'
+````
+
+You will see an output like this:
+
+````
+{
+ "id": "2de57de7-38f7-4a33-bb7e-670bedefbcf1",
+ "workflowdata": {
+ "echo": "Hello!",
+ "echoResult": {
+ "id": "cf3405af-c903-4a7f-86cc-d2287d383d36",
+ "echo": "Hello!",
+ "createdAt": "2025-08-04T12:03:35.705894795+02:00[Europe/Madrid]"
+ }
+ }
+}
+````
+
+3. Configure the external service `circuitBreakerEcho` operation to fail using
the following command:
+
+````
+curl -X 'POST' \
+ 'http://localhost:8080/external-service/admin' \
+ -H 'accept: */*' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "operation": "circuitBreakerEcho",
+ "enabled": false
+}'
+````
+> **NOTE:** The external service was designed to expose an `/admin` endpoint
that can be used to program the `circuitBreakerEcho` operation intentionally to
fail.
+
+4. Execute the workflow again with the following command:
+
+````
+curl -X 'POST' \
+'http://localhost:8080/call-echo' \
+-H 'accept: */*' \
+-H 'Content-Type: application/json' \
+-d '{ "echo" : "Hello!" }'
+````
+
+This time you will see an output with the HTTP 500 error code. This means that
the workflow has executed the regular
+call to the external service `circuitBreakerEcho` operation, and has got the
error. The circuit is in the `Closed` status.
+````
+{
+ "errorCode": "500",
+ "failedNodeId": "6",
+ "id": "5e731491-8850-44de-a3c5-a68fd2817af6",
+ "message": "HTTP 500 Internal Server Error"
+}
+````
+
+5. Repeat 3 or more executions of the workflow execution command. And, this
time, you will start to see the following result:
+
+````
+{
+ "failedNodeId": "6",
+ "id": "f3f12ca3-2a1e-4267-9d82-a0ee3d9acd80",
+ "message":
"org.eclipse.microprofile.faulttolerance.exceptions.CircuitBreakerOpenException
-
org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi#circuitBreakerEcho
circuit breaker is open"
+}
+````
+
+This means that circuit has transitioned to the `Open` status, and thus, no
call to external service is produced.
+Instead, the fault tolerance layer is producing the error.
+
+6. Configure the external service `circuitBreakerEcho` operation to go back to
normal execution with the following command:
+
+````
+curl -X 'POST' \
+ 'http://localhost:8080/external-service/admin' \
+ -H 'accept: */*' \
+ -H 'Content-Type: application/json' \
+ -d '{
+ "operation": "circuitBreakerEcho",
+ "enabled": true
+}'
+````
+
+This time, the external service will not fail if executed, however, if you
repeat the workflow execution during the next 2 minutes,
+you will continue getting the
org.eclipse.microprofile.faulttolerance.exceptions.CircuitBreakerOpenException,
since
+the circuit will remain in the `Open` status because of the following
configuration:
+
+````
+# Wait 2 minutes before an Open circuit goes to the Half Open state.
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.delay=2
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.delay-unit=minutes
+````
+
+After this time, the circuit will transition to the `Half Closed`, and
`Closed` status as expected. And the workflow execution
+will be successful again.
+
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/call-echo-service-circuit-breaker.drawio
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/call-echo-service-circuit-breaker.drawio
new file mode 100644
index 000000000..791eba5d8
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/call-echo-service-circuit-breaker.drawio
@@ -0,0 +1,81 @@
+<mxfile host="Electron" agent="Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) draw.io/28.0.6 Chrome/138.0.7204.100
Electron/37.2.3 Safari/537.36" version="28.0.6">
+ <diagram name="Page-1" id="kT6VziIJ9WOg-az2wQL0">
+ <mxGraphModel dx="1069" dy="441" grid="0" gridSize="10" guides="1"
tooltips="1" connect="1" arrows="1" fold="1" page="0" pageScale="1"
pageWidth="850" pageHeight="1100" math="0" shadow="0">
+ <root>
+ <mxCell id="0" />
+ <mxCell id="1" parent="0" />
+ <mxCell id="ie0a6XAnm1fHVkazy7zu-1" value="workflow"
style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
+ <mxGeometry x="104" y="130" width="150" height="60" as="geometry" />
+ </mxCell>
+ <mxCell id="ie0a6XAnm1fHVkazy7zu-2" value="external service"
style="rounded=1;whiteSpace=wrap;html=1;" parent="1" vertex="1">
+ <mxGeometry x="511" y="130" width="150" height="60" as="geometry" />
+ </mxCell>
+ <mxCell id="ie0a6XAnm1fHVkazy7zu-4" value=""
style="ellipse;whiteSpace=wrap;html=1;aspect=fixed;" parent="1" vertex="1">
+ <mxGeometry x="455" y="155" width="10" height="10" as="geometry" />
+ </mxCell>
+ <mxCell id="ie0a6XAnm1fHVkazy7zu-6" value=""
style="endArrow=none;html=1;rounded=0;entryX=1;entryY=0.5;entryDx=0;entryDy=0;"
parent="1" source="ie0a6XAnm1fHVkazy7zu-2" target="ie0a6XAnm1fHVkazy7zu-4"
edge="1">
+ <mxGeometry width="50" height="50" relative="1" as="geometry">
+ <mxPoint x="380" y="340" as="sourcePoint" />
+ <mxPoint x="430" y="290" as="targetPoint" />
+ </mxGeometry>
+ </mxCell>
+ <mxCell id="ie0a6XAnm1fHVkazy7zu-10" value=""
style="endArrow=classic;html=1;rounded=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;dashed=1;endFill=1;"
parent="1" source="ie0a6XAnm1fHVkazy7zu-1" edge="1">
+ <mxGeometry width="50" height="50" relative="1" as="geometry">
+ <mxPoint x="380" y="340" as="sourcePoint" />
+ <mxPoint x="300" y="160" as="targetPoint" />
+ </mxGeometry>
+ </mxCell>
+ <mxCell id="ie0a6XAnm1fHVkazy7zu-15" value=""
style="pointerEvents=1;verticalLabelPosition=bottom;shadow=0;dashed=0;align=center;html=1;verticalAlign=top;shape=mxgraph.electrical.electro-mechanical.selectorSwitch3Position2;elSwitchState=1;strokeWidth=2;"
parent="1" vertex="1">
+ <mxGeometry x="313" y="137" width="75" height="46" as="geometry" />
+ </mxCell>
+ <mxCell id="ie0a6XAnm1fHVkazy7zu-16" value=""
style="endArrow=classic;html=1;rounded=0;exitX=1;exitY=0.5;exitDx=0;exitDy=0;dashed=1;endFill=1;"
parent="1" edge="1">
+ <mxGeometry width="50" height="50" relative="1" as="geometry">
+ <mxPoint x="400" y="160" as="sourcePoint" />
+ <mxPoint x="449" y="160" as="targetPoint" />
+ </mxGeometry>
+ </mxCell>
+ <mxCell id="Y1-DxkTYomo4t4mVsWZb-2" value="<div
style="background-color: rgb(255, 255, 255); color: rgb(8, 8, 8);
font-family: &quot;JetBrains Mono&quot;, monospace;
white-space-collapse: preserve;"><font style="font-size:
16px;"><span style="color: rgb(0, 51,
179);">functions</span>:<br> - <span style="color:
rgb(0, 51, 179);">name</span>:
circuitBreakerEchoFunction<br> <span s [...]
+ <mxGeometry x="51" y="1134" width="606" height="89" as="geometry" />
+ </mxCell>
+ <mxCell id="Y1-DxkTYomo4t4mVsWZb-4" value="<div
style="background-color: rgb(255, 255, 255); color: rgb(8, 8, 8);
font-family: &quot;JetBrains Mono&quot;, monospace;
white-space-collapse: preserve;"><font style="font-size:
16px;"><span style="color: rgb(0, 51,
179);">/external-service/circuit-breaker</span>:<br>
<span style="color: rgb(0, 51,
179);">post</span>:<br> <span style= [...]
+ <mxGeometry x="686" y="1120" width="451" height="204" as="geometry"
/>
+ </mxCell>
+ <mxCell id="Y1-DxkTYomo4t4mVsWZb-5" value="<div
style="background-color: rgb(255, 255, 255); color: rgb(8, 8, 8);
font-family: &quot;JetBrains Mono&quot;, monospace; white-space:
pre;"><font style="font-size:
16px;">org.kie.kogito.openapi.<b
style="">externalservice</b>.api.<b
style="">ExternalServiceResourceApi</b></font></div>"
style="text;html=1;align=center;verticalAlign=middle;whi [...]
+ <mxGeometry x="509" y="1393" width="60" height="30" as="geometry" />
+ </mxCell>
+ <mxCell id="Y1-DxkTYomo4t4mVsWZb-7" value=""
style="shape=curlyBracket;whiteSpace=wrap;html=1;rounded=1;flipH=1;labelPosition=right;verticalLabelPosition=middle;align=left;verticalAlign=middle;direction=north;"
parent="1" vertex="1">
+ <mxGeometry x="253" y="1203" width="152" height="20" as="geometry" />
+ </mxCell>
+ <mxCell id="Y1-DxkTYomo4t4mVsWZb-9" value=""
style="endArrow=classic;html=1;rounded=0;dashed=1;" parent="1" edge="1">
+ <mxGeometry width="50" height="50" relative="1" as="geometry">
+ <mxPoint x="329" y="1230" as="sourcePoint" />
+ <mxPoint x="500" y="1390" as="targetPoint" />
+ <Array as="points">
+ <mxPoint x="329" y="1314" />
+ <mxPoint x="500" y="1314" />
+ </Array>
+ </mxGeometry>
+ </mxCell>
+ <mxCell id="Y1-DxkTYomo4t4mVsWZb-10" value=""
style="shape=curlyBracket;whiteSpace=wrap;html=1;rounded=1;flipH=1;labelPosition=right;verticalLabelPosition=middle;align=left;verticalAlign=middle;direction=north;"
parent="1" vertex="1">
+ <mxGeometry x="767" y="1317" width="237" height="20" as="geometry" />
+ </mxCell>
+ <mxCell id="Y1-DxkTYomo4t4mVsWZb-11" value=""
style="endArrow=classic;html=1;rounded=0;exitX=0.1;exitY=0.5;exitDx=0;exitDy=0;exitPerimeter=0;dashed=1;"
parent="1" source="Y1-DxkTYomo4t4mVsWZb-10" edge="1">
+ <mxGeometry width="50" height="50" relative="1" as="geometry">
+ <mxPoint x="510" y="1350" as="sourcePoint" />
+ <mxPoint x="720" y="1390" as="targetPoint" />
+ <Array as="points">
+ <mxPoint x="886" y="1360" />
+ <mxPoint x="720" y="1360" />
+ </Array>
+ </mxGeometry>
+ </mxCell>
+ <mxCell id="Y1-DxkTYomo4t4mVsWZb-13" value="<span
style="color: rgb(8, 8, 8); font-family: &quot;JetBrains
Mono&quot;, monospace; text-align: left; white-space: pre;
background-color: rgb(255, 255, 255);"><b
style=""><font style="font-size:
16px;">call-echo.sw.yaml</font></b></span>"
style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;"
parent="1" vertex="1">
+ <mxGeometry x="104" y="1086" width="60" height="30" as="geometry" />
+ </mxCell>
+ <mxCell id="Y1-DxkTYomo4t4mVsWZb-14" value="<span
style="color: rgb(8, 8, 8); font-family: &quot;JetBrains
Mono&quot;, monospace; text-align: left; white-space: pre;
background-color: rgb(255, 255, 255);"><b
style=""><font style="font-size:
16px;">external-service.yaml</font></b></span>"
style="text;html=1;align=center;verticalAlign=middle;whiteSpace=wrap;rounded=0;"
parent="1" vertex="1">
+ <mxGeometry x="756" y="1086" width="60" height="30" as="geometry" />
+ </mxCell>
+ </root>
+ </mxGraphModel>
+ </diagram>
+</mxfile>
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/circuit-breaker-call.png
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/circuit-breaker-call.png
new file mode 100644
index 000000000..ae1d6ebdc
Binary files /dev/null and
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/circuit-breaker-call.png
differ
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/circuit-breaker-class-name.png
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/circuit-breaker-class-name.png
new file mode 100644
index 000000000..ecad35ec9
Binary files /dev/null and
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/circuit-breaker-class-name.png
differ
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/circuit-breaker-generated-sources.png
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/circuit-breaker-generated-sources.png
new file mode 100644
index 000000000..921e3501a
Binary files /dev/null and
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/docs/circuit-breaker-generated-sources.png
differ
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/pom.xml
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/pom.xml
new file mode 100644
index 000000000..cf2f06b73
--- /dev/null
+++ b/serverless-workflow-examples/serverless-workflow-fault-tolerance/pom.xml
@@ -0,0 +1,181 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ 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>org.kie.kogito.examples</groupId>
+ <artifactId>serverless-workflow-examples-parent</artifactId>
+ <version>999-SNAPSHOT</version>
+
<relativePath>../serverless-workflow-examples-parent/pom.xml</relativePath>
+ </parent>
+
+ <artifactId>serverless-workflow-fault-tolerance</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+
+ <name>Kogito Example :: Serverless Workflow Fault Tolerance ::
Quarkus</name>
+ <description>Kogito Serverless Workflow Fault Tolerance -
Quarkus</description>
+
+ <properties>
+ <compiler-plugin.version>3.14.0</compiler-plugin.version>
+ <maven.compiler.release>17</maven.compiler.release>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+
<quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
+
<quarkus.platform.group-id>io.quarkus.platform</quarkus.platform.group-id>
+ <quarkus.platform.version>3.20.1</quarkus.platform.version>
+ <kogito.bom.group-id>org.kie.kogito</kogito.bom.group-id>
+ <kogito.bom.artifact-id>kogito-bom</kogito.bom.artifact-id>
+ <kogito.bom.version>999-SNAPSHOT</kogito.bom.version>
+ <skipITs>true</skipITs>
+ <surefire-plugin.version>3.5.2</surefire-plugin.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>${quarkus.platform.group-id}</groupId>
+ <artifactId>${quarkus.platform.artifact-id}</artifactId>
+ <version>${quarkus.platform.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ <dependency>
+ <groupId>${kogito.bom.group-id}</groupId>
+ <artifactId>${kogito.bom.artifact-id}</artifactId>
+ <version>${kogito.bom.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-arc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-resteasy-jackson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-smallrye-openapi</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-smallrye-fault-tolerance</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.kie.sonataflow</groupId>
+ <artifactId>sonataflow-quarkus</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.quarkus</groupId>
+ <artifactId>quarkus-junit5</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>io.rest-assured</groupId>
+ <artifactId>rest-assured</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>${quarkus.platform.group-id}</groupId>
+ <artifactId>quarkus-maven-plugin</artifactId>
+ <version>${quarkus.platform.version}</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <goals>
+ <goal>build</goal>
+ <goal>generate-code</goal>
+ <goal>generate-code-tests</goal>
+ <goal>native-image-agent</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>${compiler-plugin.version}</version>
+ <configuration>
+ <parameters>true</parameters>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <version>${surefire-plugin.version}</version>
+ <configuration>
+ <systemPropertyVariables>
+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
+ <maven.home>${maven.home}</maven.home>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <version>${surefire-plugin.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>integration-test</goal>
+ <goal>verify</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <systemPropertyVariables>
+
<native.image.path>${project.build.directory}/${project.build.finalName}-runner
+ </native.image.path>
+
<java.util.logging.manager>org.jboss.logmanager.LogManager</java.util.logging.manager>
+ <maven.home>${maven.home}</maven.home>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>native</id>
+ <activation>
+ <property>
+ <name>native</name>
+ </property>
+ </activation>
+ <properties>
+ <skipITs>false</skipITs>
+ <quarkus.native.enabled>true</quarkus.native.enabled>
+ </properties>
+ </profile>
+ </profiles>
+</project>
\ No newline at end of file
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.jvm
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.jvm
new file mode 100644
index 000000000..d2e5e0620
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.jvm
@@ -0,0 +1,98 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus
application in JVM mode
+#
+# Before building the container image run:
+#
+# ./mvnw package
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.jvm -t
quarkus/serverless-workflow-fault-tolerance-jvm .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080
quarkus/serverless-workflow-fault-tolerance-jvm
+#
+# If you want to include the debug port into your docker image
+# you will have to expose the debug port (default 5005 being the default) like
this : EXPOSE 8080 5005.
+# Additionally you will have to set -e JAVA_DEBUG=true and -e
JAVA_DEBUG_PORT=*:5005
+# when running the container
+#
+# Then run the container using :
+#
+# docker run -i --rm -p 8080:8080
quarkus/serverless-workflow-fault-tolerance-jvm
+#
+# This image uses the `run-java.sh` script to run the application.
+# This scripts computes the command line to execute your Java application, and
+# includes memory/GC tuning.
+# You can configure the behavior using the following environment properties:
+# - JAVA_OPTS: JVM options passed to the `java` command (example:
"-verbose:class") - Be aware that this will override
+# the default JVM options, use `JAVA_OPTS_APPEND` to append options
+# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated
options
+# in JAVA_OPTS (example: "-Dsome.property=foo")
+# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS.
This is
+# used to calculate a default maximal heap memory based on a containers
restriction.
+# If used in a container without any memory constraints for the container
then this
+# option has no effect. If there is a memory constraint then `-Xmx` is set
to a ratio
+# of the container available memory as set here. The default is `50` which
means 50%
+# of the available memory is used as an upper boundary. You can skip this
mechanism by
+# setting this value to `0` in which case no `-Xmx` option is added.
+# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in
JAVA_OPTS. This
+# is used to calculate a default initial heap memory based on the maximum
heap memory.
+# If used in a container without any memory constraints for the container
then this
+# option has no effect. If there is a memory constraint then `-Xms` is set
to a ratio
+# of the `-Xmx` memory as set here. The default is `25` which means 25% of
the `-Xmx`
+# is used as the initial heap size. You can skip this mechanism by setting
this value
+# to `0` in which case no `-Xms` option is added (example: "25")
+# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
+# This is used to calculate the maximum value of the initial heap memory. If
used in
+# a container without any memory constraints for the container then this
option has
+# no effect. If there is a memory constraint then `-Xms` is limited to the
value set
+# here. The default is 4096MB which means the calculated value of `-Xms`
never will
+# be greater than 4096MB. The value of this variable is expressed in MB
(example: "4096")
+# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard
output
+# when things are happening. This option, if set to true, will set
+# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
+# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by
default (example:
+# true").
+# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005
(example: "8787").
+# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
+# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt.
(example: "2")
+# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example:
"1024").
+# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid
expansion.
+# (example: "20")
+# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid
shrinking.
+# (example: "40")
+# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage
collection.
+# (example: "4")
+# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time
versus
+# previous GC times. (example: "90")
+# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
+# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
+# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable
should
+# contain the necessary JRE command-line options to specify the required GC,
which
+# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
+# - HTTPS_PROXY: The location of the https proxy. (example:
"[email protected]:8080")
+# - HTTP_PROXY: The location of the http proxy. (example:
"[email protected]:8080")
+# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that
can be
+# accessed directly. (example: "foo.example.com,bar.example.com")
+#
+###
+FROM registry.access.redhat.com/ubi9/openjdk-17:1.21
+
+ENV LANGUAGE='en_US:en'
+
+
+# We make four distinct layers so if there are application changes the library
layers can be re-used
+COPY --chown=185 target/quarkus-app/lib/ /deployments/lib/
+COPY --chown=185 target/quarkus-app/*.jar /deployments/
+COPY --chown=185 target/quarkus-app/app/ /deployments/app/
+COPY --chown=185 target/quarkus-app/quarkus/ /deployments/quarkus/
+
+EXPOSE 8080
+USER 185
+ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0
-Djava.util.logging.manager=org.jboss.logmanager.LogManager"
+ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
+
+ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]
+
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.legacy-jar
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.legacy-jar
new file mode 100644
index 000000000..40a5bf920
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.legacy-jar
@@ -0,0 +1,94 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus
application in JVM mode
+#
+# Before building the container image run:
+#
+# ./mvnw package -Dquarkus.package.jar.type=legacy-jar
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.legacy-jar -t
quarkus/serverless-workflow-fault-tolerance-legacy-jar .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080
quarkus/serverless-workflow-fault-tolerance-legacy-jar
+#
+# If you want to include the debug port into your docker image
+# you will have to expose the debug port (default 5005 being the default) like
this : EXPOSE 8080 5005.
+# Additionally you will have to set -e JAVA_DEBUG=true and -e
JAVA_DEBUG_PORT=*:5005
+# when running the container
+#
+# Then run the container using :
+#
+# docker run -i --rm -p 8080:8080
quarkus/serverless-workflow-fault-tolerance-legacy-jar
+#
+# This image uses the `run-java.sh` script to run the application.
+# This scripts computes the command line to execute your Java application, and
+# includes memory/GC tuning.
+# You can configure the behavior using the following environment properties:
+# - JAVA_OPTS: JVM options passed to the `java` command (example:
"-verbose:class") - Be aware that this will override
+# the default JVM options, use `JAVA_OPTS_APPEND` to append options
+# - JAVA_OPTS_APPEND: User specified Java options to be appended to generated
options
+# in JAVA_OPTS (example: "-Dsome.property=foo")
+# - JAVA_MAX_MEM_RATIO: Is used when no `-Xmx` option is given in JAVA_OPTS.
This is
+# used to calculate a default maximal heap memory based on a containers
restriction.
+# If used in a container without any memory constraints for the container
then this
+# option has no effect. If there is a memory constraint then `-Xmx` is set
to a ratio
+# of the container available memory as set here. The default is `50` which
means 50%
+# of the available memory is used as an upper boundary. You can skip this
mechanism by
+# setting this value to `0` in which case no `-Xmx` option is added.
+# - JAVA_INITIAL_MEM_RATIO: Is used when no `-Xms` option is given in
JAVA_OPTS. This
+# is used to calculate a default initial heap memory based on the maximum
heap memory.
+# If used in a container without any memory constraints for the container
then this
+# option has no effect. If there is a memory constraint then `-Xms` is set
to a ratio
+# of the `-Xmx` memory as set here. The default is `25` which means 25% of
the `-Xmx`
+# is used as the initial heap size. You can skip this mechanism by setting
this value
+# to `0` in which case no `-Xms` option is added (example: "25")
+# - JAVA_MAX_INITIAL_MEM: Is used when no `-Xms` option is given in JAVA_OPTS.
+# This is used to calculate the maximum value of the initial heap memory. If
used in
+# a container without any memory constraints for the container then this
option has
+# no effect. If there is a memory constraint then `-Xms` is limited to the
value set
+# here. The default is 4096MB which means the calculated value of `-Xms`
never will
+# be greater than 4096MB. The value of this variable is expressed in MB
(example: "4096")
+# - JAVA_DIAGNOSTICS: Set this to get some diagnostics information to standard
output
+# when things are happening. This option, if set to true, will set
+# `-XX:+UnlockDiagnosticVMOptions`. Disabled by default (example: "true").
+# - JAVA_DEBUG: If set remote debugging will be switched on. Disabled by
default (example:
+# true").
+# - JAVA_DEBUG_PORT: Port used for remote debugging. Defaults to 5005
(example: "8787").
+# - CONTAINER_CORE_LIMIT: A calculated core limit as described in
+# https://www.kernel.org/doc/Documentation/scheduler/sched-bwc.txt.
(example: "2")
+# - CONTAINER_MAX_MEMORY: Memory limit given to the container (example:
"1024").
+# - GC_MIN_HEAP_FREE_RATIO: Minimum percentage of heap free after GC to avoid
expansion.
+# (example: "20")
+# - GC_MAX_HEAP_FREE_RATIO: Maximum percentage of heap free after GC to avoid
shrinking.
+# (example: "40")
+# - GC_TIME_RATIO: Specifies the ratio of the time spent outside the garbage
collection.
+# (example: "4")
+# - GC_ADAPTIVE_SIZE_POLICY_WEIGHT: The weighting given to the current GC time
versus
+# previous GC times. (example: "90")
+# - GC_METASPACE_SIZE: The initial metaspace size. (example: "20")
+# - GC_MAX_METASPACE_SIZE: The maximum metaspace size. (example: "100")
+# - GC_CONTAINER_OPTIONS: Specify Java GC to use. The value of this variable
should
+# contain the necessary JRE command-line options to specify the required GC,
which
+# will override the default of `-XX:+UseParallelGC` (example: -XX:+UseG1GC).
+# - HTTPS_PROXY: The location of the https proxy. (example:
"[email protected]:8080")
+# - HTTP_PROXY: The location of the http proxy. (example:
"[email protected]:8080")
+# - NO_PROXY: A comma separated lists of hosts, IP addresses or domains that
can be
+# accessed directly. (example: "foo.example.com,bar.example.com")
+#
+###
+FROM registry.access.redhat.com/ubi9/openjdk-17:1.21
+
+ENV LANGUAGE='en_US:en'
+
+
+COPY target/lib/* /deployments/lib/
+COPY target/*-runner.jar /deployments/quarkus-run.jar
+
+EXPOSE 8080
+USER 185
+ENV JAVA_OPTS_APPEND="-Dquarkus.http.host=0.0.0.0
-Djava.util.logging.manager=org.jboss.logmanager.LogManager"
+ENV JAVA_APP_JAR="/deployments/quarkus-run.jar"
+
+ENTRYPOINT [ "/opt/jboss/container/java/run/run-java.sh" ]
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.native
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.native
new file mode 100644
index 000000000..f1a2f0b8d
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.native
@@ -0,0 +1,29 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus
application in native (no JVM) mode.
+#
+# Before building the container image run:
+#
+# ./mvnw package -Dnative
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.native -t
quarkus/serverless-workflow-fault-tolerance .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080 quarkus/serverless-workflow-fault-tolerance
+#
+# The ` registry.access.redhat.com/ubi9/ubi-minimal:9.5` base image is based
on UBI 9.
+# To use UBI 8, switch to `quay.io/ubi8/ubi-minimal:8.10`.
+###
+FROM registry.access.redhat.com/ubi9/ubi-minimal:9.5
+WORKDIR /work/
+RUN chown 1001 /work \
+ && chmod "g+rwX" /work \
+ && chown 1001:root /work
+COPY --chown=1001:root --chmod=0755 target/*-runner /work/application
+
+EXPOSE 8080
+USER 1001
+
+ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.native-micro
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.native-micro
new file mode 100644
index 000000000..2a8db6bec
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/docker/Dockerfile.native-micro
@@ -0,0 +1,32 @@
+####
+# This Dockerfile is used in order to build a container that runs the Quarkus
application in native (no JVM) mode.
+# It uses a micro base image, tuned for Quarkus native executables.
+# It reduces the size of the resulting container image.
+# Check https://quarkus.io/guides/quarkus-runtime-base-image for further
information about this image.
+#
+# Before building the container image run:
+#
+# ./mvnw package -Dnative
+#
+# Then, build the image with:
+#
+# docker build -f src/main/docker/Dockerfile.native-micro -t
quarkus/serverless-workflow-fault-tolerance .
+#
+# Then run the container using:
+#
+# docker run -i --rm -p 8080:8080 quarkus/serverless-workflow-fault-tolerance
+#
+# The `quay.io/quarkus/ubi9-quarkus-micro-image:2.0` base image is based on
UBI 9.
+# To use UBI 8, switch to `quay.io/quarkus/quarkus-micro-image:2.0`.
+###
+FROM quay.io/quarkus/ubi9-quarkus-micro-image:2.0
+WORKDIR /work/
+RUN chown 1001 /work \
+ && chmod "g+rwX" /work \
+ && chown 1001:root /work
+COPY --chown=1001:root --chmod=0755 target/*-runner /work/application
+
+EXPOSE 8080
+USER 1001
+
+ENTRYPOINT ["./application", "-Dquarkus.http.host=0.0.0.0"]
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/java/org/kie/kogito/examples/AdminRequest.java
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/java/org/kie/kogito/examples/AdminRequest.java
new file mode 100644
index 000000000..2512cdab9
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/java/org/kie/kogito/examples/AdminRequest.java
@@ -0,0 +1,24 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.kie.kogito.examples;
+
+public class AdminRequest {
+ public String operation;
+ public boolean enabled;
+}
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/java/org/kie/kogito/examples/EchoResponse.java
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/java/org/kie/kogito/examples/EchoResponse.java
new file mode 100644
index 000000000..e82fef4fa
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/java/org/kie/kogito/examples/EchoResponse.java
@@ -0,0 +1,31 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.kie.kogito.examples;
+
+public class EchoResponse {
+ public String id;
+ public String echo;
+ public String createdAt;
+
+ public EchoResponse(String id, String echo, String createdAt) {
+ this.id = id;
+ this.echo = echo;
+ this.createdAt = createdAt;
+ }
+}
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/java/org/kie/kogito/examples/ExternalServiceResource.java
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/java/org/kie/kogito/examples/ExternalServiceResource.java
new file mode 100644
index 000000000..944ad5221
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/java/org/kie/kogito/examples/ExternalServiceResource.java
@@ -0,0 +1,62 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.kie.kogito.examples;
+
+import jakarta.ws.rs.Consumes;
+import jakarta.ws.rs.POST;
+import jakarta.ws.rs.Path;
+import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.WebApplicationException;
+import jakarta.ws.rs.core.MediaType;
+import jakarta.ws.rs.core.Response;
+import org.eclipse.microprofile.openapi.annotations.Operation;
+
+import java.time.ZonedDateTime;
+import java.util.HashMap;
+import java.util.UUID;
+
+@Path("external-service")
+public class ExternalServiceResource {
+
+ private static final HashMap<String, Boolean> settings = new HashMap<>();
+
+ private static final String CIRCUIT_BREAKER_ECHO = "circuitBreakerEcho";
+
+ @POST
+ @Path("admin")
+ @Consumes(MediaType.APPLICATION_JSON)
+ @Operation(operationId = "adminOperation")
+ public Response adminOperation(AdminRequest request) {
+ settings.put(request.operation, request.enabled);
+ return Response.ok().build();
+ }
+
+ @POST
+ @Path("circuit-breaker")
+ @Consumes(MediaType.TEXT_PLAIN)
+ @Produces(MediaType.APPLICATION_JSON)
+ @Operation(operationId = "circuitBreakerEcho")
+ public EchoResponse circuitBreakerEcho(String echo) {
+ Boolean enabled = settings.get(CIRCUIT_BREAKER_ECHO);
+ if (enabled != null && !enabled) {
+ throw new WebApplicationException(CIRCUIT_BREAKER_ECHO + " is
configured to fail", Response.Status.INTERNAL_SERVER_ERROR);
+ }
+ return new EchoResponse(UUID.randomUUID().toString(), echo,
ZonedDateTime.now().toString());
+ }
+}
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/resources/application.properties
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/resources/application.properties
new file mode 100644
index 000000000..c6201af29
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/resources/application.properties
@@ -0,0 +1,41 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+quarkus.devservices.enabled=false
+kogito.devservices.enabled=false
+quarkus.http.test-port=0
+
+quarkus.rest-client."external_service_yaml".url=http://localhost:${quarkus.http.port}
+
+# Build time property to add the Circuit Breaker capability to the
corresponding generated class/method, by annotating
+# it with the eclipse microprofile
@org.eclipse.microprofile.faulttolerance.CircuitBreaker.
+# NOTE: this property doesn't follow the quarkus.fault-tolerance.xxx prefix,
you must use this format instead.
+org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho/CircuitBreaker/enabled=true
+
+# Configuration values for the sake of current example. Produces a quick
circuit Open, and a long delayed transitioning
+# to the Half Closed state. Don't consider this as suggested configurations
for a production system.
+
+# Use a rolling window of 4 consecutive requests
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.request-volume-threshold=4
+# With a ratio of .5, if 2 requests fail, then, the circuit is Opened.
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.failure-ratio=0.5
+
+# Wait 2 minutes before the Open circuit goes to the Half Open state.
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.delay=2
+quarkus.fault-tolerance."org.kie.kogito.openapi.externalservice.api.ExternalServiceResourceApi/circuitBreakerEcho".circuit-breaker.delay-unit=minutes
\ No newline at end of file
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/resources/call-echo.sw.yml
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/resources/call-echo.sw.yml
new file mode 100644
index 000000000..5232e8a83
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/resources/call-echo.sw.yml
@@ -0,0 +1,22 @@
+id: call-echo
+version: "1.0"
+name: Call Echo
+start: CallExternalService
+functions:
+ - name: circuitBreakerEchoFunction
+ operation: specs/external-service.yaml#circuitBreakerEcho
+ type: rest
+states:
+ - name: CallExternalService
+ type: operation
+ actions:
+ - name: executeCircuitBreakerEcho
+ functionRef:
+ refName: circuitBreakerEchoFunction
+ arguments:
+ echo: ".echo"
+ actionDataFilter:
+ useResults: true
+ results: "."
+ toStateData: ".echoResult"
+ end: true
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/resources/specs/external-service.yaml
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/resources/specs/external-service.yaml
new file mode 100644
index 000000000..2c4301e6d
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/main/resources/specs/external-service.yaml
@@ -0,0 +1,79 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you 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.
+#
+
+---
+openapi: 3.1.0
+info:
+ title: serverless-workflow-fault-tolerance API
+ version: 1.0.0-SNAPSHOT
+paths:
+ /external-service/admin:
+ post:
+ operationId: adminOperation
+ requestBody:
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/AdminRequest"
+ required: true
+ responses:
+ "200":
+ description: OK
+ "400":
+ description: Bad Request
+ summary: Admin Operation
+ tags:
+ - External Service Resource
+ /external-service/circuit-breaker:
+ post:
+ operationId: circuitBreakerEcho
+ requestBody:
+ content:
+ text/plain:
+ schema:
+ type: string
+ required: true
+ responses:
+ "200":
+ description: OK
+ content:
+ application/json:
+ schema:
+ $ref: "#/components/schemas/EchoResponse"
+ summary: Circuit Breaker Echo
+ tags:
+ - External Service Resource
+components:
+ schemas:
+ AdminRequest:
+ type: object
+ properties:
+ operation:
+ type: string
+ enabled:
+ type: boolean
+ EchoResponse:
+ type: object
+ properties:
+ id:
+ type: string
+ echo:
+ type: string
+ createdAt:
+ type: string
diff --git
a/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/test/java/org/kie/kogito/examples/CallEchoIT.java
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/test/java/org/kie/kogito/examples/CallEchoIT.java
new file mode 100644
index 000000000..4ad364189
--- /dev/null
+++
b/serverless-workflow-examples/serverless-workflow-fault-tolerance/src/test/java/org/kie/kogito/examples/CallEchoIT.java
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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 org.kie.kogito.examples;
+
+import io.quarkus.test.junit.QuarkusIntegrationTest;
+import io.restassured.http.ContentType;
+import io.restassured.path.json.JsonPath;
+import io.restassured.response.ValidatableResponse;
+import org.junit.jupiter.api.Test;
+
+import static io.restassured.RestAssured.given;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+@QuarkusIntegrationTest
+class CallEchoIT {
+
+ private static final String ACCESS_CIRCUIT_BREAKER_ECHO_ERROR = "HTTP 500
Internal Server Error";
+ private static final String ACCESS_OPEN_CIRCUIT_ERROR =
"org.eclipse.microprofile.faulttolerance.exceptions.CircuitBreakerOpenException";
+
+ @Test
+ void circuitBreakerEcho() {
+ // regular call, no failure.
+ prepareCircuitBreakerCall().statusCode(201);
+
+ // program the circuitBreakerEcho operation to fail.
+ given()
+ .contentType(ContentType.JSON)
+ .accept(ContentType.JSON)
+ .body("{\"operation\" : \"circuitBreakerEcho\", \"enabled\" :
false}").when()
+ .post("/external-service/admin")
+ .then()
+ .statusCode(200);
+
+ // next 3 calls must fail with "HTTP 500 Internal Server Error"
+ assertCallEchoStartsWithMessage(ACCESS_CIRCUIT_BREAKER_ECHO_ERROR);
+ assertCallEchoStartsWithMessage(ACCESS_CIRCUIT_BREAKER_ECHO_ERROR);
+ assertCallEchoStartsWithMessage(ACCESS_CIRCUIT_BREAKER_ECHO_ERROR);
+
+ // fourth call must fail due to the Open circuit.
+ assertCallEchoStartsWithMessage(ACCESS_OPEN_CIRCUIT_ERROR);
+ }
+
+ private static void assertCallEchoStartsWithMessage(String prefix) {
+ JsonPath result = prepareCircuitBreakerCall()
+ .statusCode(500)
+ .extract()
+ .jsonPath();
+ String message = result.get("message");
+ assertTrue(message != null && message.startsWith(prefix),
+ "Expected message to start with: " + prefix + " but got: " + message);
+ }
+
+ private static ValidatableResponse prepareCircuitBreakerCall() {
+ return given()
+ .contentType(ContentType.JSON)
+ .accept(ContentType.JSON)
+ .body("{\"echo\" : \"Hello!\"}").when()
+ .post("/call-echo")
+ .then();
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]