Merge "Resource Configuration Snapshots Executor and API"
authorBrinda Santh Muthuramalingam <brindasanth@in.ibm.com>
Tue, 13 Aug 2019 15:52:55 +0000 (15:52 +0000)
committerGerrit Code Review <gerrit@onap.org>
Tue, 13 Aug 2019 15:52:55 +0000 (15:52 +0000)
cds-ui/client/src/app/feature-modules/resource-definition/resource-edit/resource-edit.component.ts
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionConstants.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceResolutionService.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/RestResourceResolutionProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtils.kt

index faf7fbd..9aa2deb 100644 (file)
@@ -42,8 +42,8 @@ export class ResourceEditComponent implements OnInit {
     resources:IResources;
     data:IResources;
     rdState: Observable<IResourcesState>;
-    designerMode: boolean = false;
-    editorMode: boolean = true;
+    designerMode: boolean = true;
+    editorMode: boolean = false;
     viewText: string = "Open in Editor Mode";
     @ViewChild(JsonEditorComponent) editor: JsonEditorComponent;
     options = new JsonEditorOptions();
index fb32aa7..2a9218d 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright © 2017-2018 AT&T Intellectual Property.
- * Modifications Copyright © 2019 IBM.
+ * Modifications Copyright © 2019 IBM, Bell Canada.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -29,6 +29,5 @@ object ResourceResolutionConstants {
         const val RESOURCE_RESOLUTION_INPUT_OCCURRENCE = "occurrence"
         const val RESOURCE_RESOLUTION_INPUT_RESOURCE_ID = "resource-id"
         const val RESOURCE_RESOLUTION_INPUT_RESOURCE_TYPE = "resource-type"
-
-
+        val DATA_DICTIONARY_SECRET_SOURCE_TYPES = arrayOf("vault-data") //Add more secret data dictionary source type here
 }
\ No newline at end of file
index d3b69c7..641175c 100644 (file)
@@ -47,7 +47,7 @@ interface ResourceResolutionService {
                                     resolutionKey: String): String
 
     suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
-                                 artifactNames: List<String>, properties: Map<String, Any>): MutableMap<String, JsonNode>
+                                 artifactNames: List<String>, properties: Map<String, Any>): MutableMap<String, String>
 
     suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
                                  artifactPrefix: String, properties: Map<String, Any>): String
@@ -93,17 +93,17 @@ open class ResourceResolutionServiceImpl(private var applicationContext: Applica
 
     override suspend fun resolveResources(bluePrintRuntimeService: BluePrintRuntimeService<*>, nodeTemplateName: String,
                                           artifactNames: List<String>,
-                                          properties: Map<String, Any>): MutableMap<String, JsonNode> {
+                                          properties: Map<String, Any>): MutableMap<String, String> {
 
         val resourceAssignmentRuntimeService =
                 ResourceAssignmentUtils.transformToRARuntimeService(bluePrintRuntimeService, artifactNames.toString())
 
-        val resolvedParams: MutableMap<String, JsonNode> = hashMapOf()
+        val resolvedParams: MutableMap<String, String> = hashMapOf()
         artifactNames.forEach { artifactName ->
             val resolvedContent = resolveResources(resourceAssignmentRuntimeService, nodeTemplateName,
                     artifactName, properties)
 
-            resolvedParams[artifactName] = resolvedContent.asJsonType()
+            resolvedParams[artifactName] = resolvedContent
         }
         return resolvedParams
     }
index 600de13..f8193b7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  Copyright © 2018 IBM.
- *  Modifications Copyright © 2017-2018 AT&T Intellectual Property.
+ *  Modifications Copyright © 2017-2018 AT&T Intellectual Property, Bell Canada.
  *
  *  Licensed under the Apache License, Version 2.0 (the "License");
  *  you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
 
 package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.processor
 
-import com.fasterxml.jackson.databind.node.JsonNodeFactory
 import org.onap.ccsdk.cds.blueprintsprocessor.db.BluePrintDBLibGenericService
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.BluePrintDBLibPropertySevice
 import org.onap.ccsdk.cds.blueprintsprocessor.db.primary.PrimaryDBLibGenericService
@@ -152,50 +151,13 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert
         }
         logger.info("Response processing type($type)")
 
