Resource Resolution Service: Source Rest 40/76040/2
authorSingal, Kapil (ks220y) <ks220y@att.com>
Sun, 20 Jan 2019 22:49:52 +0000 (17:49 -0500)
committerSingal, Kapil (ks220y) <ks220y@att.com>
Sun, 20 Jan 2019 23:07:36 +0000 (18:07 -0500)
Complex Data Processing for Primary-Config-Data DataSource Resource Resolution Service

Change-Id: I62492b5c4e3c0b831f9027df5d42c6b80186debc
Issue-ID: CCSDK-674
Signed-off-by: Singal, Kapil (ks220y) <ks220y@att.com>
40 files changed:
components/core/src/test/resources/dictionary/dictionary_schema.json
components/model-catalog/blueprint-model/service-blueprint/vFW/Definitions/vFW_spinup.json
components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/baseconfig-mapping.json
components/model-catalog/blueprint-model/starter-blueprint/baseconfiguration/Definitions/resources_definition_types.json
components/model-catalog/resource-dictionary/starter-dictionary/image_name.json
components/model-catalog/resource-dictionary/starter-dictionary/key_name.json
components/model-catalog/resource-dictionary/starter-dictionary/mdsal-source.json
components/model-catalog/resource-dictionary/starter-dictionary/onap_private_net_id.json
components/model-catalog/resource-dictionary/starter-dictionary/onap_private_subnet_id.json
components/model-catalog/resource-dictionary/starter-dictionary/pub_key.json
components/model-catalog/resource-dictionary/starter-dictionary/sample-licenses.json
components/model-catalog/resource-dictionary/starter-dictionary/sample-mdsal-source.json
components/model-catalog/resource-dictionary/starter-dictionary/vfw_private_ip_0.json
components/model-catalog/resource-dictionary/starter-dictionary/vfw_private_ip_1.json
components/model-catalog/resource-dictionary/starter-dictionary/vnf-name.json
components/model-catalog/resource-dictionary/starter-dictionary/vnf_name.json
components/model-catalog/resource-dictionary/starter-dictionary/vpg_private_ip_0.json
components/model-catalog/resource-dictionary/starter-dictionary/vsn_private_ip_0.json
components/resource-dict/load/resource_dictionary/mdsal-source.json
components/resource-dict/load/resource_dictionary/vfw_private_ip_0.json
components/resource-dict/load/resource_dictionary/vfw_private_ip_1.json
components/resource-dict/load/resource_dictionary/vnf-name.json
components/resource-dict/load/resource_dictionary/vnf_name.json
components/resource-dict/load/resource_dictionary/vpg_private_ip_0.json
components/resource-dict/load/resource_dictionary/vsn_private_ip_0.json
components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt
components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java
components/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt
components/resource-dict/src/test/resources/validation/cyclic.json
components/resource-dict/src/test/resources/validation/duplicate.json
components/resource-dict/src/test/resources/validation/success.json
ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/processor/SimpleRestResourceAssignmentProcessor.kt
ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/functions/resource/resolution/ResourceResolutionServiceTest.kt
ms/controllerblueprints/application/opt/app/onap/config/application-dev.properties
ms/controllerblueprints/application/opt/app/onap/config/application.properties
ms/controllerblueprints/application/src/test/resources/application.properties
ms/controllerblueprints/modules/service/src/test/resources/application.properties
ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-resource-assignment.json
ms/controllerblueprints/modules/service/src/test/resources/enhance/enhance-template.json
ms/controllerblueprints/modules/service/src/test/resources/enhance/enhanced-template.json

index f9ef9ee..51db5f5 100644 (file)
@@ -54,7 +54,7 @@
                                "aai": {\r
                                        "type": "any"\r
                                },\r
