diff options
-rw-r--r-- | ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt | 87 |
1 files changed, 47 insertions, 40 deletions
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt index 848647405..50f0b1499 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt @@ -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) |