parodos-dev / serverless-workflow-examples

Apache License 2.0
0 stars 15 forks source link

rewrite assessment subflow to openapi rest api #14

Closed RichardW98 closed 9 months ago

RichardW98 commented 9 months ago

rewrite assessment subflow to openapi rest api current issue: when send a post with "workflowdata" in requestbody, there will be an error:

2023-12-18 10:20:05,152 INFO  [org.kie.kog.ser.wor.dev.DevModeServerlessWorkflowLogger] (executor-thread-0) Triggered node 'preCheck' for process 'assessment' (b3d75dde-d603-4b95-b0fc-aa483b01dea6)
2023-12-18 10:20:05,167 ERROR [io.und.req.io] (executor-thread-0) Exception handling request e848c0cd-b8de-497c-b4ce-4331264bbc77-1 to /assessment: org.jboss.resteasy.spi.UnhandledException: java.lang.StackOverflowError
        at org.jboss.resteasy.core.ExceptionHandler.handleApplicationException(ExceptionHandler.java:105)
        at org.jboss.resteasy.core.ExceptionHandler.handleException(ExceptionHandler.java:359)
        at org.jboss.resteasy.core.SynchronousDispatcher.writeException(SynchronousDispatcher.java:218)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:519)
        at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:261)
        at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:161)
        at org.jboss.resteasy.core.interception.jaxrs.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:364)
        at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:164)
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:247)
        at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:249)
        ...

The assumption here is that "." in jq points back to "workflowdata" which caused a deadloop in the Json Node Parser, then the memory leaks result in the StackOverflowError. But we need more investigation

the "workflowdata" node can be renamed to other words, but the execution result of preCheck still can't be output into root "data" of assessment

dmartinol commented 9 months ago

@RichardW98 @masayag can you try these changes instead?

diff --git a/assessment/src/main/resources/assessment.sw.yaml b/assessment/src/main/resources/assessment.sw.yaml
index 663b2a4..1f3e533 100644
--- a/assessment/src/main/resources/assessment.sw.yaml
+++ b/assessment/src/main/resources/assessment.sw.yaml
@@ -28,6 +28,11 @@ states:
             repositoryUrl: ".repositoryUrl"
         actionDataFilter:
           toStateData: ".result"
+      - name: printAction
+        functionRef:
+          refName: logOuput
+          arguments:
+            message: "\"Before preCheck: \\(.)\""
       - name: preCheck
         functionRef:
           refName: preCheck
@@ -35,13 +40,13 @@ states:
             # replace workflowdata with any other words, then the call will be received by the precheck.
             # but the result is unable to be fetched
             workflowdata: 
-              result: .result
+              result: .
         actionDataFilter:
-          results: "${ {preCheck: .workflowdata} }"
-          toStateData: "${ .preCheck }"
+          fromStateData: .result
+          toStateData: ".preCheck"
       - name: printAction
         functionRef:
           refName: logOuput
           arguments:
-            message: ".preCheck"
+            message: "\"After preCheck: \\(.)\""
     end: true
\ No newline at end of file
diff --git a/assessment/src/main/resources/specs/precheck.yaml b/assessment/src/main/resources/specs/precheck.yaml
index 18dd31c..7a863ec 100644
--- a/assessment/src/main/resources/specs/precheck.yaml
+++ b/assessment/src/main/resources/specs/precheck.yaml
@@ -27,6 +27,10 @@ paths:
       responses:
         "200":
           description: OK
+          content:
+            application/json:
+              schema:
+                $ref: '#/components/schemas/JsonNodeModelInput'
 components:
   schemas:
     JsonNodeModelInput:
RichardW98 commented 9 months ago

Thank you @dmartinol for the advice! now the issue of response fetching is ressolved. but it seems the stackOverFlow error is still there. I have to try with:

      - name: preCheck
        functionRef:
          refName: preCheck
          arguments:
            # replace workflowdata with any other words, then the call will be received by the precheck.
            # but the precheck's execution result is still unable to be fetched
            test: 
              result: .
        actionDataFilter:
            fromStateData: .result
            toStateData: ".preCheck"

and then it will work

RichardW98 commented 9 months ago

I just tried it again and it works! Thank you @dmartinol! I will update the pr and @masayag please review again