diff options
author | Brinda Santh <brindasanth@in.ibm.com> | 2019-04-23 16:06:54 +0530 |
---|---|---|
committer | Alexis de Talhouƫt <adetalhouet89@gmail.com> | 2019-04-24 09:43:37 -0400 |
commit | f79ef8c3f922e6d467d74c2ac3e8bec9cb2b991a (patch) | |
tree | 2229aede34364e19b71d355d51ba66f129e36288 /ms/blueprintsprocessor | |
parent | 5a82232d3502a566466fac1f8d6f6aadc50fbc6e (diff) |
Rework remote command arguments
Change-Id: Ibd24ce87ed67aee6ae1a66fc9ec6af35bee5008a
Issue-ID: CCSDK-1215
Signed-off-by: Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms/blueprintsprocessor')
3 files changed, 32 insertions, 31 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 } diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt index 12f6bc47f..23588d25a 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -24,10 +24,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceOutp import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.Status import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.StepData import org.onap.ccsdk.cds.controllerblueprints.common.api.EventType -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty -import org.onap.ccsdk.cds.controllerblueprints.core.getAsString +import org.onap.ccsdk.cds.controllerblueprints.core.* import org.onap.ccsdk.cds.controllerblueprints.core.interfaces.BlueprintFunctionNode import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService import org.slf4j.LoggerFactory @@ -133,6 +130,10 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic ?: throw BluePrintProcessorException("couldn't get the operation input($key) value.") } + fun getOptionalOperationInput(key: String): JsonNode? { + return operationInputs[key] + } + fun setAttribute(key: String, value: JsonNode) { bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, key, value) } |