aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/main
diff options
context:
space:
mode:
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.kt20
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt1
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt46
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt7
4 files changed, 43 insertions, 31 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 e15705a7e..3ebd2f893 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
@@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.node.JsonNodeFactory
+import com.fasterxml.jackson.databind.node.ObjectNode
import org.onap.ccsdk.cds.blueprintsprocessor.core.api.data.ExecutionServiceInput
import org.onap.ccsdk.cds.blueprintsprocessor.services.execution.AbstractComponentFunction
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
@@ -78,11 +79,16 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_RESOLUTION_SUMMARY] = resolutionSummary
val jsonResponse = JsonNodeFactory.instance.objectNode()
- // Initialize Output Attribute to empty JSON
+ val assignmentMap = JsonNodeFactory.instance.objectNode()
+ // Initialize Output Attributes to empty JSON
bluePrintRuntimeService.setNodeTemplateAttributeValue(
nodeTemplateName,
ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, jsonResponse
)
+ bluePrintRuntimeService.setNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ResourceResolutionConstants.OUTPUT_ASSIGNMENT_MAP, assignmentMap
+ )
// validate inputs if we need to store the resource and template resolution.
if (storeResult) {
@@ -104,7 +110,7 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
for (j in 1..occurrence) {
properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE] = j
- val response = resourceResolutionService.resolveResources(
+ val result = resourceResolutionService.resolveResources(
bluePrintRuntimeService,
nodeTemplateName,
artifactPrefixNames,
@@ -113,9 +119,11 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
// provide indexed result in output if we have multiple resolution
if (occurrence != 1) {
- jsonResponse.set<JsonNode>(Integer.toString(j), response.asJsonNode())
+ jsonResponse.set<JsonNode>(j.toString(), result.templateMap.asJsonNode())
+ assignmentMap.set<JsonNode>(j.toString(), result.assignmentMap.asJsonNode())
} else {
- jsonResponse.setAll(response.asObjectNode())
+ jsonResponse.setAll<ObjectNode>(result.templateMap.asObjectNode())
+ assignmentMap.setAll<ObjectNode>(result.assignmentMap.asObjectNode())
}
}
@@ -124,6 +132,10 @@ open class ResourceResolutionComponent(private val resourceResolutionService: Re
nodeTemplateName,
ResourceResolutionConstants.OUTPUT_ASSIGNMENT_PARAMS, jsonResponse
)
+ bluePrintRuntimeService.setNodeTemplateAttributeValue(
+ nodeTemplateName,
+ ResourceResolutionConstants.OUTPUT_ASSIGNMENT_MAP, assignmentMap
+ )
}
override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ExecutionServiceInput) {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt
index 53ce65d0b..0f04ea38e 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionExtensions.kt
@@ -40,6 +40,7 @@ suspend fun AbstractComponentFunction.storedContentFromResolvedArtifactNB(
suspend fun AbstractComponentFunction.contentFromResolvedArtifactNB(artifactPrefix: String): String {
return BluePrintDependencyService.resourceResolutionService()
.resolveResources(bluePrintRuntimeService, nodeTemplateName, artifactPrefix, mapOf())
+ .first
}
/**
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 a9bfbab32..f38bfad0d 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
@@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.JsonNode
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
@@ -30,6 +29,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.util
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
@@ -46,6 +46,11 @@ import org.springframework.context.ApplicationContext
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>
@@ -61,14 +66,14 @@ interface ResourceResolutionService {
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]
@@ -79,7 +84,7 @@ interface ResourceResolutionService {
resolveDefinition: String,
sources: List<String>
):
- MutableMap<String, JsonNode>
+ MutableMap<String, JsonNode>
suspend fun resolveResourceAssignments(
blueprintRuntimeService: BluePrintRuntimeService<*>,
@@ -124,21 +129,22 @@ open class ResourceResolutionServiceImpl(
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(
@@ -146,7 +152,7 @@ open class ResourceResolutionServiceImpl(
nodeTemplateName: String,
artifactPrefix: String,
properties: Map<String, Any>
- ): String {
+ ): Pair<String, JsonNode> {
// Template Artifact Definition Name
val artifactTemplate = "$artifactPrefix-template"
@@ -160,7 +166,7 @@ open class ResourceResolutionServiceImpl(
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)) {
@@ -186,13 +192,13 @@ open class ResourceResolutionServiceImpl(
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)
@@ -221,7 +227,7 @@ open class ResourceResolutionServiceImpl(
log.info("Template resolution saved into database successfully : ($properties)")
}
- return resolvedContent
+ return Pair(resolvedContent, assignmentMap)
}
override suspend fun resolveResourceDefinition(
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
index f97c669d6..1be9649b9 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt
@@ -274,13 +274,6 @@ class ResourceAssignmentUtils {
return JacksonUtils.getJson(data, includeNull = true)
}
- fun generateAssignmentMap(
- artifactPrefix: String,
- resourceAssignments: List<ResourceAssignment>
- ): ObjectNode = resourceAssignments.associateBy({ it.name }, { it.property?.value })
- .let { mutableMapOf(artifactPrefix to it) }
- .let { JacksonUtils.objectNodeFromObject(it) }
-
private fun useDefaultValueIfNull(
resourceAssignment: ResourceAssignment,
resourceAssignmentName: String