summaryrefslogtreecommitdiffstats
path: root/ms/blueprintsprocessor/functions/resource-resolution
diff options
context:
space:
mode:
authorAlexis de Talhouët <adetalhouet89@gmail.com>2019-03-08 13:41:18 -0500
committerAlexis de Talhouët <adetalhouet89@gmail.com>2019-03-11 15:59:44 -0400
commit1a1d3654858304cfceb277b68c0ea7c48cb569ce (patch)
tree53ad15a17ad1473ebc0982aacd1de41529d715b4 /ms/blueprintsprocessor/functions/resource-resolution
parent9a3f830573454adf62b363e49b2331b9c65fcc49 (diff)
Enhance / fix REST resource resolution
- provide sync web client - add support for VERB - add support for payload - fix URI resolution from input-key-mapping Change-Id: Id4f1973a15778ad4f2ab0f7e2a4b2c61054a234d Issue-ID: CCSDK-1131 Signed-off-by: Alexis de Talhouët <adetalhouet89@gmail.com>
Diffstat (limited to 'ms/blueprintsprocessor/functions/resource-resolution')
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt3
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt10
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt52
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt16
4 files changed, 58 insertions, 23 deletions
diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt
index 1c3574461..25fc8c010 100644
--- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt
+++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceSourceProperties.kt
@@ -48,6 +48,9 @@ open class DatabaseResourceSource : ResourceSourceProperties() {
}
open class RestResourceSource : ResourceSourceProperties() {
+ lateinit var verb: String
+ @get:JsonProperty("payload")
+ var payload: String? = null
lateinit var type: String
@get:JsonProperty("endpoint-selector")
var endpointSelector: String? = null
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 39be14c93..ca4d631b6 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
@@ -22,7 +22,13 @@ 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.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
@@ -91,7 +97,7 @@ open class DatabaseResourceAssignmentProcessor(private val dBLibGenericService:
}
private fun blueprintDBLibService(sourceProperties: DatabaseResourceSource): NamedParameterJdbcTemplate {
- return if (checkNotEmpty(sourceProperties.endpointSelector!!)) {
+ return if (checkNotEmpty(sourceProperties.endpointSelector)) {
val dbPropertiesJson = raRuntimeService.resolveDSLExpression(sourceProperties.endpointSelector!!)
dBLibGenericService.remoteJdbcTemplate(dbPropertiesJson)
} else {
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 37b4774a7..9bb1ea212 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
@@ -19,9 +19,8 @@ package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.pr
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.apache.commons.collections.MapUtils
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
@@ -41,6 +40,7 @@ import org.slf4j.LoggerFactory
import org.springframework.beans.factory.config.ConfigurableBeanFactory
import org.springframework.context.annotation.Scope
import org.springframework.stereotype.Service
+import java.util.*
/**
* RestResourceResolutionProcessor
@@ -63,11 +63,11 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
validate(resourceAssignment)
// Check if It has Input
- val value = raRuntimeService.getInputValue(resourceAssignment.name)
- if (value !is MissingNode && value !is NullNode) {
- logger.info("primary-db source template key (${resourceAssignment.name}) found from input and value is ($value)")
+ try {
+ val value = raRuntimeService.getInputValue(resourceAssignment.name)
+ logger.info("rest source template key (${resourceAssignment.name}) found from input and value is ($value)")
ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
- } else {
+ } catch (e: BluePrintProcessorException) {
val dName = resourceAssignment.dictionaryName
val dSource = resourceAssignment.dictionarySource
val resourceDefinition = resourceDictionaries[dName]
@@ -78,17 +78,22 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
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 resolvedInputKeyMapping = populateInputKeyMappingVariables(inputKeyMapping)
+
+ // Resolving content Variables
+ val payload = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.payload), resolvedInputKeyMapping)
+ val urlPath =
+ resolveFromInputKeyMapping(checkNotNull(sourceProperties.urlPath), resolvedInputKeyMapping)
+ val verb = resolveFromInputKeyMapping(nullToEmpty(sourceProperties.verb), resolvedInputKeyMapping)
logger.info("$dSource dictionary information : ($urlPath), ($inputKeyMapping), (${sourceProperties.outputKeyMapping})")
// Get the Rest Client Service
val restClientService = blueprintWebClientService(resourceAssignment, sourceProperties)
- val response = restClientService.getResource(urlPath, String::class.java)
+
+ val response = restClientService.exchangeResource(verb, urlPath, payload)
if (response.isBlank()) {
logger.warn("Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath)")
} else {
@@ -104,8 +109,8 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
}
}
- open fun blueprintWebClientService(resourceAssignment: ResourceAssignment,
- restResourceSource: RestResourceSource): BlueprintWebClientService {
+ private fun blueprintWebClientService(resourceAssignment: ResourceAssignment,
+ restResourceSource: RestResourceSource): BlueprintWebClientService {
return if (checkNotEmpty(restResourceSource.endpointSelector)) {
val restPropertiesJson = raRuntimeService.resolveDSLExpression(restResourceSource.endpointSelector!!)
blueprintRestLibPropertyService.blueprintWebClientService(restPropertiesJson)
@@ -181,6 +186,29 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
}
}
+ private fun populateInputKeyMappingVariables(inputKeyMapping: Map<String, String>): Map<String, Any> {
+ val resolvedInputKeyMapping = HashMap<String, Any>()
+ if (MapUtils.isNotEmpty(inputKeyMapping)) {
+ for ((key, value) in inputKeyMapping) {
+ val expressionValue = raRuntimeService.getResolutionStore(value).asText()
+ logger.trace("Reference dictionary key ({}), value ({})", key, expressionValue)
+ resolvedInputKeyMapping[key] = expressionValue
+ }
+ }
+ return resolvedInputKeyMapping
+ }
+
+ private fun resolveFromInputKeyMapping(valueToResolve: String, keyMapping: Map<String, Any>): String {
+ if (valueToResolve.isEmpty() || !valueToResolve.contains("$")) {
+ return valueToResolve
+ }
+ var res = valueToResolve
+ for (entry in keyMapping.entries) {
+ res = res.replace(("\\$" + entry.key).toRegex(), entry.value.toString())
+ }
+ return res
+ }
+
@Throws(BluePrintProcessorException::class)
private fun validate(resourceAssignment: ResourceAssignment) {
checkNotEmptyOrThrow(resourceAssignment.name, "resource assignment template key is not defined")
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 b5b126ab6..d55ccacb2 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
@@ -24,7 +24,13 @@ 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.*
+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.service.BluePrintRuntimeService
import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment
@@ -36,7 +42,6 @@ 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?) {
@@ -85,7 +90,6 @@ class ResourceAssignmentUtils {
}
- @Synchronized
fun setFailedResourceDataValue(resourceAssignment: ResourceAssignment, message: String?) {
if (checkNotEmpty(resourceAssignment.name)) {
resourceAssignment.updatedDate = Date()
@@ -95,7 +99,6 @@ class ResourceAssignmentUtils {
}
}
- @Synchronized
@Throws(BluePrintProcessorException::class)
fun assertTemplateKeyValueNotNull(resourceAssignment: ResourceAssignment) {
val resourceProp = checkNotNull(resourceAssignment.property) { "Failed to populate mandatory resource resource mapping $resourceAssignment" }
@@ -105,7 +108,6 @@ class ResourceAssignmentUtils {
}
}
- @Synchronized
@Throws(BluePrintProcessorException::class)
fun generateResourceDataForAssignments(assignments: List<ResourceAssignment>): String {
val result: String
@@ -139,10 +141,6 @@ class ResourceAssignmentUtils {
return resourceAssignmentRuntimeService
}
- /*
- * Populate the Field property type for the Data type
- */
- @Synchronized
@Throws(BluePrintProcessorException::class)
fun getPropertyType(raRuntimeService: ResourceAssignmentRuntimeService, dataTypeName: String, propertyName: String): String {
lateinit var type: String