From 11950b7f8089a4ddd85b47133e638a27cd42ea78 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh" Date: Wed, 27 Feb 2019 20:16:47 -0500 Subject: Add blueprint runtime validator Change-Id: I9e2aa1aec392fc4191d547115fa90e8811f0f9e9 Issue-ID: CCSDK-1110 Signed-off-by: Muthuramalingam, Brinda Santh --- .../resolution/ResourceResolutionConstants.kt | 7 ++- .../CapabilityResourceResolutionProcessor.kt | 5 +- .../DatabaseResourceAssignmentProcessor.kt | 5 +- .../DefaultResourceResolutionProcessor.kt | 10 +-- .../processor/InputResourceResolutionProcessor.kt | 5 +- .../processor/RestResourceResolutionProcessor.kt | 72 +++++++++++++++------- .../resolution/utils/ResourceAssignmentUtils.kt | 35 +++-------- 7 files changed, 77 insertions(+), 62 deletions(-) (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/main') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt index 8dd738d03..b57b88b7b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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. @@ -16,8 +17,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution -class ResourceResolutionConstants { - companion object { +object ResourceResolutionConstants { + const val SERVICE_RESOURCE_RESOLUTION = "resource-resolution-service" const val PREFIX_RESOURCE_RESOLUTION_PROCESSOR = "rr-processor-" const val INPUT_ARTIFACT_PREFIX_NAMES = "artifact-prefix-names" @@ -25,6 +26,6 @@ class ResourceResolutionConstants { const val FILE_NAME_RESOURCE_DEFINITION_TYPES = "resources_definition_types.json" const val RESOURCE_RESOLUTION_INPUT_KEY = "resolution-key"; const val RESOURCE_RESOLUTION_INPUT_STORE_RESULT = "store-result"; - } + } \ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt index c6b7d77e5..c2dbd7312 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/CapabilityResourceResolutionProcessor.kt @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.CapabilityResourceSource +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR import org.onap.ccsdk.apps.blueprintsprocessor.services.execution.scripts.BlueprintJythonService import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException @@ -32,7 +33,7 @@ import org.springframework.context.annotation.Scope import org.springframework.stereotype.Service import java.io.File -@Service("rr-processor-source-capability") +@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class CapabilityResourceResolutionProcessor(private var applicationContext: ApplicationContext, private val bluePrintScriptsService: BluePrintScriptsService, @@ -40,7 +41,7 @@ open class CapabilityResourceResolutionProcessor(private var applicationContext: ResourceAssignmentProcessor() { override fun getName(): String { - return "resource-assignment-processor-capability" + return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-capability" } override fun process(resourceAssignment: ResourceAssignment) { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt index 8f0f626cd..39be14c93 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt @@ -20,6 +20,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr import com.fasterxml.jackson.databind.node.JsonNodeFactory import org.onap.ccsdk.apps.blueprintsprocessor.db.primary.DBLibGenericService import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.DatabaseResourceSource +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils import org.onap.ccsdk.apps.controllerblueprints.core.* import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils @@ -37,7 +38,7 @@ import java.util.* * * @author Kapil Singal */ -@Service("rr-processor-source-primary-db") +@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-primary-db") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService: DBLibGenericService) : ResourceAssignmentProcessor() { @@ -45,7 +46,7 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService: private val logger = LoggerFactory.getLogger(DatabaseResourceAssignmentProcessor::class.java) override fun getName(): String { - return "rr-processor-source-primary-db" + return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-primary-db" } override fun process(resourceAssignment: ResourceAssignment) { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt index a8e0ad80e..528705f1b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DefaultResourceResolutionProcessor.kt @@ -17,6 +17,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor +import com.fasterxml.jackson.databind.JsonNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment @@ -30,20 +32,20 @@ import org.springframework.stereotype.Service * * @author Kapil Singal */ -@Service("rr-processor-source-default") +@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() { private val logger = LoggerFactory.getLogger(DefaultResourceResolutionProcessor::class.java) override fun getName(): String { - return "rr-processor-source-default" + return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-default" } override fun process(resourceAssignment: ResourceAssignment) { try { // Check if It has Input - var value: Any? + var value: JsonNode? try { value = raRuntimeService.getInputValue(resourceAssignment.name) } catch (e: BluePrintProcessorException) { @@ -60,7 +62,7 @@ open class DefaultResourceResolutionProcessor : ResourceAssignmentProcessor() { } catch (e: Exception) { ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", - e) + e) } } diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt index 66519f93d..a66222281 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/InputResourceResolutionProcessor.kt @@ -19,6 +19,7 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr import com.fasterxml.jackson.databind.node.MissingNode import com.fasterxml.jackson.databind.node.NullNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty @@ -33,14 +34,14 @@ import org.springframework.stereotype.Service * * @author Kapil Singal */ -@Service("rr-processor-source-input") +@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class InputResourceResolutionProcessor : ResourceAssignmentProcessor() { private val logger = LoggerFactory.getLogger(InputResourceResolutionProcessor::class.java) override fun getName(): String { - return "rr-processor-source-input" + return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-input" } override fun process(resourceAssignment: ResourceAssignment) { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt index d8472ede4..37b4774a7 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt @@ -17,12 +17,23 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor -import com.fasterxml.jackson.databind.node.* +import com.fasterxml.jackson.databind.node.ArrayNode +import com.fasterxml.jackson.databind.node.JsonNodeFactory +import com.fasterxml.jackson.databind.node.MissingNode +import com.fasterxml.jackson.databind.node.NullNode +import com.fasterxml.jackson.databind.node.ObjectNode +import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants.PREFIX_RESOURCE_RESOLUTION_PROCESSOR import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.RestResourceSource import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.utils.ResourceAssignmentUtils import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BluePrintRestLibPropertyService import org.onap.ccsdk.apps.blueprintsprocessor.rest.service.BlueprintWebClientService -import org.onap.ccsdk.apps.controllerblueprints.core.* +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException +import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes +import org.onap.ccsdk.apps.controllerblueprints.core.checkEqualsOrThrow +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty +import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow +import org.onap.ccsdk.apps.controllerblueprints.core.nullToEmpty +import org.onap.ccsdk.apps.controllerblueprints.core.returnNotEmptyOrThrow import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceDictionaryConstants @@ -36,7 +47,7 @@ import org.springframework.stereotype.Service * * @author Kapil Singal */ -@Service("rr-processor-source-rest") +@Service("${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest") @Scope(value = ConfigurableBeanFactory.SCOPE_PROTOTYPE) open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService) : ResourceAssignmentProcessor() { @@ -44,7 +55,7 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS private val logger = LoggerFactory.getLogger(RestResourceResolutionProcessor::class.java) override fun getName(): String { - return "rr-processor-source-rest" + return "${PREFIX_RESOURCE_RESOLUTION_PROCESSOR}source-rest" } override fun process(resourceAssignment: ResourceAssignment) { @@ -60,15 +71,19 @@ 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)") - val resourceSourceProperties = checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " } - val sourceProperties = JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java) - - val urlPath = checkNotNull(sourceProperties.urlPath) { "failed to get request urlPath for $dName under $dSource properties" } + ?: throw BluePrintProcessorException("couldn't get resource definition $dName source($dSource)") + val resourceSourceProperties = + checkNotNull(resourceSource.properties) { "failed to get source properties for $dName " } + val sourceProperties = + JacksonUtils.getInstanceFromMap(resourceSourceProperties, RestResourceSource::class.java) + + val urlPath = + checkNotNull(sourceProperties.urlPath) { "failed to get request urlPath for $dName under $dSource properties" } val path = nullToEmpty(sourceProperties.path) - val inputKeyMapping = checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" } + val inputKeyMapping = + checkNotNull(sourceProperties.inputKeyMapping) { "failed to get input-key-mappings for $dName under $dSource properties" } logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})") // Get the Rest Client Service @@ -84,7 +99,8 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment) } catch (e: Exception) { ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message) - throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e) + throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", + e) } } @@ -99,16 +115,19 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS } @Throws(BluePrintProcessorException::class) - private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource, restResponse: String, path: String) { + private fun populateResource(resourceAssignment: ResourceAssignment, sourceProperties: RestResourceSource, + restResponse: String, path: String) { val dName = resourceAssignment.dictionaryName val dSource = resourceAssignment.dictionarySource val type = nullToEmpty(resourceAssignment.property?.type) lateinit var entrySchemaType: String - val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) { "failed to get output-key-mappings for $dName under $dSource properties" } + val outputKeyMapping = + 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)" } + val responseNode = + 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)") @@ -119,7 +138,8 @@ 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" } + entrySchemaType = + returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" } val arrayNode = responseNode as ArrayNode if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) { @@ -128,9 +148,13 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS val arrayChildNode = JsonNodeFactory.instance.objectNode() outputKeyMapping.map { val responseKeyValue = responseSingleJsonNode.get(it.key) - val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key) + val propertyTypeForDataType = + 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) + JacksonUtils.populateJsonNodeValues(it.value, + responseKeyValue, + propertyTypeForDataType, + arrayChildNode) } arrayNode.add(arrayChildNode) } @@ -144,7 +168,8 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS val objectNode = responseNode as ObjectNode outputKeyMapping.map { val responseKeyValue = responseNode.get(it.key) - val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, it.key) + val propertyTypeForDataType = + 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) } @@ -159,11 +184,14 @@ 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) { + 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}" } - checkNotEmptyOrThrow(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 fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt index 1c9a905fd..b5b126ab6 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt @@ -1,5 +1,6 @@ /* * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications 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. @@ -23,13 +24,7 @@ import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.NullNode import com.fasterxml.jackson.databind.node.ObjectNode import org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintConstants -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintProcessorException -import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintTypes -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmpty -import org.onap.ccsdk.apps.controllerblueprints.core.checkNotEmptyOrThrow -import org.onap.ccsdk.apps.controllerblueprints.core.nullToEmpty -import org.onap.ccsdk.apps.controllerblueprints.core.returnNotEmptyOrThrow +import org.onap.ccsdk.apps.controllerblueprints.core.* import org.onap.ccsdk.apps.controllerblueprints.core.service.BluePrintRuntimeService import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment @@ -40,9 +35,11 @@ class ResourceAssignmentUtils { private val logger: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentUtils::class.toString()) + // TODO("Modify Value type from Any to JsonNode") @Synchronized @Throws(BluePrintProcessorException::class) - fun setResourceDataValue(resourceAssignment: ResourceAssignment, raRuntimeService: ResourceAssignmentRuntimeService, value: Any?) { + fun setResourceDataValue(resourceAssignment: ResourceAssignment, + 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") @@ -111,10 +108,10 @@ class ResourceAssignmentUtils { @Synchronized @Throws(BluePrintProcessorException::class) fun generateResourceDataForAssignments(assignments: List): String { - var result = "{}" + val result: String try { val mapper = ObjectMapper() - val root = mapper.readTree(result) + val root: ObjectNode = mapper.createObjectNode() assignments.forEach { if (checkNotEmpty(it.name) && it.property != null) { @@ -122,23 +119,7 @@ class ResourceAssignmentUtils { val type = nullToEmpty(it.property?.type).toLowerCase() val value = it.property?.value logger.info("Generating Resource name ($rName), type ($type), value ($value)") - - when (value) { - null -> (root as ObjectNode).set(rName, null) - is JsonNode -> (root as ObjectNode).set(rName, value) - else -> { - when (type) { - BluePrintConstants.DATA_TYPE_TIMESTAMP -> (root as ObjectNode).put(rName, value as String) - BluePrintConstants.DATA_TYPE_STRING -> (root as ObjectNode).put(rName, value as String) - BluePrintConstants.DATA_TYPE_BOOLEAN -> (root as ObjectNode).put(rName, value as Boolean) - BluePrintConstants.DATA_TYPE_INTEGER -> (root as ObjectNode).put(rName, value as Int) - BluePrintConstants.DATA_TYPE_FLOAT -> (root as ObjectNode).put(rName, value as Float) - else -> { - (root as ObjectNode).set(rName, JacksonUtils.getJsonNode(value)) - } - } - } - } + root.set(rName, value) } } result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root) -- cgit 1.2.3-korg