From 0613ae8f927834f7621011fda3f0cb1b7f8e07ad Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Mon, 18 Feb 2019 15:10:25 -0500 Subject: Add component function scripting service Change-Id: I7c5b49617823dd623566fb4be4d431012420e17c Issue-ID: CCSDK-959 Signed-off-by: Muthuramalingam, Brinda Santh --- .../modules/services/execution-service/pom.xml | 4 + .../execution/AbstractComponentFunction.kt | 27 +++-- .../execution/ComponentFunctionScriptingService.kt | 77 ++++++++++++ .../execution/scripts/BlueprintJythonService.kt | 130 +++++++++++++++++++++ .../execution/scripts/BlueprintPythonHost.kt | 46 ++++++++ .../scripts/BlueprintPythonInterpreterProxy.kt | 40 +++++++ .../scripts/PythonExecutorConfiguration.kt | 68 +++++++++++ .../scripts/BlueprintJythonServiceTest.kt | 57 +++++++++ 8 files changed, 442 insertions(+), 7 deletions(-) create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt create mode 100644 ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt (limited to 'ms/blueprintsprocessor/modules/services') diff --git a/ms/blueprintsprocessor/modules/services/execution-service/pom.xml b/ms/blueprintsprocessor/modules/services/execution-service/pom.xml index ea5f31a36..283a8a66c 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/pom.xml +++ b/ms/blueprintsprocessor/modules/services/execution-service/pom.xml @@ -29,6 +29,10 @@ Blueprints Processor Execution Service + + org.python + jython-standalone + org.onap.ccsdk.apps.controllerblueprints blueprint-core diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt index f7c901dfd..930dc074e 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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. @@ -48,22 +49,26 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode = hashMapOf() + /** + * Store Dynamic Dependency Instances + */ + var functionDependencyInstances: MutableMap = hashMapOf() override fun getName(): String { return stepName } - override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput { + override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput { checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" } check(stepName.isNotEmpty()) { "failed to assign step name" } - this.executionServiceInput = executionRequest + this.executionServiceInput = executionRequest - processId = executionRequest.commonHeader.requestId + processId = executionRequest.commonHeader.requestId check(processId.isNotEmpty()) { "couldn't get process id for step($stepName)" } - workflowName = executionRequest.actionIdentifiers.actionName + workflowName = executionRequest.actionIdentifiers.actionName check(workflowName.isNotEmpty()) { "couldn't get action name for step($stepName)" } log.info("preparing request id($processId) for workflow($workflowName) step($stepName)") @@ -88,14 +93,14 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode functionDependencyInstanceAsType(name: String): T { + return functionDependencyInstances[name] as? T + ?: throw BluePrintProcessorException("couldn't get script property instance ($name)") + } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt new file mode 100644 index 000000000..ecdd454e5 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt @@ -0,0 +1,77 @@ +/* + * Copyright © 2018 IBM. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.blueprintsprocessor.services.execution + +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.slf4j.LoggerFactory +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service + +@Service +class ComponentFunctionScriptingService(private val applicationContext: ApplicationContext, + private val bluePrintScriptsService: BluePrintScriptsService, + private val blueprintJythonService: BlueprintJythonService) { + + private val log = LoggerFactory.getLogger(ComponentFunctionScriptingService::class.java) + + fun scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String, + scriptClassReference: String, + instanceDependencies: MutableList): T { + log.info("creating component function of script type($scriptType), reference name($scriptClassReference) and " + + "instanceDependencies($instanceDependencies)") + + val scriptComponent: T = scriptInstance(componentFunction.bluePrintRuntimeService.bluePrintContext(), + scriptType, scriptClassReference) + populateScriptDependencies(scriptComponent, instanceDependencies) + return scriptComponent + } + + + fun scriptInstance(bluePrintContext: BluePrintContext, scriptType: String, + scriptClassReference: String): T { + var scriptComponent: T? = null + + when (scriptType) { + BluePrintConstants.SCRIPT_INTERNAL -> { + scriptComponent = bluePrintScriptsService.scriptInstance(scriptClassReference) + } + BluePrintConstants.SCRIPT_KOTLIN -> { + scriptComponent = bluePrintScriptsService.scriptInstance(bluePrintContext, scriptClassReference, false) + } + BluePrintConstants.SCRIPT_JYTHON -> { + scriptComponent = blueprintJythonService.jythonComponentInstance(bluePrintContext, scriptClassReference) as T + } + else -> { + throw BluePrintProcessorException("script type($scriptType) is not supported") + } + } + return scriptComponent + } + + + private fun populateScriptDependencies(componentFunction: AbstractComponentFunction, + instanceDependencies: MutableList) { + instanceDependencies.forEach { instanceDependency -> + componentFunction.functionDependencyInstances[instanceDependency] = applicationContext + .getBean(instanceDependency) + } + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt new file mode 100644 index 000000000..9c0390166 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt @@ -0,0 +1,130 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts + +import com.fasterxml.jackson.databind.JsonNode +import com.fasterxml.jackson.databind.node.ArrayNode +import org.apache.commons.io.FilenameUtils +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow +import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationAssignment +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import org.springframework.context.ApplicationContext +import org.springframework.stereotype.Service +import java.io.File + +@Service +class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, + private val applicationContext: ApplicationContext) { + + val log: Logger = LoggerFactory.getLogger(BlueprintJythonService::class.java) + + inline fun jythonInstance(blueprintContext: BluePrintContext, pythonClassName: String, content: String, + dependencyInstanceNames: MutableMap?): T { + + val blueprintBasePath: String = blueprintContext.rootPath + val pythonPath: MutableList = arrayListOf() + pythonPath.add(blueprintBasePath) + pythonPath.addAll(pythonExecutorProperty.modulePaths) + + val blueprintPythonConfigurations = BluePrintPython(pythonExecutorProperty.executionPath, pythonPath, arrayListOf()) + + val blueprintPythonHost = BlueprintPythonHost(blueprintPythonConfigurations) + val pyObject = blueprintPythonHost.getPythonComponent(content, pythonClassName, dependencyInstanceNames) + + log.info("Component Object {}", pyObject) + + return pyObject.__tojava__(T::class.java) as T + } + + fun jythonComponentInstance(bluePrintContext: BluePrintContext, scriptClassReference: String): + AbstractComponentFunction { + val blueprintBasePath: String = bluePrintContext.rootPath + + val pythonFileName = bluePrintContext.rootPath + .plus(File.separator) + .plus(scriptClassReference) + + val pythonClassName = FilenameUtils.getBaseName(pythonFileName) + log.info("Getting Jython Script Class($pythonClassName)") + + val content: String = JacksonUtils.getContent(pythonFileName) + + val pythonPath: MutableList = arrayListOf() + pythonPath.add(blueprintBasePath) + pythonPath.addAll(pythonExecutorProperty.modulePaths) + + val jythonInstances: MutableMap = hashMapOf() + jythonInstances["log"] = LoggerFactory.getLogger(pythonClassName) + + return jythonInstance(bluePrintContext, pythonClassName, + content, jythonInstances) + } + + fun jythonComponentInstance(abstractComponentFunction: AbstractComponentFunction): AbstractComponentFunction { + + val bluePrintRuntimeService = abstractComponentFunction.bluePrintRuntimeService + val bluePrintContext = bluePrintRuntimeService.bluePrintContext() + val nodeTemplateName: String = abstractComponentFunction.nodeTemplateName + val operationInputs: MutableMap = abstractComponentFunction.operationInputs + + val operationAssignment: OperationAssignment = bluePrintContext + .nodeTemplateInterfaceOperation(abstractComponentFunction.nodeTemplateName, + abstractComponentFunction.interfaceName, abstractComponentFunction.operationName) + + val blueprintBasePath: String = bluePrintContext.rootPath + + val artifactName: String = operationAssignment.implementation?.primary + ?: 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)") + + val pythonClassName = FilenameUtils.getBaseName(pythonFileName) + log.info("Getting Jython Script Class($pythonClassName)") + + val content: String? = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactName) + + checkNotEmptyOrThrow(content, "artifact ($artifactName) content is empty") + + val pythonPath: MutableList = operationAssignment.implementation?.dependencies ?: arrayListOf() + pythonPath.add(blueprintBasePath) + pythonPath.addAll(pythonExecutorProperty.modulePaths) + + val jythonInstances: MutableMap = hashMapOf() + jythonInstances["log"] = LoggerFactory.getLogger(nodeTemplateName) + + val instanceDependenciesNode: ArrayNode = operationInputs[PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES] as? ArrayNode + ?: throw BluePrintProcessorException("Failed to get property(${PythonExecutorConstants.INPUT_INSTANCE_DEPENDENCIES})") + + instanceDependenciesNode.forEach { instanceName -> + jythonInstances[instanceName.textValue()] = applicationContext.getBean(instanceName.textValue()) + } + + val scriptComponentFunction = jythonInstance(bluePrintContext, pythonClassName, + content!!, jythonInstances) + + return scriptComponentFunction + + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt new file mode 100644 index 000000000..e5b248b6c --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt @@ -0,0 +1,46 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts + +import org.python.core.PyObject +import org.python.util.PythonInterpreter + +open class BlueprintPythonHost(private val bluePrintPython: BluePrintPython){ + private val blueprintPythonInterpreterProxy: BlueprintPythonInterpreterProxy + + init { + PythonInterpreter.initialize(System.getProperties(), bluePrintPython.props, bluePrintPython.argv.toTypedArray()) + blueprintPythonInterpreterProxy = BlueprintPythonInterpreterProxy(bluePrintPython) + } + + /** + * getPythonComponent Purpose: execute the python script and return the python interpreter object + * + * @param content String + * @param interfaceName String + * @param properties MutableMap + * @return pyObject PyObject + */ + fun getPythonComponent(content: String?, interfaceName: String, properties: MutableMap?): PyObject { + bluePrintPython.content = content!! + bluePrintPython.pythonClassName = interfaceName + bluePrintPython.moduleName = "Blueprint Python Script [Class Name = $interfaceName]" + + return blueprintPythonInterpreterProxy.getPythonInstance(properties) + } + + //TODO Check potential errors in python scripts +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt new file mode 100644 index 000000000..735b8d77a --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt @@ -0,0 +1,40 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts + +import org.python.core.PyObject +import org.python.util.PythonInterpreter + +open class BlueprintPythonInterpreterProxy(private val bluePrintPython: BluePrintPython): PythonInterpreter(){ + + fun getPythonInstance(properties: MutableMap?): PyObject{ + properties?.forEach { (name, value) -> + this.set(name, value) + } + + this.exec("import sys") + + bluePrintPython.content.let { + this.exec(bluePrintPython.content) + } + + val initCommand = bluePrintPython.pythonClassName.plus(" = ").plus( + bluePrintPython.pythonClassName).plus("()") + this.exec(initCommand) + + return this.get(bluePrintPython.pythonClassName) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt new file mode 100644 index 000000000..fa3e3a134 --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt @@ -0,0 +1,68 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Modifications Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts + +import org.springframework.beans.factory.annotation.Value +import org.springframework.boot.context.properties.EnableConfigurationProperties +import org.springframework.context.annotation.ComponentScan +import org.springframework.context.annotation.Configuration +import java.io.File +import java.util.* + +@Configuration +@ComponentScan +@EnableConfigurationProperties +open class PythonExecutorConfiguration + +@Configuration +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 +} + +class PythonExecutorConstants { + companion object { + const val INPUT_INSTANCE_DEPENDENCIES = "instance-dependencies" + } +} + +open class BluePrintPython(executablePath: String, blueprintPythonPlatform: MutableList, + val argv: MutableList){ + lateinit var moduleName: String + lateinit var pythonClassName: String + lateinit var content: String + var props: Properties = Properties() + + init { + // Build up the python.path + val sb = StringBuilder() + sb.append(System.getProperty("java.class.path")) + + for (p in blueprintPythonPlatform) { + sb.append(File.pathSeparator).append(p) + } + + props["python.import.site"] = "true" + props.setProperty("python.path", sb.toString()) + props.setProperty("python.verbose", "error") + props.setProperty("python.executable", executablePath) + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt new file mode 100644 index 000000000..b48a10e9c --- /dev/null +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt @@ -0,0 +1,57 @@ +/* + * Copyright © 2019 IBM, Bell Canada. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts + +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.TestPropertySource +import org.springframework.test.context.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [BlueprintJythonService::class, PythonExecutorProperty::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"]) +class BlueprintJythonServiceTest { + + @Autowired + private lateinit var blueprintJythonService: BlueprintJythonService + + @Test + fun testGetAbstractPythonPlugin() { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") + + val dependencies: MutableMap = hashMapOf() + + val content = JacksonUtils.getContent("./../../../../." + + "./components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py") + + val abstractComponentFunction = blueprintJythonService.jythonInstance(bluePrintContext, "SamplePythonComponentNode", content, dependencies) + + assertNotNull(abstractComponentFunction, "failed to get python component") + + abstractComponentFunction.process(ExecutionServiceInput()) + + } +} \ No newline at end of file -- cgit 1.2.3-korg