diff options
Diffstat (limited to 'ms')
10 files changed, 195 insertions, 19 deletions
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 e8b61a8fe..987390fdb 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 @@ -124,7 +124,8 @@ open class DatabaseResourceAssignmentProcessor(private val bluePrintDBLibPropert checkNotEmpty(resourceAssignment.dictionaryName) { "resource assignment dictionary name is not defined for template key (${resourceAssignment.name})" } - checkEquals(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, resourceAssignment.dictionarySource) { + check(resourceAssignment.dictionarySource in arrayOf(ResourceDictionaryConstants.SOURCE_PROCESSOR_DB, ResourceDictionaryConstants.SOURCE_PRIMARY_DB)) + { "resource assignment source is not ${ResourceDictionaryConstants.SOURCE_PROCESSOR_DB} but it is ${resourceAssignment.dictionarySource}" } } 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 656e86169..1a943d110 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 @@ -21,6 +21,7 @@ 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 com.fasterxml.jackson.databind.node.TextNode import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceAssignmentRuntimeService import org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.ResourceResolutionConstants import org.onap.ccsdk.cds.controllerblueprints.core.* @@ -122,7 +123,7 @@ class ResourceAssignmentUtils { if (isNotEmpty(it.name) && it.property != null) { val rName = it.name val type = nullToEmpty(it.property?.type).toLowerCase() - val value = it.property?.value + val value = useDefaultValueIfNull(it, rName) logger.info("Generating Resource name ($rName), type ($type), value ($value)") root.set(rName, value) } @@ -136,6 +137,15 @@ class ResourceAssignmentUtils { return result } + private fun useDefaultValueIfNull(resourceAssignment: ResourceAssignment, resourceAssignmentName: String): JsonNode { + if (resourceAssignment.property?.value == null) { + val defaultValue = "\${$resourceAssignmentName}" + return TextNode(defaultValue) + } else { + return resourceAssignment.property!!.value!! + } + } + fun transformToRARuntimeService(blueprintRuntimeService: BluePrintRuntimeService<*>, templateArtifactName: String): ResourceAssignmentRuntimeService { diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt index 89674ea24..f73197e0b 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/processor/DatabaseResourceResolutionProcessorTest.kt @@ -49,7 +49,7 @@ class DatabaseResourceResolutionProcessorTest { lateinit var databaseResourceAssignmentProcessor: DatabaseResourceAssignmentProcessor @Test - fun `test database resource resolution`() { + fun `test database resource resolution processor db`() { runBlocking { val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( "./../../../../components/model-catalog/blueprint-model/test-blueprint/baseconfiguration") @@ -74,4 +74,31 @@ class DatabaseResourceResolutionProcessorTest { println(processorName) } } + + @Test + fun `test database resource resolution primary db`() { + runBlocking { + val bluePrintContext = BluePrintMetadataUtils.getBluePrintContext( + "./../../../../components/model-catalog/blueprint-model/test-blueprint/capability_python") + + val resourceAssignmentRuntimeService = ResourceAssignmentRuntimeService("1234", bluePrintContext) + + databaseResourceAssignmentProcessor.raRuntimeService = resourceAssignmentRuntimeService + databaseResourceAssignmentProcessor.resourceDictionaries = ResourceAssignmentUtils + .resourceDefinitions(bluePrintContext.rootPath) + + val resourceAssignment = ResourceAssignment().apply { + name = "service-instance-id" + dictionaryName = "service-instance-id" + dictionarySource = "primary-db" + property = PropertyDefinition().apply { + type = "string" + } + } + + val processorName = databaseResourceAssignmentProcessor.applyNB(resourceAssignment) + assertNotNull(processorName, "couldn't get Database resource assignment processor name") + println(processorName) + } + } }
\ No newline at end of file diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt new file mode 100644 index 000000000..9b87c12eb --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/utils/ResourceAssignmentUtilsTest.kt @@ -0,0 +1,79 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2019 Nordix Foundation. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + + +package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution.utils + +import com.fasterxml.jackson.databind.node.TextNode +import org.junit.Test +import org.onap.ccsdk.cds.controllerblueprints.core.data.PropertyDefinition +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment +import kotlin.test.assertEquals + +class ResourceAssignmentUtilsTest { + + @Test + fun `generateResourceDataForAssignments - positive test`() { + //given a valid resource assignment + val validResourceAssignment = createResourceAssignmentForTest("valid_value") + + //and a list containing that resource assignment + val resourceAssignmentList = listOf<ResourceAssignment>(validResourceAssignment) + + //when the values of the resources are evaluated + val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList) + + //then the assignment should produce a valid result + val expected = "{\n" + " \"pnf-id\" : \"valid_value\"\n" + "}" + assertEquals(expected, outcome, "unexpected outcome generated") + + } + + @Test + fun `generateResourceDataForAssignments - resource without value is not resolved as null`() { + //given a valid resource assignment + val resourceAssignmentWithNullValue = createResourceAssignmentForTest(null) + + //and a list containing that resource assignment + val resourceAssignmentList = listOf<ResourceAssignment>(resourceAssignmentWithNullValue) + + //when the values of the resources are evaluated + val outcome = ResourceAssignmentUtils.generateResourceDataForAssignments(resourceAssignmentList) + + //then the assignment should produce a valid result + val expected = "{\n" + " \"pnf-id\" : \"\${pnf-id}\"\n" + "}" + assertEquals(expected, outcome, "unexpected outcome generated") + + } + + private fun createResourceAssignmentForTest(resourceValue: String?): ResourceAssignment { + val valueForTest = if (resourceValue == null) null else TextNode(resourceValue) + val resourceAssignmentForTest = ResourceAssignment().apply { + name = "pnf-id" + dictionaryName = "pnf-id" + dictionarySource = "input" + property = PropertyDefinition().apply { + type = "string" + value = valueForTest + } + } + return resourceAssignmentForTest + } +}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintImportService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintImportService.kt index a3e9cd103..5f6505309 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintImportService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintImportService.kt @@ -85,7 +85,7 @@ class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate, serviceTemplate = ServiceTemplateUtils.getServiceTemplate(importDefinition.file) } } catch (e: Exception) { - throw BluePrintException("failed to populate service template for ${importDefinition.file}", e) + throw BluePrintException("failed to populate service template for ${importDefinition.file} original error: ${e.message}", e) } if (serviceTemplate == null) { throw BluePrintException("failed to populate service template for : ${importDefinition.file}") @@ -94,4 +94,4 @@ class BluePrintImportService(private val parentServiceTemplate: ServiceTemplate, } -}
\ No newline at end of file +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt index 496182ee7..43e6d221f 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/main/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintVelocityTemplateService.kt @@ -82,4 +82,3 @@ object BluePrintVelocityTemplateService { } } - diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt index 02505acad..6f961c8ed 100644 --- a/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/kotlin/org/onap/ccsdk/cds/controllerblueprints/core/service/BluePrintTemplateServiceTest.kt @@ -26,6 +26,7 @@ import org.onap.ccsdk.cds.controllerblueprints.core.utils.BluePrintMetadataUtils import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils import org.springframework.test.context.junit4.SpringRunner import kotlin.test.BeforeTest +import kotlin.test.assertEquals import kotlin.test.assertNotNull @RunWith(SpringRunner::class) @@ -97,5 +98,39 @@ class BluePrintTemplateServiceTest { assertNotNull(content, "failed to generate content for velocity template") } } + + @Test + fun `no value variable should evaluate to default value - standalone template mesh test`() { + runBlocking { + val template = JacksonUtils.getClassPathFileContent("templates/default-variable-value-velocity-template.vtl") + val json = JacksonUtils.getClassPathFileContent("templates/default-variable-value-data.json") + + val content = BluePrintVelocityTemplateService.generateContent(template, json) + //first line represents a variable whose value was successfully retrieved, second line contains a variable + // whose value could not be evaluated + val expected = "sample-hostname\n\${node0_backup_router_address}" + assertEquals(expected, content, "No value variable should use default value") + } + } + + @Test + fun `no value variable should evaluate to default value - blueprint processing test`() { + runBlocking { + val bluePrintTemplateService = BluePrintTemplateService() + + val templateFile = "templates/default-variable-value-velocity-template.vtl" + val jsonFile = "templates/default-variable-value-data.json" + + val content = bluePrintTemplateService.generateContentFromFiles(templateFile, + BluePrintConstants.ARTIFACT_VELOCITY_TYPE_NAME, jsonFile, false, mutableMapOf()) + + //first line represents a variable whose value was successfully retrieved, second line contains a variable + // whose value could not be evaluated + val expected = "sample-hostname\n\${node0_backup_router_address}" + assertEquals(expected, content, "No value variable should use default value") + } + + } + } diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-data.json b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-data.json new file mode 100755 index 000000000..940ca8d73 --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-data.json @@ -0,0 +1,3 @@ +{ + "node0_hostname": "sample-hostname" +} diff --git a/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-velocity-template.vtl b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-velocity-template.vtl new file mode 100755 index 000000000..ce2458e2e --- /dev/null +++ b/ms/controllerblueprints/modules/blueprint-core/src/test/resources/templates/default-variable-value-velocity-template.vtl @@ -0,0 +1,2 @@ +$node0_hostname +${node0_backup_router_address}
\ No newline at end of file diff --git a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnf-name.json b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnf-name.json index 4c0320aca..bcfea9f24 100644 --- a/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnf-name.json +++ b/ms/controllerblueprints/modules/resource-dict/load/resource_dictionary/vnf-name.json @@ -7,21 +7,41 @@ "type" : "string" }, "sources" : { - "primary-config-data" : { - "type" : "source-rest", - "properties" : { - "type" : "JSON", - "url-path" : "config/GENERIC-RESOURCE-API:services/service/$service-instance-id/service-data/vnfs/vnf/$vnf-id/vnf-data/vnf-topology/vnf-parameters-data/param/vnf_name", - "path" : "/param/0/value", - "expression-type" : "JSON_POINTER", - "input-key-mapping" : { - "service-instance-id" : "service-instance-id", - "vnf-id" : "vnf-id" + "primary-config-data": { + "type": "source-rest", + "properties": { + "type": "JSON", + "url-path": "config/GENERIC-RESOURCE-API:services/service/$service-instance-id/service-data/vnfs/vnf/$vnf-name/vnf-data/vnf-topology/vnf-parameters-data/param/vnf-name", + "path": "/param/0/value", + "input-key-mapping": { + "service-instance-id": "service-instance-id", + "vnf-name": "vnf-name" }, - "output-key-mapping" : { - "vnf-name" : "value" + "output-key-mapping": { + "vnf-name": "value" }, - "key-dependencies" : [ "service-instance-id", "vnf-id" ] + "key-dependencies": [ + "service-instance-id", + "vnf-name" + ] + } + }, + "primary-aai-data": { + "type": "source-rest", + "properties": { + "type": "JSON", + "verb": "GET", + "url-path": "/aai/v14/network/generic-vnfs/generic-vnf/$vnf-id", + "path": "", + "input-key-mapping": { + "vnf-id": "vnf-id" + }, + "output-key-mapping": { + "vnf-name": "vnf-name" + }, + "key-dependencies": [ + "vnf-id" + ] } } } |