-        // Primitive Types
-        when (type) {
-            in BluePrintTypes.validPrimitiveTypes() -> {
-                val dbColumnValue = rows[0][outputKeyMapping[dName]]
-                logger.info("For template key (${resourceAssignment.name}) setting value as ($dbColumnValue)")
-                ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, dbColumnValue)
-            }
-            in BluePrintTypes.validCollectionTypes() -> {
-                val entrySchemaType = checkNotEmpty(resourceAssignment.property?.entrySchema?.type) {
-                    "Entry schema is not defined for dictionary ($dName) info"
-                }
-                val arrayNode = JacksonUtils.objectMapper.createArrayNode()
-                rows.forEach {
-                    if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) {
-                        val dbColumnValue = it[outputKeyMapping[dName]]
-                        // Add Array JSON
-                        JacksonUtils.populatePrimitiveValues(dbColumnValue!!, entrySchemaType, arrayNode)
-                    } else {
-                        val arrayChildNode = JsonNodeFactory.instance.objectNode()
-                        for (mapping in outputKeyMapping.entries) {
-                            val dbColumnValue = checkNotNull(it[mapping.key])
-                            val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, entrySchemaType, mapping.key)
-                            JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, arrayChildNode)
-                        }
-                        arrayNode.add(arrayChildNode)
-                    }
-                }
-                logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)")
-                // Set the List of Complex Values
-                ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode)
-            }
-            else -> {
-                // Custom Simple Complex Types
-                val row = rows[0]
-                val objectNode = JacksonUtils.objectMapper.createObjectNode()
-                for (mapping in outputKeyMapping.entries) {
-                    val dbColumnValue = checkNotNull(row[mapping.value])
-                    val propertyTypeForDataType = ResourceAssignmentUtils.getPropertyType(raRuntimeService, type, mapping.key)
-                    JacksonUtils.populatePrimitiveValues(mapping.key, dbColumnValue, propertyTypeForDataType, objectNode)
-                }
-                logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)")
-                ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode)
-            }
+        val responseNode = checkNotNull(JacksonUtils.getJsonNode(rows)) {
+            "Failed to get database query result into Json node."
         }
+
+        val parsedResponseNode = ResourceAssignmentUtils.parseResponseNode(responseNode, resourceAssignment,
+                raRuntimeService, outputKeyMapping)
+        ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, parsedResponseNode)
     }
 
     override suspend fun recoverNB(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
index 57e0286..da15609 100644 (file)
@@ -137,64 +137,11 @@ open class RestResourceResolutionProcessor(private val blueprintRestLibPropertyS
         }
         logger.info("populating value for output mapping ($outputKeyMapping), from json ($responseNode)")
 
+        val parsedResponseNode = ResourceAssignmentUtils.parseResponseNode(responseNode, resourceAssignment,
+                raRuntimeService, outputKeyMapping)
 
-        when (type) {
-            in BluePrintTypes.validPrimitiveTypes() -> {
-                logger.info("For template key (${resourceAssignment.name}) setting value as ($responseNode)")
-                ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, responseNode)
-            }
-            in BluePrintTypes.validCollectionTypes() -> {
-                // Array Types
-                entrySchemaType = checkNotEmpty(resourceAssignment.property?.entrySchema?.type) {
-                    "Entry schema is not defined for dictionary ($dName) info"
-                }
-                val arrayNode = JacksonUtils.objectMapper.createArrayNode()
-
-                if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) {
-
-                    val responseArrayNode = responseNode.toList()
-                    for (responseSingleJsonNode in responseArrayNode) {
-
-                        val arrayChildNode = JacksonUtils.objectMapper.createObjectNode()
-
-                        outputKeyMapping.map {
-                            val responseKeyValue = responseSingleJsonNode.get(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)
-                        }
-                        arrayNode.add(arrayChildNode)
-                    }
-                }
-                logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)")
-                // Set the List of Complex Values
-                ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, arrayNode)
-            }
-            else -> {
-                // Complex Types
-                entrySchemaType = checkNotEmpty(resourceAssignment.property?.type) {
-                    "Entry schema is not defined for dictionary ($dName) info"
-                }
-                val objectNode = JacksonUtils.objectMapper.createObjectNode()
-                outputKeyMapping.map {
-                    val responseKeyValue = responseNode.get(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)
-                }
-
-                logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)")
-                // Set the List of Complex Values
-                ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, objectNode)
-            }
-        }
+        // Set the List of Complex Values
+        ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, parsedResponseNode)
     }
 
     @Throws(BluePrintProcessorException::class)
index f8024d9..01cfd72 100644 (file)
@@ -19,6 +19,7 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.uti
 
 import com.fasterxml.jackson.databind.JsonNode
 import com.fasterxml.jackson.databind.ObjectMapper
