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
},
"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" : []
+ }
}
}
},
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
"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>()
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
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")
+ }
+ }
}
# 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=