Implement Base Jython Executor function.
authorMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Mon, 19 Nov 2018 17:48:31 +0000 (12:48 -0500)
committerMuthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
Thu, 29 Nov 2018 00:46:23 +0000 (19:46 -0500)
Change-Id: I3fb066a021de4a7b3aa1fce7f6c191bc3944fb51
Issue-ID: CCSDK-696
Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) <bs2796@att.com>
15 files changed:
ms/blueprintsprocessor/.gitignore
ms/blueprintsprocessor/functions/pom.xml
ms/blueprintsprocessor/functions/python-executor/pom.xml [new file with mode: 0644]
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutor.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtils.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentPythonExecutorTest.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/utils/PythonExecutorUtilsTest.kt [new file with mode: 0644]
ms/blueprintsprocessor/functions/python-executor/src/test/resources/logback-test.xml [new file with mode: 0644]
ms/blueprintsprocessor/functions/resource-resolution/pom.xml
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintSvcLogicService.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/executor/ComponentExecuteNodeExecutor.kt
ms/blueprintsprocessor/modules/services/workflow-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/workflow/BlueprintServiceLogicTest.kt
ms/blueprintsprocessor/parent/pom.xml

index b25ff7b..983e231 100644 (file)
@@ -15,6 +15,7 @@
 **/target/*
 **/logs/*
 **/tokens/*
+**/lib/cachedir/**
 
 # Added for Intellij IDEA IDE
 **/debug-logs/*
index 50ea7b0..efd550d 100644 (file)
@@ -31,6 +31,7 @@
     <description>Blueprints Processor Functions POM</description>
     <modules>
         <module>resource-resolution</module>
+        <module>python-executor</module>
     </modules>
 
     <dependencies>
diff --git a/ms/blueprintsprocessor/functions/python-executor/pom.xml b/ms/blueprintsprocessor/functions/python-executor/pom.xml
new file mode 100644 (file)
index 0000000..4f9cc74
--- /dev/null
@@ -0,0 +1,41 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ 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.
+  -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+    <parent>
+        <artifactId>functions</artifactId>
+        <groupId>org.onap.ccsdk.apps.blueprintsprocessor</groupId>
+        <version>0.4.0-SNAPSHOT</version>
+    </parent>
+    <modelVersion>4.0.0</modelVersion>
+
+    <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
+    <artifactId>python-executor</artifactId>
+    <name>Blueprints Processor Function - Python Executor</name>
+    <description>Blueprints Processor Function - Python Executor</description>
+
+    <dependencies>
+        <dependency>
+            <groupId>org.python</groupId>
+            <artifactId>jython-standalone</artifactId>
+        </dependency>
+    </dependencies>
+
+
+</project>
\ 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 (file)
index 0000000..823b13f
--- /dev/null
@@ -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<String> = operationAssignment.implementation?.dependencies ?: arrayListOf()
+        pythonPath.add(blueprintBasePath)
+        pythonPath.addAll(pythonExecutorProperty.modulePaths)
+
+        val properties: MutableMap<String, Any> = 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 (file)
index 0000000..dd80fb0
--- /dev/null
@@ -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<String>
+
+}
\ 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 (file)
index 0000000..66c919d
--- /dev/null
@@ -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<String>, content: String?, interfaceName: String,
+                               properties: MutableMap<String, Any>): 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<String>, argv: MutableList<String>) {
+
+            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 (file)
index 0000000..e16f2f0
--- /dev/null
@@ -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<String, JsonNode> = 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 (file)
index 0000000..6197c4b
--- /dev/null
@@ -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<String> = arrayListOf()
+        pythonPath.add("./../../../../components/scripts/python/ccsdk_blueprints")
+
+        val properties: MutableMap<String, Any> = 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 (file)
index 0000000..a816a06
--- /dev/null
@@ -0,0 +1,35 @@
+<!--\r
+  ~ Copyright © 2017-2018 AT&T Intellectual Property.\r
+  ~\r
+  ~ Licensed under the Apache License, Version 2.0 (the "License");\r
+  ~ you may not use this file except in compliance with the License.\r
+  ~ You may obtain a copy of the License at\r
+  ~\r
+  ~     http://www.apache.org/licenses/LICENSE-2.0\r
+  ~\r
+  ~ Unless required by applicable law or agreed to in writing, software\r
+  ~ distributed under the License is distributed on an "AS IS" BASIS,\r
+  ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+  ~ See the License for the specific language governing permissions and\r
+  ~ limitations under the License.\r
+  -->\r
+\r
+<configuration>\r
+    <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">\r
+        <!-- encoders are assigned the type\r
+             ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->\r
+        <encoder>\r
+            <pattern>%d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n</pattern>\r
+        </encoder>\r
+    </appender>\r
+\r
+\r
+    <logger name="org.springframework" level="warn"/>\r
+    <logger name="org.hibernate" level="info"/>\r
+    <logger name="org.onap.ccsdk.apps.blueprintsprocessor" level="info"/>\r
+\r
+    <root level="warn">\r
+        <appender-ref ref="STDOUT"/>\r
+    </root>\r
+\r
+</configuration>\r
index a2d3bb8..858be70 100644 (file)
@@ -25,7 +25,7 @@
     <groupId>org.onap.ccsdk.apps.blueprintsprocessor.functions</groupId>
     <artifactId>resource-resolution</artifactId>
     <packaging>jar</packaging>
-    <name>Blueprints Processor Resolution Service</name>
-    <description>Blueprints Processor Resolution Service</description>
+    <name>Blueprints Processor Function - Resource Resolution</name>
+    <description>Blueprints Processor Function - Resource Resolution</description>
 
 </project>
index 9a0d1f9..801b660 100644 (file)
@@ -19,7 +19,10 @@ package org.onap.ccsdk.apps.blueprintsprocessor.services.execution
 \r
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput\r
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceOutput\r
+import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
+import org.onap.ccsdk.apps.controllerblueprints.core.getAsString\r
 import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BlueprintFunctionNode\r
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService\r
 import org.slf4j.LoggerFactory\r
 \r
 /**\r
@@ -29,14 +32,39 @@ import org.slf4j.LoggerFactory
 abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServiceInput, ExecutionServiceOutput> {\r
     private val log = LoggerFactory.getLogger(AbstractComponentFunction::class.java)\r
 \r
-    override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {\r
+    var executionServiceInput: ExecutionServiceInput? = null\r
+    val executionServiceOutput = ExecutionServiceOutput()\r
+    var bluePrintRuntimeService: BluePrintRuntimeService<*>? = null\r
+    var processId: String = ""\r
+    var workflowName: String = ""\r
+    var stepName: String = ""\r
+    var interfaceName: String = ""\r
+    var operationName: String = ""\r
+    var nodeTemplateName: String = ""\r
+\r
+\r
+    override fun prepareRequest(executionServiceInput: ExecutionServiceInput): ExecutionServiceInput {\r
+\r
+        this.executionServiceInput = this.executionServiceInput\r
+\r
+        processId = executionServiceInput.commonHeader.requestId\r
+        workflowName = executionServiceInput.actionIdentifiers.actionName\r
+\r
+        val metadata = executionServiceInput.metadata\r
+        stepName = metadata.getAsString(BluePrintConstants.PROPERTY_CURRENT_STEP)\r
+        nodeTemplateName = metadata.getAsString(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE)\r
+        interfaceName = metadata.getAsString(BluePrintConstants.PROPERTY_CURRENT_INTERFACE)\r
+        operationName = metadata.getAsString(BluePrintConstants.PROPERTY_CURRENT_OPERATION)\r
+\r
+        checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" }\r
+\r
         log.info("prepareRequest...")\r
-        return executionRequest\r
+        return executionServiceInput\r
     }\r
 \r
     override fun prepareResponse(): ExecutionServiceOutput {\r
         log.info("Preparing Response...")\r
-        return ExecutionServiceOutput()\r
+        return this.executionServiceOutput\r
     }\r
 \r
     override fun apply(executionServiceInput: ExecutionServiceInput): ExecutionServiceOutput {\r
index 8750d98..0600f62 100644 (file)
@@ -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
index 125a1ff..ace9f27 100644 (file)
@@ -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
index 5c90852..6fe767c 100644 (file)
 
 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<String, JsonNode> = 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
index 761fdc7..637a07a 100644 (file)
@@ -38,6 +38,7 @@
         <eelf.version>1.0.0</eelf.version>
         <sli.version>0.3.1</sli.version>
         <guava.version>26.0-jre</guava.version>
+        <jython.version>2.7.1</jython.version>
         <springfox.swagger2.version>2.9.2</springfox.swagger2.version>
         <h2database.version>1.4.197</h2database.version>
         <onap.logger.slf4j>1.2.2</onap.logger.slf4j>
                 <artifactId>guava</artifactId>
                 <version>${guava.version}</version>
             </dependency>
+            <dependency>
+                <groupId>org.python</groupId>
+                <artifactId>jython-standalone</artifactId>
+                <version>${jython.version}</version>
+            </dependency>
 
             <!-- Database -->
             <dependency>