-                               "mdsal": {\r
+                               "primary-config-data": {\r
                                        "type": "object",\r
                                        "properties": {\r
                                                "path": {\r
                                                }\r
                                        }\r
                                },\r
-                               "mdsal": {\r
+                               "primary-config-data": {\r
                                        "type": "object",\r
                                        "properties": {\r
                                                "names": {\r
index 13847bb..4484d55 100644 (file)
                   },
                   "input-param": false,
                   "dictionary-name": "vnf-name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "image_name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "key_name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "pub_key",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "onap_private_net_id",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "onap_private_subnet_id",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "vnf-name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "image_name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "key_name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "pub_key",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "onap_private_net_id",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "onap_private_subnet_id",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "vfw_private_ip_0",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "vsn_private_ip_0",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "vpg_private_ip_0",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "vnf-name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "image_name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "key_name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "pub_key",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "onap_private_net_id",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "onap_private_subnet_id",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "vfw_private_ip_1",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
                   },
                   "input-param": false,
                   "dictionary-name": "vnf-name",
-                  "dictionary-source": "mdsal",
+                  "dictionary-source": "primary-config-data",
                   "dependencies": [
                     "service-instance-id",
                     "vnf-id"
index c457086..67d2a91 100644 (file)
@@ -27,7 +27,7 @@
       "type": "string"
     },
     "dictionary-name": "vnf_name",
-    "dictionary-source": "mdsal",
+    "dictionary-source": "primary-config-data",
     "dependencies": [
       "service-instance-id",
       "vnf-id"
index 37ef5ae..57a0ef3 100755 (executable)
@@ -10,7 +10,7 @@
     "input": {
       "type": "source-input"
     },
-    "mdsal": {
+    "primary-config-data": {
       "type": "source-rest",
       "properties": {
         "type": "JSON",
index 1f1b3e6..6eb8d92 100755 (executable)
@@ -10,7 +10,7 @@
     "input": {
       "type": "source-input"
     },
-    "mdsal": {
+    "primary-config-data": {
       "type": "source-rest",
       "properties": {
         "type": "JSON",
index 300a71f..67661ec 100755 (executable)
@@ -7,7 +7,7 @@
   },
   "updated-by": "brindasanth@onap.com",
   "sources": {
-    "mdsal": {
+    "primary-config-data": {
       "type": "source-rest",
       "properties": {
         "type": "JSON",
index bb70fe3..3dd74f7 100755 (executable)
@@ -10,7 +10,7 @@
     "input": {
       "type": "source-input"
     },
-    "mdsal": {
+    "primary-config-data": {
       "type": "source-rest",
       "properties": {
         "type": "JSON",
index d38ceb4..6cb22c3 100755 (executable)
@@ -10,7 +10,7 @@
     "input": {
       "type": "source-input"
     },
-    "mdsal": {
+    "primary-config-data": {
       "type": "source-rest",
       "properties": {
         "type": "JSON",
index ce6c2f2..fe172ca 100755 (executable)
@@ -10,7 +10,7 @@
     "input": {
       "type": "source-input"
     },
-    "mdsal": {
+    "primary-config-data": {
       "type": "source-rest",
       "properties": {
         "type": "JSON",
index 5834dd4..c0f78ac 100644 (file)
@@ -11,7 +11,7 @@
   },\r
   "updated-by": "brindasanth@onap.com",\r
   "sources": {\r
-    "mdsal": {\r
+    "primary-config-data": {\r
       "type": "source-rest",\r
       "properties": {\r
         "type": "JSON",\r
index 25464d3..75d7ca0 100644 (file)
@@ -7,7 +7,7 @@
   },\r
   "updated-by": "brindasanth@onap.com",\r
   "sources": {\r
-    "mdsal": {\r
+    "primary-config-data": {\r
       "type": "source-rest",\r
       "properties": {\r
         "type": "JSON",\r
index 71a4df2..4c227f9 100755 (executable)
@@ -12,7 +12,7 @@
       "properties" : {
       }
     },
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index 481edae..0df08c0 100755 (executable)
@@ -12,7 +12,7 @@
       "properties" : {
       }
     },
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index 89b3dc1..4c0320a 100755 (executable)
@@ -7,7 +7,7 @@
     "type" : "string"
   },
   "sources" : {
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index c55f1c1..e9d8a3b 100755 (executable)
@@ -7,7 +7,7 @@
     "type" : "string"
   },
   "sources" : {
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index 13d8999..586aa0c 100755 (executable)
@@ -12,7 +12,7 @@
       "properties" : {
       }
     },
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index fcd6d8d..1fe4797 100755 (executable)
@@ -12,7 +12,7 @@
       "properties" : {
       }
     },
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index b38986a..fa72e5d 100644 (file)
@@ -7,7 +7,7 @@
   },\r
   "updated-by": "brindasanth@onap.com",\r
   "sources": {\r
-    "mdsal": {\r
+    "primary-config-data": {\r
       "type": "source-rest",\r
       "properties": {\r
         "type": "JSON",\r
index 7c8d4f4..59f5151 100644 (file)
@@ -13,7 +13,7 @@
         "key" : "vfw_private_ip_0"
       }
     },
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index 0553b8c..6dda72f 100644 (file)
@@ -13,7 +13,7 @@
         "key" : "vfw_private_ip_1"
       }
     },
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index 47371d1..708030e 100644 (file)
@@ -7,7 +7,7 @@
     "type" : "string"\r
   },\r
   "sources" : {\r
-    "mdsal" : {\r
+    "primary-config-data" : {\r
       "type" : "source-rest",\r
       "properties" : {\r
         "type" : "JSON",\r
index 4617a26..3164367 100644 (file)
@@ -7,7 +7,7 @@
     "type" : "string"\r
   },\r
   "sources" : {\r
-    "mdsal" : {\r
+    "primary-config-data" : {\r
       "type" : "source-rest",\r
       "properties" : {\r
         "type" : "JSON",\r
index 912cfb9..9bef3c7 100644 (file)
@@ -13,7 +13,7 @@
         "key" : "vpg_private_ip_0"
       }
     },
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index bf98738..52a4542 100644 (file)
@@ -13,7 +13,7 @@
         "key" : "vsn_private_ip_0"
       }
     },
-    "mdsal" : {
+    "primary-config-data" : {
       "type" : "source-rest",
       "properties" : {
         "type" : "JSON",
index 0004b02..aa06c9d 100644 (file)
@@ -24,7 +24,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict
 object ResourceDictionaryConstants {
     const val SOURCE_INPUT = "input"
     const val SOURCE_DEFAULT = "default"
-    const val SOURCE_MDSAL = "mdsal"
+    const val SOURCE_PRIMARY_CONFIG_DATA = "primary-config-data"
     const val SOURCE_PRIMARY_DB = "primary-db"
 
     const val MODEL_DIR_RESOURCE_DEFINITION: String = "resource_dictionary"
index 3f5aef4..f11638e 100644 (file)
@@ -28,7 +28,7 @@ public class ResourceSourceMappingFactoryTest {
         ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("primary-db", "source-primary-db");\r
         ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input");\r
         ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default");\r
-        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("mdsal", "source-rest");\r
+        ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("primary-config-data", "source-rest");\r
 \r
         String nodeTypeName = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping("primary-db");\r
         Assert.notNull(nodeTypeName, "Failed to get primary-db mapping");\r
index 50e5c32..74ef6d6 100644 (file)
@@ -25,6 +25,6 @@ object ResourceDictionaryTestUtils {
         ResourceSourceMappingFactory.registerSourceMapping("primary-db", "source-primary-db")\r
         ResourceSourceMappingFactory.registerSourceMapping("input", "source-input")\r
         ResourceSourceMappingFactory.registerSourceMapping("default", "source-default")\r
-        ResourceSourceMappingFactory.registerSourceMapping("mdsal", "source-rest")\r
+        ResourceSourceMappingFactory.registerSourceMapping("primary-config-data", "source-rest")\r
     }\r
 }
\ No newline at end of file
index 7e6472f..98cd144 100644 (file)
@@ -29,7 +29,7 @@
       "required": true\r
     },\r
     "dictionary-name": "bundle-id",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "vnf-id"\r
     ]\r
@@ -42,7 +42,7 @@
       "required": true\r
     },\r
     "dictionary-name": "bundle-ip",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "vnf-id"\r
     ]\r
@@ -54,7 +54,7 @@
       "type": "string"\r
     },\r
     "dictionary-name": "bundle-mac",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "vnf-id",\r
       "bundle-id"\r
@@ -67,7 +67,7 @@
       "type": "string"\r
     },\r
     "dictionary-name": "managed-ip",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "loopback-ip"\r
     ]\r
@@ -90,7 +90,7 @@
       "type": "string"\r
     },\r
     "dictionary-name": "managed-ip1",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "loopback-ip"\r
     ]\r
index 28ab71f..7581ff6 100644 (file)
@@ -29,7 +29,7 @@
       "required": true\r
     },\r
     "dictionary-name": "bundle-id",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "vnf-id"\r
     ]\r
@@ -42,7 +42,7 @@
       "required": true\r
     },\r
     "dictionary-name": "bundle-ip",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "vnf-id"\r
     ]\r
@@ -54,7 +54,7 @@
       "type": "string"\r
     },\r
     "dictionary-name": "bundle-mac",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "vnf-id",\r
       "bundle-id"\r
@@ -67,7 +67,7 @@
       "type": "string"\r
     },\r
     "dictionary-name": "bundle-mac",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "loopback-ip"\r
     ]\r
@@ -90,7 +90,7 @@
       "type": "string"\r
     },\r
     "dictionary-name": "managed-ip1",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "loopback-ip"\r
     ]\r
index 5d0e898..486251d 100644 (file)
@@ -29,7 +29,7 @@
       "required": true\r
     },\r
     "dictionary-name": "bundle-id",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "vnf-id"\r
     ]\r
@@ -42,7 +42,7 @@
       "required": true\r
     },\r
     "dictionary-name": "bundle-ip",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "vnf-id"\r
     ]\r
@@ -54,7 +54,7 @@
       "type": "string"\r
     },\r
     "dictionary-name": "bundle-mac",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "vnf-id",\r
       "bundle-id"\r
@@ -67,7 +67,7 @@
       "type": "string"\r
     },\r
     "dictionary-name": "managed-ip",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "loopback-ip"\r
     ]\r
@@ -90,7 +90,7 @@
       "type": "string"\r
     },\r
     "dictionary-name": "managed-ip1",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": [\r
       "loopback-ip"\r
     ]\r
index e05261d..f1a4dbb 100644 (file)
 
 package org.onap.ccsdk.apps.blueprintsprocessor.functions.resource.resolution.processor
 
+import com.fasterxml.jackson.databind.node.ArrayNode
+import com.fasterxml.jackson.databind.node.JsonNodeFactory
+import com.fasterxml.jackson.databind.node.NullNode
+import com.fasterxml.jackson.databind.node.ObjectNode
+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.controllerblueprints.core.*
+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
+import org.slf4j.LoggerFactory
 import org.springframework.stereotype.Service
 
 /**
  * SimpleRestResourceAssignmentProcessor
  *
- * @author Brinda Santh
+ * @author Kapil Singal
  */
-@Service("resource-assignment-processor-mdsal")
-open class SimpleRestResourceAssignmentProcessor : ResourceAssignmentProcessor() {
+@Service("resource-assignment-processor-primary-config-data")
+open class SimpleRestResourceAssignmentProcessor(private val blueprintRestLibPropertyService: BluePrintRestLibPropertyService)
+    : ResourceAssignmentProcessor() {
+
+    private val logger = LoggerFactory.getLogger(SimpleRestResourceAssignmentProcessor::class.java)
 
     override fun getName(): String {
-        return "resource-assignment-processor-mdsal"
+        return "resource-assignment-processor-primary-config-data"
     }
 
-    override fun process(executionRequest: ResourceAssignment) {
+    override fun process(resourceAssignment: ResourceAssignment) {
+        try {
+            validate(resourceAssignment)
+
+            // Check if It has Input
+            val value = raRuntimeService.getInputValue(resourceAssignment.name)
+            if (value != null && value !is NullNode) {
+                logger.info("primary-db source template key (${resourceAssignment.name}) found from input and value is ($value)")
+                ResourceAssignmentUtils.setResourceDataValue(resourceAssignment, raRuntimeService, value)
+            } else {
+                val dName = resourceAssignment.dictionaryName
+                val dSource = resourceAssignment.dictionarySource
+                val resourceDefinition = resourceDictionaries[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" }
+                val path = nullToEmpty(sourceProperties.path)
+                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})")
+
+                val restClientService = blueprintRestLibPropertyService.blueprintWebClientService("primary-config-data")
+                val response = restClientService.getResource(urlPath, String::class.java)
+                if (response.isNotBlank()) {
+                    logger.warn("Failed to get $dSource result for dictionary name ($dName) using urlPath ($urlPath)")
+                } else {
+                    populateResource(resourceAssignment, sourceProperties, response, path)
+                }
+            }
+            // Check the value has populated for mandatory case
+            ResourceAssignmentUtils.assertTemplateKeyValueNotNull(resourceAssignment)
+        } catch (e: Exception) {
+            ResourceAssignmentUtils.setFailedResourceDataValue(resourceAssignment, e.message)
+            throw BluePrintProcessorException("Failed in template key ($resourceAssignment) assignments with: ${e.message}", e)
+        }
     }
 
-    override fun recover(runtimeException: RuntimeException, executionRequest: ResourceAssignment) {
+    @Throws(BluePrintProcessorException::class)
+    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" }
+        logger.info("Response processing type($type)")
+
+        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)")
+
+
+        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 = returnNotEmptyOrThrow(resourceAssignment.property?.entrySchema?.type) { "Entry schema is not defined for dictionary ($dName) info" }
+                val arrayNode = responseNode as ArrayNode
+
+                if (entrySchemaType !in BluePrintTypes.validPrimitiveTypes()) {
+                    val responseArrayNode = responseNode.toList()
+                    for (responseSingleJsonNode in responseArrayNode) {
+                        val arrayChildNode = JsonNodeFactory.instance.objectNode()
+                        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
+                val objectNode = responseNode as ObjectNode
+                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)
+            }
+        }
+    }
+
+    @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}"
+        }
+        checkNotEmptyOrThrow(resourceAssignment.dictionaryName, "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})")
     }
