From: Brinda Santh Date: Fri, 2 Aug 2019 16:08:54 +0000 (-0400) Subject: Add resource assignment DSL. X-Git-Tag: 0.5.2~15^2 X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=54c3633cadf1cd087efa7af6acdf54ae47a4759a;p=ccsdk%2Fcds.git Add resource assignment DSL. Change-Id: I44a3596c05b02faa171f90b9207f774ce34976a6 Issue-ID: CCSDK-1577 Signed-off-by: Brinda Santh --- diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt index 340894f1b..a48762832 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt @@ -19,15 +19,50 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import org.onap.ccsdk.cds.controllerblueprints.core.data.NodeTemplate import org.onap.ccsdk.cds.controllerblueprints.core.dsl.PropertyDefinitionBuilder +import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceAssignment import org.onap.ccsdk.cds.controllerblueprints.resource.dict.ResourceDefinition /** Resource Definition DSL **/ -fun BluePrintTypes.resourceDefinition(name: String, +fun BluePrintTypes.resourceDefinitions(block: ResourceDefinitionsBuilder.() -> Unit) + : MutableMap { + return ResourceDefinitionsBuilder().apply(block).build() +} + +fun BluePrintTypes.resourceDefinition(name: String, description: String, block: ResourceDefinitionBuilder.() -> Unit): ResourceDefinition { - return ResourceDefinitionBuilder(name).apply(block).build() + return ResourceDefinitionBuilder(name, description).apply(block).build() +} + +/** Resource Mapping DSL **/ +fun BluePrintTypes.resourceAssignments(block: ResourceAssignmentsBuilder.() -> Unit) + : MutableMap { + return ResourceAssignmentsBuilder().apply(block).build() +} + +fun BluePrintTypes.resourceAssignment(name: String, dictionaryName: String, dictionarySource: String, + block: ResourceAssignmentBuilder.() -> Unit): ResourceAssignment { + return ResourceAssignmentBuilder(name, dictionaryName, dictionarySource).apply(block).build() +} + +class ResourceDefinitionsBuilder() { + private val resourceDefinitions: MutableMap = hashMapOf() + + fun resourceDefinition(name: String, description: String, + block: ResourceDefinitionBuilder.() -> Unit) { + val resourceDefinition = ResourceDefinitionBuilder(name, description).apply(block).build() + resourceDefinitions[resourceDefinition.name] = resourceDefinition + } + + fun resourceDefinition(resourceDefinition: ResourceDefinition) { + resourceDefinitions[resourceDefinition.name] = resourceDefinition + } + + fun build(): MutableMap { + return resourceDefinitions + } } -class ResourceDefinitionBuilder(private val name: String) { +class ResourceDefinitionBuilder(private val name: String, private val description: String) { private val resourceDefinition = ResourceDefinition() fun updatedBy(updatedBy: String) { @@ -38,13 +73,13 @@ class ResourceDefinitionBuilder(private val name: String) { resourceDefinition.tags = tags } - fun property(id: String, type: String, required: Boolean, description: String? = "") { - resourceDefinition.property = PropertyDefinitionBuilder(id, type, required, description).build() + fun property(type: String, required: Boolean) { + resourceDefinition.property = PropertyDefinitionBuilder(name, type, required, description).build() } - fun property(id: String, type: String, required: Boolean, description: String? = "", + fun property(type: String, required: Boolean, block: PropertyDefinitionBuilder.() -> Unit) { - resourceDefinition.property = PropertyDefinitionBuilder(id, type, required, description).apply(block).build() + resourceDefinition.property = PropertyDefinitionBuilder(name, type, required, description).apply(block).build() } fun sources(block: ResourceDefinitionSourcesBuilder.() -> Unit) { @@ -91,4 +126,51 @@ class ResourceDefinitionSourcesBuilder { fun build(): MutableMap { return sources } +} + +class ResourceAssignmentsBuilder() { + private val resourceAssignments: MutableMap = hashMapOf() + + fun resourceAssignment(name: String, dictionaryName: String, dictionarySource: String, + block: ResourceAssignmentBuilder.() -> Unit) { + val resourceAssignment = ResourceAssignmentBuilder(name, dictionaryName, dictionarySource).apply(block).build() + resourceAssignments[resourceAssignment.name] = resourceAssignment + } + + fun resourceAssignment(resourceAssignment: ResourceAssignment) { + resourceAssignments[resourceAssignment.name] = resourceAssignment + } + + fun build(): MutableMap { + return resourceAssignments + } +} + +class ResourceAssignmentBuilder(private val name: String, private val dictionaryName: String, + private val dictionarySource: String) { + private val resourceAssignment = ResourceAssignment() + + fun inputParameter(inputParameter: Boolean) { + resourceAssignment.inputParameter = inputParameter + } + + fun property(type: String, required: Boolean, description: String? = "") { + resourceAssignment.property = PropertyDefinitionBuilder(name, type, required, description).build() + } + + fun property(type: String, required: Boolean, description: String? = "", + block: PropertyDefinitionBuilder.() -> Unit) { + resourceAssignment.property = PropertyDefinitionBuilder(name, type, required, description).apply(block).build() + } + + fun dependencies(dependencies: MutableList) { + resourceAssignment.dependencies = dependencies + } + + fun build(): ResourceAssignment { + resourceAssignment.name = name + resourceAssignment.dictionaryName = dictionaryName + resourceAssignment.dictionarySource = dictionarySource + return resourceAssignment + } } \ 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/ResourceDefinitionSDLTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSLTest.kt similarity index 61% rename from ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionSDLTest.kt rename to ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSLTest.kt index 340b2b324..f8f0e991e 100644 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionSDLTest.kt +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSLTest.kt @@ -18,16 +18,18 @@ package org.onap.ccsdk.cds.blueprintsprocessor.functions.resource.resolution import org.onap.ccsdk.cds.controllerblueprints.core.BluePrintTypes import kotlin.test.Test +import kotlin.test.assertEquals import kotlin.test.assertNotNull -class ResourceDefinitionSDLTest { +class ResourceDefinitionDSLTest { @Test fun testResourceDefinitionDSL() { - val resourceDefinition = BluePrintTypes.resourceDefinition("service-instance-id") { + val testResourceDefinition = BluePrintTypes.resourceDefinition("service-instance-id", + "VFW Service Instance Name") { tags("service-instance-name, vfw, resources") updatedBy("brindasanth@onap.com") - property("service-instance-name", "string", true, "VFW Service Instance Name") + property("string", true) sources { sourceInput("input", "") {} sourceDefault("default", "") {} @@ -73,6 +75,37 @@ class ResourceDefinitionSDLTest { } } //println(resourceDefinition.asJsonString(true)) - assertNotNull(resourceDefinition, "failed to generate resourceDefinition") + assertNotNull(testResourceDefinition, "failed to generate testResourceDefinition") + + val testResourceDefinitions = BluePrintTypes.resourceDefinitions { + resourceDefinition(testResourceDefinition) + } + assertNotNull(testResourceDefinitions, "failed to generate testResourceDefinitions") + assertEquals(1, testResourceDefinitions.size, "testResourceDefinitions size doesn't match") + } + + @Test + fun testResourceAssignment() { + val testResourceAssignment = BluePrintTypes.resourceAssignment("instance-name", + "service-instance-name", "odl-mdsal") { + inputParameter(true) + property("string", true) + dependencies(arrayListOf("service-instance-id")) + } + //println(resourceAssignment.asJsonString(true)) + assertNotNull(testResourceAssignment, "failed to generate resourceAssignment") + + val testResourceAssignments = BluePrintTypes.resourceAssignments { + resourceAssignment(testResourceAssignment) + resourceAssignment("instance-name1", + "service-instance-name", "odl-mdsal") { + inputParameter(true) + property("string", true) + dependencies(arrayListOf("service-instance-id")) + } + } + //println(testResourceAssignments.asJsonString(true)) + assertNotNull(testResourceAssignments, "failed to generate testResourceAssignments") + assertEquals(2, testResourceAssignments.size, "testResourceAssignments size doesn't match") } } \ No newline at end of file