Add component function scripting service
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Mon, 18 Feb 2019 20:10:25 +0000 (15:10 -0500)
committerAlexis de Talhouët <adetalhouet89@gmail.com>
Wed, 20 Feb 2019 21:02:05 +0000 (21:02 +0000)
Change-Id: I7c5b49617823dd623566fb4be4d431012420e17c
Issue-ID: CCSDK-959
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
24 files changed:
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutor.kt
ms/blueprintsprocessor/functions/netconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/NetconfComponentFunction.kt
ms/blueprintsprocessor/functions/netconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/netconf/executor/ComponentNetconfExecutorTest.kt
ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutor.kt
ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/ComponentJythonExecutorTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt
ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutor.kt
ms/blueprintsprocessor/functions/restconf-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/RestconfComponentFunction.kt
ms/blueprintsprocessor/functions/restconf-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/restconf/executor/ComponentRestconfExecutorTest.kt
ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/BluePrintRestLibConfiguration.kt
ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt
ms/blueprintsprocessor/modules/services/execution-service/pom.xml
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/AbstractComponentFunction.kt
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/ComponentFunctionScriptingService.kt [new file with mode: 0644]
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt [moved from ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonService.kt with 81% similarity]
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonHost.kt [moved from ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonHost.kt with 91% similarity]
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintPythonInterpreterProxy.kt [moved from ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/plugin/BlueprintPythonInterpreterProxy.kt with 88% similarity]
ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/PythonExecutorConfiguration.kt [moved from ms/blueprintsprocessor/functions/python-executor/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/PythonExecutorConfiguration.kt with 96% similarity]
ms/blueprintsprocessor/modules/services/execution-service/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonServiceTest.kt [moved from ms/blueprintsprocessor/functions/python-executor/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/python/executor/BlueprintJythonServiceTest.kt with 81% similarity]
ms/blueprintsprocessor/parent/pom.xml

index 06c9b7b..60f1e4f 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
 
