diff options
Diffstat (limited to 'ms')
6 files changed, 148 insertions, 14 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml index 925f9e337..b29149d85 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml +++ b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml @@ -35,6 +35,10 @@ <version>${project.version}</version> </dependency>--> <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>blueprint-scripts</artifactId> + </dependency> + <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> 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)") diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt new file mode 100644 index 000000000..ce05c34b2 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt @@ -0,0 +1,79 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor + +import org.junit.Test +import org.junit.runner.RunWith +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 +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +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.junit4.SpringRunner +import kotlin.test.assertNotNull + +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [CapabilityResourceAssignmentProcessor::class, BluePrintScriptsServiceImpl::class, + MockCapabilityService::class]) +class CapabilityResourceAssignmentProcessorTest { + + @Autowired + lateinit var capabilityResourceAssignmentProcessor: CapabilityResourceAssignmentProcessor + + @Test + fun `test kotlin capability`() { + + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration") + + val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + + capabilityResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService + capabilityResourceAssignmentProcessor.resourceDictionaries = hashMapOf() + + + val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf() + scriptPropertyInstances["mock-service1"] = MockCapabilityService() + scriptPropertyInstances["mock-service2"] = MockCapabilityService() + + val resourceAssignmentProcessor = capabilityResourceAssignmentProcessor + .getKotlinResourceAssignmentProcessorInstance( + "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", scriptPropertyInstances) + + assertNotNull(resourceAssignmentProcessor, "couldn't get kotlin script resource assignment processor") + + val resourceAssignment = ResourceAssignment().apply { + name = "ra-name" + dictionaryName = "ra-dict-name" + dictionarySource = "capability" + property = PropertyDefinition().apply { + type = "string" + } + } + + val processorName = resourceAssignmentProcessor.apply(resourceAssignment) + assertNotNull(processorName, "couldn't get kotlin script resource assignment processor name") + println(processorName) + } + +} + +open class MockCapabilityService { + +}
\ No newline at end of file diff --git a/ms/blueprintsprocessor/parent/pom.xml b/ms/blueprintsprocessor/parent/pom.xml index 472b466b7..0de4b429f 100755 --- a/ms/blueprintsprocessor/parent/pom.xml +++ b/ms/blueprintsprocessor/parent/pom.xml @@ -18,7 +18,7 @@ ~ limitations under the License. --> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.onap.ccsdk.apps</groupId> @@ -327,6 +327,11 @@ <artifactId>core</artifactId> <version>${project.version}</version> </dependency> + <dependency> + <groupId>org.onap.ccsdk.apps.controllerblueprints</groupId> + <artifactId>blueprint-scripts</artifactId> + <version>${project.version}</version> + </dependency> <!-- Database --> <dependency> |