diff options
author | Dan Timoney <dtimoney@att.com> | 2020-09-22 19:05:47 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2020-09-22 19:05:47 +0000 |
commit | e515a85125e5487ecd3f7127b6af0b192d4a0993 (patch) | |
tree | 1fe08a7d54c28419a44845634037d77f8c434a4b /ms/blueprintsprocessor/functions/python-executor | |
parent | 85d8f7f7701570fb745c3d6360d500f97bdf1b25 (diff) | |
parent | 1072867dfac0df993cbd3e44bcc11a5cac7465fd (diff) |
Merge "Enabling Code Formatter"
Diffstat (limited to 'ms/blueprintsprocessor/functions/python-executor')
10 files changed, 164 insertions, 140 deletions
diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt index 03daf2aa9..bd7227744 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt @@ -57,22 +57,22 @@ open class ComponentJythonExecutor( override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { bluePrintRuntimeService.getBluePrintError() - .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}") + .addError("Failed in ComponentJythonExecutor : ${runtimeException.message}") } private suspend fun populateJythonComponentInstance() { val bluePrintContext = bluePrintRuntimeService.bluePrintContext() 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) val pythonFileName = artifactDefinition.file - ?: throw BluePrintProcessorException("missing file name for node template ($nodeTemplateName)'s artifactName($artifactName)") + ?: throw BluePrintProcessorException("missing file name for node template ($nodeTemplateName)'s artifactName($artifactName)") val pythonClassName = FilenameUtils.getBaseName(pythonFileName) @@ -81,7 +81,7 @@ open class ComponentJythonExecutor( checkNotEmpty(content) { "artifact ($artifactName) content is empty" } val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode - ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})") + ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})") val jythonInstance: MutableMap<String, Any> = hashMapOf() jythonInstance["log"] = LoggerFactory.getLogger(pythonClassName) 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 b06da3810..ce51bd9ee 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 @@ -57,6 +57,7 @@ open class ComponentRemotePythonExecutor( private val log = LoggerFactory.getLogger(ComponentRemotePythonExecutor::class.java)!! companion object { + const val SELECTOR_CMD_EXEC = "blueprintsprocessor.remote-script-command" const val INPUT_ENDPOINT_SELECTOR = "endpoint-selector" const val INPUT_DYNAMIC_PROPERTIES = "dynamic-properties" @@ -151,7 +152,8 @@ open class ComponentRemotePythonExecutor( subRequestId = executionServiceInput.commonHeader.subRequestId, remoteIdentifier = RemoteIdentifier( blueprintName = blueprintName, - blueprintVersion = blueprintVersion), + blueprintVersion = blueprintVersion + ), packages = packages, timeOut = envPrepTimeout.toLong() @@ -175,8 +177,10 @@ open class ComponentRemotePythonExecutor( // in cases where the exception is caught in BP side due to timeout, we do not have `err_msg` returned by cmd-exec (inside `payload`), // hence `artifact` field will be empty } catch (grpcEx: io.grpc.StatusRuntimeException) { - val componentLevelWarningMsg = if (timeout < envPrepTimeout) "Note: component-level timeout ($timeout) is shorter than env-prepare timeout ($envPrepTimeout). " else "" - val grpcErrMsg = "Command failed during env. preparation... timeout($envPrepTimeout) requestId ($processId).$componentLevelWarningMsg grpcError: (${grpcEx.cause?.message})" + val componentLevelWarningMsg = + if (timeout < envPrepTimeout) "Note: component-level timeout ($timeout) is shorter than env-prepare timeout ($envPrepTimeout). " else "" + val grpcErrMsg = + "Command failed during env. preparation... timeout($envPrepTimeout) requestId ($processId).$componentLevelWarningMsg grpcError: (${grpcEx.cause?.message})" // no execution log in case of timeout (as cmd-exec side hasn't finished to transfer output) // set prepare-env-log to the error msg, and cmd-exec-log to empty setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, grpcErrMsg.asJsonPrimitive()) @@ -184,7 +188,8 @@ open class ComponentRemotePythonExecutor( addError(StatusType.FAILURE.name, STEP_PREPARE_ENV, grpcErrMsg) log.error(grpcErrMsg, grpcEx) } catch (e: Exception) { - val catchallErrMsg = "Command executor failed during env. preparation.. catch-all case. timeout($envPrepTimeout) requestId ($processId). exception msg: ${e.message}" + val catchallErrMsg = + "Command executor failed during env. preparation.. catch-all case. timeout($envPrepTimeout) requestId ($processId). exception msg: ${e.message}" // no environment prepare log from executor in case of timeout (as cmd-exec side hasn't finished to transfer output), set it to error msg. Execution logs is empty. setAttribute(ATTRIBUTE_PREPARE_ENV_LOG, catchallErrMsg.asJsonPrimitive()) setNodeOutputErrors(STEP_PREPARE_ENV, "[]".asJsonPrimitive(), "{}".asJsonPrimitive(), isLogResponseEnabled) @@ -204,7 +209,8 @@ open class ComponentRemotePythonExecutor( remoteIdentifier = RemoteIdentifier(blueprintName = blueprintName, blueprintVersion = blueprintVersion), command = scriptCommand, properties = properties, - timeOut = executionTimeout.toLong()) + timeOut = executionTimeout.toLong() + ) val remoteExecutionOutputDeferred = GlobalScope.async { remoteScriptExecutionService.executeCommand(remoteExecutionInput) @@ -228,18 +234,22 @@ open class ComponentRemotePythonExecutor( setNodeOutputProperties(remoteExecutionOutput.status, STEP_EXEC_CMD, logs, returnedPayload, isLogResponseEnabled) } // In timeout exception cases, we don't have payload, hence `payload` is empty value. } catch (timeoutEx: TimeoutCancellationException) { - val componentLevelWarningMsg = if (timeout < executionTimeout) "Note: component-level timeout ($timeout) is shorter than execution timeout ($executionTimeout). " else "" - val timeoutErrMsg = "Command executor execution timeout. DetailedMessage: (${timeoutEx.message}) requestId ($processId). $componentLevelWarningMsg" + val componentLevelWarningMsg = + if (timeout < executionTimeout) "Note: component-level timeout ($timeout) is shorter than execution timeout ($executionTimeout). " else "" + val timeoutErrMsg = + "Command executor execution timeout. DetailedMessage: (${timeoutEx.message}) requestId ($processId). $componentLevelWarningMsg" setNodeOutputErrors(STEP_EXEC_CMD, listOf(timeoutErrMsg).asJsonPrimitive(), logging = isLogResponseEnabled) addError(StatusType.FAILURE.name, STEP_EXEC_CMD, timeoutErrMsg) log.error(timeoutErrMsg, timeoutEx) } catch (grpcEx: io.grpc.StatusRuntimeException) { - val timeoutErrMsg = "Command executor timed out executing after $executionTimeout seconds requestId ($processId) grpcErr: ${grpcEx.status}" + val timeoutErrMsg = + "Command executor timed out executing after $executionTimeout seconds requestId ($processId) grpcErr: ${grpcEx.status}" setNodeOutputErrors(STEP_EXEC_CMD, listOf(timeoutErrMsg).asJsonPrimitive(), logging = isLogResponseEnabled) addError(StatusType.FAILURE.name, STEP_EXEC_CMD, timeoutErrMsg) log.error(timeoutErrMsg, grpcEx) } catch (e: Exception) { - val catchAllErrMsg = "Command executor failed during process catch-all case requestId ($processId) timeout($envPrepTimeout) exception msg: ${e.message}" + val catchAllErrMsg = + "Command executor failed during process catch-all case requestId ($processId) timeout($envPrepTimeout) exception msg: ${e.message}" setNodeOutputErrors(STEP_PREPARE_ENV, listOf(catchAllErrMsg).asJsonPrimitive(), logging = isLogResponseEnabled) addError(StatusType.FAILURE.name, STEP_EXEC_CMD, catchAllErrMsg) log.error(catchAllErrMsg, e) diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSL.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSL.kt index 6998f0229..3df25c402 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSL.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSL.kt @@ -112,9 +112,9 @@ fun BluePrintTypes.nodeTemplateComponentRemotePythonExecutor( description: String, block: ComponentRemotePythonExecutorNodeTemplateBuilder.() -> Unit ): - NodeTemplate { - return ComponentRemotePythonExecutorNodeTemplateBuilder(id, description).apply(block).build() -} + NodeTemplate { + return ComponentRemotePythonExecutorNodeTemplateBuilder(id, description).apply(block).build() + } class DtSystemPackageDataTypeBuilder : PropertiesAssignmentBuilder() { @@ -135,7 +135,7 @@ class DtSystemPackageDataTypeBuilder : PropertiesAssignmentBuilder() { class ComponentRemotePythonExecutorNodeTemplateBuilder(id: String, description: String) : AbstractNodeTemplateOperationImplBuilder<PropertiesAssignmentBuilder, ComponentRemotePythonExecutorNodeTemplateBuilder.InputsBuilder, - ComponentRemotePythonExecutorNodeTemplateBuilder.OutputsBuilder>( + ComponentRemotePythonExecutorNodeTemplateBuilder.OutputsBuilder>( id, "component-remote-python-executor", "ComponentRemotePythonExecutor", description ) { diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintJythonServiceImpl.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintJythonServiceImpl.kt index 9000d65d8..b0ce73588 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintJythonServiceImpl.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintJythonServiceImpl.kt @@ -67,23 +67,23 @@ class BlueprintJythonServiceImpl( override fun jythonComponentInstance(bluePrintContext: BluePrintContext, scriptClassReference: String): BlueprintFunctionNode<*, *> { - val pythonFileName = bluePrintContext.rootPath - .plus(File.separator) - .plus(scriptClassReference) + val pythonFileName = bluePrintContext.rootPath + .plus(File.separator) + .plus(scriptClassReference) - val pythonClassName = FilenameUtils.getBaseName(pythonFileName) - log.info("Getting Jython Script Class($pythonClassName)") + val pythonClassName = FilenameUtils.getBaseName(pythonFileName) + log.info("Getting Jython Script Class($pythonClassName)") - val content: String = JacksonUtils.getContent(pythonFileName) + val content: String = JacksonUtils.getContent(pythonFileName) - val jythonInstances: MutableMap<String, Any> = hashMapOf() - jythonInstances["log"] = LoggerFactory.getLogger(pythonClassName) + val jythonInstances: MutableMap<String, Any> = hashMapOf() + jythonInstances["log"] = LoggerFactory.getLogger(pythonClassName) - return jythonInstance<BlueprintFunctionNode<*, *>>( - bluePrintContext, pythonClassName, - content, jythonInstances - ) - } + return jythonInstance<BlueprintFunctionNode<*, *>>( + bluePrintContext, pythonClassName, + content, jythonInstances + ) + } suspend fun jythonComponentInstance(abstractComponentFunction: AbstractComponentFunction): AbstractComponentFunction { diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintPythonHost.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintPythonHost.kt index 3d2f10ec0..f8f0e7e32 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintPythonHost.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintPythonHost.kt @@ -23,6 +23,7 @@ import org.python.util.PythonInterpreter @Deprecated("CDS won't support JythonService") open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython) { + private val blueprintPythonInterpreterProxy: BlueprintPythonInterpreterProxy init { @@ -46,8 +47,10 @@ open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython) { return blueprintPythonInterpreterProxy.getPythonInstance(properties) } catch (e: BluePrintProcessorException) { val errorMsg = "Failed to get python instance." - throw e.updateErrorMessage(ExecutionServiceDomains.PYTHON_EXECUTOR, errorMsg, - "Error in environment properties") + throw e.updateErrorMessage( + ExecutionServiceDomains.PYTHON_EXECUTOR, errorMsg, + "Error in environment properties" + ) } catch (e: Exception) { throw BluePrintProcessorException("Failed to execute Jython component $e", e) } diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/PythonExecutorConfiguration.kt index 8951e3e7b..593c0552b 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/PythonExecutorConfiguration.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/PythonExecutorConfiguration.kt @@ -37,13 +37,16 @@ open class PythonExecutorProperty { @Value("\${blueprints.processor.functions.python.executor.executionPath}") lateinit var executionPath: String + @Value("#{'\${blueprints.processor.functions.python.executor.modulePaths}'.split(',')}") lateinit var modulePaths: List<String> } @Deprecated("CDS won't support JythonService") class PythonExecutorConstants { + companion object { + const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies" } } diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt index 784c6b7ff..d5fa0b20c 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt @@ -37,13 +37,17 @@ import org.springframework.test.context.junit4.SpringRunner @RunWith(SpringRunner::class) @ContextConfiguration( - classes = [PythonExecutorConfiguration::class, PythonExecutorProperty::class, - ComponentJythonExecutor::class, MockInstanceConfiguration::class] + classes = [ + PythonExecutorConfiguration::class, PythonExecutorProperty::class, + ComponentJythonExecutor::class, MockInstanceConfiguration::class + ] ) @TestPropertySource( properties = - ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints", - "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints"] + [ + "blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../components/scripts/python/ccsdk_blueprints" + ] ) class ComponentJythonExecutorTest { diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSLTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSLTest.kt index 5e77937bc..46a3120d5 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSLTest.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/ComponentRemotePythonExecutorDSLTest.kt @@ -44,7 +44,8 @@ class ComponentRemotePythonExecutorDSLTest { "prop1" : "1234", "prop2" : true, "prop3" : 23 - }""".trimIndent() + } + """.trimIndent() ) argumentProperties("""["one", "two"]""") packages { 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 d4edf4bb2..0a0d1659e 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 @@ -49,8 +49,8 @@ class ComponentRemotePythonExecutorTest { val remoteScriptExecutionService = MockRemoteScriptExecutionService() val componentRemotePythonExecutor = ComponentRemotePythonExecutor( - remoteScriptExecutionService, - mockk<BluePrintPropertiesService>() + remoteScriptExecutionService, + mockk<BluePrintPropertiesService>() ) val executionServiceInput = @@ -93,8 +93,8 @@ class ComponentRemotePythonExecutorTest { runBlocking { val remoteScriptExecutionService = MockRemoteScriptExecutionService() val componentRemotePythonExecutor = ComponentRemotePythonExecutor( - remoteScriptExecutionService, - mockk<BluePrintPropertiesService>() + remoteScriptExecutionService, + mockk<BluePrintPropertiesService>() ) val bluePrintRuntime = mockk<DefaultBluePrintRuntimeService>("123456-1000") @@ -112,113 +112,114 @@ class ComponentRemotePythonExecutorTest { */ fun getMockedOutput(svc: DefaultBluePrintRuntimeService): ExecutionServiceInput { - val stepMetaData: MutableMap<String, JsonNode> = hashMapOf() - - stepMetaData.putJsonElement( - BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, - "execute-remote-python" - ) - stepMetaData.putJsonElement( - BluePrintConstants.PROPERTY_CURRENT_INTERFACE, - "ComponentRemotePythonExecutor" - ) - stepMetaData.putJsonElement( - BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process" - ) - - val mapper = ObjectMapper() - val rootNode = mapper.createObjectNode() - rootNode.put("ip-address", "0.0.0.0") - rootNode.put("type", "rest") - - val operationalInputs: MutableMap<String, JsonNode> = hashMapOf() - operationalInputs.putJsonElement( - BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, - "execute-remote-python" - ) - operationalInputs.putJsonElement( - BluePrintConstants.PROPERTY_CURRENT_INTERFACE, - "ComponentRemotePythonExecutor" - ) - operationalInputs.putJsonElement( - BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process" - ) - operationalInputs.putJsonElement("endpoint-selector", "aai") - operationalInputs.putJsonElement("dynamic-properties", rootNode) - operationalInputs.putJsonElement("command", "./run.sh") - operationalInputs.putJsonElement("packages", "py") - - every { - svc.resolveNodeTemplateInterfaceOperationInputs( - "execute-remote-python", - "ComponentRemotePythonExecutor", "process" - ) - } returns operationalInputs - - val stepInputData = StepData().apply { - name = "execute-remote-python" - properties = stepMetaData - } - - val executionServiceInput = JacksonUtils - .readValueFromClassPathFile( - "payload/requests/sample-remote-python-request.json", - ExecutionServiceInput::class.java - )!! - executionServiceInput.stepData = stepInputData + val stepMetaData: MutableMap<String, JsonNode> = hashMapOf() - val operationOutputs = hashMapOf<String, JsonNode>() - every { - svc.resolveNodeTemplateInterfaceOperationOutputs( - "execute-remote-python", - "ComponentRemotePythonExecutor", "process" + stepMetaData.putJsonElement( + BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, + "execute-remote-python" ) - } returns operationOutputs - val bluePrintRuntimeService = BluePrintMetadataUtils.bluePrintRuntime( - "123456-1000", - "./../../../../components/model-" + - "catalog/blueprint-model/test-blueprint/" + - "remote_scripts" - ) - every { - svc.resolveNodeTemplateArtifactDefinition( - "execute-remote-python", "component-script" + stepMetaData.putJsonElement( + BluePrintConstants.PROPERTY_CURRENT_INTERFACE, + "ComponentRemotePythonExecutor" ) - } returns bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition( - "execute-remote-python", "component-script" - ) - every { - svc.setNodeTemplateAttributeValue( - "execute-remote-python", "prepare-environment-logs", - "prepared successfully".asJsonPrimitive() + stepMetaData.putJsonElement( + BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process" ) - } returns Unit - every { - svc.setNodeTemplateAttributeValue( - "execute-remote-python", - "execute-command-logs", "N/A".asJsonPrimitive() + + val mapper = ObjectMapper() + val rootNode = mapper.createObjectNode() + rootNode.put("ip-address", "0.0.0.0") + rootNode.put("type", "rest") + + val operationalInputs: MutableMap<String, JsonNode> = hashMapOf() + operationalInputs.putJsonElement( + BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, + "execute-remote-python" ) - } returns Unit - every { - svc.setNodeTemplateAttributeValue( - "execute-remote-python", - "execute-command-logs", - "processed successfully".asJsonPrimitive() + operationalInputs.putJsonElement( + BluePrintConstants.PROPERTY_CURRENT_INTERFACE, + "ComponentRemotePythonExecutor" ) - } returns Unit + operationalInputs.putJsonElement( + BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process" + ) + operationalInputs.putJsonElement("endpoint-selector", "aai") + operationalInputs.putJsonElement("dynamic-properties", rootNode) + operationalInputs.putJsonElement("command", "./run.sh") + operationalInputs.putJsonElement("packages", "py") + + every { + svc.resolveNodeTemplateInterfaceOperationInputs( + "execute-remote-python", + "ComponentRemotePythonExecutor", "process" + ) + } returns operationalInputs - every { - svc.resolveDSLExpression("aai") - } returns """{"url" : "http://xxx.com"}""".asJsonType() + val stepInputData = StepData().apply { + name = "execute-remote-python" + properties = stepMetaData + } - every { - svc.bluePrintContext() - } returns bluePrintRuntimeService.bluePrintContext() - return executionServiceInput - } + val executionServiceInput = JacksonUtils + .readValueFromClassPathFile( + "payload/requests/sample-remote-python-request.json", + ExecutionServiceInput::class.java + )!! + executionServiceInput.stepData = stepInputData + + val operationOutputs = hashMapOf<String, JsonNode>() + every { + svc.resolveNodeTemplateInterfaceOperationOutputs( + "execute-remote-python", + "ComponentRemotePythonExecutor", "process" + ) + } returns operationOutputs + val bluePrintRuntimeService = BluePrintMetadataUtils.bluePrintRuntime( + "123456-1000", + "./../../../../components/model-" + + "catalog/blueprint-model/test-blueprint/" + + "remote_scripts" + ) + every { + svc.resolveNodeTemplateArtifactDefinition( + "execute-remote-python", "component-script" + ) + } returns bluePrintRuntimeService.resolveNodeTemplateArtifactDefinition( + "execute-remote-python", "component-script" + ) + every { + svc.setNodeTemplateAttributeValue( + "execute-remote-python", "prepare-environment-logs", + "prepared successfully".asJsonPrimitive() + ) + } returns Unit + every { + svc.setNodeTemplateAttributeValue( + "execute-remote-python", + "execute-command-logs", "N/A".asJsonPrimitive() + ) + } returns Unit + every { + svc.setNodeTemplateAttributeValue( + "execute-remote-python", + "execute-command-logs", + "processed successfully".asJsonPrimitive() + ) + } returns Unit + + every { + svc.resolveDSLExpression("aai") + } returns """{"url" : "http://xxx.com"}""".asJsonType() + + every { + svc.bluePrintContext() + } returns bluePrintRuntimeService.bluePrintContext() + return executionServiceInput + } } class MockRemoteScriptExecutionService : RemoteScriptExecutionService { + override suspend fun init(selector: Any) { } diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintPythonHostTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintPythonHostTest.kt index bec8ccae7..0efaaa113 100644 --- a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintPythonHostTest.kt +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/python/executor/scripts/BlueprintPythonHostTest.kt @@ -29,8 +29,10 @@ import kotlin.test.assertNotNull @ContextConfiguration(classes = [BluePrintPython::class, PythonExecutorProperty::class, String::class]) @TestPropertySource( properties = - ["blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", - "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints"] + [ + "blueprints.processor.functions.python.executor.modulePaths=./../../../../../components/scripts/python/ccsdk_blueprints", + "blueprints.processor.functions.python.executor.executionPath=./../../../../../components/scripts/python/ccsdk_blueprints" + ] ) class BlueprintPythonHostTest { |