+import com.fasterxml.jackson.databind.node.ArrayNode
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.apps.controllerblueprints.core.getAsString
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.annotation.Scope
@@ -29,23 +31,40 @@ import org.springframework.stereotype.Component
 
 @Component("component-netconf-executor")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentNetconfExecutor(private val blueprintJythonService: BlueprintJythonService,
-                                    private var resourceResolutionService: ResourceResolutionService)
+open class ComponentNetconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService)
     : AbstractComponentFunction() {
 
     private val log = LoggerFactory.getLogger(ComponentNetconfExecutor::class.java)
 
+    companion object {
+        const val SCRIPT_TYPE = "script-type"
+        const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
+        const val INSTANCE_DEPENDENCIES = "instance-dependencies"
+    }
+
+
     lateinit var scriptComponent: NetconfComponentFunction
 
     override fun process(executionRequest: ExecutionServiceInput) {
 
-        scriptComponent = blueprintJythonService.jythonComponentInstance(this) as NetconfComponentFunction
+        val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
+        val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
+        val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode
+
+        val scriptDependencies: MutableList<String> = arrayListOf()
+        scriptDependencies.add(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+
+        instanceDependenciesNode?.forEach { instanceName ->
+            scriptDependencies.add(instanceName.textValue())
+        }
+
+        scriptComponent = componentFunctionScriptingService.scriptInstance<NetconfComponentFunction>(this, scriptType,
+                scriptClassReference, scriptDependencies)
+
+
         checkNotNull(scriptComponent) { "failed to get netconf script component" }
 
-        // FIXME("Populate the reference in Abstract Script Instance Injection map")
         scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService
-        scriptComponent.resourceResolutionService = resourceResolutionService
-
         scriptComponent.processId = processId
         scriptComponent.workflowName = workflowName
         scriptComponent.stepName = stepName
index e1160ac..26e51ec 100644 (file)
@@ -18,13 +18,16 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor
 
 import com.fasterxml.jackson.databind.JsonNode
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.netconf.executor.api.DeviceInfo
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 
 abstract class NetconfComponentFunction : AbstractComponentFunction() {
 
-    lateinit var resourceResolutionService: ResourceResolutionService
+
+    open fun resourceResolutionService(): ResourceResolutionService =
+            functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
 
     // Called from python script
     fun initializeNetconfConnection(requirementName: String): NetconfDevice {
@@ -37,12 +40,12 @@ abstract class NetconfComponentFunction : AbstractComponentFunction() {
     }
 
     fun resolveAndGenerateMessage(artifactMapping: String, artifactTemplate: String): String {
-        return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName,
+        return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
             artifactMapping, artifactTemplate)
     }
 
     fun resolveAndGenerateMessage(artifactPrefix: String): String {
-        return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName,
+        return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
             artifactPrefix)
     }
 
index 5b7b14a..6ed3a6d 100644 (file)
@@ -22,14 +22,16 @@ import com.fasterxml.jackson.databind.JsonNode
 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.functions.python.executor.BlueprintJythonService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionServiceImpl
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
 import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.ContextConfiguration
 import org.springframework.test.context.TestPropertySource
@@ -37,6 +39,7 @@ import org.springframework.test.context.junit4.SpringRunner
 
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [BlueprintJythonService::class, PythonExecutorProperty::class,
+    BluePrintScriptsServiceImpl::class, ComponentFunctionScriptingService::class,
     ComponentNetconfExecutor::class, JsonParserService::class, ResourceResolutionServiceImpl::class])
 @TestPropertySource(properties =
 ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_netconf,./../../../../components/scripts/python/ccsdk_blueprints",
@@ -51,17 +54,17 @@ class ComponentNetconfExecutorTest {
     fun testComponentNetconfExecutor() {
 
         val executionServiceInput = JacksonUtils.readValueFromClassPathFile("requests/sample-activate-request.json",
-            ExecutionServiceInput::class.java)!!
+                ExecutionServiceInput::class.java)!!
 
         val bluePrintRuntimeService = BluePrintMetadataUtils.getBluePrintRuntime("1234",
-            "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+                "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
 
         val executionContext = bluePrintRuntimeService.getExecutionContext()
 
 
         componentNetconfExecutor.bluePrintRuntimeService = bluePrintRuntimeService
 
-
+        //TODO("Set Attribute properties")
         val stepMetaData: MutableMap<String, JsonNode> = hashMapOf()
         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_NODE_TEMPLATE, "activate-netconf")
         stepMetaData.putJsonElement(BluePrintConstants.PROPERTY_CURRENT_INTERFACE, "ComponentNetconfExecutor")
index a74a779..b7f7771 100644 (file)
@@ -22,6 +22,8 @@ import com.fasterxml.jackson.databind.node.ArrayNode
 import org.apache.commons.io.FilenameUtils
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorConstants
 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
index 67a3d95..dd8eb50 100644 (file)
@@ -20,6 +20,9 @@ import com.fasterxml.jackson.databind.JsonNode
 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.functions.python.executor.mock.MockInstanceConfiguration
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorConfiguration
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
 import org.onap.ccsdk.apps.controllerblueprints.core.putJsonElement
@@ -31,7 +34,8 @@ import org.springframework.test.context.TestPropertySource
 import org.springframework.test.context.junit4.SpringRunner
 
 @RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [PythonExecutorConfiguration::class, PythonExecutorProperty::class])
+@ContextConfiguration(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"])
index eaa8eac..5765609 100644 (file)
@@ -18,6 +18,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution
 
 class ResourceResolutionConstants {
     companion object {
+        const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service"
+
         const val PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR = "resource-assignment-processor-"
         const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
         const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params"
index 3498552..24401cc 100644 (file)
@@ -22,7 +22,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.uti
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants\r
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException\r
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService\r
-import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment\r
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDefinition\r
@@ -32,39 +32,39 @@ import org.springframework.context.ApplicationContext
 import org.springframework.stereotype.Service\r
 import java.io.File\r
 \r
-interface ResourceResolutionService {
-
-    fun registeredResourceSources(): List<String>
-
-    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
-                         artifactNames: List<String>): MutableMap<String, String>
-
-    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
-                         artifactPrefix: String): String
-
-    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
-                         artifactMapping: String, artifactTemplate: String?): String
-
-    fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
-                                   resourceDictionaries: MutableMap<String, ResourceDefinition>,
-                                   resourceAssignments: MutableList<ResourceAssignment>,
-                                   identifierName: String)
-}
-\r
-@Service\r
-open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext) :
-        ResourceResolutionService {
+interface ResourceResolutionService {\r
+\r
+    fun registeredResourceSources(): List<String>\r
+\r
+    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,\r
+                         artifactNames: List<String>): MutableMap<String, String>\r
+\r
+    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,\r
+                         artifactPrefix: String): String\r
+\r
+    fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,\r
+                         artifactMapping: String, artifactTemplate: String?): String\r
+\r
+    fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,\r
+                                   resourceDictionaries: MutableMap<String, ResourceDefinition>,\r
+                                   resourceAssignments: MutableList<ResourceAssignment>,\r
+                                   identifierName: String)\r
+}\r
+\r
+@Service(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)\r
+open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext) :\r
+        ResourceResolutionService {\r
 \r
     private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java)\r
 \r
