Get DSL Property in Resource Resolution 33/79133/6
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Mon, 25 Feb 2019 21:03:16 +0000 (16:03 -0500)
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
Fri, 1 Mar 2019 20:54:08 +0000 (15:54 -0500)
Change-Id: I768c2515bc4b0eaa829213ac4d045628ca960adb
Issue-ID: CCSDK-1106
Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
18 files changed:
components/model-catalog/definition-type/starter-type/node_type/source-capability.json
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/ResourceSourceProperties.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt [moved from ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessor.kt with 88% similarity]
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt [moved from ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceAssignmentProcessor.kt with 86% similarity]
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt [moved from ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceAssignmentProcessor.kt with 84% similarity]
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceResolutionProcessor.kt [moved from ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/PrimaryDataResourceAssignmentProcessor.kt with 95% similarity]
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt [moved from ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt with 87% similarity]
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponentTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessorTest.kt [moved from ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceAssignmentProcessorTest.kt with 89% similarity]
ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/mapping/capability/jython-resource-definitions.json
ms/blueprintsprocessor/modules/commons/rest-lib/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/rest/service/BluePrintRestLibPropertyService.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/BluePrintConstants.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/BluePrintRuntimeService.kt
ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/core/service/PropertyAssignmentService.kt

index 4d9488c..e0c4406 100644 (file)
@@ -2,22 +2,22 @@
   "description": "This is Component Resource Source Node Type",
   "version": "1.0.0",
   "properties": {
-    "type": {
+    "script-type": {
       "required": true,
       "type": "string",
-      "default": "KOTLIN-COMPONENT",
+      "default": "kotlin",
       "constraints": [
         {
           "valid_values": [
-            "KOTLIN-COMPONENT",
-            "JAVA-COMPONENT",
-            "JYTHON-COMPONENT"
+            "kotlin",
+            "internal",
+            "jython"
           ]
         }
       ]
     },
-    "instance-name": {
-      "description": "Capability component instance reference name for JAVA-COMPONENT, Script Class name for KOTLIN-COMPONENT.",
+    "script-class-reference": {
+      "description": "Capability reference name for internal and kotlin, for jython script file path",
       "required": true,
       "type": "string"
     },
index 5765609..ca92e96 100644 (file)
@@ -20,7 +20,7 @@ class ResourceResolutionConstants {
     companion object {
         const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service"
 
-        const val PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR = "resource-assignment-processor-"
+        const val PREFIX_RESOURCE_RESOLUTION_PROCESSOR = "rr-processor-"
         const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names"
         const val OUTPUT_ASSIGNMENT_PARAMS = "assignment-params"
         const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json"
index 24401cc..48415ef 100644 (file)
@@ -21,6 +21,7 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pro
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils\r
 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.checkNotEmptyOrThrow\r
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService\r
 import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintTemplateService\r
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils\r
@@ -59,8 +60,8 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
 \r
     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
+                .filter { it.startsWith(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }\r
+                .map { it.substringAfter(ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR) }\r
     }\r
 \r
     override fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,\r
@@ -123,6 +124,11 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
         return resolvedContent\r
     }\r
 \r
+    /**\r
+     * Iterate the Batch, get the Resource Assignment, dictionary Name, Look for the Resource definition for the\r
+     * name, then get the type of the Resource Definition, Get the instance for the Resource Type and process the\r
+     * request.\r
+     */\r
     override fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,\r
                                             resourceDictionaries: MutableMap<String, ResourceDefinition>,\r
                                             resourceAssignments: MutableList<ResourceAssignment>,\r
@@ -133,12 +139,17 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
 \r
         bulkSequenced.map { batchResourceAssignments ->\r
             batchResourceAssignments.filter { it.name != "*" && it.name != "start" }\r
-                    .map { resourceAssignment ->\r
+                    .forEach { resourceAssignment ->\r
+                        val dictionaryName = resourceAssignment.dictionaryName\r
                         val dictionarySource = resourceAssignment.dictionarySource\r
-                        val processorInstanceName = ResourceResolutionConstants.PREFIX_RESOURCE_ASSIGNMENT_PROCESSOR.plus(dictionarySource)\r
-\r
-                        val resourceAssignmentProcessor = applicationContext.getBean(processorInstanceName) as? ResourceAssignmentProcessor\r
-                                ?: throw BluePrintProcessorException("failed to get resource processor for instance name($processorInstanceName) " +\r
+                        /**\r
+                         * Get the Processor name\r
+                         */\r
+                        val processorName = processorName(dictionaryName!!, dictionarySource!!,\r
+                                resourceDictionaries)\r
+\r
+                        val resourceAssignmentProcessor = applicationContext.getBean(processorName) as? ResourceAssignmentProcessor\r
+                                ?: throw BluePrintProcessorException("failed to get resource processor for name($processorName) " +\r
                                         "for resource assignment(${resourceAssignment.name})")\r
                         try {\r
                             // Set BluePrint Runtime Service\r
@@ -155,4 +166,37 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
         }\r
     }\r
 \r
+\r
+    /**\r
+     * If the Source instance is "input", then it is not mandatory to have source Resource Definition, So it can\r
+     *  derive the default input processor.\r
+     */\r
+    private fun processorName(dictionaryName: String, dictionarySource: String,\r
+                              resourceDictionaries: MutableMap<String, ResourceDefinition>): String {\r
+        var processorName: String? = null\r
+        when (dictionarySource) {\r
+            "input" -> {\r
+                processorName = "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input"\r
+            }\r
+            "default" -> {\r
+                processorName = "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default"\r
+            }\r
+            else -> {\r
+                val resourceDefinition = resourceDictionaries[dictionaryName]\r
+                        ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName")\r
+\r
+                val resourceSource = resourceDefinition.sources[dictionarySource]\r
+                        ?: throw BluePrintProcessorException("couldn't get resource definition $dictionaryName source($dictionarySource)")\r
+\r
+                processorName = ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR\r
+                        .plus(resourceSource.type)\r
+            }\r
+        }\r
+        checkNotEmptyOrThrow(processorName,\r
+                "couldn't get processor name for resource dictionary definition($dictionaryName) source" +\r
+                        "($dictionarySource)")\r
+\r
+        return processorName\r
+\r
+    }\r
 }\r
index 0f1267c..1c35744 100644 (file)
@@ -36,6 +36,8 @@ open class DefaultResourceSource : ResourceSourceProperties() {
 
 open class DatabaseResourceSource : ResourceSourceProperties() {
     lateinit var type: String
+    @get:JsonProperty("endpoint-selector")
+    var endpointSelector: String? = null
     lateinit var query: String
     @get:JsonProperty("input-key-mapping")
     var inputKeyMapping: MutableMap<String, String>? = null
@@ -47,6 +49,8 @@ open class DatabaseResourceSource : ResourceSourceProperties() {
 
 open class RestResourceSource : ResourceSourceProperties() {
     lateinit var type: String
+    @get:JsonProperty("endpoint-selector")
+    var endpointSelector: String? = null
     @get:JsonProperty("url-path")
     lateinit var urlPath: String
     lateinit var path: String
@@ -61,9 +65,10 @@ open class RestResourceSource : ResourceSourceProperties() {
 }
 
 open class CapabilityResourceSource : ResourceSourceProperties() {
-    lateinit var type: String
-    @get:JsonProperty("instance-name")
-    lateinit var instanceName: String
+    @get:JsonProperty("script-type")
+    lateinit var scriptType: String
+    @get:JsonProperty("script-class-reference")
+    lateinit var scriptClassReference: String
     @get:JsonProperty("instance-dependencies")
     var instanceDependencies: List<String>? = null
     @get:JsonProperty("key-dependencies")
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
-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.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.utils.JacksonUtils
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
 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.Service
 import java.io.File
 
-@Service("resource-assignment-processor-capability")
-open class CapabilityResourceAssignmentProcessor(private var applicationContext: ApplicationContext,
+@Service("rr-processor-source-capability")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class CapabilityResourceResolutionProcessor(private var applicationContext: ApplicationContext,
                                                  private val bluePrintScriptsService: BluePrintScriptsService,
                                                  private val bluePrintJythonService: BlueprintJythonService) :
         ResourceAssignmentProcessor() {
 
-    companion object {
-        const val CAPABILITY_TYPE_KOTLIN_COMPONENT = "KOTLIN-COMPONENT"
-        const val CAPABILITY_TYPE_JAVA_COMPONENT = "JAVA-COMPONENT"
-        const val CAPABILITY_TYPE_JYTHON_COMPONENT = "JYTHON-COMPONENT"
-    }
-
     override fun getName(): String {
         return "resource-assignment-processor-capability"
     }
@@ -62,28 +59,28 @@ open class CapabilityResourceAssignmentProcessor(private var applicationContext:
         val capabilityResourceSourceProperty = JacksonUtils
                 .getInstanceFromMap(resourceSourceProps, CapabilityResourceSource::class.java)
 
-        val instanceType = capabilityResourceSourceProperty.type
-        val instanceName = capabilityResourceSourceProperty.instanceName
+        val scriptType = capabilityResourceSourceProperty.scriptType
+        val scriptClassReference = capabilityResourceSourceProperty.scriptClassReference
 
         var componentResourceAssignmentProcessor: ResourceAssignmentProcessor? = null
 
-        when (instanceType) {
-            CAPABILITY_TYPE_KOTLIN_COMPONENT -> {
-                componentResourceAssignmentProcessor = getKotlinResourceAssignmentProcessorInstance(instanceName,
+        when (scriptType) {
+            BluePrintConstants.SCRIPT_KOTLIN -> {
+                componentResourceAssignmentProcessor = getKotlinResourceAssignmentProcessorInstance(scriptClassReference,
                         capabilityResourceSourceProperty.instanceDependencies)
             }
-            CAPABILITY_TYPE_JAVA_COMPONENT -> {
+            BluePrintConstants.SCRIPT_INTERNAL -> {
                 // Initialize Capability Resource Assignment Processor
-                componentResourceAssignmentProcessor = applicationContext.getBean(instanceName, ResourceAssignmentProcessor::class.java)
+                componentResourceAssignmentProcessor = applicationContext.getBean(scriptClassReference, ResourceAssignmentProcessor::class.java)
             }
-            CAPABILITY_TYPE_JYTHON_COMPONENT -> {
-                val content = getJythonContent(instanceName)
-                componentResourceAssignmentProcessor = getJythonResourceAssignmentProcessorInstance(instanceName,
+            BluePrintConstants.SCRIPT_JYTHON -> {
+                val content = getJythonContent(scriptClassReference)
+                componentResourceAssignmentProcessor = getJythonResourceAssignmentProcessorInstance(scriptClassReference,
                         content, capabilityResourceSourceProperty.instanceDependencies)
             }
         }
 
-        checkNotNull(componentResourceAssignmentProcessor) { "failed to get capability resource assignment processor($instanceName)" }
+        checkNotNull(componentResourceAssignmentProcessor) { "failed to get capability resource assignment processor($scriptClassReference)" }
 
         // Assign Current Blueprint runtime and ResourceDictionaries
         componentResourceAssignmentProcessor.raRuntimeService = raRuntimeService
@@ -22,20 +22,23 @@ import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.uti
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
 import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Service
 
 /**
- * DefaultResourceAssignmentProcessor
+ * DefaultResourceResolutionProcessor
  *
  * @author Kapil Singal
  */
-@Service("resource-assignment-processor-default")
-open class DefaultResourceAssignmentProcessor : ResourceAssignmentProcessor() {
+@Service("rr-processor-source-default")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() {
 
-    private val logger = LoggerFactory.getLogger(DefaultResourceAssignmentProcessor::class.java)
+    private val logger = LoggerFactory.getLogger(DefaultResourceResolutionProcessor::class.java)
 
     override fun getName(): String {
-        return "resource-assignment-processor-default"
+        return "rr-processor-source-default"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
@@ -23,20 +23,23 @@ import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
 import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
 import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Service
 
 /**
- * InputResourceAssignmentProcessor
+ * InputResourceResolutionProcessor
  *
  * @author Kapil Singal
  */
-@Service("resource-assignment-processor-input")
-open class InputResourceAssignmentProcessor : ResourceAssignmentProcessor() {
+@Service("rr-processor-source-input")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() {
 
-    private val logger = LoggerFactory.getLogger(InputResourceAssignmentProcessor::class.java)
+    private val logger = LoggerFactory.getLogger(InputResourceResolutionProcessor::class.java)
 
     override fun getName(): String {
-        return "resource-assignment-processor-input"
+        return "rr-processor-source-input"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
@@ -28,22 +28,25 @@ import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants
 import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Service
 import java.util.*
 
 /**
- * PrimaryDataResourceAssignmentProcessor
+ * PrimaryDataResourceResolutionProcessor
  *
  * @author Kapil Singal
  */
-@Service("resource-assignment-processor-primary-db")
-open class PrimaryDataResourceAssignmentProcessor(private val primaryDBLibGenericService: PrimaryDBLibGenericService)
+@Service("rr-processor-source-primary-db")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class PrimaryDataResourceResolutionProcessor(private val primaryDBLibGenericService: PrimaryDBLibGenericService)
     : ResourceAssignmentProcessor() {
 
-    private val logger = LoggerFactory.getLogger(PrimaryDataResourceAssignmentProcessor::class.java)
+    private val logger = LoggerFactory.getLogger(PrimaryDataResourceResolutionProcessor::class.java)
 
     override fun getName(): String {
-        return "resource-assignment-processor-primary-db"
+        return "rr-processor-source-primary-db"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
index b07155a..9b7c70a 100644 (file)
@@ -57,9 +57,13 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
         return ResourceAssignment()
     }
 
-    override fun apply(executionServiceInput: ResourceAssignment): ResourceAssignment {
-        prepareRequest(executionServiceInput)
-        process(executionServiceInput)
+    override fun apply(resourceAssignment: ResourceAssignment): ResourceAssignment {
+        try {
+            prepareRequest(resourceAssignment)
+            process(resourceAssignment)
+        } catch (runtimeException: RuntimeException) {
+            recover(runtimeException, resourceAssignment)
+        }
         return prepareResponse()
     }
 
@@ -24,26 +24,30 @@ import com.fasterxml.jackson.databind.node.ObjectNode
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.RestResourceSource
 import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService
+import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService
 import org.onap.ccsdk.apps.controllerblueprints.core.*
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
 import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants
 import org.slf4j.LoggerFactory
+import org.springframework.beans.factory.config.ConfigurableBeanFactory
+import org.springframework.context.annotation.Scope
 import org.springframework.stereotype.Service
 
 /**
- * SimpleRestResourceAssignmentProcessor
+ * RestResourceResolutionProcessor
  *
  * @author Kapil Singal
  */
-@Service("resource-assignment-processor-primary-config-data")
-open class SimpleRestResourceAssignmentProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService)
+@Service("rr-processor-source-rest")
+@Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE)
+open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService)
     : ResourceAssignmentProcessor() {
 
-    private val logger = LoggerFactory.getLogger(SimpleRestResourceAssignmentProcessor::class.java)
+    private val logger = LoggerFactory.getLogger(RestResourceResolutionProcessor::class.java)
 
     override fun getName(): String {
-        return "resource-assignment-processor-primary-config-data"
+        return "rr-processor-source-rest"
     }
 
     override fun process(resourceAssignment: ResourceAssignment) {
@@ -70,8 +74,8 @@ 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")
+                // Get the Rest Client Service
+                val restClientService = blueprintWebClientService(resourceAssignment, sourceProperties)
                 val response = restClientService.getResource(urlPath, String::class.java)
                 if (response.isNotBlank()) {
                     logger.warn("Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath)")
@@ -87,6 +91,16 @@ open class SimpleRestResourceAssignmentProcessor(private val blueprintRestLibPro
         }
     }
 
+    open fun blueprintWebClientService(resourceAssignment: ResourceAssignment,
+                                       restResourceSource: RestResourceSource): BlueprintWebClientService {
+        return if (checkNotEmpty(restResourceSource.endpointSelector)) {
+            val restPropertiesJson = raRuntimeService.resolveDSLExpression(restResourceSource.endpointSelector!!)
+            blueprintRestLibPropertyService.blueprintWebClientService(restPropertiesJson)
+        } else {
+            blueprintRestLibPropertyService.blueprintWebClientService(resourceAssignment.dictionarySource!!)
+        }
+    }
+
     @Throws(BluePrintProcessorException::class)
     private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource, restResponse: String, path: String) {
         val dName = resourceAssignment.dictionaryName
index fbecb55..c3b1018 100644 (file)
@@ -42,9 +42,9 @@ import org.springframework.test.context.junit4.SpringRunner
 
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
-    InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class,
-    PrimaryDataResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class,
-    CapabilityResourceAssignmentProcessor::class, PrimaryDBLibGenericService::class,
+    InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
+    PrimaryDataResourceResolutionProcessor::class, RestResourceResolutionProcessor::class,
+    CapabilityResourceResolutionProcessor::class, PrimaryDBLibGenericService::class,
     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
index d0d3a13..6d2d3f2 100644 (file)
@@ -47,9 +47,9 @@ import kotlin.test.assertTrue
  */
 @RunWith(SpringRunner::class)
 @ContextConfiguration(classes = [ResourceResolutionServiceImpl::class,
-    InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class,
-    PrimaryDataResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class,
-    CapabilityResourceAssignmentProcessor::class, PrimaryDBLibGenericService::class,
+    InputResourceResolutionProcessor::class, DefaultResourceResolutionProcessor::class,
+    PrimaryDataResourceResolutionProcessor::class, RestResourceResolutionProcessor::class,
+    CapabilityResourceResolutionProcessor::class, PrimaryDBLibGenericService::class,
     BlueprintPropertyConfiguration::class, BluePrintProperties::class,
     BluePrintDBLibConfiguration::class, BluePrintLoadConfiguration::class])
 @TestPropertySource(locations = ["classpath:application-test.properties"])
@@ -66,7 +66,8 @@ class ResourceResolutionServiceTest {
     fun testRegisteredSource() {
         val sources = resourceResolutionService.registeredResourceSources()
         assertNotNull(sources, "failed to get registered sources")
-        assertTrue(sources.containsAll(arrayListOf("input", "default", "primary-db", "primary-config-data")), "failed to get registered sources")
+        assertTrue(sources.containsAll(arrayListOf("source-input", "source-default", "source-primary-db",
+                "source-rest")), "failed to get registered sources")
     }
 
     @Test
@@ -20,9 +20,9 @@ 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.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
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
@@ -36,15 +36,15 @@ import org.springframework.test.context.junit4.SpringRunner
 import kotlin.test.assertNotNull
 
 @RunWith(SpringRunner::class)
-@ContextConfiguration(classes = [CapabilityResourceAssignmentProcessor::class, BluePrintScriptsServiceImpl::class,
+@ContextConfiguration(classes = [CapabilityResourceResolutionProcessor::class, BluePrintScriptsServiceImpl::class,
     BlueprintJythonService::class, PythonExecutorProperty::class, MockCapabilityService::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"])
-class CapabilityResourceAssignmentProcessorTest {
+class CapabilityResourceResolutionProcessorTest {
 
     @Autowired
-    lateinit var capabilityResourceAssignmentProcessor: CapabilityResourceAssignmentProcessor
+    lateinit var capabilityResourceResolutionProcessor: CapabilityResourceResolutionProcessor
 
     @Test
     fun `test kotlin capability`() {
@@ -54,15 +54,15 @@ class CapabilityResourceAssignmentProcessorTest {
 
         val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
 
-        capabilityResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
-        capabilityResourceAssignmentProcessor.resourceDictionaries = hashMapOf()
+        capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
+        capabilityResourceResolutionProcessor.resourceDictionaries = hashMapOf()
 
 
         val scriptPropertyInstances: MutableMap<String, Any> = mutableMapOf()
         scriptPropertyInstances["mock-service1"] = MockCapabilityService()
         scriptPropertyInstances["mock-service2"] = MockCapabilityService()
 
-        val resourceAssignmentProcessor = capabilityResourceAssignmentProcessor
+        val resourceAssignmentProcessor = capabilityResourceResolutionProcessor
                 .getKotlinResourceAssignmentProcessorInstance(
                         "ResourceAssignmentProcessor_cba\$ScriptResourceAssignmentProcessor", scriptPropertyInstances)
 
@@ -90,14 +90,14 @@ class CapabilityResourceAssignmentProcessorTest {
 
         val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
 
-        capabilityResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
+        capabilityResourceResolutionProcessor.raRuntimeService = resourceAssignmentRuntimeService
 
         val resourceDefinition = JacksonUtils
                 .readValueFromClassPathFile("mapping/capability/jython-resource-definitions.json",
                         ResourceDefinition::class.java)!!
         val resourceDefinitions: MutableMap<String, ResourceDefinition> = mutableMapOf()
         resourceDefinitions[resourceDefinition.name] = resourceDefinition
-        capabilityResourceAssignmentProcessor.resourceDictionaries = resourceDefinitions
+        capabilityResourceResolutionProcessor.resourceDictionaries = resourceDefinitions
 
         val resourceAssignment = ResourceAssignment().apply {
             name = "service-instance-id"
@@ -108,7 +108,7 @@ class CapabilityResourceAssignmentProcessorTest {
             }
         }
 
-        val processorName = capabilityResourceAssignmentProcessor.apply(resourceAssignment)
+        val processorName = capabilityResourceResolutionProcessor.apply(resourceAssignment)
         assertNotNull(processorName, "couldn't get Jython script resource assignment processor name")
 
     }
index d3780e0..fe89291 100644 (file)
@@ -10,8 +10,8 @@
     "capability": {
       "type": "source-capability",
       "properties": {
-        "type": "JYTHON-COMPONENT",
-        "instance-name": "SampleRAProcessor",
+        "script-type": "jython",
+        "script-class-reference": "SampleRAProcessor",
         "instance-dependencies": []
       }
     }
index 47577b3..705caa2 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.rest.service
 
+import com.fasterxml.jackson.databind.JsonNode
 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintProperties
 import org.onap.ccsdk.apps.blueprintsprocessor.rest.*
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
 import org.springframework.stereotype.Service
 
 @Service(RestLibConstants.SERVICE_BLUEPRINT_REST_LIB_PROPERTY)
 open class BluePrintRestLibPropertyService(private var bluePrintProperties: BluePrintProperties) {
 
-    @Throws(BluePrintProcessorException::class)
     fun restClientProperties(prefix: String): RestClientProperties {
         val type = bluePrintProperties.propertyBeanType("$prefix.type", String::class.java)
         return when (type) {
@@ -47,19 +48,39 @@ open class BluePrintRestLibPropertyService(private var bluePrintProperties: Blue
         }
     }
 
-    @Throws(BluePrintProcessorException::class)
+    fun restClientProperties(jsonNode: JsonNode): RestClientProperties {
+        val type = jsonNode.get("type").textValue()
+        return when (type) {
+            RestLibConstants.TYPE_BASIC_AUTH -> {
+                JacksonUtils.readValue(jsonNode, BasicAuthRestClientProperties::class.java)!!
+            }
+            RestLibConstants.TYPE_SSL_BASIC_AUTH -> {
+                JacksonUtils.readValue(jsonNode, SSLBasicAuthRestClientProperties::class.java)!!
+            }
+            RestLibConstants.TYPE_DME2_PROXY -> {
+                JacksonUtils.readValue(jsonNode, DME2RestClientProperties::class.java)!!
+            }
+            RestLibConstants.TYPE_POLICY_MANAGER -> {
+                JacksonUtils.readValue(jsonNode, PolicyManagerRestClientProperties::class.java)!!
+            }
+            else -> {
+                throw BluePrintProcessorException("Rest adaptor($type) is not supported")
+            }
+        }
+    }
+
+
     fun blueprintWebClientService(selector: String): BlueprintWebClientService {
         val prefix = "blueprintsprocessor.restclient.$selector"
         val restClientProperties = restClientProperties(prefix)
         return blueprintWebClientService(restClientProperties)
     }
 
-
-    fun blueprintDynamicWebClientService(sourceType: String, selector: String): BlueprintWebClientService {
-        TODO()
+    fun blueprintWebClientService(jsonNode: JsonNode): BlueprintWebClientService {
+        val restClientProperties = restClientProperties(jsonNode)
+        return blueprintWebClientService(restClientProperties)
     }
 
-    @Throws(BluePrintProcessorException::class)
     fun blueprintWebClientService(restClientProperties: RestClientProperties): BlueprintWebClientService {
         when (restClientProperties) {
             is BasicAuthRestClientProperties -> {
index 2c2e67d..e3545df 100644 (file)
@@ -159,7 +159,11 @@ object BluePrintConstants {
     const val TOSCA_SCRIPTS_KOTLIN_DIR: String = "$TOSCA_SCRIPTS_DIR/kotlin"
     const val TOSCA_SCRIPTS_JYTHON_DIR: String = "$TOSCA_SCRIPTS_DIR/python"
 
-    const val METADATA_USER_GROUPS = "user-groups"
+    const val PROPERTY_ENV = "ENV"
+    const val PROPERTY_APP = "APP"
+    const val PROPERTY_BPP = "BPP"
+    const val PROPERTY_SELF = "SELF"
+
     const val METADATA_TEMPLATE_NAME = "template_name"
     const val METADATA_TEMPLATE_VERSION = "template_version"
     const val METADATA_TEMPLATE_AUTHOR = "template_author"
@@ -174,11 +178,5 @@ object BluePrintConstants {
     const val PROPERTY_CURRENT_IMPLEMENTATION = "current-implementation"
     const val PROPERTY_EXECUTION_REQUEST = "execution-request"
 
-    const val OPERATION_PROCESS = "process"
-    const val OPERATION_PREPARE = "prepare"
-
-    const val BLUEPRINT_RETRIEVE_TYPE_DB = "db"
-    const val BLUEPRINT_RETRIEVE_TYPE_FILE = "file"
-    const val BLUEPRINT_RETRIEVE_TYPE_REPO = "repo"
 
 }
\ No newline at end of file
index f8ac5d6..80ad3f2 100644 (file)
@@ -62,7 +62,7 @@ interface BluePrintRuntimeService<T> {
 
     fun setBluePrintError(bluePrintError: BluePrintError)
 
-    fun loadEnvironments(fileName: String)
+    fun loadEnvironments(type: String, fileName: String)
 
     fun resolveNodeTemplatePropertyAssignments(nodeTemplateName: String,
                                                propertyDefinitions: MutableMap<String, PropertyDefinition>,
@@ -135,11 +135,11 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
 
     init {
         /**
-         * Load Default Environments Properties
+         * Load Blueprint Environments Properties
          */
         val absoluteEnvFilePath = bluePrintContext.rootPath.plus(File.separator)
                 .plus(BluePrintConstants.TOSCA_ENVIRONMENTS_DIR)
-        loadEnvironments(absoluteEnvFilePath)
+        loadEnvironments(BluePrintConstants.PROPERTY_BPP, absoluteEnvFilePath)
 
     }
 
@@ -204,9 +204,10 @@ open class DefaultBluePrintRuntimeService(private var id: String, private var bl
         this.bluePrintError = bluePrintError
     }
 
-    override fun loadEnvironments(fileName: String) {
+    override fun loadEnvironments(type: String, fileName: String) {
         BluePrintMetadataUtils.environmentFileProperties(fileName).forEach { key, value ->
-            setNodeTemplateAttributeValue("ENV", key.toString(), value.toString().asJsonPrimitive())
+            setNodeTemplateAttributeValue(type, key.toString(), value.toString()
+                    .asJsonPrimitive())
         }
     }
 
index ae4f40b..7905b8f 100644 (file)
@@ -24,6 +24,7 @@ import com.fasterxml.jackson.databind.JsonNode
 import com.fasterxml.jackson.databind.node.NullNode
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants
 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.apps.controllerblueprints.core.asJsonPrimitive
 import org.onap.ccsdk.apps.controllerblueprints.core.data.*
 import org.onap.ccsdk.apps.controllerblueprints.core.format
 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
@@ -109,13 +110,27 @@ If Property Assignment is Expression.
         val subAttributeName: String? = attributeExpression.subAttributeName
 
         var attributeNodeTemplateName = nodeTemplateName
+        /**
+         * Attributes are dynamic runtime properties information. There are multiple types of Attributes,
+         * ENV : Environment Variables
+         * APP : Application properties ( ie Spring resolved properties )
+         * BPP : Blueprint Properties, Specific to Blue Print execution.
+         * SELF : Current Node Template properties.
+         */
         when (attributeExpression.modelableEntityName) {
-            "ENV" -> {
+            BluePrintConstants.PROPERTY_ENV -> {
                 val environmentValue = System.getProperty(attributeName)
-                valueNode = JacksonUtils.jsonNode(environmentValue)
+                valueNode = environmentValue.asJsonPrimitive()
+            }
+            BluePrintConstants.PROPERTY_APP -> {
+                TODO("Get property from application properties")
+            }
+            BluePrintConstants.PROPERTY_BPP -> {
+                valueNode = bluePrintRuntimeService.getNodeTemplateAttributeValue(BluePrintConstants.PROPERTY_BPP, attributeName)
+                        ?: throw BluePrintException("failed to get env attribute name ($attributeName) ")
             }
             else -> {
-                if (!attributeExpression.modelableEntityName.equals("SELF", true)) {
+                if (!attributeExpression.modelableEntityName.equals(BluePrintConstants.PROPERTY_SELF, true)) {
                     attributeNodeTemplateName = attributeExpression.modelableEntityName
                 }
 
@@ -146,7 +161,8 @@ If Property Assignment is Expression.
         val subPropertyName: String? = propertyExpression.subPropertyName
 
         var propertyNodeTemplateName = nodeTemplateName
-        if (!propertyExpression.modelableEntityName.equals("SELF", true)) {
+
+        if (!propertyExpression.modelableEntityName.equals(BluePrintConstants.PROPERTY_SELF, true)) {
             propertyNodeTemplateName = propertyExpression.modelableEntityName
         }