aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <bs2796@att.com>2019-01-30 15:52:30 -0500
committerSteve Alphonse Siani <alphonse.steve.siani.djissitchi@ibm.com>2019-02-04 09:45:59 -0500
commit73528fe9ce4471be5e76c042ea02b40199d36532 (patch)
tree7c332a906d1df80ab6051db5f9668baed13241ea /ms/blueprintsprocessor/functions
parent7727f3dd84ce4ca2af5c3e589651ef57e3813fa9 (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')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/pom.xml4
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt6
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt56
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt10
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt79
5 files changed, 142 insertions, 13 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/pom.xml b/ms/blueprintsprocessor/functions/resource-resolution/pom.xml
index 925f9e33..b29149d8 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 9bad0998..a44d366c 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 6c235599..1370a479 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 43238a53..d6f46a6f 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 00000000..ce05c34b
--- /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