+
+    override fun recover(runtimeException: RuntimeException, resourceAssignment: ResourceAssignment) {
+    }
+
+
 }
\ No newline at end of file
index 9a846d6..ef69eb5 100644 (file)
@@ -65,7 +65,7 @@ class ResourceResolutionServiceTest {
     fun testRegisteredSource() {
         val sources = resourceResolutionService.registeredResourceSources()
         assertNotNull(sources, "failed to get registered sources")
-        assertTrue(sources.containsAll(arrayListOf("input", "default", "primary-db", "mdsal")), "failed to get registered sources")
+        assertTrue(sources.containsAll(arrayListOf("input", "default", "primary-db", "primary-config-data")), "failed to get registered sources")
     }
 
     @Test
index e574778..1a90df2 100755 (executable)
@@ -49,7 +49,7 @@ spring.jpa.hibernate.ddl-auto=none
 spring.jpa.hibernate.naming-strategy=org.hibernate.cfg.ImprovedNamingStrategy
 spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
 # Load Resource Source Mappings
-resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest,capability=source-capability
+resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
 # Controller Blueprints Core Configuration
 controllerblueprints.blueprintDeployPath=/etc/blueprints/deploy
 controllerblueprints.blueprintArchivePath=/etc/blueprints/archive
index 9179239..8d4dd58 100755 (executable)
@@ -51,7 +51,7 @@ spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
 spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect
 
 # Load Resource Source Mappings
-resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest,capability=source-capability
+resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
 
 # Controller Blueprints Core Configuration
 controllerblueprints.blueprintDeployPath=/etc/blueprints/deploy
index 1fafd8b..13b2aa7 100755 (executable)
@@ -33,7 +33,7 @@ swagger.contact.url=www.onap.com
 swagger.contact.email=brindasanth@onap.com\r
 \r
 # Load Resource Source Mappings\r
-resourceSourceMappings=db=source-db,input=source-input,default=source-default,mdsal=source-rest,capability=source-capability\r
+resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability\r
 \r
 # Controller Blueprints Core Configuration\r
 controllerblueprints.blueprintDeployPath=./target/blueprints/deploy\r
index 24cb23a..1c2c1c0 100755 (executable)
@@ -20,7 +20,7 @@ logging.level.org.springframework.web=INFO
 logging.level.org.hibernate.SQL=warn
 logging.level.org.hibernate.type.descriptor.sql=debug
 # Load Resource Source Mappings
-resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,mdsal=source-rest,capability=source-capability
+resourceSourceMappings=primary-db=source-primary-db,input=source-input,default=source-default,primary-config-data=source-rest,capability=source-capability
 # Controller Blueprints Core Configuration
 controllerblueprints.blueprintDeployPath=./target/blueprints/deploy
 controllerblueprints.blueprintArchivePath=./target/blueprints/archive
index 1c81b74..3ed188b 100644 (file)
@@ -56,7 +56,7 @@
       "required": true\r
     },\r
     "dictionary-name": "sample-mdsal-source",\r
