summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/python-executor/src
diff options
context:
space:
mode:
authorDan Timoney <dtimoney@att.com>2019-04-24 18:09:46 +0000
committerGerrit Code Review <gerrit@onap.org>2019-04-24 18:09:46 +0000
commit535002fbb8b2ffeb81564b4ed8858889ac6404d4 (patch)
treee3b54f266aca62a5209f46bf51253df81db2c85b /ms/blueprintsprocessor/functions/python-executor/src
parentfb8d3807fe21a575bfe918687ed0ae971b4367c8 (diff)
parentf79ef8c3f922e6d467d74c2ac3e8bec9cb2b991a (diff)
Merge "Rework remote command arguments"
Diffstat (limited to 'ms/blueprintsprocessor/functions/python-executor/src')
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutor.kt52
-rw-r--r--ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorTest.kt2
2 files changed, 27 insertions, 27 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 df92d7157..df9b014ee 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
@@ -16,26 +16,17 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.python.executor
-import com.fasterxml.jackson.databind.node.MissingNode
-import com.fasterxml.jackson.databind.node.NullNode
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.*
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.ExecutionServiceConstant
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.RemoteScriptExecutionService
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
-import org.onap.ccsdk.cds.controllerblueprints.core.checkFileExists
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotBlank
+import org.onap.ccsdk.cds.controllerblueprints.core.*
import org.onap.ccsdk.cds.controllerblueprints.core.data.OperationAssignment
-import org.onap.ccsdk.cds.controllerblueprints.core.normalizedFile
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintVelocityTemplateService
-import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Component
-import java.lang.Exception
@ConditionalOnBean(name = [ExecutionServiceConstant.SERVICE_GRPC_REMOTE_SCRIPT_EXECUTION])
@Component("component-remote-python-executor")
@@ -65,13 +56,13 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
val blueprintVersion = bluePrintContext.version()
val operationAssignment: OperationAssignment = bluePrintContext
- .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName)
+ .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName)
val artifactName: String = operationAssignment.implementation?.primary
- ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)")
+ ?: throw BluePrintProcessorException("missing primary field to get artifact name for node template ($nodeTemplateName)")
val artifactDefinition =
- bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName)
+ bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition(nodeTemplateName, artifactName)
checkNotBlank(artifactDefinition.file) { "couldn't get python script path($artifactName)" }
@@ -80,24 +71,28 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
checkFileExists(pythonScript) { "python script(${pythonScript.absolutePath}) doesn't exists" }
val endPointSelector = getOperationInput(INPUT_ENDPOINT_SELECTOR)
- val dynamicProperties = getOperationInput(INPUT_DYNAMIC_PROPERTIES)
- val packages = getOperationInput(INPUT_PACKAGES)
- val argumentProperties = getOperationInput(INPUT_ARGUMENT_PROPERTIES)
+ val dynamicProperties = getOptionalOperationInput(INPUT_DYNAMIC_PROPERTIES)
+ val packages = getOptionalOperationInput(INPUT_PACKAGES)?.returnNullIfMissing()
- var command = getOperationInput(INPUT_COMMAND).asText()
- command = command.replace(pythonScript.name, pythonScript.absolutePath)
- val scriptCommand = BluePrintVelocityTemplateService.generateContent(command, json = JacksonUtils.getJson(argumentProperties))
+ val args = getOptionalOperationInput(INPUT_ARGUMENT_PROPERTIES)?.returnNullIfMissing()
+ ?.rootFieldsToMap()?.toSortedMap()?.values?.map { it.textValue() }?.joinToString(" ")
+
+ val command = getOperationInput(INPUT_COMMAND).asText()
+ var scriptCommand = command.replace(pythonScript.name, pythonScript.absolutePath)
+ if (args != null && args.isNotEmpty()) {
+ scriptCommand = scriptCommand.plus(" ").plus(args)
+ }
try {
// Open GRPC Connection
remoteScriptExecutionService.init(endPointSelector.asText())
// If packages are defined, then install in remote server
- if (packages !is MissingNode && packages !is NullNode) {
+ if (packages != null) {
val prepareEnvInput = PrepareRemoteEnvInput(requestId = processId,
- remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName,
- blueprintVersion = blueprintVersion),
- packages = packages
+ remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName,
+ blueprintVersion = blueprintVersion),
+ packages = packages
)
val prepareEnvOutput = remoteScriptExecutionService.prepareEnv(prepareEnvInput)
setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, prepareEnvOutput.response.asJsonPrimitive())
@@ -105,11 +100,14 @@ open class ComponentRemotePythonExecutor(private val remoteScriptExecutionServic
"failed to get prepare remote env response status for requestId(${prepareEnvInput.requestId})"
}
}
+ // 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)
+ requestId = processId,
+ remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion),
+ command = scriptCommand,
+ properties = properties)
val remoteExecutionOutput = remoteScriptExecutionService.executeCommand(remoteExecutionInput)
setAttribute(ATTRIBUTE_EXEC_CMD_LOG, remoteExecutionOutput.response.asJsonPrimitive())
check(remoteExecutionOutput.status == StatusType.SUCCESS) {
@@ -125,6 +123,6 @@ 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 ComponentJythonExecutor : ${runtimeException.message}")
}
} \ No newline at end of file
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 03616d5e4..0c5a947f1 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
@@ -71,6 +71,7 @@ class MockRemoteScriptExecutionService : RemoteScriptExecutionService {
assertNotNull(prepareEnvInput.packages, "failed to get packages")
val remoteScriptExecutionOutput = mockk<RemoteScriptExecutionOutput>()
+ every { remoteScriptExecutionOutput.response } returns "prepared successfully"
every { remoteScriptExecutionOutput.status } returns StatusType.SUCCESS
return remoteScriptExecutionOutput
}
@@ -79,6 +80,7 @@ class MockRemoteScriptExecutionService : RemoteScriptExecutionService {
assertEquals(remoteExecutionInput.requestId, "123456-1000", "failed to match request id")
val remoteScriptExecutionOutput = mockk<RemoteScriptExecutionOutput>()
+ every { remoteScriptExecutionOutput.response } returns "processed successfully"
every { remoteScriptExecutionOutput.status } returns StatusType.SUCCESS
return remoteScriptExecutionOutput
}