+import com.fasterxml.jackson.databind.node.ArrayNode
 import com.fasterxml.jackson.databind.node.ObjectNode
 import com.fasterxml.jackson.databind.node.TextNode
 import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService
@@ -26,6 +27,7 @@ import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.Reso
 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
@@ -188,5 +190,89 @@ class ResourceAssignmentUtils {
             }
             return type
         }
+
+        @Throws(BluePrintProcessorException::class)
+        fun parseResponseNode(responseNode: JsonNode, resourceAssignment: ResourceAssignment,
+                              raRuntimeService: ResourceAssignmentRuntimeService, outputKeyMapping: MutableMap<String, String>): JsonNode {
+            val dName = resourceAssignment.dictionaryName
+            val dSource = resourceAssignment.dictionarySource
+            val type = nullToEmpty(resourceAssignment.property?.type)
+            lateinit var entrySchemaType: String
+            when (type) {
+                in BluePrintTypes.validPrimitiveTypes() -> {
+                    if (dSource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES)
+                        logger.info("For template key (${resourceAssignment.name}) setting value as ($responseNode)")
+                    val result = if (responseNode is ArrayNode)
+                        responseNode.get(0)
+                    else
+                        responseNode
+                    return if (result.isComplexType()) {
+                        check(result.has(outputKeyMapping[dName])) {
+                            "Fail to find output key mapping ($dName) in result."
+                        }
+                        result[outputKeyMapping[dName]]
+                    } else {
+                        result
+                    }
+                }
+                in BluePrintTypes.validCollectionTypes() -> {
+                    // Array Types
+                    entrySchemaType = checkNotEmpty(resourceAssignment.property?.entrySchema?.type) {
+                        "Entry schema is not defined for dictionary ($dName) info"
+                    }
+                    val arrayNode = JacksonUtils.objectMapper.createArrayNode()
+                    lateinit var responseValueNode: JsonNode
+                    lateinit var propertyType: String
+                    outputKeyMapping.map {
+                        val arrayChildNode = JacksonUtils.objectMapper.createObjectNode()
+                        val responseArrayNode = responseNode.rootFieldsToMap()
+                        outer@ for ((key, responseSingleJsonNode) in responseArrayNode) {
+                            if (key == it.key) {
+                                if (entrySchemaType in BluePrintTypes.validPrimitiveTypes()) {
+                                    responseValueNode = responseSingleJsonNode
+                                    propertyType = entrySchemaType
+
+                                } else {
+                                    responseValueNode = responseSingleJsonNode.get(it.key)
+                                    propertyType = getPropertyType(raRuntimeService, entrySchemaType, it.key)
+                                }
+                                if (resourceAssignment.dictionarySource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES)
+                                    logger.info("For List Type Resource: key (${it.key}), value ($responseValueNode), " +
+                                            "type  ({$propertyType})")
+                                JacksonUtils.populateJsonNodeValues(it.value,
+                                        responseValueNode, propertyType, arrayChildNode)
+                                arrayNode.add(arrayChildNode)
+                                break@outer
+                            }
+                        }
+                    }
+                    if (resourceAssignment.dictionarySource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES)
+                        logger.info("For template key (${resourceAssignment.name}) setting value as ($arrayNode)")
+
+                    return arrayNode
+                }
+                else -> {
+                    // Complex Types
+                    entrySchemaType = checkNotEmpty(resourceAssignment.property?.type) {
+                        "Entry schema is not defined for dictionary ($dName) info"
+                    }
+                    val objectNode = JacksonUtils.objectMapper.createObjectNode()
+                    outputKeyMapping.map {
+                        val responseKeyValue = responseNode.get(it.key)
+                        val propertyTypeForDataType = ResourceAssignmentUtils
+                                .getPropertyType(raRuntimeService, entrySchemaType, it.key)
+
+                        if (resourceAssignment.dictionarySource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES)
+                            logger.info("For List Type Resource: key (${it.key}), value ($responseKeyValue), type  ({$propertyTypeForDataType})")
+                        JacksonUtils.populateJsonNodeValues(it.value, responseKeyValue, propertyTypeForDataType, objectNode)
+                    }
+
+                    if (resourceAssignment.dictionarySource !in ResourceResolutionConstants.DATA_DICTIONARY_SECRET_SOURCE_TYPES)
+                        logger.info("For template key (${resourceAssignment.name}) setting value as ($objectNode)")
+
+                    return objectNode
+                }
+            }
+        }
     }
 }
\ No newline at end of file