From 3b68a155707477cadc118add5b10b6fb5c008a68 Mon Sep 17 00:00:00 2001 From: Arne Chrestin Date: Mon, 20 Dec 2021 13:16:57 +0100 Subject: Add functions for retrieving multiple artifacts Add the functions AbstractComponentFunction .storedArtifactNamesAndResolutionKeysNB() to retrieve all artifact_names and resolution_keys for a given blueprint and AbstractComponentFunction .storedResolutionKeysForArtifactNameNB(artifactName) to retrieve all resolution_keys for a given blueprint and artifact_name. To support the required JPA query, an interface TemplateResolutionSelector was added in resource-resolution. Issue-ID: CCSDK-3543 Signed-off-by: arne.chrestin@telekom.de Change-Id: I1907949e49134ec13d28a876474f08502759762f --- .../resolution/ResourceResolutionExtensions.kt | 16 ++++++- .../resolution/ResourceResolutionService.kt | 28 +++++++++++- .../resolution/db/TemplateResolutionRepository.kt | 21 +++++++++ .../resolution/db/TemplateResolutionSelector.kt | 6 +++ .../resolution/db/TemplateResolutionService.kt | 53 +++++++++++++++++++++- 5 files changed, 120 insertions(+), 4 deletions(-) create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionSelector.kt diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt index 4774ad57a..f7d41bcc3 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt @@ -39,6 +39,18 @@ suspend fun AbstractComponentFunction.storedContentFromResolvedArtifactNB( .resolveFromDatabase(bluePrintRuntimeService, artifactName, resolutionKey) } +suspend fun AbstractComponentFunction.storedResolutionKeysForArtifactNameNB( + artifactName: String +): List { + return BluePrintDependencyService.resourceResolutionService() + .resolveResolutionKeysFromDatabase(bluePrintRuntimeService, artifactName) +} + +suspend fun AbstractComponentFunction.storedArtifactNamesAndResolutionKeysNB(): Map> { + return BluePrintDependencyService.resourceResolutionService() + .resolveArtifactNamesAndResolutionKeysFromDatabase(bluePrintRuntimeService) +} + suspend fun AbstractComponentFunction.storedResourceResolutionsNB( resolutionKey: String, artifactName: String, @@ -72,5 +84,5 @@ fun AbstractComponentFunction.storedContentFromResolvedArtifact(resolutionKey: S } fun AbstractComponentFunction.contentFromResolvedArtifact(artifactPrefix: String): String = runBlocking { - contentFromResolvedArtifactNB(artifactPrefix) -} + contentFromResolvedArtifactNB(artifactPrefix) + } \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt index 6b4260ad0..2352c7dbe 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt @@ -61,6 +61,15 @@ interface ResourceResolutionService { resolutionKey: String ): String + suspend fun resolveResolutionKeysFromDatabase( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + artifactTemplate: String + ): List + + suspend fun resolveArtifactNamesAndResolutionKeysFromDatabase( + bluePrintRuntimeService: BluePrintRuntimeService<*> + ): Map> + suspend fun resolveResources( bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, @@ -125,6 +134,23 @@ open class ResourceResolutionServiceImpl( ) } + override suspend fun resolveResolutionKeysFromDatabase( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + artifactTemplate: String + ): List { + return templateResolutionDBService.findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactName( + bluePrintRuntimeService, + artifactTemplate + ) + } + + override suspend fun resolveArtifactNamesAndResolutionKeysFromDatabase( + bluePrintRuntimeService: BluePrintRuntimeService<*>): Map> { + return templateResolutionDBService.findArtifactNamesAndResolutionKeysByBlueprintNameAndBlueprintVersion( + bluePrintRuntimeService + ) + } + override suspend fun resolveResources( bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String, @@ -472,4 +498,4 @@ open class ResourceResolutionServiceImpl( properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive() ) } -} +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt index 642a41b1c..3df613745 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt @@ -16,6 +16,8 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db import org.springframework.data.jpa.repository.JpaRepository +import org.springframework.data.jpa.repository.Query +import org.springframework.data.repository.query.Param import org.springframework.stereotype.Repository import javax.transaction.Transactional @@ -39,6 +41,25 @@ interface TemplateResolutionRepository : JpaRepository? + + @Query( + "select tr.artifactName as artifactName, tr.resolutionKey as resolutionKey from TemplateResolution tr where tr.blueprintName = :blueprintName and tr.blueprintVersion = :blueprintVersion and tr.occurrence = :occurrence" + ) + fun findArtifactNamesAndResolutionKeysByBlueprintNameAndBlueprintVersionAndOccurrence( + @Param("blueprintName") blueprintName: String?, + @Param("blueprintVersion") blueprintVersion: String?, + @Param("occurrence") occurrence: Int + ): List? + @Transactional fun deleteByResourceIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( resourceId: String, diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionSelector.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionSelector.kt new file mode 100644 index 000000000..4fadf969c --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionSelector.kt @@ -0,0 +1,6 @@ +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db + +interface TemplateResolutionSelector { + fun getArtifactName(): String + fun getResolutionKey(): String +} \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt index 4bdd5d985..fd4cc8cd6 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt @@ -70,6 +70,57 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa )?.result ?: throw EmptyResultDataAccessException(1) } + suspend fun findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactName( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + artifactPrefix: String, + occurrence: Int = 1 + ): List = + withContext(Dispatchers.IO) { + + val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + + val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!! + val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!! + + templateResolutionRepository.findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence( + blueprintName, + blueprintVersion, + artifactPrefix, + occurrence + ) ?: throw EmptyResultDataAccessException(1) + } + + suspend fun findArtifactNamesAndResolutionKeysByBlueprintNameAndBlueprintVersion( + bluePrintRuntimeService: BluePrintRuntimeService<*>, + occurrence: Int = 1 + ): Map> = + withContext(Dispatchers.IO) { + + val metadata = bluePrintRuntimeService.bluePrintContext().metadata!! + + val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!! + val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!! + + val resultList = templateResolutionRepository.findArtifactNamesAndResolutionKeysByBlueprintNameAndBlueprintVersionAndOccurrence( + blueprintName, + blueprintVersion, + occurrence + ) ?: throw EmptyResultDataAccessException(1) + + var resultMap: MutableMap> = mutableMapOf() + + resultList.forEach { it -> + if (!resultMap.containsKey(it.getArtifactName())) { + resultMap[it.getArtifactName()] = mutableListOf(it.getResolutionKey()) + } else { + resultMap[it.getArtifactName()]!!.add(it.getResolutionKey()) + } + } + resultMap + .mapValues { it.value.toList() } + .toMap() + } + suspend fun findByResoureIdAndResourceTypeAndBlueprintNameAndBlueprintVersionAndArtifactName( blueprintName: String, blueprintVersion: String, @@ -190,4 +241,4 @@ class TemplateResolutionService(private val templateResolutionRepository: Templa throw BluePrintException("Failed to store resource api result.", ex) } } -} +} \ No newline at end of file -- cgit 1.2.3-korg