Enable force-resolution 26/129326/1
authorOleg Mitsura <oleg.mitsura@bell.ca>
Thu, 21 May 2020 14:33:18 +0000 (10:33 -0400)
committerJozsef Csongvai <jozsef.csongvai@bell.ca>
Thu, 19 May 2022 13:47:16 +0000 (09:47 -0400)
If force-resolution is set to true in a CBA, all resolved values
and templates will be overwritten for the given resolution-key or
resource-id & resource-type.

Issue-ID: CCSDK-3670
Change-Id: I1859a7029a16190a6e691cb1fa0c76ced470279a
Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca>
components/model-catalog/definition-type/starter-type/node_type/component-resource-resolution.json
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionComponent.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/db/ResourceResolutionDBService.kt

index cc20130..853fe56 100644 (file)
               "required": false,
               "type": "boolean"
             },
+            "force-resolution": {
+              "description": "Delete existing values to force new resolution. Ineffective when occurrence < 1",
+              "required": false,
+              "type": "boolean"
+            },
             "resource-type": {
               "description": "Request type.",
               "required": false,
     }
   },
   "derived_from": "tosca.nodes.Component"
-}
\ No newline at end of file
+}
index 0435d1d..e060cdc 100644 (file)
@@ -63,6 +63,7 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
         val resolutionKey =
             getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY)?.returnNullIfMissing()?.textValue() ?: ""
         val storeResult = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT)?.asBoolean() ?: false
+        val forceResolution = getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_FORCE_RESOLUTION)?.asBoolean() ?: false
         val resourceId =
             getOptionalOperationInput(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID)?.returnNullIfMissing()?.textValue() ?: ""
 
@@ -73,6 +74,7 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
 
         val properties: MutableMap<String, Any> = mutableMapOf()
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] = storeResult
+        properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_FORCE_RESOLUTION] = forceResolution
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY] = resolutionKey
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_ID] = resourceId
         properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE] = resourceType
index e2a8920..9f22b81 100644 (file)
@@ -27,6 +27,7 @@ object ResourceResolutionConstants {
     const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json"
     const val RESOURCE_RESOLUTION_INPUT_RESOLUTION_KEY = "resolution-key"
     const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result"
+    const val RESOURCE_RESOLUTION_INPUT_FORCE_RESOLUTION = "force-resolution"
     const val RESOURCE_RESOLUTION_INPUT_OCCURRENCE = "occurrence"
     const val RESOURCE_RESOLUTION_INPUT_RESOURCE_ID = "resource-id"
     const val RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE = "resource-type"
index df07b8e..8923a11 100644 (file)
@@ -199,6 +199,7 @@ open class ResourceResolutionServiceImpl(
         val artifactTemplate = "$artifactPrefix-template"
         // Resource Assignment Artifact Definition Name
         val artifactMapping = "$artifactPrefix-mapping"
+        val forceResolution = isForceResolution(properties)
 
         log.info("Resolving resource with resource assignment artifact($artifactMapping)")
 
@@ -213,10 +214,16 @@ open class ResourceResolutionServiceImpl(
         if (isToStore(properties)) {
             val existingResourceResolution = isNewResolution(bluePrintRuntimeService, properties, artifactPrefix)
             if (existingResourceResolution.isNotEmpty()) {
-                updateResourceAssignmentWithExisting(
-                    bluePrintRuntimeService as ResourceAssignmentRuntimeService,
-                    existingResourceResolution, resourceAssignments
-                )
+                if (forceResolution) {
+                    resourceResolutionDBService.deleteResourceResolutionList(existingResourceResolution)
+                    log.info("Force resolution is enabled - will resolve all resources.")
+                } else {
+                    updateResourceAssignmentWithExisting(
+                        bluePrintRuntimeService as ResourceAssignmentRuntimeService,
+                        existingResourceResolution, resourceAssignments
+                    )
+                    log.info("Force resolution is disabled - will resolve all resources not already resolved.")
+                }
             }
         }
 
@@ -407,6 +414,10 @@ open class ResourceResolutionServiceImpl(
             properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean
     }
 
+    private fun isForceResolution(properties: Map<String, Any>): Boolean =
+        properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_FORCE_RESOLUTION) &&
+            properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_FORCE_RESOLUTION] as Boolean
+
     // Check whether resolution already exist in the database for the specified resolution-key or resourceId/resourceType
     private suspend fun isNewResolution(
         bluePrintRuntimeService: BluePrintRuntimeService<*>,
@@ -428,7 +439,7 @@ open class ResourceResolutionServiceImpl(
                 )
             if (existingResourceAssignments.isNotEmpty()) {
                 log.info(
-                    "Resolution with resolutionKey=($resolutionKey) already exist - will resolve all resources not already resolved.",
+                    "Resolution with resolutionKey=($resolutionKey) already exist",
                     resolutionKey
                 )
             }
@@ -445,8 +456,7 @@ open class ResourceResolutionServiceImpl(
                 )
             if (existingResourceAssignments.isNotEmpty()) {
                 log.info(
-                    "Resolution with resourceId=($resourceId) and resourceType=($resourceType) already " +
-                        "exist - will resolve all resources not already resolved."
+                    "Resolution with resourceId=($resourceId) and resourceType=($resourceType) already exist"
                 )
             }
             return existingResourceAssignments
index 5958c78..d694ca2 100644 (file)
@@ -221,4 +221,12 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso
             resolutionKey
         )
     }
+
+    suspend fun deleteResourceResolutionList(listResourceResolution: List<ResourceResolution>) = withContext(Dispatchers.IO) {
+        try {
+            resourceResolutionRepository.deleteInBatch(listResourceResolution)
+        } catch (ex: Exception) {
+            throw BluePrintException("Failed to batch delete resource resolution", ex)
+        }
+    }
 }