cmdexec should return status=FAILURE on errors 21/109321/7
authorOleg Mitsura <oleg.mitsura@amdocs.com>
Thu, 18 Jun 2020 18:13:30 +0000 (14:13 -0400)
committerOleg Mitsura <omitsura@gmail.com>
Fri, 26 Jun 2020 13:37:22 +0000 (13:37 +0000)
Issue-ID: CCSDK-2445

In certain cases, status message is returned on error instead of status=FAILURE.
rev 2: reuse same msg
rev 3: past elalto, compoment level timeout is implementation.timeout

Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Change-Id: I2651e5706b7e62894c5e071dc1563fb1b9dd67e1

ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt

index 8486474..50f0b14 100644 (file)
@@ -123,8 +123,8 @@ open class ComponentRemotePythonExecutor(
         val executionTimeout = getOptionalOperationInput(INPUT_EXECUTE_TIMEOUT)?.asInt()
             ?: DEFAULT_EXECUTE_TIMEOUT_IN_SEC
 
-        // set the component level timeout as envPrepTimeout + executionTimeout (small delta will be applied in AbstractComponentFunction
-        val timeout = envPrepTimeout + executionTimeout
+        // component level timeout should be => env_prep_timeout + execution_timeout
+        val timeout = implementation.timeout
 
         var scriptCommand = command.replace(pythonScript.name, pythonScript.absolutePath)
         if (args != null && args.isNotEmpty()) {
@@ -161,17 +161,17 @@ open class ComponentRemotePythonExecutor(
                 if (prepareEnvOutput.status != StatusType.SUCCESS) {
                     val errorMessage = prepareEnvOutput.payload
                     setNodeOutputErrors(prepareEnvOutput.status.name,
-                            STEP_PREPARE_ENV,
-                            logs,
-                            errorMessage,
-                            isLogResponseEnabled
+                        STEP_PREPARE_ENV,
+                        logs,
+                        errorMessage,
+                        isLogResponseEnabled
                     )
                 } else {
                     setNodeOutputProperties(prepareEnvOutput.status.name.asJsonPrimitive(),
-                            STEP_PREPARE_ENV,
-                            logsEnv,
-                            "".asJsonPrimitive(),
-                            isLogResponseEnabled
+                        STEP_PREPARE_ENV,
+                        logsEnv,
+                        "".asJsonPrimitive(),
+                        isLogResponseEnabled
                     )
                 }
             } else {
@@ -180,17 +180,15 @@ open class ComponentRemotePythonExecutor(
             }
         } catch (grpcEx: io.grpc.StatusRuntimeException) {
             val componentLevelWarningMsg = if (timeout < envPrepTimeout) "Note: component-level timeout ($timeout) is shorter than env-prepare timeout ($envPrepTimeout). " else ""
-            val grpcErrMsg = "Command failed during env. preparation... timeout($envPrepTimeout) requestId ($processId). $componentLevelWarningMsg"
+            val grpcErrMsg = "Command failed during env. preparation... timeout($envPrepTimeout) requestId ($processId). $componentLevelWarningMsg grpcError: ${grpcEx.status}"
             setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, grpcErrMsg.asJsonPrimitive())
-            setNodeOutputErrors(status = grpcErrMsg, step = STEP_PREPARE_ENV, error = "${grpcEx.status}".asJsonPrimitive(), logging = isLogResponseEnabled)
+            setNodeOutputErrors(status = StatusType.FAILURE.name, step = STEP_PREPARE_ENV, error = grpcErrMsg.asJsonPrimitive(), logging = isLogResponseEnabled)
             log.error(grpcErrMsg, grpcEx)
-            addError(grpcErrMsg)
         } catch (e: Exception) {
-            val timeoutErrMsg = "Command executor failed during env. preparation.. timeout($envPrepTimeout) requestId ($processId)."
+            val timeoutErrMsg = "Command executor failed during env. preparation.. catch-all case timeout($envPrepTimeout) requestId ($processId). exception msg: ${e.message}"
             setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, e.message.asJsonPrimitive())
-            setNodeOutputErrors(status = timeoutErrMsg, step = STEP_PREPARE_ENV, error = "${e.message}".asJsonPrimitive(), logging = isLogResponseEnabled)
-            log.error("Failed to process on remote executor requestId ($processId)", e)
-            addError(timeoutErrMsg)
+            setNodeOutputErrors(status = StatusType.FAILURE.name, step = STEP_PREPARE_ENV, error = timeoutErrMsg.asJsonPrimitive(), logging = isLogResponseEnabled)
+            log.error(timeoutErrMsg, e)
         }
         // if Env preparation was successful, then proceed with command execution in this Env
         if (bluePrintRuntimeService.getBluePrintError().errors.isEmpty()) {
@@ -214,45 +212,47 @@ open class ComponentRemotePythonExecutor(
                 }
 
                 checkNotNull(remoteExecutionOutput) {
-                    "Error: Request-id $processId did not return a restul from remote command execution."
+                    "Error: Request-id $processId did not return a result from remote command execution."
                 }
                 val logs = JacksonUtils.jsonNodeFromObject(remoteExecutionOutput.response)
                 if (remoteExecutionOutput.status != StatusType.SUCCESS) {
                     setNodeOutputErrors(remoteExecutionOutput.status.name,
-                            STEP_EXEC_CMD,
-                            logs,
-                            remoteExecutionOutput.payload,
-                            isLogResponseEnabled
+                        STEP_EXEC_CMD,
+                        logs,
+                        remoteExecutionOutput.payload,
+                        isLogResponseEnabled
                     )
                 } else {
                     setNodeOutputProperties(remoteExecutionOutput.status.name.asJsonPrimitive(),
-                            STEP_EXEC_CMD,
-                            logs,
-                            remoteExecutionOutput.payload,
-                            isLogResponseEnabled
+                        STEP_EXEC_CMD,
+                        logs,
+                        remoteExecutionOutput.payload,
+                        isLogResponseEnabled
                     )
                 }
             } catch (timeoutEx: TimeoutCancellationException) {
                 val componentLevelWarningMsg = if (timeout < executionTimeout) "Note: component-level timeout ($timeout) is shorter than execution timeout ($executionTimeout). " else ""
                 val timeoutErrMsg = "Command executor execution timeout. DetailedMessage: (${timeoutEx.message}) requestId ($processId). $componentLevelWarningMsg"
-                setNodeOutputErrors(status = timeoutErrMsg,
-                        step = STEP_EXEC_CMD,
-                        logs = "".asJsonPrimitive(),
-                        error = "".asJsonPrimitive(),
-                        logging = isLogResponseEnabled
+                setNodeOutputErrors(status = StatusType.FAILURE.name,
+                    step = STEP_EXEC_CMD,
+                    logs = "".asJsonPrimitive(),
+                    error = timeoutErrMsg.asJsonPrimitive(),
+                    logging = isLogResponseEnabled
                 )
                 log.error(timeoutErrMsg, timeoutEx)
             } catch (grpcEx: io.grpc.StatusRuntimeException) {
-                val timeoutErrMsg = "Command executor failed to execute requestId ($processId) error (${grpcEx.status.cause?.message})"
-                setNodeOutputErrors(status = timeoutErrMsg,
-                        step = STEP_EXEC_CMD,
-                        logs = "".asJsonPrimitive(),
-                        error = "".asJsonPrimitive(),
-                        logging = isLogResponseEnabled
+                val timeoutErrMsg = "Command executor timed out executing after $executionTimeout seconds requestId ($processId) grpcErr: ${grpcEx.status}"
+                setNodeOutputErrors(status = StatusType.FAILURE.name,
+                    step = STEP_EXEC_CMD,
+                    logs = "".asJsonPrimitive(),
+                    error = timeoutErrMsg.asJsonPrimitive(),
+                    logging = isLogResponseEnabled
                 )
-                log.error("Command executor time out during GRPC call", grpcEx)
+                log.error(timeoutErrMsg, grpcEx)
             } catch (e: Exception) {
-                log.error("Failed to process on remote executor requestId ($processId)", e)
+                val timeoutErrMsg = "Command executor failed during process catch-all case requestId ($processId) timeout($envPrepTimeout) exception msg: ${e.message}"
+                setNodeOutputErrors(status = StatusType.FAILURE.name, step = STEP_PREPARE_ENV, error = timeoutErrMsg.asJsonPrimitive(), logging = isLogResponseEnabled)
+                log.error(timeoutErrMsg, e)
             }
         }
         log.debug("Trying to close GRPC channel. request ($processId)")
@@ -277,7 +277,14 @@ open class ComponentRemotePythonExecutor(
     /**
      * Utility function to set the output properties of the executor node
      */
-    private fun setNodeOutputProperties(status: JsonNode, step: String, message: JsonNode, artifacts: JsonNode, logging: Boolean = true) {
+    private fun setNodeOutputProperties(
+        status: JsonNode = StatusType.FAILURE.name.asJsonPrimitive(),
+        step: String,
+        message: JsonNode,
+        artifacts: JsonNode,
+        logging: Boolean = true
+    ) {
+
         setAttribute(ATTRIBUTE_EXEC_CMD_STATUS, status)
         setAttribute(ATTRIBUTE_RESPONSE_DATA, artifacts)
         setAttribute(ATTRIBUTE_EXEC_CMD_LOG, message)