-    "dictionary-source": "mdsal",\r
+    "dictionary-source": "primary-config-data",\r
     "dependencies": []\r
   }\r
 ]\r
index 42978f8..2e48b6d 100644 (file)
                   },\r
                   "input-param": false,\r
                   "dictionary-name": "sample-mdsal-source",\r
-                  "dictionary-source": "mdsal",\r
+                  "dictionary-source": "primary-config-data",\r
                   "dependencies": [\r
                     "service-instance-id"\r
                   ],\r
                   },\r
                   "input-param": false,\r
                   "dictionary-name": "sample-licenses",\r
-                  "dictionary-source": "mdsal",\r
+                  "dictionary-source": "primary-config-data",\r
                   "dependencies": [\r
                     "service-instance-id"\r
                   ],\r
index 66f18f8..6937c71 100644 (file)
                 },
                 "input-param" : false,
                 "dictionary-name" : "sample-mdsal-source",
-                "dictionary-source" : "mdsal",
+                "dictionary-source" : "primary-config-data",
                 "dependencies" : [ "service-instance-id" ],
                 "version" : 0
               }, {
                 },
                 "input-param" : false,
                 "dictionary-name" : "sample-licenses",
-                "dictionary-source" : "mdsal",
+                "dictionary-source" : "primary-config-data",
                 "dependencies" : [ "service-instance-id" ],
                 "version" : 0
               }, {