-    override fun registeredResourceSources(): List<String> {
+    override fun registeredResourceSources(): List<String> {\r
         return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java)\r
                 .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) }\r
                 .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR) }\r
     }\r
 \r
-    override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
-                                  artifactNames: List<String>): MutableMap<String, String> {
+    override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,\r
+                                  artifactNames: List<String>): MutableMap<String, String> {\r
 \r
         val resolvedParams: MutableMap<String, String> = hashMapOf()\r
         artifactNames.forEach { artifactName ->\r
@@ -74,27 +74,27 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
         return resolvedParams\r
     }\r
 \r
-    override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
-                                  artifactPrefix: String): String {
+    override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,\r
+                                  artifactPrefix: String): String {\r
 \r
         // Velocity Artifact Definition Name\r
-        val artifactTemplate = "$artifactPrefix-template"
+        val artifactTemplate = "$artifactPrefix-template"\r
         // Resource Assignment Artifact Definition Name\r
-        val artifactMapping = "$artifactPrefix-mapping"
-
-        return resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate)
-    }
-
-\r
-    override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
-                                  artifactMapping: String, artifactTemplate: String?): String {
-\r
-        var resolvedContent = ""
-        log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)")
-
-        val identifierName = artifactTemplate ?: "no-template"
-
-        val resourceAssignmentContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping)
+        val artifactMapping = "$artifactPrefix-mapping"\r
+\r
+        return resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate)\r
+    }\r
+\r
+\r
+    override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,\r
+                                  artifactMapping: String, artifactTemplate: String?): String {\r
+\r
+        var resolvedContent = ""\r
+        log.info("Resolving resource for template artifact($artifactTemplate) with resource assignment artifact($artifactMapping)")\r
+\r
+        val identifierName = artifactTemplate ?: "no-template"\r
+\r
+        val resourceAssignmentContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping)\r
 \r
         val resourceAssignments: MutableList<ResourceAssignment> = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java)\r
                 as? MutableList<ResourceAssignment>\r
@@ -108,28 +108,28 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
         val resourceDictionaries: MutableMap<String, ResourceDefinition> = JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)\r
                 ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")\r
 \r
-        // Resolve resources
-        resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName)
+        // Resolve resources\r
+        resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName)\r
 \r
-        val resolvedParamJsonContent = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
+        val resolvedParamJsonContent = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())\r
 \r
