summaryrefslogtreecommitdiffstats
path: root/ms
diff options
context:
space:
mode:
authorSingal, Kapil (ks220y) <ks220y@att.com>2019-09-23 18:47:29 -0400
committerSingal, Kapil (ks220y) <ks220y@att.com>2019-09-24 12:53:44 -0400
commite0e2aa06217ea5299e720e97f4275197551b3e68 (patch)
tree5744e56b68f0b27f9190c55f326a81bcb2040024 /ms
parent7acab9f8a2f0da70ecdbf8d7850134fcbbbf46c2 (diff)
Refactoring ResourceAssignmentUtils
Changing isNull condition to isNullOrEmpty to make sure Empty value doesn't get assigned to resource Issue-ID: CCSDK-1748 Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com> Change-Id: I0744537c7ddec80f20ffd7e6545b947439f63743
Diffstat (limited to 'ms')
-rw-r--r--ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt8
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt6
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/ResourceAssignmentProcessor.kt2
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt2
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt54
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt15
-rw-r--r--ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt26
-rw-r--r--ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt22
8 files changed, 81 insertions, 54 deletions
diff --git a/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt b/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt
index 25bb3c938..3a655ded7 100644
--- a/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt
+++ b/ms/blueprintsprocessor/functions/ansible-awx-executor/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/ansible/executor/ComponentRemoteAnsibleExecutor.kt
@@ -296,20 +296,20 @@ open class ComponentRemoteAnsibleExecutor(private val blueprintRestLibPropertySe
val skipTagsProp = getOptionalOperationInput(INPUT_SKIP_TAGS)
val askLimitOnLaunch = jtLaunchReqs.at("/ask_limit_on_launch").asBoolean()
- if (askLimitOnLaunch && limitProp.isNotNull()) {
+ if (askLimitOnLaunch && !limitProp.isNullOrMissing()) {
payload.set(INPUT_LIMIT_TO_HOST, limitProp)
}
val askTagsOnLaunch = jtLaunchReqs.at("/ask_tags_on_launch").asBoolean()
- if (askTagsOnLaunch && tagsProp.isNotNull()) {
+ if (askTagsOnLaunch && !tagsProp.isNullOrMissing()) {
payload.set(INPUT_TAGS, tagsProp)
}
- if (askTagsOnLaunch && skipTagsProp.isNotNull()) {
+ if (askTagsOnLaunch && !skipTagsProp.isNullOrMissing()) {
payload.set("skip_tags", skipTagsProp)
}
}
val askInventoryOnLaunch = jtLaunchReqs.at("/ask_inventory_on_launch").asBoolean()
- if (askInventoryOnLaunch && inventoryProp.isNotNull()) {
+ if (askInventoryOnLaunch && !inventoryProp.isNullOrMissing()) {
var inventoryKeyId = if (inventoryProp is TextNode) {
resolveInventoryIdByName(awxClient, inventoryProp.textValue())?.asJsonPrimitive()
} else {
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 8d21e9a70..2120449ab 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
@@ -135,7 +135,9 @@ open class DatabaseResourceAssignmentProcessor(
logger.trace("Reference dictionary key (${it.key}) resulted in value ($expressionValue)")
namedParameters[it.key] = expressionValue
}
- logger.info("Parameter information : ($namedParameters)")
+ if (namedParameters.isNotEmpty()) {
+ logger.info("Parameter information : ($namedParameters)")
+ }
return namedParameters
}
@@ -152,7 +154,7 @@ open class DatabaseResourceAssignmentProcessor(
val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) {
"failed to get output-key-mappings for $dName under $dSource properties"
}
- logger.info("Response processing type($type)")
+ logger.info("Response processing type ($type)")
val responseNode = checkNotNull(JacksonUtils.getJsonNode(rows)) {
"Failed to get database query result into Json node."
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 af89bcef6..c4c308efb 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
@@ -51,7 +51,7 @@ abstract class ResourceAssignmentProcessor : BlueprintFunctionNode<ResourceAssig
open fun setFromInput(resourceAssignment: ResourceAssignment): Boolean {
try {
val value = raRuntimeService.getInputValue(resourceAssignment.name)
- if (value.returnNullIfMissing() != null) {
+ if (!value.isNullOrMissing()) {
ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
return true
}
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 dab6ff79f..70da462c4 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
@@ -133,7 +133,7 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
val outputKeyMapping = checkNotNull(sourceProperties.outputKeyMapping) {
"failed to get output-key-mappings for $dName under $dSource properties"
}
- logger.info("Response processing type($type)")
+ logger.info("Response processing type ($type)")
val responseNode = checkNotNull(JacksonUtils.jsonNode(restResponse).at(path)) {
"Failed to find path ($path) in response ($restResponse)"
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 05e7b6941..688713469 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
@@ -124,9 +124,7 @@ class ResourceAssignmentUtils {
val resourceProp = checkNotNull(resourceAssignment.property) {
"Failed to populate mandatory resource resource mapping $resourceAssignment"
}
- if (resourceProp.required != null && resourceProp.required!!
- && (resourceProp.value == null || resourceProp.value!!.returnNullIfMissing() == null)
- ) {
+ if (resourceProp.required != null && resourceProp.required!! && resourceProp.value.isNullOrMissing()) {
logger.error("failed to populate mandatory resource mapping ($resourceAssignment)")
throw BluePrintProcessorException("failed to populate mandatory resource mapping ($resourceAssignment)")
}
@@ -244,9 +242,10 @@ class ResourceAssignmentUtils {
val type = resourceAssignment.property!!.type
val valueToPrint = getValueToLog(metadata, responseNode)
- logger.info("For template key (${resourceAssignment.name}) setting value as ($valueToPrint)")
+ logger.info("For template key (${resourceAssignment.name}) trying to get value from responseNode ($valueToPrint)")
return when (type) {
in BluePrintTypes.validPrimitiveTypes() -> {
+ // Primitive Types
parseResponseNodeForPrimitiveTypes(responseNode, outputKeyMapping)
}
in BluePrintTypes.validCollectionTypes() -> {
@@ -268,34 +267,33 @@ class ResourceAssignmentUtils {
responseNode: JsonNode,
outputKeyMapping: MutableMap<String, String>
): JsonNode {
- if (responseNode.isComplexType()) {
- val outputKey = outputKeyMapping.keys.firstOrNull()
- var returnNode = if (responseNode is ArrayNode) {
- val arrayNode = responseNode.toList()
- if (outputKey.isNullOrEmpty()) {
- arrayNode.first()
- } else {
- arrayNode.firstOrNull { element ->
- element.isComplexType() && element.has(outputKeyMapping[outputKey])
- }
- }
- } else {
- responseNode
- }
+ // Return responseNode if is not a Complex Type
+ if (!responseNode.isComplexType()) {
+ return responseNode
+ }
- if (returnNode.isNull() || returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[outputKey])) {
- throw BluePrintProcessorException("Fail to find output key mapping ($outputKey) in the responseNode.")
- }
- return if (returnNode.isComplexType()) {
- returnNode[outputKeyMapping[outputKey]]
+ val outputKey = outputKeyMapping.keys.firstOrNull()
+ var returnNode = if (responseNode is ArrayNode) {
+ val arrayNode = responseNode.toList()
+ if (outputKey.isNullOrEmpty()) {
+ arrayNode.first()
} else {
- returnNode
+ arrayNode.firstOrNull { element ->
+ element.isComplexType() && element.has(outputKeyMapping[outputKey])
+ }
}
+ } else {
+ responseNode
}
- if (outputKeyMapping.isNotEmpty()) {
- throw BluePrintProcessorException("Fail to find key-value in response node to map output-key-mapping.")
+
+ if (returnNode.isNullOrMissing() || returnNode!!.isComplexType() && !returnNode.has(outputKeyMapping[outputKey])) {
+ throw BluePrintProcessorException("Fail to find output key mapping ($outputKey) in the responseNode.")
+ }
+ return if (returnNode.isComplexType()) {
+ returnNode[outputKeyMapping[outputKey]]
+ } else {
+ returnNode
}
- return responseNode
}
private fun parseResponseNodeForCollection(
@@ -566,7 +564,7 @@ class ResourceAssignmentUtils {
fun getValueToLog(metadata: MutableMap<String, String>?, value: Any): Any {
return if (checkIfLogIsProtected(metadata)) {
- "*************"
+ "******REDACTED******"
} else {
value
}
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
index b74b7e4cf..1aaf9d8a4 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctions.kt
@@ -175,7 +175,7 @@ fun ArrayNode.asListOfString(): List<String> {
fun <T> JsonNode.asType(clazzType: Class<T>): T {
return JacksonUtils.readValue(this, clazzType)
- ?: throw BluePrintException("couldn't convert JsonNode of type $clazzType")
+ ?: throw BluePrintException("couldn't convert JsonNode of type $clazzType")
}
fun JsonNode.asListOfString(): List<String> {
@@ -183,20 +183,17 @@ fun JsonNode.asListOfString(): List<String> {
return this.asListOfString()
}
-fun JsonNode.returnNullIfMissing(): JsonNode? {
- return if (this is NullNode || this is MissingNode) {
+fun <T : JsonNode> T?.returnNullIfMissing(): JsonNode? {
+ return if (this == null || this is NullNode || this is MissingNode) {
null
- } else this
+ }
+ else this
}
-fun <T : JsonNode> T?.isNull(): Boolean {
+fun <T : JsonNode> T?.isNullOrMissing(): Boolean {
return this == null || this is NullNode || this is MissingNode
}
-fun <T : JsonNode> T?.isNotNull(): Boolean {
- return !(this == null || this is NullNode || this is MissingNode)
-}
-
/**
* Convert Json to map of json node, the root fields will be map keys
*/
diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt
index 487b1d15b..76be647f1 100644
--- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt
+++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/CustomFunctionsTest.kt
@@ -129,6 +129,32 @@ class CustomFunctionsTest {
assertNull(missingValue)
}
+ @Test
+ fun testIsNullOrMissing() {
+ assertTrue(NullNode.instance.isNullOrMissing())
+ assertTrue(MissingNode.getInstance().isNullOrMissing())
+
+ assertFalse(TextNode("").isNullOrMissing())
+ assertFalse("".asJsonType().isNullOrMissing())
+ assertFalse("hello".asJsonType().isNullOrMissing())
+ assertFalse("{\"key\": \"value\"}".asJsonType().isNullOrMissing())
+ assertFalse(TextNode("hello").isNullOrMissing())
+ }
+
+ @Test
+ fun testIsComplexType() {
+ assertFalse(NullNode.instance.isComplexType())
+ assertFalse(MissingNode.getInstance().isComplexType())
+
+ assertFalse(TextNode("").isComplexType())
+ assertFalse("".asJsonType().isComplexType())
+ assertFalse("hello".asJsonType().isComplexType())
+ assertFalse(TextNode("hello").isComplexType())
+
+ assertTrue("{\"key\": \"value\"}".asJsonType().isComplexType())
+ assertTrue("[{\"key\": \"value\"},{\"key\": \"value\"}]".asJsonType().isComplexType())
+ }
+
@Test(expected = BluePrintException::class)
fun testRootFieldsToMap() {
1.asJsonType().rootFieldsToMap()
diff --git a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
index c222de9e5..2966d8b5d 100644
--- a/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
+++ b/ms/controllerblueprints/modules/resource-dict/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/resource/dict/ResourceDefinition.kt
@@ -84,15 +84,19 @@ open class ResourceAssignment {
var updatedBy: String? = null
override fun toString(): String {
- return StringBuilder()
- .append("[")
- .append("name=", name)
- .append(", status=", status)
- .append(", property=", property?.value ?: "")
- .append(", dictionaryName=", dictionaryName)
- .append(", dictionarySource=", dictionarySource)
- .append("]")
- .toString()
+ return """
+ [
+ name = $name
+ status = $status
+ property [
+ defaultValue = ${property?.defaultValue}
+ required = ${property?.required}
+ metadata = ${property?.metadata}
+ ]
+ dictionaryName = $dictionaryName
+ dictionarySource = $dictionarySource
+ ]
+ """.trimIndent()
}
}