diff options
author | Muthuramalingam, Brinda Santh <bs2796@att.com> | 2019-01-30 15:52:30 -0500 |
---|---|---|
committer | Steve Alphonse Siani <alphonse.steve.siani.djissitchi@ibm.com> | 2019-02-04 09:45:59 -0500 |
commit | fd14fc13d91d597e26a2e8dca9afbda6d035ef39 (patch) | |
tree | 8523bef8fe1f3da239b92faa0340452f2c4a3407 /ms/blueprintsprocessor/functions/resource-resolution/src/main | |
parent | 694217a818ec3b087a19c5f6bfaf516a191e8ea5 (diff) |
blueprint scripting services
Change-Id: I834b83e0c2716eceadeec8a5f17a7604e938166a
Issue-ID: CCSDK-941
Signed-off-by: Muthuramalingam, Brinda Santh <bs2796@att.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main')
3 files changed, 59 insertions, 13 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt index 9bad09988..a44d366c3 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt @@ -13,12 +13,11 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@file:Suppress("unused") package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution -open class ResourceSourceProperties { - -} +open class ResourceSourceProperties open class InputResourceSource : ResourceSourceProperties() { lateinit var key: String @@ -51,6 +50,7 @@ open class RestResourceSource : ResourceSourceProperties() { open class CapabilityResourceSource : ResourceSourceProperties() { lateinit var type: String lateinit var instanceName: String + var instanceDependencies: List<String>? = null lateinit var path: String lateinit var expressionType: String var inputKeyMapping: MutableMap<String, String>? = null diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt index 6c2355994..1370a4796 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt @@ -18,14 +18,16 @@ 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.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.springframework.beans.factory.annotation.Autowired import org.springframework.context.ApplicationContext import org.springframework.stereotype.Service @Service("resource-assignment-processor-capability") -open class CapabilityResourceAssignmentProcessor : ResourceAssignmentProcessor() { +open class CapabilityResourceAssignmentProcessor(private var applicationContext: ApplicationContext, + private val bluePrintScriptsService: BluePrintScriptsService) : + ResourceAssignmentProcessor() { companion object { const val CAPABILITY_TYPE_KOTLIN_COMPONENT = "KOTLIN-COMPONENT" @@ -33,9 +35,6 @@ open class CapabilityResourceAssignmentProcessor : ResourceAssignmentProcessor() const val CAPABILITY_TYPE_JYTHON_COMPONENT = "JYTHON-COMPONENT" } - @Autowired - private lateinit var applicationContext: ApplicationContext - override fun getName(): String { return "resource-assignment-processor-capability" } @@ -46,20 +45,25 @@ open class CapabilityResourceAssignmentProcessor : ResourceAssignmentProcessor() ?: throw BluePrintProcessorException("couldn't get resource definition for ${resourceAssignment.dictionaryName}") val resourceSource = resourceDefinition.sources[resourceAssignment.dictionarySource] - ?: throw BluePrintProcessorException("couldn't get resource definition ${resourceAssignment.dictionaryName} source(${resourceAssignment.dictionarySource})") + ?: throw BluePrintProcessorException("couldn't get resource definition " + + "${resourceAssignment.dictionaryName} source(${resourceAssignment.dictionarySource})") val resourceSourceProps = checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" } - val capabilityResourceSourceProperty = JacksonUtils.getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java) + /** + * Get the Capability Resource Source Info from Property Definitions. + */ + val capabilityResourceSourceProperty = JacksonUtils + .getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java) val instanceType = capabilityResourceSourceProperty.type val instanceName = capabilityResourceSourceProperty.instanceName - var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null when (instanceType) { - CAPABILITY_TYPE_KOTLIN_COMPONENT ->{ - TODO("NO implementation") + CAPABILITY_TYPE_KOTLIN_COMPONENT -> { + componentResourceAssignmentProcessor = getKotlinResourceAssignmentProcessorInstance(instanceName, + capabilityResourceSourceProperty.instanceDependencies) } CAPABILITY_TYPE_JAVA_COMPONENT -> { // Initialize Capability Resource Assignment Processor @@ -84,4 +88,36 @@ open class CapabilityResourceAssignmentProcessor : ResourceAssignmentProcessor() 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 + } + + return resourceAssignmentProcessor + } }
\ 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 43238a530..d6f46a6f3 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 @@ -31,6 +31,16 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig lateinit var raRuntimeService: ResourceAssignmentRuntimeService lateinit var resourceDictionaries: Map<String, ResourceDefinition> + var scriptPropertyInstances: Map<String, Any> = hashMapOf() + + /** + * This will be called from the scripts to serve instance from runtime to scripts. + */ + open fun <T> scriptPropertyInstanceType(name: String): T { + return scriptPropertyInstances as? T + ?: throw BluePrintProcessorException("couldn't get script property instance ($name)") + } + open fun resourceDefinition(name: String): ResourceDefinition { return resourceDictionaries[name] ?: throw BluePrintProcessorException("couldn't get resource definition for ($name)") |