diff options
Diffstat (limited to 'ms/blueprintsprocessor')
4 files changed, 120 insertions, 3 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 |