summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
diff options
context:
space:
mode:
authorSerge Simard <serge@agilitae.com>2019-10-24 01:42:27 -0400
committerOleg Mitsura <omitsura@gmail.com>2019-11-01 15:09:58 +0000
commitadf475f6ad5b821f9985f6df28968c9ce68443ac (patch)
tree9545e0c9ba7719d4572cd482f8d38dd5fad29f0a /ms/blueprintsprocessor/functions
parent083247bd4410f2737ceb4aecb007fa660b560792 (diff)
Improve Remote Python Executor error handling and
Issue-ID: CCSDK-1855 Signed-off-by: Serge Simard <serge@agilitae.com> Change-Id: I924918fb06a5a0f118772dedaa41c536c7eca9e7 Signed-off-by: Serge Simard <serge@agilitae.com> (cherry picked from commit 35ab81bb9ff203e14116de10bc2735ffb2883f67)
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.kt50
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt2
2 files changed, 43 insertions, 9 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 2a227ebe1..6b1f186c9 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
@@ -46,6 +46,7 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
const val INPUT_PACKAGES = "packages"
const val DEFAULT_SELECTOR = "remote-python"
+ const val ATTRIBUTE_EXEC_CMD_STATUS = "status"
const val ATTRIBUTE_PREPARE_ENV_LOG = "prepare-environment-logs"
const val ATTRIBUTE_EXEC_CMD_LOG = "execute-command-logs"
const val ATTRIBUTE_RESPONSE_DATA = "response-data"
@@ -53,7 +54,7 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
override suspend fun processNB(executionRequest: ExecutionServiceInput) {
- log.info("Processing : $operationInputs")
+ log.debug("Processing : $operationInputs")
val bluePrintContext = bluePrintRuntimeService.bluePrintContext()
val blueprintName = bluePrintContext.name()
@@ -109,12 +110,17 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
)
val prepareEnvOutput = remoteScriptExecutionService.prepareEnv(prepareEnvInput)
log.info("$ATTRIBUTE_PREPARE_ENV_LOG - ${prepareEnvOutput.response}")
- setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, JacksonUtils.jsonNodeFromObject(prepareEnvOutput.response))
+ val logs = JacksonUtils.jsonNodeFromObject(prepareEnvOutput.response)
+ setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, logs)
setAttribute(ATTRIBUTE_EXEC_CMD_LOG, "N/A".asJsonPrimitive())
- check(prepareEnvOutput.status == StatusType.SUCCESS) {
- "failed to get prepare remote env response status for requestId(${prepareEnvInput.requestId})"
+
+ if (prepareEnvOutput.status != StatusType.SUCCESS) {
+ setNodeOutputErrors(prepareEnvOutput.status.name, logs)
+ } else {
+ setNodeOutputProperties(prepareEnvOutput.status.name.asJsonPrimitive(), logs, "".asJsonPrimitive())
}
}
+
// Populate command execution properties and pass it to the remote server
val properties = dynamicProperties?.returnNullIfMissing()?.rootFieldsToMap() ?: hashMapOf()
@@ -124,10 +130,13 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
command = scriptCommand,
properties = properties)
val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput)
- log.info("$ATTRIBUTE_EXEC_CMD_LOG - ${remoteExecutionOutput.response}")
- setAttribute(ATTRIBUTE_EXEC_CMD_LOG, JacksonUtils.jsonNodeFromObject(remoteExecutionOutput.response))
- check(remoteExecutionOutput.status == StatusType.SUCCESS) {
- "failed to get prepare remote command response status for requestId(${remoteExecutionOutput.requestId})"
+
+ 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) {
@@ -139,7 +148,7 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
bluePrintRuntimeService.getBluePrintError()
- .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}")
+ .addError("Failed in ComponentRemotePythonExecutor : ${runtimeException.message}")
}
private fun formatNestedJsonNode(node: JsonNode): String {
@@ -151,4 +160,27 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
}
return sb.toString()
}
+
+ /**
+ * Utility function to set the output properties of the executor node
+ */
+ private fun setNodeOutputProperties(status: JsonNode, message: JsonNode, artifacts: JsonNode) {
+ setAttribute(ATTRIBUTE_EXEC_CMD_STATUS, status)
+ log.info("Executor status : $status")
+ setAttribute(ATTRIBUTE_RESPONSE_DATA, artifacts)
+ log.info("Executor artifacts: $artifacts")
+ setAttribute(ATTRIBUTE_EXEC_CMD_LOG, message)
+ log.info("Executor message : $message")
+ }
+
+ /**
+ * Utility function to set the output properties and errors of the executor node, in cas of errors
+ */
+ private fun setNodeOutputErrors(status: String, message: JsonNode, artifacts: JsonNode = "".asJsonPrimitive() ) {
+ setAttribute(ATTRIBUTE_EXEC_CMD_STATUS, status.asJsonPrimitive())
+ setAttribute(ATTRIBUTE_EXEC_CMD_LOG, message)
+ setAttribute(ATTRIBUTE_RESPONSE_DATA, artifacts)
+
+ addError(status, ATTRIBUTE_EXEC_CMD_LOG, message.asText())
+ }
}
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt
index d103bbf08..89af42579 100644
--- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt
+++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt
@@ -194,6 +194,7 @@ class MockRemoteScriptExecutionService : RemoteScriptExecutionService {
assertNotNull(prepareEnvInput.packages, "failed to get packages")
val remoteScriptExecutionOutput = mockk<RemoteScriptExecutionOutput>()
+ every { remoteScriptExecutionOutput.payload } returns "payload".asJsonPrimitive()
every { remoteScriptExecutionOutput.response } returns listOf("prepared successfully")
every { remoteScriptExecutionOutput.status } returns StatusType.SUCCESS
return remoteScriptExecutionOutput
@@ -203,6 +204,7 @@ class MockRemoteScriptExecutionService : RemoteScriptExecutionService {
assertEquals(remoteExecutionInput.requestId, "123456-1000", "failed to match request id")
val remoteScriptExecutionOutput = mockk<RemoteScriptExecutionOutput>()
+ every { remoteScriptExecutionOutput.payload } returns "payload".asJsonPrimitive()
every { remoteScriptExecutionOutput.response } returns listOf("processed successfully")
every { remoteScriptExecutionOutput.status } returns StatusType.SUCCESS
return remoteScriptExecutionOutput