aboutsummaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution/src/main
diff options
context:
space:
mode:
authorMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-04-03 21:36:57 -0400
committerMuthuramalingam, Brinda Santh <brindasanth@in.ibm.com>2019-04-04 08:09:16 -0400
commit0007063cc856483e36dd49718dea5dda80ed6809 (patch)
treef97d43008e4f0d816a8041b02e5d986cc5f3557e /ms/blueprintsprocessor/functions/resource-resolution/src/main
parenta2a21cd7a80c3ff3b754d7a4e47fc48f45ff2312 (diff)
Improve step data access.
Change-Id: I3917905b1e38cebcb26e4422784a5553e2dbac9f Issue-ID: CCSDK-1127 Signed-off-by: Muthuramalingam, Brinda Santh <brindasanth@in.ibm.com>
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/ResourceResolutionService.kt32
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt12
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt4
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt52
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt32
5 files changed, 68 insertions, 64 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 8a14ded61..31cb9ca77 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
@@ -23,9 +23,8 @@ import kotlinx.coroutines.coroutineScope
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.db.ResourceResolutionResultService
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.controllerblueprints.core.BluePrintConstants
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmptyOrThrow
+import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintTemplateService
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
@@ -35,7 +34,6 @@ import org.onap.ccsdk.cds.controllerblueprints.resource.dict.utils.BulkResourceS
import org.slf4j.LoggerFactory
import org.springframework.context.ApplicationContext
import org.springframework.stereotype.Service
-import java.io.File
interface ResourceResolutionService {
@@ -54,7 +52,7 @@ interface ResourceResolutionService {
artifactMapping: String, artifactTemplate: String?): String
suspend fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
- resourceDictionaries: MutableMap<String, ResourceDefinition>,
+ resourceDefinitions: MutableMap<String, ResourceDefinition>,
resourceAssignments: MutableList<ResourceAssignment>,
identifierName: String)
}
@@ -127,15 +125,11 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
?: throw BluePrintProcessorException("couldn't get Dictionary Definitions")
// Get the Resource Dictionary Name
- val dictionaryFile = bluePrintRuntimeService.bluePrintContext().rootPath.plus(File.separator)
- .plus(BluePrintConstants.TOSCA_DEFINITIONS_DIR).plus(File.separator)
- .plus(ResourceResolutionConstants.FILE_NAME_RESOURCE_DEFINITION_TYPES)
-
- val resourceDictionaries: MutableMap<String, ResourceDefinition> =
- JacksonUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)
+ val resourceDefinitions: MutableMap<String, ResourceDefinition> = ResourceAssignmentUtils
+ .resourceDefinitions(bluePrintRuntimeService.bluePrintContext().rootPath)
// Resolve resources
- resolveResourceAssignments(bluePrintRuntimeService, resourceDictionaries, resourceAssignments, identifierName)
+ resolveResourceAssignments(bluePrintRuntimeService, resourceDefinitions, resourceAssignments, identifierName)
val resolvedParamJsonContent =
ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignments.toList())
@@ -158,7 +152,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
* request.
*/
override suspend fun resolveResourceAssignments(blueprintRuntimeService: BluePrintRuntimeService<*>,
- resourceDictionaries: MutableMap<String, ResourceDefinition>,
+ resourceDefinitions: MutableMap<String, ResourceDefinition>,
resourceAssignments: MutableList<ResourceAssignment>,
identifierName: String) {
@@ -177,7 +171,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
/**
* Get the Processor name
*/
- val processorName = processorName(dictionaryName!!, dictionarySource!!, resourceDictionaries)
+ val processorName = processorName(dictionaryName!!, dictionarySource!!, resourceDefinitions)
val resourceAssignmentProcessor =
applicationContext.getBean(processorName) as? ResourceAssignmentProcessor
@@ -187,7 +181,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
// Set BluePrint Runtime Service
resourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService
// Set Resource Dictionaries
- resourceAssignmentProcessor.resourceDictionaries = resourceDictionaries
+ resourceAssignmentProcessor.resourceDictionaries = resourceDefinitions
// Invoke Apply Method
resourceAssignmentProcessor.applyNB(resourceAssignment)
// Set errors from RA
@@ -210,7 +204,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
* derive the default input processor.
*/
private fun processorName(dictionaryName: String, dictionarySource: String,
- resourceDictionaries: MutableMap<String, ResourceDefinition>): String {
+ resourceDefinitions: MutableMap<String, ResourceDefinition>): String {
val processorName: String = when (dictionarySource) {
"input" -> {
"${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input"
@@ -219,7 +213,7 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
"${ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default"
}
else -> {
- val resourceDefinition = resourceDictionaries[dictionaryName]
+ val resourceDefinition = resourceDefinitions[dictionaryName]
?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dictionaryName")
val resourceSource = resourceDefinition.sources[dictionarySource]
@@ -228,9 +222,9 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR.plus(resourceSource.type)
}
}
- checkNotEmptyOrThrow(processorName,
- "couldn't get processor name for resource dictionary definition($dictionaryName) source" +
- "($dictionarySource)")
+ checkNotEmpty(processorName) {
+ "couldn't get processor name for resource dictionary definition($dictionaryName) source($dictionarySource)"
+ }
return processorName
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
index 1d9aed2d2..f17257ccf 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
@@ -102,7 +102,7 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
}
private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): BluePrintDBLibGenericService {
- return if (checkNotEmpty(sourceProperties.endpointSelector)) {
+ return if (isNotEmpty(sourceProperties.endpointSelector)) {
val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!)
bluePrintDBLibPropertySevice.JdbcTemplate(dbPropertiesJson)
} else {
@@ -113,9 +113,11 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
@Throws(BluePrintProcessorException::class)
private fun validate(resourceAssignment: ResourceAssignment) {
- checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined")
- checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
- checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.dictionarySource) {
+ checkNotEmpty(resourceAssignment.name) { "resource assignment template key is not defined" }
+ checkNotEmpty(resourceAssignment.dictionaryName) {
+ "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})"
+ }
+ checkEquals(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.dictionarySource) {
"resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PROCESSOR_DB} but it is ${resourceAssignment.dictionarySource}"
}
}
@@ -148,7 +150,7 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, dbColumnValue)
}
in BluePrintTypes.validCollectionTypes() -> {
- val entrySchemaType = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
+ val entrySchemaType = checkNotEmpty(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
val arrayNode = JsonNodeFactory.instance.arrayNode()
rows.forEach {
if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
index ce618af9f..db51453b4 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt
@@ -22,7 +22,7 @@ import com.fasterxml.jackson.databind.node.NullNode
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils
import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
+import org.onap.ccsdk.cds.controllerblueprints.core.isNotEmpty
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
@@ -46,7 +46,7 @@ open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() {
override suspend fun processNB(resourceAssignment: ResourceAssignment) {
try {
- if (checkNotEmpty(resourceAssignment.name)) {
+ if (isNotEmpty(resourceAssignment.name)) {
val value = raRuntimeService.getInputValue(resourceAssignment.name)
// if value is null don't call setResourceDataValue to populate the value
if (value !is MissingNode && value !is NullNode) {
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
index de97b2f83..d95d6b614 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
@@ -60,22 +60,22 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
val dName = resourceAssignment.dictionaryName
val dSource = resourceAssignment.dictionarySource
val resourceDefinition = resourceDictionaries[dName]
- ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
+ ?: throw BluePrintProcessorException("couldn't get resource dictionary definition for $dName")
val resourceSource = resourceDefinition.sources[dSource]
- ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
+ ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)")
val resourceSourceProperties =
- checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
+ checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " }
val sourceProperties =
- JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java)
+ JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java)
val path = nullToEmpty(sourceProperties.path)
val inputKeyMapping =
- checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
+ checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" }
val resolvedInputKeyMapping = resolveInputKeyMappingVariables(inputKeyMapping)
// Resolving content Variables
val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping)
val urlPath =
- resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
+ resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping)
logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
@@ -94,13 +94,13 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
} catch (e: Exception) {
ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}",
- e)
+ e)
}
}
private fun blueprintWebClientService(resourceAssignment: ResourceAssignment,
restResourceSource: RestResourceSource): BlueprintWebClientService {
- return if (checkNotEmpty(restResourceSource.endpointSelector)) {
+ return if (isNotEmpty(restResourceSource.endpointSelector)) {
val restPropertiesJson = raRuntimeService.resolveDSLExpression(restResourceSource.endpointSelector!!)
blueprintRestLibPropertyService.blueprintWebClientService(restPropertiesJson)
} else {
@@ -117,11 +117,11 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
lateinit var entrySchemaType: String
val outputKeyMapping =
- checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" }
+ checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" }
logger.info("Response processing type($type)")
val responseNode =
- checkNotNull(JacksonUtils.jsonNode(restResponse).at(path)) { "Failed to find path ($path) in response ($restResponse)" }
+ checkNotNull(JacksonUtils.jsonNode(restResponse).at(path)) { "Failed to find path ($path) in response ($restResponse)" }
logger.info("populating value for output mapping ($outputKeyMapping), from json ($responseNode)")
@@ -133,7 +133,7 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
in BluePrintTypes.validCollectionTypes() -> {
// Array Types
entrySchemaType =
- returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
+ checkNotEmpty(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
val arrayNode = responseNode as ArrayNode
if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) {
@@ -143,12 +143,12 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
outputKeyMapping.map {
val responseKeyValue = responseSingleJsonNode.get(it.key)
val propertyTypeForDataType =
- ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
+ ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})")
JacksonUtils.populateJsonNodeValues(it.value,
- responseKeyValue,
- propertyTypeForDataType,
- arrayChildNode)
+ responseKeyValue,
+ propertyTypeForDataType,
+ arrayChildNode)
}
arrayNode.add(arrayChildNode)
}
@@ -160,12 +160,12 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
else -> {
// Complex Types
entrySchemaType =
- returnNotEmptyOrThrow(resourceAssignment.property?.type) { "Entry schema is not defined for dictionary ($dName) info" }
+ checkNotEmpty(resourceAssignment.property?.type) { "Entry schema is not defined for dictionary ($dName) info" }
val objectNode = JsonNodeFactory.instance.objectNode()
outputKeyMapping.map {
val responseKeyValue = responseNode.get(it.key)
val propertyTypeForDataType =
- ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
+ ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key)
logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type ({$propertyTypeForDataType})")
JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode)
}
@@ -179,15 +179,17 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
@Throws(BluePrintProcessorException::class)
private fun validate(resourceAssignment: ResourceAssignment) {
- checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined")
- checkNotEmptyOrThrow(resourceAssignment.dictionaryName,
- "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
- checkEqualsOrThrow(ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA,
- resourceAssignment.dictionarySource) {
- "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA} but it is ${resourceAssignment.dictionarySource}"
+ checkNotEmpty(resourceAssignment.name) { "resource assignment template key is not defined" }
+ checkNotEmpty(resourceAssignment.dictionaryName) {
+ "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})"
+ }
+ checkEquals(ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA, resourceAssignment.dictionarySource) {
+ "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PRIMARY_CONFIG_DATA} but it is " +
+ "${resourceAssignment.dictionarySource}"
+ }
+ checkNotEmpty(resourceAssignment.dictionaryName) {
+ "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})"
}
- checkNotEmptyOrThrow(resourceAssignment.dictionaryName,
- "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
}
override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
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 4fc933612..86440e691 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
@@ -17,28 +17,32 @@
package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils
-import org.slf4j.LoggerFactory
import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.node.NullNode
import com.fasterxml.jackson.databind.node.ObjectNode
import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintConstants
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintProcessorException
-import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmpty
-import org.onap.ccsdk.cds.controllerblueprints.core.checkNotEmptyOrThrow
-import org.onap.ccsdk.cds.controllerblueprints.core.nullToEmpty
-import org.onap.ccsdk.cds.controllerblueprints.core.returnNotEmptyOrThrow
+import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants
+import org.onap.ccsdk.cds.controllerblueprints.core.*
import org.onap.ccsdk.cds.controllerblueprints.core.service.BluePrintRuntimeService
+import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonReactorUtils
import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment
+import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition
+import org.slf4j.LoggerFactory
import java.util.*
class ResourceAssignmentUtils {
companion object {
- private val logger= LoggerFactory.getLogger(ResourceAssignmentUtils::class.toString())
+ private val logger = LoggerFactory.getLogger(ResourceAssignmentUtils::class.toString())
+
+ suspend fun resourceDefinitions(blueprintBasePath: String): MutableMap<String, ResourceDefinition> {
+ val dictionaryFile = normalizedFile(blueprintBasePath, BluePrintConstants.TOSCA_DEFINITIONS_DIR,
+ ResourceResolutionConstants.FILE_NAME_RESOURCE_DEFINITION_TYPES)
+ checkFileExists(dictionaryFile) { "resource definition file(${dictionaryFile.absolutePath}) is missing" }
+ return JacksonReactorUtils.getMapFromFile(dictionaryFile, ResourceDefinition::class.java)
+ }
// TODO("Modify Value type from Any to JsonNode")
@Throws(BluePrintProcessorException::class)
@@ -46,7 +50,9 @@ class ResourceAssignmentUtils {
raRuntimeService: ResourceAssignmentRuntimeService, value: Any?) {
val resourceProp = checkNotNull(resourceAssignment.property) { "Failed in setting resource value for resource mapping $resourceAssignment" }
- checkNotEmptyOrThrow(resourceAssignment.name, "Failed in setting resource value for resource mapping $resourceAssignment")
+ checkNotEmpty(resourceAssignment.name) {
+ "Failed in setting resource value for resource mapping $resourceAssignment"
+ }
if (resourceAssignment.dictionaryName.isNullOrEmpty()) {
resourceAssignment.dictionaryName = resourceAssignment.name
@@ -90,7 +96,7 @@ class ResourceAssignmentUtils {
}
fun setFailedResourceDataValue(resourceAssignment: ResourceAssignment, message: String?) {
- if (checkNotEmpty(resourceAssignment.name)) {
+ if (isNotEmpty(resourceAssignment.name)) {
resourceAssignment.updatedDate = Date()
resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM
resourceAssignment.status = BluePrintConstants.STATUS_FAILURE
@@ -115,7 +121,7 @@ class ResourceAssignmentUtils {
val root: ObjectNode = mapper.createObjectNode()
assignments.forEach {
- if (checkNotEmpty(it.name) && it.property != null) {
+ if (isNotEmpty(it.name) && it.property != null) {
val rName = it.name
val type = nullToEmpty(it.property?.type).toLowerCase()
val value = it.property?.value
@@ -146,7 +152,7 @@ class ResourceAssignmentUtils {
try {
val dataTypeProps = checkNotNull(raRuntimeService.bluePrintContext().dataTypeByName(dataTypeName)?.properties)
val propertyDefinition = checkNotNull(dataTypeProps[propertyName])
- type = returnNotEmptyOrThrow(propertyDefinition.type) { "Couldn't get data type ($dataTypeName)" }
+ type = checkNotEmpty(propertyDefinition.type) { "Couldn't get data type ($dataTypeName)" }
logger.trace("Data type({})'s property ({}) is ({})", dataTypeName, propertyName, type)
} catch (e: Exception) {
logger.error("couldn't get data type($dataTypeName)'s property ($propertyName), error message $e")