From 328e55fd0b989513b62566ecc69a03b98733f4fc Mon Sep 17 00:00:00 2001 From: Serge Simard Date: Tue, 19 Nov 2019 10:24:56 -0500 Subject: Changes return value from boolean to typical process return code; Also ensure that if environment preparation does not succeed the processing fails. Issue-ID: CCSDK-1855 Signed-off-by: Serge Simard Change-Id: Iab2ec8b44a0e9e7edef68d0d5c13860eedc5be67 Signed-off-by: Serge Simard --- .../executor/ComponentRemotePythonExecutor.kt | 52 ++++++++++++---------- .../src/main/python/command_executor_server.py | 4 +- 2 files changed, 31 insertions(+), 25 deletions(-) (limited to 'ms') 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 6b1f186c9..91d51757a 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 @@ -110,35 +110,38 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic ) val prepareEnvOutput = remoteScriptExecutionService.prepareEnv(prepareEnvInput) log.info("$ATTRIBUTE_PREPARE_ENV_LOG - ${prepareEnvOutput.response}") - val logs = JacksonUtils.jsonNodeFromObject(prepareEnvOutput.response) - setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, logs) - setAttribute(ATTRIBUTE_EXEC_CMD_LOG, "N/A".asJsonPrimitive()) + val logs = prepareEnvOutput.response + val logsEnv = logs.toString().asJsonPrimitive() + setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, logsEnv) if (prepareEnvOutput.status != StatusType.SUCCESS) { - setNodeOutputErrors(prepareEnvOutput.status.name, logs) + setAttribute(ATTRIBUTE_EXEC_CMD_LOG, "N/A".asJsonPrimitive()) + setNodeOutputErrors(prepareEnvOutput.status.name, logsEnv) } else { - setNodeOutputProperties(prepareEnvOutput.status.name.asJsonPrimitive(), logs, "".asJsonPrimitive()) + setNodeOutputProperties(prepareEnvOutput.status.name.asJsonPrimitive(), logsEnv, "".asJsonPrimitive()) } } - // Populate command execution properties and pass it to the remote server - val properties = dynamicProperties?.returnNullIfMissing()?.rootFieldsToMap() ?: hashMapOf() - - val remoteExecutionInput = RemoteScriptExecutionInput( - requestId = processId, - remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), - command = scriptCommand, - properties = properties) - val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput) - - val logs = JacksonUtils.jsonNodeFromObject(remoteExecutionOutput.response) - if (remoteExecutionOutput.status != StatusType.SUCCESS) { - setNodeOutputErrors(remoteExecutionOutput.status.name,logs, remoteExecutionOutput.payload) - } else { - setNodeOutputProperties(remoteExecutionOutput.status.name.asJsonPrimitive(), logs, - remoteExecutionOutput.payload) + // if Env preparation was successful, then proceed with command execution in this Env + if (bluePrintRuntimeService.getBluePrintError().errors.isEmpty()) { + // Populate command execution properties and pass it to the remote server + val properties = dynamicProperties?.returnNullIfMissing()?.rootFieldsToMap() ?: hashMapOf() + + val remoteExecutionInput = RemoteScriptExecutionInput( + requestId = processId, + remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), + command = scriptCommand, + properties = properties) + val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput) + + val logs = JacksonUtils.jsonNodeFromObject(remoteExecutionOutput.response) + if (remoteExecutionOutput.status != StatusType.SUCCESS) { + setNodeOutputErrors(remoteExecutionOutput.status.name, logs, remoteExecutionOutput.payload) + } else { + setNodeOutputProperties(remoteExecutionOutput.status.name.asJsonPrimitive(), logs, + remoteExecutionOutput.payload) + } } - } catch (e: Exception) { log.error("Failed to process on remote executor", e) } finally { @@ -178,9 +181,12 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic */ private fun setNodeOutputErrors(status: String, message: JsonNode, artifacts: JsonNode = "".asJsonPrimitive() ) { setAttribute(ATTRIBUTE_EXEC_CMD_STATUS, status.asJsonPrimitive()) + log.info("Executor status : $status") setAttribute(ATTRIBUTE_EXEC_CMD_LOG, message) + log.info("Executor message : $message") setAttribute(ATTRIBUTE_RESPONSE_DATA, artifacts) + log.info("Executor artifacts: $artifacts") - addError(status, ATTRIBUTE_EXEC_CMD_LOG, message.asText()) + addError(status, ATTRIBUTE_EXEC_CMD_LOG, message.toString()) } } diff --git a/ms/command-executor/src/main/python/command_executor_server.py b/ms/command-executor/src/main/python/command_executor_server.py index 577c8a0ca..39cd1e6da 100644 --- a/ms/command-executor/src/main/python/command_executor_server.py +++ b/ms/command-executor/src/main/python/command_executor_server.py @@ -53,12 +53,12 @@ class CommandExecutorServer(CommandExecutor_pb2_grpc.CommandExecutorServiceServi payload_result = {} handler = CommandExecutorHandler(request) payload_result = handler.execute_command(request, log_results) - if not payload_result["cds_return_code"]: + if payload_result["cds_return_code"] != 0: self.logger.info("{} - Failed to executeCommand. {}".format(blueprint_id, log_results)) else: self.logger.info("{} - Execution finished successfully.".format(blueprint_id)) - ret = utils.build_response(request, log_results, payload_result, payload_result["cds_return_code"]) + ret = utils.build_response(request, log_results, payload_result, payload_result["cds_return_code"] == 0) self.logger.info("Payload returned %s" % payload_result) return ret \ No newline at end of file -- cgit 1.2.3-korg