import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.BlueprintException
-import org.onap.ccsdk.cds.controllerblueprints.core.service.BlueprintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintException
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.slf4j.LoggerFactory
private val log = LoggerFactory.getLogger(ResourceResolutionDBService::class.toString())
suspend fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
- bluePrintRuntimeService: BlueprintRuntimeService<*>,
+ bluePrintRuntimeService: BluePrintRuntimeService<*>,
key: String,
occurrence: Int,
artifactPrefix: String
return try {
val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
- val blueprintVersion = metadata[BlueprintConstants.METADATA_TEMPLATE_VERSION]!!
- val blueprintName = metadata[BlueprintConstants.METADATA_TEMPLATE_NAME]!!
+ val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
+ val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
resourceResolutionRepository.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResolutionKeyAndOccurrence(
blueprintName,
}
suspend fun findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
- bluePrintRuntimeService: BlueprintRuntimeService<*>,
+ bluePrintRuntimeService: BluePrintRuntimeService<*>,
resourceId: String,
resourceType: String,
occurrence: Int,
val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
- val blueprintVersion = metadata[BlueprintConstants.METADATA_TEMPLATE_VERSION]!!
- val blueprintName = metadata[BlueprintConstants.METADATA_TEMPLATE_NAME]!!
+ val blueprintVersion = metadata[BluePrintConstants.METADATA_TEMPLATE_VERSION]!!
+ val blueprintName = metadata[BluePrintConstants.METADATA_TEMPLATE_NAME]!!
resourceResolutionRepository.findByBlueprintNameAndBlueprintVersionAndArtifactNameAndResourceIdAndResourceTypeAndOccurrence(
blueprintName,
artifactPrefix: String,
resolutionKey: String,
name: String
- ): ResourceResolution = withContext(Dispatchers.IO) {
+ ): ResourceResolution? = withContext(Dispatchers.IO) {
resourceResolutionRepository.findByResolutionKeyAndBlueprintNameAndBlueprintVersionAndArtifactNameAndName(
resolutionKey,
suspend fun write(
properties: Map<String, Any>,
- bluePrintRuntimeService: BlueprintRuntimeService<*>,
+ bluePrintRuntimeService: BluePrintRuntimeService<*>,
artifactPrefix: String,
resourceAssignment: ResourceAssignment
): ResourceResolution = withContext(Dispatchers.IO) {
val metadata = bluePrintRuntimeService.bluePrintContext().metadata!!
- val blueprintVersion = metadata[BlueprintConstants.METADATA_TEMPLATE_VERSION]!!
- val blueprintName = metadata[BlueprintConstants.METADATA_TEMPLATE_NAME]!!
+ 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
resourceResolution.resourceType = resourceType
resourceResolution.resourceId = resourceId
resourceResolution.value = resourceAssignment.property?.value?.let {
- if (BlueprintConstants.STATUS_SUCCESS == resourceAssignment.status)
+ if (BluePrintConstants.STATUS_SUCCESS == resourceAssignment.status)
JacksonUtils.getValue(it).toString()
else ""
} ?: ""
resourceResolution.dictionaryName = resourceAssignment.dictionaryName
resourceResolution.dictionaryVersion = resourceAssignment.version
resourceResolution.dictionarySource = resourceAssignment.dictionarySource
- resourceResolution.status = resourceAssignment.status ?: BlueprintConstants.STATUS_FAILURE
+ resourceResolution.status = resourceAssignment.status ?: BluePrintConstants.STATUS_FAILURE
try {
resourceResolutionRepository.saveAndFlush(resourceResolution)
} catch (ex: Exception) {
- throw BlueprintException("Failed to store resource resolution result.", ex)
+ throw BluePrintException("Failed to store resource resolution result.", ex)
}
}
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)
+ }
+ }
+
+ /**
+ * 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
+ }
}