diff options
author | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-03-11 16:34:55 -0400 |
---|---|---|
committer | Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com> | 2019-03-13 15:09:10 -0400 |
commit | 5eea68f0a351af133e873ef98f3c3fa258150270 (patch) | |
tree | 0607371d2ee7f9821893c9827c3634867d199d8a /ms | |
parent | 758458d3f0ecb9c9abeca5b5f8dde39171c0e9f2 (diff) |
Improve RA capability processor.
Change-Id: I44a8157c9e2a27b49aa8af00a857ebc7b3e845c3
Issue-ID: CCSDK-1137
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Diffstat (limited to 'ms')
7 files changed, 94 insertions, 168 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index c1282344..335aea1e 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -59,14 +59,14 @@ interface ResourceResolutionService { @Service(ResourceResolutionConstants.SERVICE_RESOURCE_RESOLUTION) open class ResourceResolutionServiceImpl(private var applicationContext: ApplicationContext, private var resolutionResultService: ResourceResolutionResultService) : - ResourceResolutionService { + ResourceResolutionService { private val log = LoggerFactory.getLogger(ResourceResolutionService::class.java) override fun registeredResourceSources(): List<String> { return applicationContext.getBeanNamesForType(ResourceAssignmentProcessor::class.java) - .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } - .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } + .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } + .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) } } override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, @@ -92,7 +92,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica val result = resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactMapping, artifactTemplate) if (properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT) - && properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean) { + && properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean) { resolutionResultService.write(properties, result, bluePrintRuntimeService, artifactPrefix) } @@ -113,32 +113,32 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica val identifierName = artifactTemplate ?: "no-template" val resourceAssignmentContent = - bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping) + bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactMapping) val resourceAssignments: MutableList<ResourceAssignment> = - JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) - as? MutableList<ResourceAssignment> - ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") + JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) + as? MutableList<ResourceAssignment> + ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") // Get the Resource Dictionary Name val dictionaryFile = bluePrintRuntimeService.bluePrintContext().rootPath.plus(File.separator) - .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator) - .plus(ResourceResolutionConstants.FILE_NAME_RESOURCE_DEFINITION_TYPES) + .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator) + .plus(ResourceResolutionConstants.FILE_NAME_RESOURCE_DEFINITION_TYPES) val resourceDictionaries: MutableMap<String, ResourceDefinition> = - JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java) - ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") + JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java) + ?: throw BluePrintProcessorException("couldn't get Dictionary Definitions") // Resolve resources resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName) val resolvedParamJsonContent = - ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList()) + ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList()) // Check Template is there if (artifactTemplate != null) { val templateContent = - bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate) + bluePrintRuntimeService.resolveNodeTemplateArtifact(nodeTemplateName, artifactTemplate) resolvedContent = BluePrintTemplateService.generateContent(templateContent, resolvedParamJsonContent) } else { resolvedContent = resolvedParamJsonContent @@ -159,35 +159,33 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica val bulkSequenced = BulkResourceSequencingUtils.process(resourceAssignments) val resourceAssignmentRuntimeService = - ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName) + ResourceAssignmentUtils.transformToRARuntimeService(blueprintRuntimeService, identifierName) bulkSequenced.map { batchResourceAssignments -> batchResourceAssignments.filter { it.name != "*" && it.name != "start" } - .forEach { resourceAssignment -> - val dictionaryName = resourceAssignment.dictionaryName - val dictionarySource = resourceAssignment.dictionarySource - /** - * Get the Processor name - */ - val processorName = processorName(dictionaryName!!, dictionarySource!!, - resourceDictionaries) - - val resourceAssignmentProcessor = - applicationContext.getBean(processorName) as? ResourceAssignmentProcessor - ?: throw BluePrintProcessorException("failed to get resource processor for name($processorName) " + - "for resource assignment(${resourceAssignment.name})") - try { - // Set BluePrint Runtime Service - resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService - // Set Resource Dictionaries - resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries - // Invoke Apply Method - resourceAssignmentProcessor.apply(resourceAssignment) - } catch (e: RuntimeException) { - resourceAssignmentProcessor.recover(e, resourceAssignment) - throw BluePrintProcessorException(e) + .forEach { resourceAssignment -> + val dictionaryName = resourceAssignment.dictionaryName + val dictionarySource = resourceAssignment.dictionarySource + /** + * Get the Processor name + */ + val processorName = processorName(dictionaryName!!, dictionarySource!!, resourceDictionaries) + + val resourceAssignmentProcessor = + applicationContext.getBean(processorName) as? ResourceAssignmentProcessor + ?: throw BluePrintProcessorException("failed to get resource processor for name($processorName) " + + "for resource assignment(${resourceAssignment.name})") + try { + // Set BluePrint Runtime Service + resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService + // Set Resource Dictionaries + resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries + // Invoke Apply Method + resourceAssignmentProcessor.apply(resourceAssignment) + } catch (e: RuntimeException) { + throw BluePrintProcessorException(e) + } } - } } } @@ -208,18 +206,18 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica } else -> { val resourceDefinition = resourceDictionaries[dictionaryName] - ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName") + ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName") val resourceSource = resourceDefinition.sources[dictionarySource] - ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)") + ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)") processorName = ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR - .plus(resourceSource.type) + .plus(resourceSource.type) } } checkNotEmptyOrThrow(processorName, - "couldn't get processor name for resource dictionary definition($dictionaryName) source" + - "($dictionarySource)") + "couldn't get processor name for resource dictionary definition($dictionaryName) source" + + "($dictionarySource)") return processorName diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt index c2dbd731..6469e78d 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt @@ -20,10 +20,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR -import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants +import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.ComponentFunctionScriptingService import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.interfaces.BluePrintScriptsService import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.slf4j.LoggerFactory @@ -31,14 +29,16 @@ import org.springframework.beans.factory.config.ConfigurableBeanFactory import org.springframework.context.ApplicationContext import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service -import java.io.File @Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) -open class CapabilityResourceResolutionProcessor(private var applicationContext: ApplicationContext, - private val bluePrintScriptsService: BluePrintScriptsService, - private val bluePrintJythonService: BlueprintJythonService) : - ResourceAssignmentProcessor() { +open class CapabilityResourceResolutionProcessor(private val applicationContext: ApplicationContext, + private var componentFunctionScriptingService: ComponentFunctionScriptingService) + : ResourceAssignmentProcessor() { + + private val log = LoggerFactory.getLogger(CapabilityResourceResolutionProcessor::class.java) + + var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null override fun getName(): String { return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability" @@ -62,118 +62,43 @@ open class CapabilityResourceResolutionProcessor(private var applicationContext: val scriptType = capabilityResourceSourceProperty.scriptType val scriptClassReference = capabilityResourceSourceProperty.scriptClassReference + val instanceDependencies = capabilityResourceSourceProperty.instanceDependencies ?: listOf() - var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null - - when (scriptType) { - BluePrintConstants.SCRIPT_KOTLIN -> { - componentResourceAssignmentProcessor = getKotlinResourceAssignmentProcessorInstance(scriptClassReference, - capabilityResourceSourceProperty.instanceDependencies) - } - BluePrintConstants.SCRIPT_INTERNAL -> { - // Initialize Capability Resource Assignment Processor - componentResourceAssignmentProcessor = applicationContext.getBean(scriptClassReference, ResourceAssignmentProcessor::class.java) - } - BluePrintConstants.SCRIPT_JYTHON -> { - val content = getJythonContent(scriptClassReference) - componentResourceAssignmentProcessor = getJythonResourceAssignmentProcessorInstance(scriptClassReference, - content, capabilityResourceSourceProperty.instanceDependencies) - } - } + componentResourceAssignmentProcessor = scriptInstance(scriptType, scriptClassReference, instanceDependencies) - checkNotNull(componentResourceAssignmentProcessor) { "failed to get capability resource assignment processor($scriptClassReference)" } + checkNotNull(componentResourceAssignmentProcessor) { + "failed to get capability resource assignment processor($scriptClassReference)" + } // Assign Current Blueprint runtime and ResourceDictionaries - componentResourceAssignmentProcessor.raRuntimeService = raRuntimeService - componentResourceAssignmentProcessor.resourceDictionaries = resourceDictionaries + componentResourceAssignmentProcessor!!.raRuntimeService = raRuntimeService + componentResourceAssignmentProcessor!!.resourceDictionaries = resourceDictionaries // Invoke componentResourceAssignmentProcessor - componentResourceAssignmentProcessor.apply(resourceAssignment) + componentResourceAssignmentProcessor!!.apply(resourceAssignment) } override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { - - TODO("To Implement") - } - - private fun getKotlinResourceAssignmentProcessorInstance(scriptClassName: String, - instanceNames: List<String>? = null): ResourceAssignmentProcessor { - var scriptPropertyInstances: MutableMap<String, Any>? = null - - if (instanceNames != null && instanceNames.isNotEmpty()) { - scriptPropertyInstances = hashMapOf() - instanceNames.forEach { - scriptPropertyInstances[it] = applicationContext.getBean(it) - ?: throw BluePrintProcessorException("couldn't get the dependency instance($it)") - } - } - - return getKotlinResourceAssignmentProcessorInstance(scriptClassName, scriptPropertyInstances) - - } - - fun getKotlinResourceAssignmentProcessorInstance(scriptClassName: String, - scriptPropertyInstances: MutableMap<String, Any>? = null): - ResourceAssignmentProcessor { - - val resourceAssignmentProcessor = bluePrintScriptsService - .scriptInstance<ResourceAssignmentProcessor>(raRuntimeService.bluePrintContext(), - scriptClassName, false) - - // Add additional Instance - if (scriptPropertyInstances != null) { - resourceAssignmentProcessor.scriptPropertyInstances = scriptPropertyInstances + log.info("Recovering for : ${resourceAssignment.name} : ${runtimeException.toString()}") + if (componentResourceAssignmentProcessor != null) { + componentResourceAssignmentProcessor!!.recover(runtimeException, resourceAssignment) } - - return resourceAssignmentProcessor - } - - private fun getJythonContent(instanceName: String): String { - val absolutePath = raRuntimeService.bluePrintContext().rootPath - .plus(File.separator) - .plus(BluePrintConstants.TOSCA_SCRIPTS_JYTHON_DIR) - .plus(File.separator) - .plus("$instanceName.py") - - return JacksonUtils.getContent(absolutePath) - } - /** - * getJythonResourceAssignmentProcessorInstance Purpose: prepare the jython - * executor component as a resource assignment processor - * - * @param pythonClassName String - * @param content String - * @param dependencyInstances List<String> - * @return resourceAssignmentProcessor ResourceAssignmentProcessor - */ - private fun getJythonResourceAssignmentProcessorInstance(pythonClassName: String, content: String, - dependencyInstances: List<String>?): - ResourceAssignmentProcessor { - val jythonContextInstance: MutableMap<String, Any> = hashMapOf() - jythonContextInstance["log"] = LoggerFactory.getLogger(pythonClassName) - jythonContextInstance["raRuntimeService"] = raRuntimeService - dependencyInstances?.forEach { instanceName -> - jythonContextInstance[instanceName] = applicationContext.getBean(instanceName) - } - - return getJythonResourceAssignmentProcessorInstance(pythonClassName, content, jythonContextInstance) - } + fun scriptInstance(scriptType: String, scriptClassReference: String, instanceDependencies: List<String>) + : ResourceAssignmentProcessor { - fun getJythonResourceAssignmentProcessorInstance(pythonClassName: String, content: String, - dependencyInstances: MutableMap<String, Any>): - ResourceAssignmentProcessor { + log.info("creating resource resolution of script type($scriptType), reference name($scriptClassReference) and" + + "instanceDependencies($instanceDependencies)") - val resourceAssignmentProcessor = bluePrintJythonService - .jythonInstance<ResourceAssignmentProcessor>(raRuntimeService.bluePrintContext(), pythonClassName, - content, dependencyInstances) + val scriptComponent = componentFunctionScriptingService + .scriptInstance<ResourceAssignmentProcessor>(raRuntimeService.bluePrintContext(), scriptType, + scriptClassReference) - // Add additional Instance - if (dependencyInstances != null) { - resourceAssignmentProcessor.scriptPropertyInstances = dependencyInstances + instanceDependencies.forEach { instanceDependency -> + scriptPropertyInstances[instanceDependency] = applicationContext + .getBean(instanceDependency) } - - return resourceAssignmentProcessor + return scriptComponent } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt index 64cc1d2d..8e9606c4 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt @@ -37,7 +37,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig lateinit var raRuntimeService: ResourceAssignmentRuntimeService lateinit var resourceDictionaries: MutableMap<String, ResourceDefinition> - var scriptPropertyInstances: Map<String, Any> = hashMapOf() + var scriptPropertyInstances: MutableMap<String, Any> = hashMapOf() /** * This will be called from the scripts to serve instance from runtime to scripts. diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt index f779054e..6da3fd71 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt @@ -21,6 +21,7 @@ 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.resource.resolution.ResourceAssignmentRuntimeService +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.data.PropertyDefinition @@ -36,7 +37,8 @@ import org.springframework.test.context.junit4.SpringRunner import kotlin.test.assertNotNull @RunWith(SpringRunner::class) -@ContextConfiguration(classes = [CapabilityResourceResolutionProcessor::class, BluePrintScriptsServiceImpl::class, +@ContextConfiguration(classes = [CapabilityResourceResolutionProcessor::class, ComponentFunctionScriptingService::class, + BluePrintScriptsServiceImpl::class, BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::class]) @TestPropertySource(properties = ["blueprints.processor.functions.python.executor.modulePaths=./../../../../components/scripts/python/ccsdk_blueprints", @@ -62,9 +64,11 @@ class CapabilityResourceResolutionProcessorTest { scriptPropertyInstances["mock-service1"] = MockCapabilityService() scriptPropertyInstances["mock-service2"] = MockCapabilityService() + val instanceDependencies: List<String> = listOf() + val resourceAssignmentProcessor = capabilityResourceResolutionProcessor - .getKotlinResourceAssignmentProcessorInstance( - "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", scriptPropertyInstances) + .scriptInstance("kotlin", + "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", instanceDependencies) assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor") diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json index fe89291c..b565eec8 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json @@ -11,7 +11,7 @@ "type": "source-capability", "properties": { "script-type": "jython", - "script-class-reference": "SampleRAProcessor", + "script-class-reference": "Scripts/python/SampleRAProcessor.py", "instance-dependencies": [] } } 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 index ecdd454e..9bae4eb3 100644 --- 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 @@ -20,6 +20,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.Bluepr 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.interfaces.BlueprintFunctionNode import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext import org.slf4j.LoggerFactory import org.springframework.context.ApplicationContext @@ -34,19 +35,24 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat fun <T : AbstractComponentFunction> scriptInstance(componentFunction: AbstractComponentFunction, scriptType: String, scriptClassReference: String, - instanceDependencies: MutableList<String>): T { + instanceDependencies: List<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) + // Populate Instance Properties + instanceDependencies.forEach { instanceDependency -> + componentFunction.functionDependencyInstances[instanceDependency] = applicationContext + .getBean(instanceDependency) + } return scriptComponent } - fun <T : AbstractComponentFunction> scriptInstance(bluePrintContext: BluePrintContext, scriptType: String, - scriptClassReference: String): T { + fun <T : BlueprintFunctionNode<*, *>> scriptInstance(bluePrintContext: BluePrintContext, scriptType: String, + scriptClassReference: String): T { var scriptComponent: T? = null when (scriptType) { @@ -66,12 +72,4 @@ class ComponentFunctionScriptingService(private val applicationContext: Applicat 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 diff --git a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt index 9c039016..3937f27c 100644 --- a/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt +++ b/ms/blueprintsprocessor/modules/services/execution-service/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/execution/scripts/BlueprintJythonService.kt @@ -22,6 +22,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.AbstractCompon 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.interfaces.BlueprintFunctionNode import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintContext import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.slf4j.Logger @@ -55,7 +56,7 @@ class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, } fun jythonComponentInstance(bluePrintContext: BluePrintContext, scriptClassReference: String): - AbstractComponentFunction { + BlueprintFunctionNode<*, *> { val blueprintBasePath: String = bluePrintContext.rootPath val pythonFileName = bluePrintContext.rootPath @@ -74,7 +75,7 @@ class BlueprintJythonService(val pythonExecutorProperty: PythonExecutorProperty, val jythonInstances: MutableMap<String, Any> = hashMapOf() jythonInstances["log"] = LoggerFactory.getLogger(pythonClassName) - return jythonInstance<AbstractComponentFunction>(bluePrintContext, pythonClassName, + return jythonInstance<BlueprintFunctionNode<*, *>>(bluePrintContext, pythonClassName, content, jythonInstances) } |