import kotlinx.coroutines.async
import kotlinx.coroutines.awaitAll
import kotlinx.coroutines.coroutineScope
-import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.OUTPUT_ASSIGNMENT_MAP
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolution
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionDBService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.TemplateResolutionService
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceDefinitionUtils.createResourceAssignments
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonNode
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonPrimitive
import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
import org.springframework.stereotype.Service
import java.util.UUID
+data class ResourceResolutionResult(
+ val templateMap: MutableMap<String, String>,
+ val assignmentMap: MutableMap<String, JsonNode>
+)
+
interface ResourceResolutionService {
fun registeredResourceSources(): List<String>
nodeTemplateName: String,
artifactNames: List<String>,
properties: Map<String, Any>
- ): MutableMap<String, String>
+ ): ResourceResolutionResult
suspend fun resolveResources(
bluePrintRuntimeService: BluePrintRuntimeService<*>,
nodeTemplateName: String,
artifactPrefix: String,
properties: Map<String, Any>
- ): String
+ ): Pair<String, JsonNode>
/** Resolve resources for all the sources defined in a particular resource Definition[resolveDefinition]
* with other [resourceDefinitions] dependencies for the sources [sources]
resolveDefinition: String,
sources: List<String>
):
- MutableMap<String, JsonNode>
+ MutableMap<String, JsonNode>
suspend fun resolveResourceAssignments(
blueprintRuntimeService: BluePrintRuntimeService<*>,
nodeTemplateName: String,
artifactNames: List<String>,
properties: Map<String, Any>
- ): MutableMap<String, String> {
+ ): ResourceResolutionResult {
val resourceAssignmentRuntimeService =
ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString())
- val resolvedParams: MutableMap<String, String> = hashMapOf()
+ val templateMap: MutableMap<String, String> = hashMapOf()
+ val assignmentMap: MutableMap<String, JsonNode> = hashMapOf()
artifactNames.forEach { artifactName ->
- val resolvedContent = resolveResources(
+ val (resolvedStringContent, resolvedJsonContent) = resolveResources(
resourceAssignmentRuntimeService, nodeTemplateName,
artifactName, properties
)
-
- resolvedParams[artifactName] = resolvedContent
+ templateMap[artifactName] = resolvedStringContent
+ assignmentMap[artifactName] = resolvedJsonContent
}
- return resolvedParams
+ return ResourceResolutionResult(templateMap, assignmentMap)
}
override suspend fun resolveResources(
nodeTemplateName: String,
artifactPrefix: String,
properties: Map<String, Any>
- ): String {
+ ): Pair<String, JsonNode> {
// Template Artifact Definition Name
val artifactTemplate = "$artifactPrefix-template"
val resourceAssignments: MutableList<ResourceAssignment> =
JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java)
- as? MutableList<ResourceAssignment>
+ as? MutableList<ResourceAssignment>
?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")
if (isToStore(properties)) {
properties
)
- bluePrintRuntimeService.setNodeTemplateAttributeValue(
- nodeTemplateName,
- OUTPUT_ASSIGNMENT_MAP,
- ResourceAssignmentUtils.generateAssignmentMap(artifactPrefix, resourceAssignments)
- )
-
- val resolutionSummary = properties.getOrDefault(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY, false) as Boolean
+ val resolutionSummary = properties.getOrDefault(
+ ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY,
+ false
+ ) as Boolean
+ val assignmentMap = resourceAssignments
+ .associateBy({ it.name }, { it.property?.value })
+ .asJsonNode()
val resolvedParamJsonContent =
ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
val artifactTemplateDefinition = bluePrintRuntimeService.bluePrintContext().checkNodeTemplateArtifact(nodeTemplateName, artifactTemplate)
log.info("Template resolution saved into database successfully : ($properties)")
}
- return resolvedContent
+ return Pair(resolvedContent, assignmentMap)
}
override suspend fun resolveResourceDefinition(