Return errormessages in failing imperative workflows 33/128533/1
authorJozsef Csongvai <jozsef.csongvai@bell.ca>
Tue, 12 Apr 2022 23:24:37 +0000 (19:24 -0400)
committerJozsef Csongvai <jozsef.csongvai@bell.ca>
Tue, 12 Apr 2022 23:31:23 +0000 (19:31 -0400)
Instead of discarding error messages after each node has executed, they
are now kept until the workflow completes. If the workflow completes
without exceptions, it means that all errors were handled and the error
messages can be cleared. If the workflow does complete with exceptions,
all error messages will be propagated in the response.

Also update UatExecutor to enable expected status codes other than 200.

Issue-ID: CCSDK-3630
Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca>
Change-Id: I94fd81c342ad2a798e64051c603beb62bf1aaacd

components/model-catalog/blueprint-model/uat-blueprints/imperative_workflow/Definitions/uat-imperative-workflow.json
components/model-catalog/blueprint-model/uat-blueprints/imperative_workflow/Tests/uat.yaml
ms/blueprintsprocessor/application/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/uat/utils/UatExecutor.kt
ms/blueprintsprocessor/modules/blueprints/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/BluePrintError.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/workflow/ImperativeWorkflowExecutionService.kt

index 508d8b2..16466df 100644 (file)
             }
           }
         }
+      },
+      "uat-unhandled-error" : {
+        "steps" : {
+          "execute-A" : {
+            "target" : "execute-script-1",
+            "on_success" : [ "finalize" ],
+            "on_failure" : [ "clean-up" ]
+          },
+          "finalize" : {
+            "target" : "execute-script-3"
+          },
+          "clean-up" : {
+            "target" : "execute-script-4"
+          }
+        },
+        "inputs" : {
+          "service-instance-id" : {
+            "type" : "string"
+          },
+          "failing-steps" : {
+            "type" : "json"
+          }
+        },
+        "outputs" : {}
       }
     },
     "node_templates" : {
index 3aab65e..693cad6 100644 (file)
@@ -305,4 +305,29 @@ processes:
             execute-script-1: FAILED
             execute-script-2: FAILED
             execute-script-3: null
-            execute-script-4: SUCCEEDED
\ No newline at end of file
+            execute-script-4: SUCCEEDED
+
+  - name: uat-unhandled-error
+    request:
+      commonHeader: &ch
+        originatorId: sdnc
+        requestId: "1234"
+        subRequestId: "1234-12234"
+      actionIdentifiers: &ai
+        blueprintName: uat-imperative-workflow
+        blueprintVersion: "1.0.0"
+        actionName: uat-unhandled-error
+        mode: sync
+      payload:
+        uat-unhandled-error-request:
+          failing-steps:
+            execute-A: true
+            clean-up: true
+    expectedResponse:
+      commonHeader: *ch
+      actionIdentifiers: *ai
+      status:
+        code: 500
+        eventType: EVENT_COMPONENT_FAILURE
+        errorMessage: "Step failed: execute-A, Step failed: clean-up, node(clean-up) outgoing edge(FAILURE) is missing."
+        message: failure
\ No newline at end of file
index 1e1d3ac..ae9b7d3 100644 (file)
@@ -241,7 +241,8 @@ class UatExecutor(
         }
         val response = client.execute(request) { response ->
             val statusLine = response.statusLine
-            assertThat("${process.name}", statusLine.statusCode, equalTo(HttpStatus.SC_OK))
+            val expectedCode = expectedResponse?.get("status")?.get("code")?.intValue()
+            assertThat("${process.name}", statusLine.statusCode, equalTo(expectedCode ?: HttpStatus.SC_OK))
             val entity = response.entity
             assertThat("${process.name} Response contains no content", entity, notNullValue())
             entity.content.bufferedReader().use { it.readText() }
index b8350f4..fbe51ac 100644 (file)
@@ -119,6 +119,7 @@ open class ImperativeBluePrintWorkflowService(private val nodeTemplateExecutionS
                 }
                 message = BluePrintConstants.STATUS_FAILURE
             } else {
+                bluePrintRuntimeService.getBluePrintError().clearAll()
                 message = BluePrintConstants.STATUS_SUCCESS
             }
             eventType = EventType.EVENT_COMPONENT_EXECUTED.name
@@ -163,8 +164,6 @@ open class ImperativeBluePrintWorkflowService(private val nodeTemplateExecutionS
             .executeNodeTemplate(bluePrintRuntimeService, node.id, nodeTemplateName, nodeInput)
 
         if (executionServiceOutput.status.message == BluePrintConstants.STATUS_FAILURE) {
-            // Clear step errors so that the workflow does not fail
-            bluePrintRuntimeService.getBluePrintError().stepErrors(node.id)?.clear()
             return EdgeLabel.FAILURE
         }