From d2ec19b59ee0bdc1ba3a22baff5d0d30bd8a9e19 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Mon, 19 Nov 2018 12:48:31 -0500 Subject: Implement Base Jython Executor function. Change-Id: I3fb066a021de4a7b3aa1fce7f6c191bc3944fb51 Issue-ID: CCSDK-696 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- ms/blueprintsprocessor/.gitignore | 1 + ms/blueprintsprocessor/functions/pom.xml | 1 + .../functions/python-executor/pom.xml | 41 +++++++++++ .../python/executor/ComponentPythonExecutor.kt | 82 ++++++++++++++++++++++ .../python/executor/PythonExecutorConfiguration.kt | 36 ++++++++++ .../python/executor/utils/PythonExecutorUtils.kt | 77 ++++++++++++++++++++ .../python/executor/ComponentPythonExecutorTest.kt | 76 ++++++++++++++++++++ .../executor/utils/PythonExecutorUtilsTest.kt | 52 ++++++++++++++ .../src/test/resources/logback-test.xml | 35 +++++++++ .../functions/resource-resolution/pom.xml | 4 +- .../execution/AbstractComponentFunction.kt | 34 ++++++++- .../services/workflow/BlueprintSvcLogicService.kt | 10 +-- .../executor/ComponentExecuteNodeExecutor.kt | 2 + .../services/workflow/BlueprintServiceLogicTest.kt | 31 +++++++- ms/blueprintsprocessor/parent/pom.xml | 6 ++ 15 files changed, 473 insertions(+), 15 deletions(-) create mode 100644 ms/blueprintsprocessor/functions/python-executor/pom.xml create mode 100644 ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutor.kt create mode 100644 ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt create mode 100644 ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt create mode 100644 ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutorTest.kt create mode 100644 ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtilsTest.kt create mode 100644 ms/blueprintsprocessor/functions/python-executor/src/test/resources/logback-test.xml (limited to 'ms') diff --git a/ms/blueprintsprocessor/.gitignore b/ms/blueprintsprocessor/.gitignore index b25ff7b05..983e231d6 100644 --- a/ms/blueprintsprocessor/.gitignore +++ b/ms/blueprintsprocessor/.gitignore @@ -15,6 +15,7 @@ **/target/* **/logs/* **/tokens/* +**/lib/cachedir/** # Added for Intellij IDEA IDE **/debug-logs/* diff --git a/ms/blueprintsprocessor/functions/pom.xml b/ms/blueprintsprocessor/functions/pom.xml index 50ea7b0e7..efd550ddb 100644 --- a/ms/blueprintsprocessor/functions/pom.xml +++ b/ms/blueprintsprocessor/functions/pom.xml @@ -31,6 +31,7 @@ Blueprints Processor Functions POM resource-resolution + python-executor diff --git a/ms/blueprintsprocessor/functions/python-executor/pom.xml b/ms/blueprintsprocessor/functions/python-executor/pom.xml new file mode 100644 index 000000000..4f9cc7458 --- /dev/null +++ b/ms/blueprintsprocessor/functions/python-executor/pom.xml @@ -0,0 +1,41 @@ + + + + + + functions + org.onap.ccsdk.apps.blueprintsprocessor + 0.4.0-SNAPSHOT + + 4.0.0 + + org.onap.ccsdk.apps.blueprintsprocessor.functions + python-executor + Blueprints Processor Function - Python Executor + Blueprints Processor Function - Python Executor + + + + org.python + jython-standalone + + + + + \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutor.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutor.kt new file mode 100644 index 000000000..823b13f27 --- /dev/null +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutor.kt @@ -0,0 +1,82 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.functions.python.executor + +import org.apache.commons.io.FilenameUtils +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.utils.PythonExecutorUtils +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyNThrow +import org.onap.ccsdk.apps.controllerblueprints.core.data.OperationAssignment +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Component + +@Component("component-python-executor") +class ComponentPythonExecutor(private val pythonExecutorProperty: PythonExecutorProperty) : AbstractComponentFunction() { + + private val log = LoggerFactory.getLogger(ComponentPythonExecutor::class.java) + + private var componentFunction: AbstractComponentFunction? = null + + + override fun process(executionServiceInput: ExecutionServiceInput) { + + log.info("Processing : ${executionServiceInput.metadata}") + checkNotNull(bluePrintRuntimeService) { "failed to get bluePrintRuntimeService" } + + val bluePrintContext = bluePrintRuntimeService!!.bluePrintContext() + + val operationAssignment: OperationAssignment = bluePrintContext + .nodeTemplateInterfaceOperation(nodeTemplateName, interfaceName, operationName) + + val blueprintBasePath: String = bluePrintRuntimeService!!.get(BluePrintConstants.PROPERTY_BLUEPRINT_BASE_PATH)?.asText() + ?: throw BluePrintProcessorException("python execute path is missing for node template ($nodeTemplateName)") + + 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) + + val content: String? = bluePrintRuntimeService!!.resolveNodeTemplateArtifact(nodeTemplateName, artifactName) + + checkNotEmptyNThrow(content, "artifact ($artifactName) content is empty") + + val pythonPath: MutableList = operationAssignment.implementation?.dependencies ?: arrayListOf() + pythonPath.add(blueprintBasePath) + pythonPath.addAll(pythonExecutorProperty.modulePaths) + + val properties: MutableMap = hashMapOf() + properties["log"] = log + + componentFunction = PythonExecutorUtils.getPythonComponent(pythonExecutorProperty.executionPath, pythonPath, content, pythonClassName, properties) + + componentFunction!!.process(executionServiceInput) + + } + + override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) { + componentFunction!!.recover(runtimeException, executionRequest) + } + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt new file mode 100644 index 000000000..dd80fb0ae --- /dev/null +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt @@ -0,0 +1,36 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.functions.python.executor + +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 + +@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 + +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt new file mode 100644 index 000000000..66c919d4d --- /dev/null +++ b/ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt @@ -0,0 +1,77 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.functions.python.executor.utils + +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction +import org.python.core.PyObject +import org.python.util.PythonInterpreter +import org.slf4j.LoggerFactory +import java.util.* + +class PythonExecutorUtils { + companion object { + + private val log = LoggerFactory.getLogger(PythonExecutorUtils::class.java) + + fun getPythonComponent(executePath: String, pythonPath: MutableList, content: String?, interfaceName: String, + properties: MutableMap): AbstractComponentFunction { + + initPython(executePath, pythonPath, arrayListOf()) + val pythonInterpreter = PythonInterpreter() + + properties.forEach { (name, value) -> + pythonInterpreter.set(name, value) + } + + pythonInterpreter.exec("import sys") + + content?.let { + pythonInterpreter.exec(content) + } + + val initCommand = interfaceName.plus(" = ").plus(interfaceName).plus("()") + pythonInterpreter.exec(initCommand) + val pyObject: PyObject = pythonInterpreter.get(interfaceName) + + log.info("Component Object {}", pyObject) + + return pyObject.__tojava__(AbstractComponentFunction::class.java) as AbstractComponentFunction + } + + private fun initPython(executablePath: String, + pythonPath: MutableList, argv: MutableList) { + + val props = Properties() + // Build up the python.path + val sb = StringBuilder() + sb.append(System.getProperty("java.class.path")) + + for (p in pythonPath) { + sb.append(":").append(p) + } + log.debug("Paths : $sb") + + props["python.import.site"] = "true" + props.setProperty("python.path", sb.toString()) + props.setProperty("python.verbose", "error") + props.setProperty("python.executable", executablePath) + + PythonInterpreter.initialize(System.getProperties(), props, argv.toTypedArray()) + } + + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutorTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutorTest.kt new file mode 100644 index 000000000..e16f2f030 --- /dev/null +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutorTest.kt @@ -0,0 +1,76 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.functions.python.executor + +import com.fasterxml.jackson.databind.JsonNode +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement +import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils +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 + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [PythonExecutorConfiguration::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 ComponentPythonExecutorTest { + + @Autowired + lateinit var componentPythonExecutor: ComponentPythonExecutor + + + @Test + fun testPythonComponentInjection() { + + val executionServiceInput = ExecutionServiceInput() + val commonHeader = CommonHeader() + commonHeader.requestId = "1234" + executionServiceInput.commonHeader = commonHeader + + val actionIdentifiers = ActionIdentifiers() + actionIdentifiers.blueprintName = "baseconfiguration" + actionIdentifiers.blueprintVersion = "1.0.0" + actionIdentifiers.actionName = "activate" + executionServiceInput.actionIdentifiers = actionIdentifiers + + + val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime(commonHeader.requestId, + "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") + + componentPythonExecutor.bluePrintRuntimeService = bluePrintRuntimeService + + + val metaData: MutableMap = hashMapOf() + metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_STEP, "resource-assignment-py") + metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment-py") + metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "DefaultComponentNode") + metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process") + executionServiceInput.metadata = metaData + + componentPythonExecutor.apply(executionServiceInput) + + } +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtilsTest.kt b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtilsTest.kt new file mode 100644 index 000000000..6197c4b28 --- /dev/null +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtilsTest.kt @@ -0,0 +1,52 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * 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.functions.python.executor.utils + +import org.junit.Test +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.slf4j.LoggerFactory +import kotlin.test.assertNotNull + + +class PythonExecutorUtilsTest { + + private val log = LoggerFactory.getLogger(PythonExecutorUtils::class.java) + + @Test + fun testGetPythonComponent() { + + val pythonPath: MutableList = arrayListOf() + pythonPath.add("./../../../../components/scripts/python/ccsdk_blueprints") + + val properties: MutableMap = hashMapOf() + properties["logger"] = log + + val content = JacksonUtils.getContent("./../../../../components/scripts/python/ccsdk_blueprints/sample_blueprint_component.py") + + val abstractComponentFunction = PythonExecutorUtils.getPythonComponent("/home/brindasanth/onap/apps/components/scripts/python/ccsdk_blueprints", pythonPath, content, + "SampleBlueprintComponent", properties) + + assertNotNull(abstractComponentFunction, "failed to get python component") + + abstractComponentFunction.process(ExecutionServiceInput()) + + } + + +} + diff --git a/ms/blueprintsprocessor/functions/python-executor/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/python-executor/src/test/resources/logback-test.xml new file mode 100644 index 000000000..a816a06c5 --- /dev/null +++ b/ms/blueprintsprocessor/functions/python-executor/src/test/resources/logback-test.xml @@ -0,0 +1,35 @@ + + + + + + + %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n + + + + + + + + + + + + + diff --git a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml index a2d3bb85e..858be70cd 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml +++ b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml @@ -25,7 +25,7 @@ org.onap.ccsdk.apps.blueprintsprocessor.functions resource-resolution jar - Blueprints Processor Resolution Service - Blueprints Processor Resolution Service + Blueprints Processor Function - Resource Resolution + Blueprints Processor Function - Resource Resolution 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 9a0d1f91c..801b66036 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 @@ -19,7 +19,10 @@ package org.onap.ccsdk.apps.blueprintsprocessor.services.execution import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.getAsString import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode +import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.slf4j.LoggerFactory /** @@ -29,14 +32,39 @@ import org.slf4j.LoggerFactory abstract class AbstractComponentFunction : BlueprintFunctionNode { private val log = LoggerFactory.getLogger(AbstractComponentFunction::class.java) - override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput { + var executionServiceInput: ExecutionServiceInput? = null + val executionServiceOutput = ExecutionServiceOutput() + var bluePrintRuntimeService: BluePrintRuntimeService<*>? = null + var processId: String = "" + var workflowName: String = "" + var stepName: String = "" + var interfaceName: String = "" + var operationName: String = "" + var nodeTemplateName: String = "" + + + override fun prepareRequest(executionServiceInput: ExecutionServiceInput): ExecutionServiceInput { + + this.executionServiceInput = this.executionServiceInput + + processId = executionServiceInput.commonHeader.requestId + workflowName = executionServiceInput.actionIdentifiers.actionName + + val metadata = executionServiceInput.metadata + stepName = metadata.getAsString(BluePrintConstants.PROPERTY_CURRENT_STEP) + nodeTemplateName = metadata.getAsString(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE) + interfaceName = metadata.getAsString(BluePrintConstants.PROPERTY_CURRENT_INTERFACE) + operationName = metadata.getAsString(BluePrintConstants.PROPERTY_CURRENT_OPERATION) + + checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" } + log.info("prepareRequest...") - return executionRequest + return executionServiceInput } override fun prepareResponse(): ExecutionServiceOutput { log.info("Preparing Response...") - return ExecutionServiceOutput() + return this.executionServiceOutput } override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput { diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt index 8750d98b3..0600f62d2 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt @@ -125,12 +125,6 @@ class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService { override fun execute(graph: SvcLogicGraph, svcLogicContext: SvcLogicContext): SvcLogicContext { MDC.put("currentGraph", graph.toString()) - val ctx = svcLogicContext as BlueprintSvcLogicContext - - val blueprintRuntimeService = ctx.getBluePrintService() - - log.info("Blueprint Runtime Service : ${blueprintRuntimeService}") - var curNode: SvcLogicNode? = graph.getRootNode() log.info("About to execute graph {}", graph.toString()) @@ -138,7 +132,7 @@ class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService { while (curNode != null) { MDC.put("nodeId", curNode.nodeId.toString() + " (" + curNode.nodeType + ")") log.info("About to execute node # {} ({})", curNode.nodeId, curNode.nodeType) - val nextNode = this.executeNode(curNode, ctx) + val nextNode = this.executeNode(curNode, svcLogicContext) curNode = nextNode } } catch (var5: ExitNodeException) { @@ -147,6 +141,6 @@ class DefaultBlueprintSvcLogicService : BlueprintSvcLogicService { MDC.remove("nodeId") MDC.remove("currentGraph") - return ctx + return svcLogicContext } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt index 125a1ff6f..ace9f2787 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt @@ -60,6 +60,8 @@ open class ComponentExecuteNodeExecutor : ExecuteNodeExecutor() { log.info("executing node template($nodeTemplateName) component($componentName)") // Get the Component Instance val plugin = this.getComponentFunction(componentName) + // Set the Blueprint Service + plugin.bluePrintRuntimeService = ctx.getBluePrintService() val executionInput = ctx.getRequest() as ExecutionServiceInput // Get the Request from the Context and Set to the Function Input and Invoke the function diff --git a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt index 5c90852ee..6fe767ce2 100644 --- a/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt +++ b/ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt @@ -16,11 +16,16 @@ package org.onap.ccsdk.apps.blueprintsprocessor.services.workflow +import com.fasterxml.jackson.databind.JsonNode import org.junit.Test import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ActionIdentifiers +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.CommonHeader import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.executor.ComponentExecuteNodeExecutor import org.onap.ccsdk.apps.blueprintsprocessor.services.workflow.utils.SvcGraphUtils +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired @@ -45,7 +50,7 @@ class BlueprintServiceLogicTest { val graph = SvcGraphUtils.getSvcGraphFromClassPathFile("service-logic/one-component.xml") val svcLogicContext = BlueprintSvcLogicContext() svcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService) - svcLogicContext.setRequest(ExecutionServiceInput()) + svcLogicContext.setRequest(getDefaultExecutionServiceInput()) blueprintSvcLogicService.execute(graph, svcLogicContext) } @@ -55,8 +60,30 @@ class BlueprintServiceLogicTest { val graph = SvcGraphUtils.getSvcGraphFromClassPathFile("service-logic/two-component.xml") val svcLogicContext = BlueprintSvcLogicContext() svcLogicContext.setBluePrintRuntimeService(bluePrintRuntimeService) - svcLogicContext.setRequest(ExecutionServiceInput()) + svcLogicContext.setRequest(getDefaultExecutionServiceInput()) blueprintSvcLogicService.execute(graph, svcLogicContext) } + + private fun getDefaultExecutionServiceInput(): ExecutionServiceInput { + val executionServiceInput = ExecutionServiceInput() + val commonHeader = CommonHeader() + commonHeader.requestId = "1234" + executionServiceInput.commonHeader = commonHeader + + val actionIdentifiers = ActionIdentifiers() + actionIdentifiers.blueprintName = "baseconfiguration" + actionIdentifiers.blueprintVersion = "1.0.0" + actionIdentifiers.actionName = "activate" + executionServiceInput.actionIdentifiers = actionIdentifiers + + val metaData: MutableMap = hashMapOf() + metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_STEP,"resource-assignment-py") + metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "resource-assignment-py") + metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "DefaultComponentNode") + metaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_OPERATION, "process") + executionServiceInput.metadata = metaData + + return executionServiceInput + } } \ No newline at end of file diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml index 761fdc724..637a07a67 100644 --- a/ms/blueprintsprocessor/parent/pom.xml +++ b/ms/blueprintsprocessor/parent/pom.xml @@ -38,6 +38,7 @@ 1.0.0 0.3.1 26.0-jre + 2.7.1 2.9.2 1.4.197 1.2.2 @@ -228,6 +229,11 @@ guava ${guava.version} + + org.python + jython-standalone + ${jython.version} + -- cgit 1.2.3-korg