-        // Check Template is there
-        if (artifactTemplate != null) {
-            val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate)
-            resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent)
+        // Check Template is there\r
+        if (artifactTemplate != null) {\r
+            val templateContent = bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate)\r
+            resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent)\r
         } else {\r
             resolvedContent = resolvedParamJsonContent\r
         }\r
         return resolvedContent\r
     }\r
 \r
-    override fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
-                                            resourceDictionaries: MutableMap<String, ResourceDefinition>,
-                                            resourceAssignments: MutableList<ResourceAssignment>,
-                                            identifierName: String) {
+    override fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,\r
+                                            resourceDictionaries: MutableMap<String, ResourceDefinition>,\r
+                                            resourceAssignments: MutableList<ResourceAssignment>,\r
+                                            identifierName: String) {\r
 \r
         val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments)\r
-        val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName)
+        val resourceAssignmentRuntimeService = ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName)\r
 \r
         bulkSequenced.map { batchResourceAssignments ->\r
             batchResourceAssignments.filter { it.name != "*" && it.name != "start" }\r
index 162a7b4..489645f 100644 (file)
@@ -18,7 +18,7 @@
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
index f1a4dbb..a264ba5 100644 (file)
@@ -70,7 +70,7 @@ open class SimpleRestResourceAssignmentProcessor(private val blueprintRestLibPro
                 val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
 
                 logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
-
+                // TODO("Dynamic Rest Client Service, call (blueprintDynamicWebClientService || blueprintWebClientService")
                 val restClientService = blueprintRestLibPropertyService.blueprintWebClientService("primary-config-data")
                 val response = restClientService.getResource(urlPath, String::class.java)
                 if (response.isNotBlank()) {
index 6428126..0dbd0f6 100644 (file)
@@ -20,8 +20,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr
 
 import org.junit.Test
 import org.junit.runner.RunWith
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
 import org.onap.ccsdk.apps.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintMetadataUtils
index bd05595..742fef4 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
 
+import com.fasterxml.jackson.databind.node.ArrayNode
 import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ExecutionServiceInput
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BlueprintJythonService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
-import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestLibConstants
 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.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
 import org.onap.ccsdk.apps.controllerblueprints.core.getAsString
-import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
-import org.springframework.context.ApplicationContext
 import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Component
 
 @Component("component-restconf-executor")
 @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
-open class ComponentRestconfExecutor(private var applicationContext: ApplicationContext,
-                                     private val blueprintJythonService: BlueprintJythonService,
-                                     private val bluePrintScriptsService: BluePrintScriptsService,
-                                     private var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService,
-                                     private var resourceResolutionService: ResourceResolutionService) :
+open class ComponentRestconfExecutor(private var componentFunctionScriptingService: ComponentFunctionScriptingService) :
         AbstractComponentFunction() {
 
     private val log = LoggerFactory.getLogger(ComponentRestconfExecutor::class.java)
@@ -47,16 +40,28 @@ open class ComponentRestconfExecutor(private var applicationContext: Application
     companion object {
         const val SCRIPT_TYPE = "script-type"
         const val SCRIPT_CLASS_REFERENCE = "script-class-reference"
+        const val INSTANCE_DEPENDENCIES = "instance-dependencies"
     }
 
     override fun process(executionRequest: ExecutionServiceInput) {
 
         val scriptType = operationInputs.getAsString(SCRIPT_TYPE)
         val scriptClassReference = operationInputs.getAsString(SCRIPT_CLASS_REFERENCE)
+        val instanceDependenciesNode = operationInputs.get(INSTANCE_DEPENDENCIES) as? ArrayNode
+
+        val scriptDependencies: MutableList<String> = arrayListOf()
+        scriptDependencies.add(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+        scriptDependencies.add(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+
+        instanceDependenciesNode?.forEach { instanceName ->
+            scriptDependencies.add(instanceName.textValue())
+        }
         /**
          * Populate the Script Instance based on the Type
          */
-        restconfComponentFunction(scriptType, scriptClassReference)
+        scriptComponent = componentFunctionScriptingService.scriptInstance<RestconfComponentFunction>(this, scriptType,
+                scriptClassReference, scriptDependencies)
+
         checkNotNull(scriptComponent) { "failed to get restconf script component" }
 
         scriptComponent.bluePrintRuntimeService = bluePrintRuntimeService
@@ -68,35 +73,10 @@ open class ComponentRestconfExecutor(private var applicationContext: Application
         scriptComponent.nodeTemplateName = nodeTemplateName
         scriptComponent.operationInputs = operationInputs
 
-        // FIXME("Populate the reference in Abstract Script Instance Injection map")
-        // Set the Rest Lib Property Service
-        scriptComponent.bluePrintRestLibPropertyService = bluePrintRestLibPropertyService
-        scriptComponent.resourceResolutionService = resourceResolutionService
-
         scriptComponent.process(executionServiceInput)
     }
 
     override fun recover(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
         scriptComponent.recover(runtimeException, executionRequest)
     }
-
-    fun restconfComponentFunction(scriptType: String, scriptClassReference: String): RestconfComponentFunction {
-        log.info("processing restconf script type($scriptType), reference name($scriptClassReference)")
-        when (scriptType) {
-            BluePrintConstants.SCRIPT_INTERNAL -> {
-                scriptComponent = bluePrintScriptsService.scriptInstance<RestconfComponentFunction>(scriptClassReference)
-            }
-            BluePrintConstants.SCRIPT_KOTLIN -> {
-                scriptComponent = bluePrintScriptsService.scriptInstance<RestconfComponentFunction>(bluePrintRuntimeService
-                        .bluePrintContext(), scriptClassReference, false)
-            }
-            BluePrintConstants.SCRIPT_JYTHON -> {
-                scriptComponent = blueprintJythonService.jythonComponentInstance(this) as RestconfComponentFunction
-            }
-            else -> {
-                throw BluePrintProcessorException("script type($scriptType) is not supported")
-            }
-        }
-        return scriptComponent
-    }
 }
\ No newline at end of file
index d9362af..c6afc3b 100644 (file)
  *  limitations under the License.
  */
 @file:Suppress("unused")
+
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
 
+import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionService
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.RestLibConstants
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService
 import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractComponentFunction
@@ -24,11 +27,15 @@ import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractCompon
 
 abstract class RestconfComponentFunction : AbstractComponentFunction() {
 
-    lateinit var bluePrintRestLibPropertyService: BluePrintRestLibPropertyService
-    lateinit var resourceResolutionService: ResourceResolutionService
+    open fun bluePrintRestLibPropertyService(): BluePrintRestLibPropertyService =
+            functionDependencyInstanceAsType(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
+
+    open fun resourceResolutionService(): ResourceResolutionService =
+            functionDependencyInstanceAsType(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION)
+
 
     fun restClientService(selector: String): BlueprintWebClientService {
-        return bluePrintRestLibPropertyService.blueprintWebClientService(selector)
+        return bluePrintRestLibPropertyService().blueprintWebClientService(selector)
     }
 
     fun generateMessage(artifactName: String): String {
@@ -36,12 +43,12 @@ abstract class RestconfComponentFunction : AbstractComponentFunction() {
     }
 
     fun resolveAndGenerateMessage(artifactMapping: String, artifactTemplate: String): String {
-        return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName,
+        return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
                 artifactMapping, artifactTemplate)
     }
 
     fun resolveAndGenerateMessage(artifactPrefix: String): String {
-        return resourceResolutionService.resolveResources(bluePrintRuntimeService, nodeTemplateName,
+        return resourceResolutionService().resolveResources(bluePrintRuntimeService, nodeTemplateName,
                 artifactPrefix)
     }
 }
\ No newline at end of file
index 31bd4eb..c8a2090 100644 (file)
@@ -17,6 +17,7 @@
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.restconf.executor
 
 import com.fasterxml.jackson.databind.JsonNode
+import com.fasterxml.jackson.databind.node.ArrayNode
 import com.fasterxml.jackson.databind.node.ObjectNode
 import io.mockk.every
 import io.mockk.mockk
@@ -27,13 +28,15 @@ import org.onap.ccsdk.apps.blueprintsprocessor.core.BlueprintPropertyConfigurati
 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.functions.python.executor.BlueprintJythonService
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.PythonExecutorProperty
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionServiceImpl
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService
+import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.PythonExecutorProperty
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonNode
 import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
+import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext
 import org.onap.ccsdk.apps.controllerblueprints.core.service.DefaultBluePrintRuntimeService
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.apps.controllerblueprints.scripts.BluePrintScriptsServiceImpl
@@ -48,7 +51,7 @@ import kotlin.test.assertNotNull
 @ContextConfiguration(classes = [RestconfExecutorConfiguration::class, ComponentRestconfExecutor::class,
     BlueprintJythonService::class, PythonExecutorProperty::class, BluePrintRestLibPropertyService::class,
     BlueprintPropertyConfiguration::class, BluePrintProperties::class, BluePrintScriptsServiceImpl::class,
-    ResourceResolutionServiceImpl::class])
+    ResourceResolutionServiceImpl::class, ComponentFunctionScriptingService::class])
 @TestPropertySource(properties =
 ["server.port=9111",
     "blueprintsprocessor.restconfEnabled=true",
@@ -83,7 +86,10 @@ class ComponentRestconfExecutorTest {
         operationInputs[BluePrintConstants.PROPERTY_CURRENT_OPERATION] = "operationName".asJsonPrimitive()
         operationInputs[ComponentRestconfExecutor.SCRIPT_TYPE] = BluePrintConstants.SCRIPT_INTERNAL.asJsonPrimitive()
         operationInputs[ComponentRestconfExecutor.SCRIPT_CLASS_REFERENCE] = "InternalSimpleRestconf_cba\$TestRestconfConfigure".asJsonPrimitive()
+        operationInputs[ComponentRestconfExecutor.INSTANCE_DEPENDENCIES] = JacksonUtils.jsonNode("[]") as ArrayNode
 
+        val blueprintContext = mockk<BluePrintContext>()
+        every { bluePrintRuntime.bluePrintContext() } returns blueprintContext
         every { bluePrintRuntime.get("sample-step-step-inputs") } returns operationInputs.asJsonNode()
         every {
             bluePrintRuntime.resolveNodeTemplateInterfaceOperationInputs("activate-restconf",
index 50d69ae..f63e39f 100644 (file)
@@ -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.
@@ -28,6 +29,7 @@ open class BluePrintRestLibConfiguration
 
 class RestLibConstants {
     companion object {
+        const val SERVICE_BLUEPRINT_REST_LIB_PROPERTY = "blueprint-rest-lib-property-service"
         const val TYPE_BASIC_AUTH = "basic-auth"
         const val TYPE_SSL_BASIC_AUTH = "ssl-basic-auth"
         const val TYPE_DME2_PROXY = "dme2-proxy"
index 21d080d..47577b3 100644 (file)
@@ -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.
@@ -21,7 +22,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.rest.*
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
 import org.springframework.stereotype.Service
 
-@Service
+@Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
 open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
 
     @Throws(BluePrintProcessorException::class)
@@ -49,22 +50,31 @@ open class BluePrintRestLibPropertyService(private var bluePrintProperties: Blue
     @Throws(BluePrintProcessorException::class)
     fun blueprintWebClientService(selector: String): BlueprintWebClientService {
         val prefix = "blueprintsprocessor.restclient.$selector"
-        val beanProperties = restClientProperties(prefix)
-        when (beanProperties) {
+        val restClientProperties = restClientProperties(prefix)
+        return blueprintWebClientService(restClientProperties)
+    }
+
+
+    fun blueprintDynamicWebClientService(sourceType: String, selector: String): BlueprintWebClientService {
+        TODO()
+    }
+
+    @Throws(BluePrintProcessorException::class)
+    fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService {
+        when (restClientProperties) {
             is BasicAuthRestClientProperties -> {
-                return BasicAuthRestClientService(beanProperties)
+                return BasicAuthRestClientService(restClientProperties)
             }
             is SSLBasicAuthRestClientProperties -> {
-                return SSLBasicAuthRestClientService(beanProperties)
+                return SSLBasicAuthRestClientService(restClientProperties)
             }
             is DME2RestClientProperties -> {
-                return DME2ProxyRestClientService(beanProperties)
+                return DME2ProxyRestClientService(restClientProperties)
             }
             else -> {
-                throw BluePrintProcessorException("couldn't get rest service for selector($selector)")
+                throw BluePrintProcessorException("couldn't get rest service for")
             }
         }
-
     }
 
     fun basicAuthRestClientProperties(prefix: String): BasicAuthRestClientProperties {
index ea5f31a..283a8a6 100644 (file)
     <description>Blueprints Processor Execution Service</description>
 
     <dependencies>
+        <dependency>
+            <groupId>org.python</groupId>
+            <artifactId>jython-standalone</artifactId>
+        </dependency>
         <dependency>
             <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId>
             <artifactId>blueprint-core</artifactId>
index f7c901d..930dc07 100644 (file)
@@ -1,5 +1,6 @@
 /*\r
  *  Copyright © 2017-2018 AT&T Intellectual Property.\r
+ *  Modifications Copyright © 2019 IBM.\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
@@ -48,22 +49,26 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
     lateinit var operationName: String\r
     lateinit var nodeTemplateName: String\r
     var operationInputs: MutableMap<String, JsonNode> = hashMapOf()\r
+    /**\r
+     * Store Dynamic Dependency Instances\r
+     */\r
+    var functionDependencyInstances: MutableMap<String, Any> = hashMapOf()\r
 \r
     override fun getName(): String {\r
         return stepName\r
     }\r
 \r
-    override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {
+    override fun prepareRequest(executionRequest: ExecutionServiceInput): ExecutionServiceInput {\r
         checkNotNull(bluePrintRuntimeService) { "failed to prepare blueprint runtime" }\r
 \r
         check(stepName.isNotEmpty()) { "failed to assign step name" }\r
 \r
-        this.executionServiceInput = executionRequest
+        this.executionServiceInput = executionRequest\r
 \r
-        processId = executionRequest.commonHeader.requestId
+        processId = executionRequest.commonHeader.requestId\r
         check(processId.isNotEmpty()) { "couldn't get process id for step($stepName)" }\r
 \r
-        workflowName = executionRequest.actionIdentifiers.actionName
+        workflowName = executionRequest.actionIdentifiers.actionName\r
         check(workflowName.isNotEmpty()) { "couldn't get action name for step($stepName)" }\r
 \r
         log.info("preparing request id($processId) for workflow($workflowName) step($stepName)")\r
@@ -88,14 +93,14 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
 \r
         this.operationInputs.putAll(operationResolvedProperties)\r
 \r
-        return executionRequest
+        return executionRequest\r
     }\r
 \r
     override fun prepareResponse(): ExecutionServiceOutput {\r
         log.info("Preparing Response...")\r
         executionServiceOutput.commonHeader = executionServiceInput.commonHeader\r
-        executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers
-        executionServiceOutput.payload = executionServiceInput.payload
+        executionServiceOutput.actionIdentifiers = executionServiceInput.actionIdentifiers\r
+        executionServiceOutput.payload = executionServiceInput.payload\r
 \r
         // Resolve the Output Expression\r
         val stepOutputs = bluePrintRuntimeService\r
@@ -126,4 +131,12 @@ abstract class AbstractComponentFunction : BlueprintFunctionNode<ExecutionServic
     fun setAttribute(key: String, value: JsonNode) {\r
         bluePrintRuntimeService.setNodeTemplateAttributeValue(nodeTemplateName, key, value)\r
     }\r
+\r
+    /**\r
+     * This will be called from the scripts to serve instance from runtime to scripts.\r
+     */\r
+    open fun <T> functionDependencyInstanceAsType(name: String): T {\r
+        return functionDependencyInstances[name] as? T\r
+                ?: throw BluePrintProcessorException("couldn't get script property instance ($name)")\r
+    }\r
 }
\ 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 (file)
index 0000000..ecdd454
--- /dev/null
@@ -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 <T : AbstractComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String,
+                                                       scriptClassReference: String,
+                                                       instanceDependencies: MutableList<String>): 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 <T : AbstractComponentFunction> scriptInstance(bluePrintContext: BluePrintContext, scriptType: String,
+                                                       scriptClassReference: String): T {
+        var scriptComponent: T? = null
+
+        when (scriptType) {
+            BluePrintConstants.SCRIPT_INTERNAL -> {
+                scriptComponent = bluePrintScriptsService.scriptInstance<T>(scriptClassReference)
+            }
+            BluePrintConstants.SCRIPT_KOTLIN -> {
+                scriptComponent = bluePrintScriptsService.scriptInstance<T>(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<String>) {
+        instanceDependencies.forEach { instanceDependency ->
+            componentFunction.functionDependencyInstances[instanceDependency] = applicationContext
+                    .getBean(instanceDependency)
+        }
+    }
+}
\ No newline at end of file
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor
+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.functions.python.executor.plugin.BlueprintPythonHost
 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,
@@ -53,6 +54,30 @@ class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty,
         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<String> = arrayListOf()
+        pythonPath.add(blueprintBasePath)
+        pythonPath.addAll(pythonExecutorProperty.modulePaths)
+
+        val jythonInstances: MutableMap<String, Any> = hashMapOf()
+        jythonInstances["log"] = LoggerFactory.getLogger(pythonClassName)
+
+        return jythonInstance<AbstractComponentFunction>(bluePrintContext, pythonClassName,
+                content, jythonInstances)
+    }
+
     fun jythonComponentInstance(abstractComponentFunction: AbstractComponentFunction): AbstractComponentFunction {
 
         val bluePrintRuntimeService = abstractComponentFunction.bluePrintRuntimeService
@@ -13,9 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.plugin
+package org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts
 
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BluePrintPython
 import org.python.core.PyObject
 import org.python.util.PythonInterpreter
 
@@ -13,9 +13,8 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.plugin
+package org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts
 
-import org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor.BluePrintPython
 import org.python.core.PyObject
 import org.python.util.PythonInterpreter
 
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.onap.ccsdk.apps.blueprintsprocessor.functions.python.executor
+package org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts
 
 import org.junit.Test
 import org.junit.runner.RunWith
@@ -30,8 +30,8 @@ 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"])
+["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
@@ -40,11 +40,12 @@ class BlueprintJythonServiceTest {
     @Test
     fun testGetAbstractPythonPlugin() {
         val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
-                "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
+                "./../../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration")
 
         val dependencies: MutableMap<String, Any> = hashMapOf()
 
-        val content = JacksonUtils.getContent("./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py")
+        val content = JacksonUtils.getContent("./../../../../." +
+                "./components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Scripts/python/SamplePythonComponentNode.py")
 
         val abstractComponentFunction = blueprintJythonService.jythonInstance<AbstractComponentFunction>(bluePrintContext, "SamplePythonComponentNode", content, dependencies)
 
index 6b16a7f..ab418f4 100755 (executable)
@@ -31,6 +31,7 @@
     <name>Blueprints Processor Parent</name>
     <description>Blueprints Processor Parent</description>
     <properties>
+        <kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
         <spring.boot.version>2.1.2.RELEASE</spring.boot.version>
         <spring.version>5.1.4.RELEASE</spring.version>
         <kotlin.version>1.3.20</kotlin.version>