diff options
author | Oleg Mitsura <oleg.mitsura@amdocs.com> | 2020-01-23 12:39:50 -0500 |
---|---|---|
committer | Oleg Mitsura <oleg.mitsura@amdocs.com> | 2020-01-23 13:00:15 -0500 |
commit | 87b00f3a63482fe21ab468541d6f89b8348422a0 (patch) | |
tree | 4d39b4470f3a66f3f6d005231db4a16cd498f5aa /ms/blueprintsprocessor/functions | |
parent | 7d6baeb4b4a0f49ef05ef2744cd96130afbd9f83 (diff) |
cmd-exec 0-return is success; env.prep.fix.
Issue-ID: CCSDK-1855
This is cherry-pick of https://gerrit.onap.org/r/c/ccsdk/cds/+/98609
rev2. pasted wrong file, modified back...
rev3. added catch-all.
Change-Id: I30eccc3b18b428970bfa873b9f0ce359a1f5e97d
Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions')
-rw-r--r-- | ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt | 68 |
1 files changed, 38 insertions, 30 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 3250cd3a2..6ad1e1f11 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 @@ -1,5 +1,5 @@ /* - * Copyright © 2019 IBM. + * Copyright © 2019 IBM. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -114,46 +114,51 @@ 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() + // 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, - timeOut = timeout.toLong()) + val remoteExecutionInput = RemoteScriptExecutionInput( + requestId = processId, + remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), + command = scriptCommand, + properties = properties, + timeOut = timeout.toLong()) - val remoteExecutionOutputDeferred = GlobalScope.async { - remoteScriptExecutionService.executeCommand(remoteExecutionInput) - } + val remoteExecutionOutputDeferred = GlobalScope.async { + remoteScriptExecutionService.executeCommand(remoteExecutionInput) + } - val remoteExecutionOutput = withTimeout(timeout * 1000L) { - remoteExecutionOutputDeferred.await() - } + val remoteExecutionOutput = withTimeout(timeout * 1000L) { + remoteExecutionOutputDeferred.await() + } - checkNotNull(remoteExecutionOutput) { - "Error: Request-id $processId did not return a restul from remote command execution." - } + checkNotNull(remoteExecutionOutput) { + "Error: Request-id $processId did not return a restul from remote command execution." + } - 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) + + 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 (timeoutEx: TimeoutCancellationException) { @@ -201,9 +206,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()) } } |