aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap
diff options
context:
space:
mode:
authorPaira, Saurav(sp694w) <sp694w@att.com>2020-05-07 12:54:40 +0000
committerSaurav Paira <sp694w@att.com>2020-05-18 17:13:58 +0000
commita726d7aa14e0ae841ede2dbdbc1a825290bf1452 (patch)
tree94d81ad88c66a413e044d93e24dcbd0c30e77496 /ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap
parent6b6ac70007ba2b52c6beb8c0d22453a628c891f3 (diff)
Add Naming Service & IP Assign custom resource resolution capability
Issue-ID: CCSDK-2185 Signed-off-by: Paira, Saurav(sp694w) <sp694w@att.com> Change-Id: I70550fe9582b2db0a70c7b66591438b674173411
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt40
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt175
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt197
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt9
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt15
5 files changed, 414 insertions, 22 deletions
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 dff00c7eb..15fd1d673 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
@@ -78,7 +78,7 @@ interface ResourceResolutionService {
resolveDefinition: String,
sources: List<String>
):
- MutableMap<String, JsonNode>
+ MutableMap<String, JsonNode>
suspend fun resolveResourceAssignments(
blueprintRuntimeService: BluePrintRuntimeService<*>,
@@ -159,7 +159,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)) {
@@ -185,19 +185,24 @@ open class ResourceResolutionServiceImpl(
properties
)
- 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 resolvedParamJsonContent =
ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
- val artifactTemplateDefinition = bluePrintRuntimeService.bluePrintContext().checkNodeTemplateArtifact(nodeTemplateName, artifactTemplate)
+ val artifactTemplateDefinition =
+ bluePrintRuntimeService.bluePrintContext().checkNodeTemplateArtifact(nodeTemplateName, artifactTemplate)
val resolvedContent = when {
artifactTemplateDefinition != null -> {
blueprintTemplateService.generateContent(
- bluePrintRuntimeService, nodeTemplateName,
- artifactTemplate, resolvedParamJsonContent, false,
- mutableMapOf(
- ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE to
- properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE].asJsonPrimitive()
+ bluePrintRuntimeService, nodeTemplateName,
+ artifactTemplate, resolvedParamJsonContent, false,
+ mutableMapOf(
+ ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE to
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_OCCURRENCE]
+ .asJsonPrimitive()
)
)
}
@@ -277,13 +282,16 @@ open class ResourceResolutionServiceImpl(
applicationContext.getBean(processorName) as? ResourceAssignmentProcessor
?: throw BluePrintProcessorException(
"failed to get resource processor ($processorName) " +
- "for resource assignment(${resourceAssignment.name})"
+ "for resource assignment(${resourceAssignment.name})"
)
try {
// Set BluePrint Runtime Service
resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
// Set Resource Dictionaries
resourceAssignmentProcessor.resourceDictionaries = resourceDefinitions
+
+ resourceAssignmentProcessor.resourceAssignments = resourceAssignments
+
// Invoke Apply Method
resourceAssignmentProcessor.applyNB(resourceAssignment)
@@ -347,7 +355,7 @@ open class ResourceResolutionServiceImpl(
// Check whether to store or not the resolution of resource and template
private fun isToStore(properties: Map<String, Any>): Boolean {
return properties.containsKey(ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT) &&
- properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean
+ properties[ResourceResolutionConstants.RESOURCE_RESOLUTION_INPUT_STORE_RESULT] as Boolean
}
// Check whether resolution already exist in the database for the specified resolution-key or resourceId/resourceType
@@ -388,8 +396,8 @@ 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 - will resolve all resources not already resolved."
)
}
return existingResourceAssignments
@@ -426,9 +434,9 @@ open class ResourceResolutionServiceImpl(
// Comparision between what we have in the database vs what we have to assign.
private fun compareOne(resourceResolution: ResourceResolution, resourceAssignment: ResourceAssignment): Boolean {
return (resourceResolution.name == resourceAssignment.name &&
- resourceResolution.dictionaryName == resourceAssignment.dictionaryName &&
- resourceResolution.dictionarySource == resourceAssignment.dictionarySource &&
- resourceResolution.dictionaryVersion == resourceAssignment.version)
+ resourceResolution.dictionaryName == resourceAssignment.dictionaryName &&
+ resourceResolution.dictionarySource == resourceAssignment.dictionarySource &&
+ resourceResolution.dictionaryVersion == resourceAssignment.version)
}
private fun exposeOccurrencePropertyInResourceAssignments(
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt
new file mode 100644
index 000000000..b38c32056
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/IpAssignResolutionCapability.kt
@@ -0,0 +1,175 @@
+/*
+ * Copyright © 2019 AT&T.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.capabilities
+
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.restClientService
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
+import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.KeyIdentifier
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.springframework.http.HttpMethod
+
+/**
+ * @author saurav.paira
+ */
+
+open class IpAssignResolutionCapability : ResourceAssignmentProcessor() {
+
+ val log = logger(IpAssignResolutionCapability::class)
+
+ override fun getName(): String {
+ return "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}ipassignment-capability"
+ }
+
+ override suspend fun processNB(resourceAssignment: ResourceAssignment) {
+ try {
+ if (!setFromInput(resourceAssignment) && isTemplateKeyValueNull(resourceAssignment)) {
+ val dName = resourceAssignment.dictionaryName!!
+ val dSource = resourceAssignment.dictionarySource!!
+ val resourceDefinition = resourceDefinition(dName)
+
+ /** Check Resource Assignment has the source definitions, If not get from Resource Definitions **/
+ val resourceSource = resourceAssignment.dictionarySourceDefinition
+ ?: resourceDefinition?.sources?.get(dSource)
+ ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
+
+ val resourceSourceProperties =
+ checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
+
+ // Get all matching resources assignments to process
+ val groupResourceAssignments =
+ resourceAssignments.filter {
+ it.dictionarySource == dSource
+ }.toMutableList()
+
+ // inputKeyMapping is dynamic based on dependencies
+ val inputKeyMapping: MutableMap<String, String> =
+ resourceAssignment.dependencies?.map { it to it }?.toMap()
+ as MutableMap<String, String>
+
+ // Get the values from runtime store
+ val resolvedKeyValues = resolveInputKeyMappingVariables(inputKeyMapping)
+ log.info("\nResolved Input Key mappings: \n{}", resolvedKeyValues)
+
+ resolvedKeyValues?.map { KeyIdentifier(it.key, it.value) }
+ ?.let { resourceAssignment.keyIdentifiers.addAll(it) }
+
+ // Generate the payload using already resolved value
+ val generatedPayload = generatePayload(resolvedKeyValues, groupResourceAssignments)
+ log.info("\nIP Assign mS Request Payload: \n{}", generatedPayload.asJsonType().toPrettyString())
+
+ resourceSourceProperties["resolved-payload"] = JacksonUtils.jsonNode(generatedPayload)
+
+ // Get the Rest Client service, selector will be included in application.properties
+ val restClientService = BluePrintDependencyService.restClientService(
+ "ipassign-ms"
+ )
+
+ // Get the Rest Response
+ val response = restClientService.exchangeResource(
+ HttpMethod.POST.name,
+ "/web/service/v1/assign", generatedPayload
+ )
+ val responseStatusCode = response.status
+ val responseBody = response.body
+ log.info("\nIP Assign mS Response : \n{}", responseBody.asJsonType().toPrettyString())
+ if (responseStatusCode in 200..299 && !responseBody.isBlank()) {
+ populateResource(groupResourceAssignments, responseBody)
+ } else {
+ val errMsg =
+ "Failed to dictionary name ($dName), dictionary source($($dName) " +
+ "response_code: ($responseStatusCode)"
+ log.warn(errMsg)
+ throw BluePrintProcessorException(errMsg)
+ }
+ // Parse the error Body and assign the property value
+ }
+ // Check the value has populated for mandatory case
+ ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+ } catch (e: Exception) {
+ ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
+ throw BluePrintProcessorException(
+ "Failed in template key ($resourceAssignment) assignments with: ${e.message}",
+ e
+ )
+ }
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ResourceAssignment) {
+ raRuntimeService.getBluePrintError().addError(runtimeException.message!!)
+ }
+
+ /** Generates aggregated request payload for Ip Assign mS. Parses the resourceassignments of
+ * sourceCapability "ipassign-ms". It generates below sample payload
+ * {
+ "requests": [{
+ "name": "fixed_ipv4_Address_01",
+ "property": {
+ "CloudRegionId": "abcd123",
+ "IpServiceName": "MobilityPlan",
+ }
+ }, {
+ "name": "fixed_ipv4_Address_02",
+ "property": {
+ "CloudRegionId": "abcd123",
+ "IpServiceName": "MobilityPlan",
+ }
+ }
+ ]
+ } */
+ private fun generatePayload(
+ input: Map<String, Any>,
+ groupResourceAssignments: MutableList<ResourceAssignment>
+ ): String {
+ data class IpRequest(val name: String = "", val property: Map<String, String> = mutableMapOf<String, String>())
+ data class IpAssignRequest(val requests: MutableList<IpRequest> = mutableListOf())
+
+ val ipAssignRequests = IpAssignRequest()
+ groupResourceAssignments.forEach {
+ val ipRequest = IpRequest(it.name, input.mapValues { it.value.toString().removeSurrounding("\"") })
+ ipAssignRequests.requests.add(ipRequest)
+ }
+ return ipAssignRequests.asJsonType().toString()
+ }
+
+ private fun populateResource(
+ resourceAssignments: MutableList<ResourceAssignment>,
+ restResponse: String
+ ) {
+ /** Parse all the resource assignment fields and set the corresponding value */
+ resourceAssignments.forEach { resourceAssignment ->
+ // Set the List of Complex Values
+ val parsedResourceAssignmentValue = checkNotNull(
+ JacksonUtils.jsonNode(restResponse).path(resourceAssignment.name).textValue()
+ ) {
+ "Failed to find path ($resourceAssignment.name) in response ($restResponse)"
+ }
+
+ ResourceAssignmentUtils.setResourceDataValue(
+ resourceAssignment,
+ raRuntimeService,
+ parsedResourceAssignmentValue
+ )
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt
new file mode 100644
index 000000000..dbac70a39
--- /dev/null
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/capabilities/NamingResolutionCapability.kt
@@ -0,0 +1,197 @@
+/*
+ * Copyright © 2019 IBM.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.capabilities
+
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor.ResourceAssignmentProcessor
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
+import org.onap.ccsdk.cds.blueprintsprocessor.rest.restClientService
+import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
+import org.onap.ccsdk.cds.controllerblueprints.core.asJsonType
+import org.onap.ccsdk.cds.controllerblueprints.core.logger
+import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintDependencyService
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.KeyIdentifier
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.springframework.http.HttpMethod
+
+/**
+ * @author brindasanth
+ */
+
+open class NamingResolutionCapability : ResourceAssignmentProcessor() {
+
+ val log = logger(NamingResolutionCapability::class)
+
+ override fun getName(): String {
+ return "${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}naming-capability"
+ }
+
+ override suspend fun processNB(resourceAssignment: ResourceAssignment) {
+ try {
+ if (!setFromInput(resourceAssignment) && isTemplateKeyValueNull(resourceAssignment)) {
+ val dName = resourceAssignment.dictionaryName!!
+ val dSource = resourceAssignment.dictionarySource!!
+ val resourceDefinition = resourceDefinition(dName)
+
+ /** Check Resource Assignment has the source definitions, If not get from Resource Definitions **/
+ val resourceSource = resourceAssignment.dictionarySourceDefinition
+ ?: resourceDefinition?.sources?.get(dSource)
+ ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
+
+ val resourceSourceProperties =
+ checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
+
+ // Get all matching resources assignments to process
+ val groupResourceAssignments =
+ resourceAssignments.filter {
+ it.dictionarySource == dSource
+ }.toMutableList()
+
+ // inputKeyMapping is dynamic based on dependencies
+ val inputKeyMapping: MutableMap<String, String> =
+ resourceAssignment.dependencies?.map { it to it }?.toMap()
+ as MutableMap<String, String>
+ log.info("\nResolving Input Key mappings: \n{}", inputKeyMapping)
+
+ // Get the values from runtime store
+ val resolvedKeyValues = resolveInputKeyMappingVariables(inputKeyMapping)
+ log.info("\nResolved Input Key mappings: \n{}", resolvedKeyValues)
+
+ resolvedKeyValues?.map { KeyIdentifier(it.key, it.value) }
+ ?.let { resourceAssignment.keyIdentifiers.addAll(it) }
+
+ // Generate the payload using already resolved value
+ val generatedPayload = generatePayload(resolvedKeyValues, groupResourceAssignments)
+ log.info("\nNaming mS Request Payload: \n{}", generatedPayload.asJsonType().toPrettyString())
+
+ resourceSourceProperties["resolved-payload"] = JacksonUtils.jsonNode(generatedPayload)
+
+ // Get the Rest Client service, selector will be included in application.properties
+ val restClientService = BluePrintDependencyService.restClientService(
+ "naming-ms"
+ )
+
+ // Get the Rest Response
+ val response = restClientService.exchangeResource(
+ HttpMethod.POST.name,
+ "/web/service/v1/genNetworkElementName/cds", generatedPayload
+ )
+
+ val responseStatusCode = response.status
+ val responseBody = response.body
+ log.info("\nNaming mS Response : \n{}", responseBody.asJsonType().toPrettyString())
+ if (responseStatusCode in 200..299 && !responseBody.isBlank()) {
+ populateResource(groupResourceAssignments, responseBody)
+ } else {
+ val errMsg =
+ "Failed to dictionary name ($dName), dictionary source($($dName) " +
+ "response_code: ($responseStatusCode)"
+ log.warn(errMsg)
+ throw BluePrintProcessorException(errMsg)
+ }
+ // Parse the error Body and assign the property value
+ }
+ // Check the value has populated for mandatory case
+ ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+ } catch (e: Exception) {
+ ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
+ throw BluePrintProcessorException(
+ "Failed in template key ($resourceAssignment) assignments with: ${e.message}",
+ e
+ )
+ }
+ }
+
+ override suspend fun recoverNB(runtimeException: RuntimeException, executionRequest: ResourceAssignment) {
+ raRuntimeService.getBluePrintError().addError(runtimeException.message!!)
+ }
+
+ /** Generates aggregated request payload for Naming mS. Parses the resourceassignments of
+ * sourceCapability "naming-ms". "naming-type" should be provides as property metadata for
+ * each resourceassigment of sourceCapability "naming-ms". It generates below sample payload
+ * {
+ "elements": [{
+ "vf-module-name": "${vf-module-name}",
+ "naming-type": "VF-MODULE",
+ "naming-code": "dbc",
+ "vf-module-label": "adsf",
+ "policy-instance-name": "SDNC_Policy.Config_Json.xml",
+ "vnf-name": "vnf-123",
+ "vf-module-type": "base"
+ }, {
+ "vnfc-name": "${vnfc-name}",
+ "naming-type": "VNFC",
+ "naming-code": "dbc",
+ "vf-module-label": "adsf",
+ "policy-instance-name": "SDNC_Policy.Config_Json.xml",
+ "vnf-name": "vnf-123",
+ "vf-module-type": "base"
+ }
+ ]
+ } */
+ private fun generatePayload(
+ input: Map<String, Any>,
+ groupResourceAssignments: MutableList<ResourceAssignment>
+ ): String {
+ data class NameAssignRequest(val elements: MutableList<Map<String, String>> = mutableListOf())
+
+ val nameAssignRequests = NameAssignRequest()
+ groupResourceAssignments.forEach {
+ val metadata = resourceDictionaries[it.dictionaryName]?.property?.metadata
+ val namingType = metadata?.get("naming-type")
+ val moduleName = namingType.plus("-name").toLowerCase()
+ val moduleValue = "\${".plus(moduleName.plus("}"))
+
+ val request: MutableMap<String, String> = input.mapValues {
+ it.value.toString().removeSurrounding("\"") } as MutableMap<String, String>
+ if (namingType != null) {
+ request["naming-type"] = namingType
+ }
+ request[moduleName] = moduleValue
+ nameAssignRequests.elements.add(request)
+ }
+ return nameAssignRequests.asJsonType().toString()
+ }
+
+ private fun populateResource(
+ resourceAssignments: MutableList<ResourceAssignment>,
+ restResponse: String
+ ) {
+ /** Parse all the resource assignment fields and set the corresponding value */
+ resourceAssignments.forEach { resourceAssignment ->
+ // Set the List of Complex Values
+ val metadata =
+ resourceDictionaries[resourceAssignment.dictionaryName]?.property?.metadata
+
+ /** Naming ms returns the keys with "${naming-type}-name" */
+ val responseKey = metadata?.get("naming-type")?.toLowerCase().plus("-name")
+
+ val parsedResourceAssignmentValue = checkNotNull(
+ JacksonUtils.jsonNode(restResponse).path(responseKey).textValue()
+ ) {
+ "Failed to find path ($responseKey) in response ($restResponse)"
+ }
+
+ ResourceAssignmentUtils.setResourceDataValue(
+ resourceAssignment,
+ raRuntimeService,
+ parsedResourceAssignmentValue
+ )
+ }
+ }
+}
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
index 868f919c1..42e086137 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt
@@ -57,6 +57,7 @@ open class CapabilityResourceResolutionProcessor(private var componentFunctionSc
val resourceSourceProps =
checkNotNull(resourceSource.properties) { "failed to get $resourceSource properties" }
+
/**
* Get the Capability Resource Source Info from Property Definitions.
*/
@@ -77,6 +78,7 @@ open class CapabilityResourceResolutionProcessor(private var componentFunctionSc
// Assign Current Blueprint runtime and ResourceDictionaries
componentResourceAssignmentProcessor!!.scriptType = scriptType
componentResourceAssignmentProcessor!!.raRuntimeService = raRuntimeService
+ componentResourceAssignmentProcessor!!.resourceAssignments = resourceAssignments
componentResourceAssignmentProcessor!!.resourceDictionaries = resourceDictionaries
// Invoke componentResourceAssignmentProcessor
@@ -93,12 +95,9 @@ open class CapabilityResourceResolutionProcessor(private var componentFunctionSc
}
suspend fun scriptInstance(scriptType: String, scriptClassReference: String, instanceDependencies: List<String>):
- ResourceAssignmentProcessor {
+ ResourceAssignmentProcessor {
- log.info(
- "creating resource resolution of script type($scriptType), reference name($scriptClassReference) and" +
- "instanceDependencies($instanceDependencies)"
- )
+ log.info("creating resource resolution of script type($scriptType), reference name($scriptClassReference)")
val scriptComponent = componentFunctionScriptingService
.scriptInstance<ResourceAssignmentProcessor>(
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
index 454a899aa..0c0735ff0 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt
@@ -40,6 +40,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
lateinit var raRuntimeService: ResourceAssignmentRuntimeService
var resourceDictionaries: MutableMap<String, ResourceDefinition> = hashMapOf()
+ var resourceAssignments: MutableList<ResourceAssignment> = arrayListOf()
var scriptPropertyInstances: MutableMap<String, Any> = hashMapOf()
lateinit var scriptType: String
@@ -104,7 +105,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
}
open suspend fun resolveFromInputKeyMapping(valueToResolve: String, keyMapping: MutableMap<String, JsonNode>):
- String {
+ String {
if (valueToResolve.isEmpty() || !valueToResolve.contains("$")) {
return valueToResolve
}
@@ -196,4 +197,16 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
fun addError(error: String) {
raRuntimeService.getBluePrintError().addError(error)
}
+
+ fun isTemplateKeyValueNull(resourceAssignment: ResourceAssignment): Boolean {
+ val resourceProp = checkNotNull(resourceAssignment.property) {
+ "Failed to populate mandatory resource resource mapping $resourceAssignment"
+ }
+ if (resourceProp.required != null && resourceProp.required!! &&
+ resourceProp.value.isNullOrMissing()
+ ) {
+ return true
+ }
+ return false
+ }
}