summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution
diff options
context:
space:
mode:
authorArne Chrestin <arne.chrestin@telekom.de>2021-12-20 13:16:57 +0100
committerArne Chrestin <arne.chrestin@telekom.de>2022-01-17 14:35:20 +0000
commit3b68a155707477cadc118add5b10b6fb5c008a68 (patch)
treeb67427035eedd70750a9869bb21c16e208cb437a /ms/blueprintsprocessor/functions/resource-resolution
parent23bbabcd5bd5b107e6536b88390bab09dac5e636 (diff)
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
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt16
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt28
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionRepository.kt21
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionSelector.kt6
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/TemplateResolutionService.kt53
5 files changed, 120 insertions, 4 deletions
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<String> {
+ return BluePrintDependencyService.resourceResolutionService()
+ .resolveResolutionKeysFromDatabase(bluePrintRuntimeService, artifactName)
+}
+
+suspend fun AbstractComponentFunction.storedArtifactNamesAndResolutionKeysNB(): Map<String,List<String>> {
+ 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<String>
+
+ suspend fun resolveArtifactNamesAndResolutionKeysFromDatabase(
+ bluePrintRuntimeService: BluePrintRuntimeService<*>
+ ): Map<String, List<String>>
+
suspend fun resolveResources(
bluePrintRuntimeService: BluePrintRuntimeService<*>,
nodeTemplateName: String,
@@ -125,6 +134,23 @@ open class ResourceResolutionServiceImpl(
)
}
+ override suspend fun resolveResolutionKeysFromDatabase(
+ bluePrintRuntimeService: BluePrintRuntimeService<*>,
+ artifactTemplate: String
+ ): List<String> {
+ return templateResolutionDBService.findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactName(
+ bluePrintRuntimeService,
+ artifactTemplate
+ )
+ }
+
+ override suspend fun resolveArtifactNamesAndResolutionKeysFromDatabase(
+ bluePrintRuntimeService: BluePrintRuntimeService<*>): Map<String, List<String>> {
+ 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<TemplateResolution, Strin
occurrence: Int
): TemplateResolution?
+ @Query(
+ "select tr.resolutionKey from TemplateResolution tr where tr.blueprintName = :blueprintName and tr.blueprintVersion = :blueprintVersion and tr.artifactName = :artifactName and tr.occurrence = :occurrence"
+ )
+ fun findResolutionKeysByBlueprintNameAndBlueprintVersionAndArtifactNameAndOccurrence(
+ @Param("blueprintName") blueprintName: String?,
+ @Param("blueprintVersion") blueprintVersion: String?,
+ @Param("artifactName") artifactName: String,
+ @Param("occurrence") occurrence: Int
+ ): List<String>?
+
+ @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<TemplateResolutionSelector>?
+
@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<String> =
+ 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<String,List<String>> =
+ 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<String, MutableList<String>> = 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