apache / incubator-kie-kogito-runtimes

Kogito Runtimes - Kogito is a cloud-native business automation technology for building cloud-ready business applications.
http://kogito.kie.org
Apache License 2.0
536 stars 206 forks source link

SW - Failed to parse end node produceEvents #3574

Closed deepakkapoor23 closed 2 months ago

deepakkapoor23 commented 2 months ago

Describe the bug

For an end node with produceEvents in one of the states like below, build fails to parse the produceEvent element.

{ "name": "ErrorWithCompensation", "type": "operation", "actions": [ { "functionRef": "logProcessContext" } ], "end": { "terminate": true, "compensate": true, "produceEvents": [{ "eventRef": "FailureEvent", "data": { "error": ".error", "replay": true }, "contextAttributes": { "correlationid": ".someId" } }] } }

Expected behavior

Build should pass and event produced at end node should contain the data object as defined.

Actual behavior

Build fails parsing the sw definition with following error.

Failed to build quarkus application: io.quarkus.builder.BuildException: Build failure: Build failed due to errors [ERROR] [error]: Build step org.kie.kogito.quarkus.common.deployment.KogitoAssetsProcessor#generateSources threw an exception: org.kie.kogito.codegen.process.ProcessCodegenException: Processes with errors are Invalid process: 'xxx.sw.json'. Found error: com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "error" (class io.serverlessworkflow.api.produce.ProduceEvent), not marked as ignorable (3 known properties: "eventRef", "data", "contextAttributes"]) [ERROR] at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: io.serverlessworkflow.api.Workflow["states"]->java.util.ArrayList[1]->io.serverlessworkflow.api.states.OperationState["end"]->io.serverlessworkflow.api.produce.ProduceEvent["error"])

How to Reproduce?

No response

Output of uname -a or ver

Windows 11

Output of java -version

java 17

GraalVM version (if different from Java)

No response

Kogito version or git rev (or at least Quarkus version if you are using Kogito via Quarkus platform BOM)

999-snapshot

Build tool (ie. output of mvnw --version or gradlew --version)

gradle 8.6

Additional information

No response

fjtirado commented 2 months ago

@deepakkapoor23 There is a mismatch between the 0.8 version of the spec and the Java SDK. The spec mentions that data might be an object or a string but here data is defined as string https://github.com/serverlessworkflow/sdk-java/blob/2.0.x/api/src/main/resources/schema/events/eventref.json I think this should be fixed in the SDK. Please open the issue there In the meantime, as a workaroung, use

{
"name": "ErrorWithCompensation",
"type": "operation",
"actions": [
{
"functionRef": "logProcessContext"
}
],
"end": {
"terminate": true,
"compensate": true,
"produceEvents": [{
"eventRef": "FailureEvent",
"data":  "{
error: .error,
replay: true
}",
"contextAttributes": {
"correlationid": ".someId"
}
}]
}
}
deepakkapoor23 commented 2 months ago

@fjtirado I have noticed that the data element does not honor either the string or an object, it always attempts to publish entire workflow data as "data" element regardless of what's defined in the workflow definition.