summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/main
diff options
context:
space:
mode:
authorJozsef Csongvai <jozsef.csongvai@bell.ca>2020-05-28 13:57:06 -0400
committerKAPIL SINGAL <ks220y@att.com>2020-06-09 14:19:14 +0000
commit8a3d5215f2424bbea855ac1b86dfefb98f349496 (patch)
treed32c53b0936e73c7336e514964b3492b150d945d /ms/blueprintsprocessor/functions/resource-resolution/src/main
parent7999215bcb96bfca2111014c47c9e8766936b254 (diff)
Add ResourceResolutionResult to ResourceResolutionService
In order to ensure consistent behavior for assignment-map, supporting occurences and multiple artifact-prefixes, ResourceResolutionService needs to return assignment-map alongside generated template content. Issue-ID: CCSDK-2389 Signed-off-by: Jozsef Csongvai <jozsef.csongvai@bell.ca> Change-Id: I54c1991d23d65217f3492b08a2170a6d41b6482d
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.kt37
-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, 37 insertions, 28 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 4ad86b4ad..836db4c70 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]
@@ -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"
@@ -186,16 +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 assignmentMap = resourceAssignments
+ .associateBy({ it.name }, { it.property?.value })
+ .asJsonNode()
val resolvedParamJsonContent =
ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
val artifactTemplateDefinition =
@@ -226,7 +229,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