From d035fe08249fe8b1e5988b79c7355620727e5da0 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Fri, 11 Jan 2019 13:58:38 -0500 Subject: Resource Resolution Service : 2 Changes for Primary-DB Resource Resolution Processor Service Change-Id: Iaf6ad6277d36787d87881819ae530de1d7038a2e Issue-ID: CCSDK-942 Signed-off-by: Singal, Kapil (ks220y) --- .../load/model_type/node_type/source-db.json | 44 ------ .../model_type/node_type/source-primary-db.json | 44 ++++++ .../load/resource_dictionary/db-source.json | 24 ---- .../load/resource_dictionary/nf-role.json | 4 +- .../load/resource_dictionary/nfc-naming-code.json | 4 +- .../resource_dictionary/onap_private_net_cidr.json | 4 +- .../resource_dictionary/primary-db-source.json | 24 ++++ .../resource_dictionary/private-prefix-id.json | 4 +- .../resource_dictionary/protected-prefix-id.json | 4 +- .../protected_private_net_cidr.json | 4 +- .../resource_dictionary/unprotected-prefix-id.json | 4 +- .../unprotected_private_net_cidr.json | 4 +- .../load/resource_dictionary/vf-module-label.json | 4 +- .../load/resource_dictionary/vf-module-type.json | 4 +- .../load/resource_dictionary/vf-naming-policy.json | 4 +- .../load/resource_dictionary/vf-nf-code.json | 4 +- .../resource_dictionary/vfccustomizationuuid.json | 4 +- .../load/resource_dictionary/vm-type.json | 4 +- .../vnfc-model-invariant-uuid.json | 4 +- .../resource_dictionary/vnfc-model-version.json | 4 +- .../resource/dict/ResourceDictionaryConstants.kt | 2 +- .../resource/dict/utils/ResourceAssignmentUtils.kt | 156 +++++++++++++++++++++ .../dict/utils/ResourceDictionaryTestUtils.kt | 30 ---- .../resource/dict/ResourceDefinitionTest.java | 4 +- .../factory/ResourceSourceMappingFactoryTest.java | 6 +- .../ResourceDefinitionValidationServiceTest.java | 4 +- .../dict/utils/ResourceDictionaryTestUtils.kt | 30 ++++ .../src/test/resources/validation/cyclic.json | 2 +- .../src/test/resources/validation/duplicate.json | 2 +- .../src/test/resources/validation/success.json | 2 +- 30 files changed, 297 insertions(+), 141 deletions(-) delete mode 100644 components/resource-dict/load/model_type/node_type/source-db.json create mode 100644 components/resource-dict/load/model_type/node_type/source-primary-db.json delete mode 100644 components/resource-dict/load/resource_dictionary/db-source.json create mode 100644 components/resource-dict/load/resource_dictionary/primary-db-source.json create mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceAssignmentUtils.kt delete mode 100644 components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt create mode 100644 components/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt (limited to 'components/resource-dict') diff --git a/components/resource-dict/load/model_type/node_type/source-db.json b/components/resource-dict/load/model_type/node_type/source-db.json deleted file mode 100644 index 661a9503..00000000 --- a/components/resource-dict/load/model_type/node_type/source-db.json +++ /dev/null @@ -1,44 +0,0 @@ -{ - "description": "This is Database Resource Source Node Type", - "version": "1.0.0", - "properties": { - "type": { - "required": true, - "type": "string", - "constraints": [ - { - "valid_values": [ - "SQL", - "PLSQL" - ] - } - ] - }, - "query": { - "required": true, - "type": "string" - }, - "input-key-mapping": { - "required": false, - "type": "map", - "entry_schema": { - "type": "string" - } - }, - "output-key-mapping": { - "required": false, - "type": "map", - "entry_schema": { - "type": "string" - } - }, - "key-dependencies": { - "required": true, - "type": "list", - "entry_schema": { - "type": "string" - } - } - }, - "derived_from": "tosca.nodes.ResourceSource" -} \ No newline at end of file diff --git a/components/resource-dict/load/model_type/node_type/source-primary-db.json b/components/resource-dict/load/model_type/node_type/source-primary-db.json new file mode 100644 index 00000000..661a9503 --- /dev/null +++ b/components/resource-dict/load/model_type/node_type/source-primary-db.json @@ -0,0 +1,44 @@ +{ + "description": "This is Database Resource Source Node Type", + "version": "1.0.0", + "properties": { + "type": { + "required": true, + "type": "string", + "constraints": [ + { + "valid_values": [ + "SQL", + "PLSQL" + ] + } + ] + }, + "query": { + "required": true, + "type": "string" + }, + "input-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "output-key-mapping": { + "required": false, + "type": "map", + "entry_schema": { + "type": "string" + } + }, + "key-dependencies": { + "required": true, + "type": "list", + "entry_schema": { + "type": "string" + } + } + }, + "derived_from": "tosca.nodes.ResourceSource" +} \ No newline at end of file diff --git a/components/resource-dict/load/resource_dictionary/db-source.json b/components/resource-dict/load/resource_dictionary/db-source.json deleted file mode 100644 index b96dc63f..00000000 --- a/components/resource-dict/load/resource_dictionary/db-source.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "name": "db-source", - "property" :{ - "description": "name of the ", - "type": "string" - }, - "updated-by": "brindasanth@onap.com", - "tags": "bundle-id, brindasanth@onap.com", - "sources": { - "db": { - "type": "source-db", - "properties": { - "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name", - "input-key-mapping": { - "profile_name": "profile_name" - }, - "output-key-mapping": { - "db-country": "country", - "db-state": "state" - } - } - } - } -} \ No newline at end of file diff --git a/components/resource-dict/load/resource_dictionary/nf-role.json b/components/resource-dict/load/resource_dictionary/nf-role.json index 0e108c5c..df6b5df4 100644 --- a/components/resource-dict/load/resource_dictionary/nf-role.json +++ b/components/resource-dict/load/resource_dictionary/nf-role.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.VF_MODEL.nf_role as vf_model_role from sdnctl.VF_MODEL where sdnctl.VF_MODEL.customization_uuid=:vnfmodelcustomizationuuid", diff --git a/components/resource-dict/load/resource_dictionary/nfc-naming-code.json b/components/resource-dict/load/resource_dictionary/nfc-naming-code.json index f0f2b7f0..7c521a7c 100644 --- a/components/resource-dict/load/resource_dictionary/nfc-naming-code.json +++ b/components/resource-dict/load/resource_dictionary/nfc-naming-code.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select nfc_naming_code as nfc_naming_code from sdnctl.VFC_MODEL where customization_uuid=:vfccustomizationuuid", diff --git a/components/resource-dict/load/resource_dictionary/onap_private_net_cidr.json b/components/resource-dict/load/resource_dictionary/onap_private_net_cidr.json index 07c5cbc1..f2067a19 100644 --- a/components/resource-dict/load/resource_dictionary/onap_private_net_cidr.json +++ b/components/resource-dict/load/resource_dictionary/onap_private_net_cidr.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.IPAM_IP_POOL.prefix as prefix from sdnctl.IPAM_IP_POOL where description = private", diff --git a/components/resource-dict/load/resource_dictionary/primary-db-source.json b/components/resource-dict/load/resource_dictionary/primary-db-source.json new file mode 100644 index 00000000..dfac66ae --- /dev/null +++ b/components/resource-dict/load/resource_dictionary/primary-db-source.json @@ -0,0 +1,24 @@ +{ + "name": "primary-db-source", + "property" :{ + "description": "name of the ", + "type": "string" + }, + "updated-by": "brindasanth@onap.com", + "tags": "bundle-id, brindasanth@onap.com", + "sources": { + "primary-db": { + "type": "source-primary-db", + "properties": { + "query": "SELECT db-country, db-state FROM DEVICE_PROFILE WHERE profile_name = :profile_name", + "input-key-mapping": { + "profile_name": "profile_name" + }, + "output-key-mapping": { + "db-country": "country", + "db-state": "state" + } + } + } + } +} \ No newline at end of file diff --git a/components/resource-dict/load/resource_dictionary/private-prefix-id.json b/components/resource-dict/load/resource_dictionary/private-prefix-id.json index a95bae30..309647d7 100644 --- a/components/resource-dict/load/resource_dictionary/private-prefix-id.json +++ b/components/resource-dict/load/resource_dictionary/private-prefix-id.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.IPAM_IP_POOL.prefix_id as prefix_id from sdnctl.IPAM_IP_POOL where description = private", diff --git a/components/resource-dict/load/resource_dictionary/protected-prefix-id.json b/components/resource-dict/load/resource_dictionary/protected-prefix-id.json index 56b0d6d2..816405b4 100644 --- a/components/resource-dict/load/resource_dictionary/protected-prefix-id.json +++ b/components/resource-dict/load/resource_dictionary/protected-prefix-id.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.IPAM_IP_POOL.prefix_id as prefix_id from sdnctl.IPAM_IP_POOL where description = protected", diff --git a/components/resource-dict/load/resource_dictionary/protected_private_net_cidr.json b/components/resource-dict/load/resource_dictionary/protected_private_net_cidr.json index db0a43dc..bf46fb3a 100644 --- a/components/resource-dict/load/resource_dictionary/protected_private_net_cidr.json +++ b/components/resource-dict/load/resource_dictionary/protected_private_net_cidr.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.IPAM_IP_POOL.prefix as prefix from sdnctl.IPAM_IP_POOL where description = protected", diff --git a/components/resource-dict/load/resource_dictionary/unprotected-prefix-id.json b/components/resource-dict/load/resource_dictionary/unprotected-prefix-id.json index a0d966a2..8a09b149 100644 --- a/components/resource-dict/load/resource_dictionary/unprotected-prefix-id.json +++ b/components/resource-dict/load/resource_dictionary/unprotected-prefix-id.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.IPAM_IP_POOL.prefix_id as prefix_id from sdnctl.IPAM_IP_POOL where description = unprotected", diff --git a/components/resource-dict/load/resource_dictionary/unprotected_private_net_cidr.json b/components/resource-dict/load/resource_dictionary/unprotected_private_net_cidr.json index 8f9385d8..241147c3 100644 --- a/components/resource-dict/load/resource_dictionary/unprotected_private_net_cidr.json +++ b/components/resource-dict/load/resource_dictionary/unprotected_private_net_cidr.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.IPAM_IP_POOL.prefix as prefix from sdnctl.IPAM_IP_POOL where description = unprotected", diff --git a/components/resource-dict/load/resource_dictionary/vf-module-label.json b/components/resource-dict/load/resource_dictionary/vf-module-label.json index a9543722..01355c20 100644 --- a/components/resource-dict/load/resource_dictionary/vf-module-label.json +++ b/components/resource-dict/load/resource_dictionary/vf-module-label.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.VF_MODULE_MODEL.vf_module_label as vf_module_label from sdnctl.VF_MODULE_MODEL where sdnctl.VF_MODULE_MODEL.customization_uuid=:customizationid", diff --git a/components/resource-dict/load/resource_dictionary/vf-module-type.json b/components/resource-dict/load/resource_dictionary/vf-module-type.json index 805d834b..ead69d46 100644 --- a/components/resource-dict/load/resource_dictionary/vf-module-type.json +++ b/components/resource-dict/load/resource_dictionary/vf-module-type.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select vf_module_type as vf_module_type from sdnctl.VF_MODULE_MODEL where customization_uuid=:customizationid", diff --git a/components/resource-dict/load/resource_dictionary/vf-naming-policy.json b/components/resource-dict/load/resource_dictionary/vf-naming-policy.json index ceed3186..cde861f8 100644 --- a/components/resource-dict/load/resource_dictionary/vf-naming-policy.json +++ b/components/resource-dict/load/resource_dictionary/vf-naming-policy.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.VF_MODEL.naming_policy as vf_naming_policy from sdnctl.VF_MODEL where sdnctl.VF_MODEL.customization_uuid=:vnf_model_customization_uuid", diff --git a/components/resource-dict/load/resource_dictionary/vf-nf-code.json b/components/resource-dict/load/resource_dictionary/vf-nf-code.json index 0d25d0e9..adbd22af 100644 --- a/components/resource-dict/load/resource_dictionary/vf-nf-code.json +++ b/components/resource-dict/load/resource_dictionary/vf-nf-code.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.VF_MODEL.nf_code as vf_nf_code from sdnctl.VF_MODEL where sdnctl.VF_MODEL.customization_uuid=:customizationid", diff --git a/components/resource-dict/load/resource_dictionary/vfccustomizationuuid.json b/components/resource-dict/load/resource_dictionary/vfccustomizationuuid.json index a34a9a78..b3485791 100644 --- a/components/resource-dict/load/resource_dictionary/vfccustomizationuuid.json +++ b/components/resource-dict/load/resource_dictionary/vfccustomizationuuid.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select sdnctl.VF_MODULE_TO_VFC_MAPPING.vfc_customization_uuid as vnf_customid from sdnctl.VF_MODULE_TO_VFC_MAPPING where vm_count = 1 and sdnctl.VF_MODULE_TO_VFC_MAPPING.vf_module_customization_uuid=:vfmodulecustomizationuuid", diff --git a/components/resource-dict/load/resource_dictionary/vm-type.json b/components/resource-dict/load/resource_dictionary/vm-type.json index 7bb5ef1c..e559f9b5 100644 --- a/components/resource-dict/load/resource_dictionary/vm-type.json +++ b/components/resource-dict/load/resource_dictionary/vm-type.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select vfc_model.vm_type as vm_type from VFC_MODEL where customization_uuid=:vfccustomizationuuid", diff --git a/components/resource-dict/load/resource_dictionary/vnfc-model-invariant-uuid.json b/components/resource-dict/load/resource_dictionary/vnfc-model-invariant-uuid.json index b2ccd45d..9eb94cff 100644 --- a/components/resource-dict/load/resource_dictionary/vnfc-model-invariant-uuid.json +++ b/components/resource-dict/load/resource_dictionary/vnfc-model-invariant-uuid.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select vfc_model.invariant_uuid as vfc_invariant_uuid from VFC_MODEL where customization_uuid=:vfccustomizationuuid", diff --git a/components/resource-dict/load/resource_dictionary/vnfc-model-version.json b/components/resource-dict/load/resource_dictionary/vnfc-model-version.json index fb59eea7..e4e66229 100644 --- a/components/resource-dict/load/resource_dictionary/vnfc-model-version.json +++ b/components/resource-dict/load/resource_dictionary/vnfc-model-version.json @@ -7,8 +7,8 @@ "type" : "string" }, "sources" : { - "db" : { - "type" : "source-db", + "primary-db" : { + "type" : "source-primary-db", "properties" : { "type" : "SQL", "query" : "select vfc_model.version as vnfc_model_version from VFC_MODEL where customization_uuid=:vfccustomizationuuid", diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt index a39139ed..e4219c13 100644 --- a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDictionaryConstants.kt @@ -23,7 +23,7 @@ package org.onap.ccsdk.apps.controllerblueprints.resource.dict object ResourceDictionaryConstants { const val SOURCE_INPUT = "input" const val SOURCE_DEFAULT = "default" - const val SOURCE_DB = "db" + const val SOURCE_DB = "primary-db" const val MODEL_DIR_RESOURCE_DEFINITION: String = "resource_dictionary" diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceAssignmentUtils.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceAssignmentUtils.kt new file mode 100644 index 00000000..a234a89e --- /dev/null +++ b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceAssignmentUtils.kt @@ -0,0 +1,156 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils + +import java.util.Date +import com.att.eelf.configuration.EELFLogger +import com.att.eelf.configuration.EELFManager +import com.fasterxml.jackson.databind.JsonNode +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.controllerblueprints.core.* +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment + +class ResourceAssignmentUtils { + companion object { + + private val logger: EELFLogger = EELFManager.getInstance().getLogger(ResourceAssignmentUtils::class.toString()) + + @Synchronized + @Throws(BluePrintProcessorException::class) + fun setResourceDataValue(resourceAssignment: ResourceAssignment, value: Any?) { + + val resourceProp = checkNotNull(resourceAssignment.property) { "Failed in setting resource value for resource mapping $resourceAssignment" } + checkNotEmptyNThrow(resourceAssignment.name, "Failed in setting resource value for resource mapping $resourceAssignment") + + if (checkNotEmpty(resourceAssignment.dictionaryName)) { + resourceAssignment.dictionaryName = resourceAssignment.name + logger.warn("Missing dictionary key, setting with template key (${resourceAssignment.name}) as dictionary key (${resourceAssignment.dictionaryName})") + } + + try { + if (checkNotEmpty(resourceProp.type)) { + val convertedValue = convertResourceValue(resourceProp.type, value) + logger.info("Setting Resource Value ($convertedValue) for Resource Name (${resourceAssignment.dictionaryName}) of type (${resourceProp.type})") + resourceProp.value = convertedValue + resourceAssignment.updatedDate = Date() + resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM + resourceAssignment.status = BluePrintConstants.STATUS_SUCCESS + } + } catch (e: Exception) { + throw BluePrintProcessorException("Failed in setting value for template key (%s) and " + + "dictionary key (${resourceAssignment.name}) of type (${resourceProp.type}) with error message (${e.message})", e) + } + } + + private fun convertResourceValue(type: String, value: Any?): JsonNode? { + var convertedValue: JsonNode? + + if (value == null || value is NullNode) { + logger.info("Returning {} value from convertResourceValue", value) + return null + } else if (BluePrintTypes.validPrimitiveTypes().contains(type) && value is String) { + convertedValue = JacksonUtils.convertPrimitiveResourceValue(type, value) + } else { + // Case where Resource is non-primitive type + if (value is String) { + convertedValue = JacksonUtils.jsonNode(value) + } else { + convertedValue = JacksonUtils.getJsonNode(value) + } + } + return convertedValue + } + + @Synchronized + fun setFailedResourceDataValue(resourceAssignment: ResourceAssignment, message: String?) { + if (checkNotEmpty(resourceAssignment.name)) { + resourceAssignment.updatedDate = Date() + resourceAssignment.updatedBy = BluePrintConstants.USER_SYSTEM + resourceAssignment.status = BluePrintConstants.STATUS_FAILURE + resourceAssignment.message = message + } + } + + @Synchronized + @Throws(BluePrintProcessorException::class) + fun assertTemplateKeyValueNotNull(resourceAssignment: ResourceAssignment) { + val resourceProp = checkNotNull(resourceAssignment.property) { "Failed to populate mandatory resource resource mapping $resourceAssignment" } + if (resourceProp.required != null && resourceProp.required!! && (resourceProp.value == null || resourceProp.value !is NullNode)) { + logger.error("failed to populate mandatory resource mapping ($resourceAssignment)") + throw BluePrintProcessorException("failed to populate mandatory resource mapping ($resourceAssignment)") + } + } + + @Synchronized + @Throws(BluePrintProcessorException::class) + fun generateResourceDataForAssignments(assignments: List): String { + var result = "{}" + try { + val mapper = ObjectMapper() + val root = mapper.readTree(result) + + assignments.forEach { + if (checkNotEmpty(it.name) && it.property != null) { + + val type = it.property?.type + val value = it.property?.value + logger.info("Generating Resource name ({}), type ({}), value ({})", it.name, type, + value) + if (value == null) { + (root as ObjectNode).set(it.name, null) + } else if (value is JsonNode) { + (root as ObjectNode).put(it.name, value as JsonNode) + } else if (BluePrintConstants.DATA_TYPE_STRING.equals(type, ignoreCase = true)) { + (root as ObjectNode).put(it.name, value as String) + } else if (BluePrintConstants.DATA_TYPE_BOOLEAN.equals(type, ignoreCase = true)) { + (root as ObjectNode).put(it.name, value as Boolean) + } else if (BluePrintConstants.DATA_TYPE_INTEGER.equals(type, ignoreCase = true)) { + (root as ObjectNode).put(it.name, value as Int) + } else if (BluePrintConstants.DATA_TYPE_FLOAT.equals(type, ignoreCase = true)) { + (root as ObjectNode).put(it.name, value as Float) + } else if (BluePrintConstants.DATA_TYPE_TIMESTAMP.equals(type, ignoreCase = true)) { + (root as ObjectNode).put(it.name, value as String) + } else { + val jsonNode = JacksonUtils.getJsonNode(value) + if (jsonNode != null) { + (root as ObjectNode).put(it.name, jsonNode) + } else { + (root as ObjectNode).set(it.name, null) + } + } + } + } + result = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(root) + logger.info("Generated Resource Param Data ({})", result) + } catch (e: Exception) { + throw BluePrintProcessorException("kapil is failing with $e.message", e) + } + + return result + } + + fun transformResourceSource(properties: MutableMap, classType: Class): T { + val content = JacksonUtils.getJson(properties) + return JacksonUtils.readValue(content, classType) + ?: throw BluePrintProcessorException("failed to transform content($content) to type($classType)") + } + + } +} \ No newline at end of file diff --git a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt b/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt deleted file mode 100644 index bebe27d8..00000000 --- a/components/resource-dict/src/main/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils - -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory - -object ResourceDictionaryTestUtils { - - @JvmStatic - fun setUpResourceSourceMapping() { - ResourceSourceMappingFactory.registerSourceMapping("db", "source-db") - ResourceSourceMappingFactory.registerSourceMapping("input", "source-input") - ResourceSourceMappingFactory.registerSourceMapping("default", "source-default") - ResourceSourceMappingFactory.registerSourceMapping("mdsal", "source-rest") - } -} \ No newline at end of file diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java index cb39200f..1ed306e2 100644 --- a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/ResourceDefinitionTest.java @@ -46,9 +46,9 @@ public class ResourceDefinitionTest { @Test public void testDictionaryDefinitionDBSource(){ - String fileName = basePath + "/db-source.json"; + String fileName = basePath + "/primary-db-source.json"; ResourceDefinition resourceDefinition = JacksonUtils.Companion.readValueFromFile(fileName, ResourceDefinition.class); - Assert.assertNotNull("Failed to populate dictionaryDefinition for db type", resourceDefinition); + Assert.assertNotNull("Failed to populate dictionaryDefinition for primary-db type", resourceDefinition); } @Test diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java index b67aa799..3f5aef43 100644 --- a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/factory/ResourceSourceMappingFactoryTest.java @@ -25,13 +25,13 @@ public class ResourceSourceMappingFactoryTest { @Test public void testRegisterResourceMapping() { - ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("db", "source-db"); + ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("primary-db", "source-primary-db"); ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("input", "source-input"); ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("default", "source-default"); ResourceSourceMappingFactory.INSTANCE.registerSourceMapping("mdsal", "source-rest"); - String nodeTypeName = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping("db"); - Assert.notNull(nodeTypeName, "Failed to get db mapping"); + String nodeTypeName = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping("primary-db"); + Assert.notNull(nodeTypeName, "Failed to get primary-db mapping"); ResourceSourceMapping resourceSourceMapping = ResourceSourceMappingFactory.INSTANCE.getRegisterSourceMapping(); Assert.notNull(resourceSourceMapping, "Failed to get resource source mapping"); diff --git a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java index f5c3567f..7f040b2e 100644 --- a/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java +++ b/components/resource-dict/src/test/java/org/onap/ccsdk/apps/controllerblueprints/resource/dict/service/ResourceDefinitionValidationServiceTest.java @@ -30,10 +30,10 @@ public class ResourceDefinitionValidationServiceTest { @Test public void testValidateSource() throws Exception { - String inputFileName = dictionaryPath + "/db-source.json"; + String inputFileName = dictionaryPath + "/input-source.json"; testValidate(inputFileName); - String dbFileName = dictionaryPath + "/db-source.json"; + String dbFileName = dictionaryPath + "/primary-db-source.json"; testValidate(dbFileName); String defaultFileName = dictionaryPath + "/default-source.json"; diff --git a/components/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt b/components/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt new file mode 100644 index 00000000..50e5c329 --- /dev/null +++ b/components/resource-dict/src/test/kotlin/org/onap/ccsdk/apps/controllerblueprints/resource/dict/utils/ResourceDictionaryTestUtils.kt @@ -0,0 +1,30 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.controllerblueprints.resource.dict.utils + +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.factory.ResourceSourceMappingFactory + +object ResourceDictionaryTestUtils { + + @JvmStatic + fun setUpResourceSourceMapping() { + ResourceSourceMappingFactory.registerSourceMapping("primary-db", "source-primary-db") + ResourceSourceMappingFactory.registerSourceMapping("input", "source-input") + ResourceSourceMappingFactory.registerSourceMapping("default", "source-default") + ResourceSourceMappingFactory.registerSourceMapping("mdsal", "source-rest") + } +} \ No newline at end of file diff --git a/components/resource-dict/src/test/resources/validation/cyclic.json b/components/resource-dict/src/test/resources/validation/cyclic.json index d837dc5d..7e6472f5 100644 --- a/components/resource-dict/src/test/resources/validation/cyclic.json +++ b/components/resource-dict/src/test/resources/validation/cyclic.json @@ -102,7 +102,7 @@ "type": "string" }, "dictionary-name": "loopback-ip", - "dictionary-source": "db", + "dictionary-source": "primary-db", "dependencies": [ "bundle-mac", "managed-ip1" diff --git a/components/resource-dict/src/test/resources/validation/duplicate.json b/components/resource-dict/src/test/resources/validation/duplicate.json index 330324cd..28ab71fc 100644 --- a/components/resource-dict/src/test/resources/validation/duplicate.json +++ b/components/resource-dict/src/test/resources/validation/duplicate.json @@ -102,7 +102,7 @@ "type": "string" }, "dictionary-name": "loopback-ip", - "dictionary-source": "db", + "dictionary-source": "primary-db", "dependencies": [ "bundle-mac" ] diff --git a/components/resource-dict/src/test/resources/validation/success.json b/components/resource-dict/src/test/resources/validation/success.json index 3215d06d..5d0e8980 100644 --- a/components/resource-dict/src/test/resources/validation/success.json +++ b/components/resource-dict/src/test/resources/validation/success.json @@ -102,7 +102,7 @@ "type": "string" }, "dictionary-name": "loopback-ip", - "dictionary-source": "db", + "dictionary-source": "primary-db", "dependencies": [ "bundle-mac" ] -- cgit 1.2.3-korg