From dab10311925fe9603e0750a29e566f5e45c2e567 Mon Sep 17 00:00:00 2001 From: Oleg Mitsura Date: Thu, 21 May 2020 10:33:18 -0400 Subject: Enable force-resolution 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 --- .../resolution/ResourceResolutionComponent.kt | 2 ++ .../resolution/ResourceResolutionConstants.kt | 1 + .../resolution/ResourceResolutionService.kt | 24 +++++++++++++++------- .../resolution/db/ResourceResolutionDBService.kt | 8 ++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) (limited to 'ms') 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 0435d1d2c..e060cdcc5 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 @@ -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 = 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 diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt index e2a8920f5..9f22b8134 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt @@ -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" 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 df07b8e03..8923a1143 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 @@ -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): 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 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 5958c7899..d694ca23f 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 @@ -221,4 +221,12 @@ class ResourceResolutionDBService(private val resourceResolutionRepository: Reso resolutionKey ) } + + suspend fun deleteResourceResolutionList(listResourceResolution: List) = withContext(Dispatchers.IO) { + try { + resourceResolutionRepository.deleteInBatch(listResourceResolution) + } catch (ex: Exception) { + throw BluePrintException("Failed to batch delete resource resolution", ex) + } + } } -- cgit 1.2.3-korg