aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/main/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSL.kt96
-rw-r--r--ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionDSLTest.kt (renamed from ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/cds/blueprintsprocessor/functions/resource/resolution/ResourceDefinitionSDLTest.kt)41
2 files changed, 126 insertions, 11 deletions
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<String, ResourceDefinition> {
+ 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<String, ResourceAssignment> {
+ 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<String, ResourceDefinition> = 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<String, ResourceDefinition> {
+ 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<String, NodeTemplate> {
return sources
}
+}
+
+class ResourceAssignmentsBuilder() {
+ private val resourceAssignments: MutableMap<String, ResourceAssignment> = 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<String, ResourceAssignment> {
+ 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<String>) {
+ 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
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