summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/main
diff options
context:
space:
mode:
authorkuldipr <kuldip.rai@amdocs.com>2022-03-18 10:35:56 -0400
committerkuldipr <kuldip.rai@amdocs.com>2022-05-24 11:04:45 -0400
commit414949bd6d65a46f296b3c7a0057a6a58a54db22 (patch)
treea350d772074e5c2c29bce9ccf5618fc32b48d117 /ms/blueprintsprocessor/functions/resource-resolution/src/main
parent009c9b41e3219bbf889ba040e95d397eebb25d2e (diff)
Enable versioned resource resolution by using occurrence
By setting occurrence to <= 0 in the CBA, a user indicates that each time resource resolution executes, it should produce a new set of values for a resolution-key or (resourceId, resourceType) pair. For each new execution, the occurrence is incremented to serve as the version number for the new set of values. Issue-ID: CCSDK-3663 Signed-off-by: kuldipr <kuldip.rai@amdocs.com> Change-Id: Ib535b20cb775dcbb5b02fe5a5f6904a335fda310
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt12
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt62
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt48
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt22
4 files changed, 136 insertions, 8 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
index e060cdcc5..d46f75e41 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
@@ -109,9 +109,13 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
val artifactPrefixNamesNode = getOperationInput(ResourceResolutionConstants.INPUT_ARTIFACT_PREFIX_NAMES)
val artifactPrefixNames = JacksonUtils.getListFromJsonNode(artifactPrefixNamesNode, String::class.java)
+ val alwaysPerformNewResolution = occurrence <= 0
+ val resolutionsToPerform: Int = if (alwaysPerformNewResolution) 1 else occurrence
+ for (j in 1..resolutionsToPerform) {
- for (j in 1..occurrence) {
- properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = j
+ if (!alwaysPerformNewResolution) {
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = j
+ }
val result = resourceResolutionService.resolveResources(
bluePrintRuntimeService,
@@ -121,8 +125,8 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
stepName
)
- // provide indexed result in output if we have multiple resolution
- if (occurrence != 1) {
+ // provide indexed result in output if we have multiple resolution.
+ if (resolutionsToPerform != 1) {
jsonResponse.set<JsonNode>(j.toString(), result.templateMap.asJsonNode())
assignmentMap.set<JsonNode>(j.toString(), result.assignmentMap.asJsonNode())
} else {
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 8923a1143..a3c137807 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
@@ -201,6 +201,7 @@ open class ResourceResolutionServiceImpl(
val artifactMapping = "$artifactPrefix-mapping"
val forceResolution = isForceResolution(properties)
+ val propertiesMutableMap = properties.toMutableMap()
log.info("Resolving resource with resource assignment artifact($artifactMapping)")
val resourceAssignmentContent =
@@ -212,7 +213,16 @@ open class ResourceResolutionServiceImpl(
?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")
if (isToStore(properties)) {
- val existingResourceResolution = isNewResolution(bluePrintRuntimeService, properties, artifactPrefix)
+ val alwaysPerformNewResolution = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] as Int <= 0
+ val existingResourceResolution = if (alwaysPerformNewResolution) {
+ val occurrence = findNextOccurrence(bluePrintRuntimeService, properties, artifactPrefix)
+ log.info("Always perform new resolutions - next occurrence: $occurrence")
+ propertiesMutableMap[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = occurrence
+ // Since we are performing new resolution, simply pass empty list.
+ emptyList()
+ } else {
+ isNewResolution(bluePrintRuntimeService, properties, artifactPrefix)
+ }
if (existingResourceResolution.isNotEmpty()) {
if (forceResolution) {
resourceResolutionDBService.deleteResourceResolutionList(existingResourceResolution)
@@ -237,7 +247,7 @@ open class ResourceResolutionServiceImpl(
resourceDefinitions,
resourceAssignments,
artifactPrefix,
- properties
+ propertiesMutableMap
)
val resolutionSummary = properties.getOrDefault(
@@ -271,7 +281,7 @@ open class ResourceResolutionServiceImpl(
}
if (isToStore(properties)) {
- templateResolutionDBService.write(properties, resolvedContent, bluePrintRuntimeService, artifactPrefix)
+ templateResolutionDBService.write(propertiesMutableMap, resolvedContent, bluePrintRuntimeService, artifactPrefix)
log.info("Template resolution saved into database successfully : ($properties)")
}
@@ -490,7 +500,7 @@ open class ResourceResolutionServiceImpl(
}
}
- // Comparision between what we have in the database vs what we have to assign.
+ // Comparison between what we have in the database vs what we have to assign.
private fun compareOne(resourceResolution: ResourceResolution, resourceAssignment: ResourceAssignment): Boolean {
return (
resourceResolution.name == resourceAssignment.name &&
@@ -509,4 +519,48 @@ open class ResourceResolutionServiceImpl(
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive()
)
}
+
+ /**
+ * This method returns 'occurrence' required to persist new resource resolution.
+ *
+ * @param bluePrintRuntimeService
+ * @param properties
+ * @param artifactPrefix
+ */
+ private suspend fun findNextOccurrence(
+ bluePrintRuntimeService: BluePrintRuntimeService<*>,
+ properties: Map<String, Any>,
+ artifactPrefix: String
+ ): Int {
+ val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
+ val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
+ val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
+ val resolutionKey = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] as String
+ val resourceId = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] as String
+ val resourceType = properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] as String
+
+ // This should not happen since the request has already been validated but worth to check it here as well.
+ if (resourceType.isEmpty() && resourceId.isEmpty() && resolutionKey.isEmpty()) {
+ throw BluePrintProcessorException(
+ "Can't proceed to get next occurrence: " +
+ "Either provide a resolution-key OR combination of resource-id and resource-type"
+ )
+ }
+
+ if (resolutionKey.isNotEmpty()) {
+ return resourceResolutionDBService.findNextOccurrenceByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ resolutionKey,
+ blueprintName,
+ blueprintVersion,
+ artifactPrefix
+ )
+ } else {
+ return resourceResolutionDBService.findNextOccurrenceByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
+ blueprintName,
+ blueprintVersion,
+ resourceId,
+ resourceType
+ )
+ }
+ }
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
index b5d4e4515..1f0171f9f 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt
@@ -229,4 +229,52 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso
throw BluePrintException("Failed to batch delete resource resolution", ex)
}
}
+
+ /**
+ * This method returns the (highest occurrence + 1) of resource resolutions if present in DB, returns 1 otherwise.
+ * The 'occurrence' is used to persist new resource resolution in the DB.
+ *
+ * @param resolutionKey
+ * @param blueprintName
+ * @param blueprintVersion
+ * @param artifactPrefix
+ */
+ suspend fun findNextOccurrenceByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ resolutionKey: String,
+ blueprintName: String,
+ blueprintVersion: String,
+ artifactPrefix: String
+ ) = withContext(Dispatchers.IO) {
+ val maxOccurrence = resourceResolutionRepository.findMaxOccurrenceByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ resolutionKey,
+ blueprintName,
+ blueprintVersion,
+ artifactPrefix
+ )
+ maxOccurrence?.inc() ?: 1
+ }
+
+ /**
+ * This method returns the (highest occurrence + 1) of resource resolutions if present in DB, returns 1 otherwise.
+ * The 'occurrence' is used to persist new resource resolution in the DB.
+ *
+ * @param blueprintName
+ * @param blueprintVersion
+ * @param resourceId
+ * @param resourceType
+ */
+ suspend fun findNextOccurrenceByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
+ blueprintName: String,
+ blueprintVersion: String,
+ resourceId: String,
+ resourceType: String
+ ) = withContext(Dispatchers.IO) {
+ val maxOccurrence = resourceResolutionRepository.findMaxOccurrenceByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
+ blueprintName,
+ blueprintVersion,
+ resourceId,
+ resourceType
+ )
+ maxOccurrence?.inc() ?: 1
+ }
}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
index 6e0ed3a4b..8513bda88 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionRepository.kt
@@ -36,6 +36,28 @@ interface ResourceResolutionRepository : JpaRepository<ResourceResolution, Strin
@Param("name")name: String
): ResourceResolution?
+ @Query(
+ value = "SELECT max(occurrence) FROM RESOURCE_RESOLUTION WHERE resolution_key = :key AND blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion AND artifact_name = :artifactName ",
+ nativeQuery = true
+ )
+ fun findMaxOccurrenceByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
+ @Param("key")key: String,
+ @Param("blueprintName")blueprintName: String,
+ @Param("blueprintVersion")blueprintVersion: String,
+ @Param("artifactName")artifactName: String
+ ): Int?
+
+ @Query(
+ value = "SELECT max(occurrence) FROM RESOURCE_RESOLUTION WHERE blueprint_name = :blueprintName AND blueprint_version = :blueprintVersion AND resource_id = :resourceId AND resource_type = :resourceType ",
+ nativeQuery = true
+ )
+ fun findMaxOccurrenceByBlueprintNameAndBlueprintVersionAndResourceIdAndResourceType(
+ @Param("blueprintName")blueprintName: String,
+ @Param("blueprintVersion")blueprintVersion: String,
+ @Param("resourceId")resourceId: String,
+ @Param("resourceType")resourceType: String
+ ): Int?
+
fun findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactName(
resolutionKey: String,
blueprintName: String,