[Blueprintsprocessor] Use all source-db resources instead of only processor-db 30/129730/8
authorMichal Jagiello <michal.jagiello@t-mobile.pl>
Fri, 1 Jul 2022 09:04:36 +0000 (09:04 +0000)
committerMichal Jagiello <michal.jagiello@t-mobile.pl>
Tue, 19 Jul 2022 06:59:13 +0000 (06:59 +0000)
In DatabaseResourceAssignmentProcessor class filter resourceSourceMappings to get all source-db resources instead of using only one: processor-db

Issue-ID: CCSDK-3699
Signed-off-by: Michal Jagiello <michal.jagiello@t-mobile.pl>
Change-Id: I616ca6fe1336427b0b603a0386878ba4c8ea5828

components/model-catalog/blueprint-model/test-blueprint/baseconfiguration/Definitions/resources_definition_types.json
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/application-test.properties

index 523329d..e679a9a 100644 (file)
           },
           "key-dependencies" : []
         }
+      },
+      "any-db": {
+        "type": "source-db",
+        "properties": {
+          "endpoint-selector": "dynamic-db-source",
+          "query": "SELECT artifact_name FROM sdnctl.BLUEPRINT_MODEL where artifact_version=\"1.0.0\"",
+          "input-key-mapping": {
+          },
+          "output-key-mapping": {
+            "service-instance-id": "artifact_name"
+          },
+          "key-dependencies" : []
+        }
       }
     }
   },
index 98df3f1..785f477 100644 (file)
@@ -32,7 +32,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.updateErrorMessage
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.KeyIdentifier
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
-import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDictionaryConstants
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
 import org.slf4j.LoggerFactory
 import org.springframework.beans.factory.config.ConfigurableBeanFactory
 import org.springframework.context.annotation.Scope
@@ -135,13 +135,15 @@ open class DatabaseResourceAssignmentProcessor(
             "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})"
         }
         check(resourceAssignment.dictionarySource in getListOfDBSources()) {
-            "resource assignment source is not ${ResourceDictionaryConstants.PROCESSOR_DB} but it is ${resourceAssignment.dictionarySource}"
+            "resource assignment source ${resourceAssignment.dictionarySource} is not registered in \"resourceSourceMappings\""
         }
     }
 
     // placeholder to get the list of DB sources.
-    // TODO: This will be replaced with a DB
-    private fun getListOfDBSources(): Array<String> = arrayOf(ResourceDictionaryConstants.PROCESSOR_DB)
+    private fun getListOfDBSources(): Array<String> {
+        return ResourceSourceMappingFactory.getRegisterSourceMapping()
+            .resourceSourceMappings.filterValues { it == "source-db" }.keys.toTypedArray()
+    }
 
     private fun populateNamedParameter(inputKeyMapping: Map<String, String>): Map<String, Any> {
         val namedParameters = HashMap<String, Any>()
index 0c8ec7d..8a9f657 100644 (file)
@@ -28,6 +28,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.util
 import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition
 import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils
 import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory
 import org.springframework.beans.factory.annotation.Autowired
 import org.springframework.test.context.ContextConfiguration
 import org.springframework.test.context.TestPropertySource
@@ -75,4 +76,34 @@ class DatabaseResourceResolutionProcessorTest {
             assertNotNull(processorName, "couldn't get Database resource assignment processor name")
         }
     }
+
+    @Test
+    fun `test database resource resolution any db`() {
+        runBlocking {
+            val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext(
+                "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration"
+            )
+
+            val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext)
+
+            ResourceSourceMappingFactory.registerSourceMapping("processor-db", "source-db")
+            ResourceSourceMappingFactory.registerSourceMapping("any-db", "source-db")
+
+            databaseResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
+            databaseResourceAssignmentProcessor.resourceDictionaries = ResourceAssignmentUtils
+                .resourceDefinitions(bluePrintContext.rootPath)
+
+            val resourceAssignment = ResourceAssignment().apply {
+                name = "service-instance-id"
+                dictionaryName = "service-instance-id"
+                dictionarySource = "any-db"
+                property = PropertyDefinition().apply {
+                    type = "string"
+                }
+            }
+
+            val processorName = databaseResourceAssignmentProcessor.applyNB(resourceAssignment)
+            assertNotNull(processorName, "couldn't get Database resource assignment processor name")
+        }
+    }
 }
index 4483ac8..95a6505 100644 (file)
@@ -14,6 +14,8 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 #
+resourceSourceMappings=processor-db=source-db,input=source-input,default=source-default,sdnc=source-rest,aai-data=source-rest,capability=source-capability,rest=source-rest,vault-data=source-rest,script=source-capability,any-db=source-db
+
 blueprintsprocessor.db.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1
 blueprintsprocessor.db.username=sa
 blueprintsprocessor.db.password=